Skip to content

Commit

Permalink
Fix remaining tests. Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xaqq committed May 20, 2015
1 parent 2551d97 commit b5e3634
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 96 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ RUN apt-get install autotools-dev automake pkg-config libsodium-dev -y

RUN apt-get install libgtest-dev python valgrind python-pip libpython2.7-dev -y

RUN pip install pyzmq

RUN apt-get install python3 python3-pip -y
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
RUN pip3 install pyzmq


RUN git clone git://github.com/zeromq/libzmq.git; \
cd libzmq; \
git checkout e9b9860752ffac1a561fdb64f5f72bbfc5515b34; \
Expand Down
2 changes: 1 addition & 1 deletion scripts/remote_control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python2.7

import struct
import time
Expand Down
2 changes: 1 addition & 1 deletion test_helper/instrumentation_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python2.7

import time
import sys
Expand Down
52 changes: 51 additions & 1 deletion test_helper/leopytest/RemoteControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ModuleConfigCommand(Command):
"""
Command object to retrieve the configuration of a Leosac module.
Config format is force to XML.
Config format is forced to XML.
"""

def __init__(self, module_name):
Expand Down Expand Up @@ -152,3 +152,53 @@ def feed_response(self, frames):

def __str__(self):
return "<RemoteControl.ModuleConfigCommand>"


class ModuleListCommand(Command):
"""
Command object to retrieve the list of modules running on Leosac.
"""

def __init__(self):
"""
Initialize the command
:return:
"""
self.modules = None

def to_zmq_message(self):
return ["MODULE_LIST".encode("utf-8")]

def feed_response(self, frames):
self.status = True
self.modules = []
for frame in frames:
self.modules.append(frame.decode("ascii"))

def __str__(self):
return "<RemoteControl.ModuleListCommand>"


class SaveCommand(Command):
"""
Command object to retrieve to trigger configuration save.
"""

def __init__(self):
"""
Initialize the command
:return:
"""
pass

def to_zmq_message(self):
return ["SAVE".encode("utf-8")]

def feed_response(self, frames):
if frames[0] == bytes("OK", "ascii"):
self.status = True
else:
self.status = False

def __str__(self):
return "<RemoteControl.SaveCommand>"
11 changes: 4 additions & 7 deletions test_helper/leopytest/Utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import subprocess


def test_assert(res, msg):
Expand All @@ -23,16 +24,12 @@ def get_leosac_path():
"""

path = os.getcwd() + "/install/bin/leosac"
if not os.path.isfile(path):
path = subprocess.check_output(["which", "leosac"])

test_assert(os.path.isfile(path), "Cannot find leosac binary")
return path

if os.environ.get("INSTALL_DIR"):
path = os.environ["INSTALL_DIR"] + "/install/bin/leosac"
test_assert(os.path.isfile(path), "Cannot find leosac binary")
return path
logging.error("Cannot find Leosac.")
exit(-1)


def preconfigure():
"""
Expand Down
2 changes: 1 addition & 1 deletion test_helper/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ total_test=`find . -maxdepth 1 -mindepth 1 -type d | wc -l`
echo -e ${Yel} "We will run ${total_test} tests" ${RCol}

## the run_docker script require a test-folder name.
find . -maxdepth 1 -mindepth 1 -type d | parallel ./run_docker.sh {} ;
find . -name "test-*" -maxdepth 1 -mindepth 1 -type d | parallel ./run_docker.sh {} ;

RET_VALUE=$?
## parallel ret value is our test suite return value.
Expand Down
20 changes: 0 additions & 20 deletions test_helper/test-module-config/test-invalid.py

This file was deleted.

21 changes: 0 additions & 21 deletions test_helper/test-module-config/test-valid.py

This file was deleted.

27 changes: 27 additions & 0 deletions test_helper/test-module-list/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Test the MODULE_LIST command.
#

from RemoteControl import RemoteController, ModuleListCommand
from Utils import *
from Runner import LeosacRunner


def main():
leosac = LeosacRunner("this_test/test-module-list.xml")

rc = RemoteController("127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT")
cmd = ModuleListCommand()

rc.execute_command(cmd)
test_assert(cmd.status is True
and ("MONITOR" in cmd.modules)
and ("WIEGAND_READER" in cmd.modules)
and ("NOT_A_MODULE" not in cmd.modules),
"Failed to retrieve config from valid module.")

leosac.interrupt()
leosac.wait_abort(30)

if __name__ == "__main__":
preconfigure()
main()
30 changes: 1 addition & 29 deletions test_helper/test-module-list/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
#!/bin/bash
#
# Test the MODULE_LIST command.
# One running Leosac. We use the remote_control script to query the results.
#

[ -r ../shell_helper.sh ] || { echo "Cannot source shell_helper.sh"; exit -1; }
source ../shell_helper.sh

set -e
set -x

config_file="$TMP_DIR/this_test/test-module-list.xml"

(${REMOTE_CONTROL} "127.0.0.1:12345" 'TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT' "module_list" > remote_result
sleep $SLEEP_TIME
kill $(cat pid-file)
)&


## start leosac and wait for return value
## Use custom work directory to access the factory config file
(valgrind --error-exitcode=42 ./install/bin/leosac -k $config_file > leosac-log &
echo $! > pid-file; wait $! && echo $? > exit-status)

if ! grep "MONITOR" remote_result ; then
fail "MONITOR module should be reported present."
fi

if ! grep "WIEGAND_READER" remote_result ; then
fail "WIEGAND_READER module should be reported present."
fi

[ $(cat exit-status) -eq 0 ] || fail "Non zero return code"

die 0
python this_test/run_test.py
27 changes: 12 additions & 15 deletions test_helper/test-save-fail/test-save.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#!/usr/bin/env python
# Test the SAVE command.
#

import remote_control
import sys
from RemoteControl import RemoteController, SaveCommand
from Utils import *

def main():
print "Hello, will attempt to SAVE"

p = ["", "127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT", "save"]
ret = remote_control.run(p)

print ret
def main():
rc = RemoteController("127.0.0.1:12345", "TJz$:^DbZvFN@wv/ct&[Su6Nnu6w!fMGHEcIttyT")
cmd = SaveCommand()

if len(ret) == 2 and ret[0] == "KO":
return 0;
print "Looks like SAVE succeeded but should have failed"
return 1
rc.execute_command(cmd)
test_assert(cmd.status is False,
"Successfully saved configuration while it was supposed to fail")

if __name__ == "__main__":
ret = main()
exit(ret)
preconfigure()
main()

0 comments on commit b5e3634

Please sign in to comment.