Commit 22791635 authored by Daniel Salzman's avatar Daniel Salzman

func-test: add support for setting of test/case to run

parent 60bdb71f
#!/usr/bin/env python3
import argparse, importlib, os, sys, tempfile, time, traceback
import argparse, importlib, os, re, sys, tempfile, time, traceback
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/tools")
from dnstest import log, err
import params
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", \
help="enable exception traceback on stdout", \
action='store_true')
parser.add_argument("-d", dest="debug", action="store_true", \
help="enable exception traceback on stdout")
parser.add_argument("tests", metavar="[:]test[/case]", nargs="*", \
help="([exclude] | run) specific (test set | [test case])")
args = parser.parse_args()
if args.debug:
params.debug = True
outs_dir = tempfile.mkdtemp(prefix="knottest-%s-" % int(time.time()))
tests_dir = "tests"
test_cnt = 0
fail_cnt = 0
log("Starting Knot test suite %s" % outs_dir)
excluded = dict()
included = dict()
for item in args.tests:
if re.match(":", item):
item = item[1:]
storage = excluded
else:
storage = included
parts = item.split("/")
if len(parts) == 1:
case = list()
elif len(parts) == 2:
case = [parts[1]]
else:
print("Invalid argument %s" % item)
exit(1)
test = parts[0]
if test in storage:
storage[test].append(case)
else:
storage[test] = case
# List all tests if nothing was specified.
if not included:
for i in sorted(os.listdir("./" + tests_dir)):
included[i] = list()
def save_traceback(outdir):
file = open(params.out_dir + "/traceback", mode="a")
traceback.print_exc(file=file)
file.close()
for test in sorted(os.listdir("./" + tests_dir)):
log("Starting Knot test suite %s" % outs_dir)
for test in sorted(included):
# Skip excluded test set.
if test in excluded and not excluded[test]:
continue
# Check test directory.
test_dir = "./%s/%s" % (tests_dir, test)
if not os.path.isdir(test_dir):
log("Invalid test name %s (ignored)" % test)
continue
log("Test \'%s\'" % test)
for case in sorted(os.listdir(test_dir)):
# Set test cases to run.
if not included[test]:
# List all test cases.
cases = sorted(os.listdir(test_dir))
else:
cases = included[test]
for case in cases:
# Skip excluded cases.
if test in excluded and case in excluded[test]:
continue
test_cnt += 1
case_dir = test_dir + "/" + case
test_file = case_dir + "/test.py"
if not os.path.isfile(test_file):
log(" * case \'%s\': NOT EXECUTABLE!" % case)
fail_cnt += 1
continue
log(" * case \'%s\'" % case)
test_cnt += 1
try:
out_dir = outs_dir + "/" + test + "/" + case
......@@ -59,12 +107,12 @@ for test in sorted(os.listdir("./" + tests_dir)):
params.err = True
params.errmsg = format(exc)
save_traceback(params.out_dir)
if params.debug:
if args.debug:
traceback.print_exc()
except BaseException as exc:
log("Interrupted")
save_traceback(params.out_dir)
if params.debug:
if args.debug:
traceback.print_exc()
exit(1)
......@@ -77,10 +125,10 @@ for test in sorted(os.listdir("./" + tests_dir)):
if params.test:
params.test.stop()
log("TEST CASES: %i, FAILED: %i" % (test_cnt, fail_cnt))
if fail_cnt:
log("Failed test cases: %i/%i" % (fail_cnt, test_cnt))
exit(1)
else:
log("All test cases passed")
exit(0)
......@@ -15,5 +15,3 @@ test = None
err = False
# Error message text.
errmsg = ""
# Enable exception traceback.
debug = False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment