Add check for masscanned panic in python tests

This commit is contained in:
_Frky 2022-05-30 14:45:49 +02:00
parent bf1a2c7429
commit 843729b961
2 changed files with 9 additions and 4 deletions

View file

@ -44,9 +44,13 @@ def test(f):
KO = "\033[1m\033[1;%dmKO\033[0m" % 31 KO = "\033[1m\033[1;%dmKO\033[0m" % 31
fname = f.__name__.ljust(50, ".") fname = f.__name__.ljust(50, ".")
def w(): def w(m):
try: try:
# check that masscanned is still running
assert(m.poll() is None), "masscanned not running"
f() f()
# check that masscanned is still running
assert(m.poll() is None), "masscanned terminated unexpectedly"
LOG.info("{}{}".format(fname, OK)) LOG.info("{}{}".format(fname, OK))
except AssertionError as e: except AssertionError as e:
LOG.error("{}{}: {}".format(fname, KO, e)) LOG.error("{}{}: {}".format(fname, KO, e))
@ -56,11 +60,12 @@ def test(f):
return w return w
def test_all(): def test_all(m):
global ERRORS, TESTS global ERRORS, TESTS
# execute tests # execute tests
for t in TESTS: for t in TESTS:
t() # perform unit test
t(m)
LOG.info(f"\033[1mRan {len(TESTS)} tests with {len(ERRORS)} errors\033[0m") LOG.info(f"\033[1mRan {len(TESTS)} tests with {len(ERRORS)} errors\033[0m")
return len(ERRORS) return len(ERRORS)

View file

@ -177,7 +177,7 @@ masscanned = subprocess.Popen(
sleep(1) sleep(1)
try: try:
result = test_all() result = test_all(masscanned)
except AssertionError: except AssertionError:
result = -1 result = -1