Changeset View
Changeset View
Standalone View
Standalone View
test/util/bctest.py
- This file was moved from src/test/bctest.py.
Show All 18 Lines | def parse_output(a, fmt): | ||||
if fmt == 'json': # json: compare parsed data | if fmt == 'json': # json: compare parsed data | ||||
return json.loads(a) | return json.loads(a) | ||||
elif fmt == 'hex': # hex: parse and compare binary data | elif fmt == 'hex': # hex: parse and compare binary data | ||||
return binascii.a2b_hex(a.strip()) | return binascii.a2b_hex(a.strip()) | ||||
else: | else: | ||||
raise NotImplementedError("Don't know how to compare %s" % fmt) | raise NotImplementedError("Don't know how to compare %s" % fmt) | ||||
def bctest(testDir, testObj, exeext): | def bctest(testDir, testObj, buildenv): | ||||
"""Runs a single test, comparing output and RC to expected output and RC. | """Runs a single test, comparing output and RC to expected output and RC. | ||||
Raises an error if input can't be read, executable fails, or output/RC | Raises an error if input can't be read, executable fails, or output/RC | ||||
are not as expected. Error is caught by bctester() and reported. | are not as expected. Error is caught by bctester() and reported. | ||||
""" | """ | ||||
# Get the exec names and arguments | # Get the exec names and arguments | ||||
execprog = testObj['exec'] + exeext | execprog = buildenv.BUILDDIR + "/src/" + testObj['exec'] + buildenv.exeext | ||||
execargs = testObj['args'] | execargs = testObj['args'] | ||||
execrun = [execprog] + execargs | execrun = [execprog] + execargs | ||||
# Read the input data (if there is any) | # Read the input data (if there is any) | ||||
stdinCfg = None | stdinCfg = None | ||||
inputData = None | inputData = None | ||||
if "input" in testObj: | if "input" in testObj: | ||||
filename = testDir + "/" + testObj['input'] | filename = testDir + "/" + testObj['input'] | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | def bctester(testDir, input_basename, buildenv): | ||||
input_filename = testDir + "/" + input_basename | input_filename = testDir + "/" + input_basename | ||||
raw_data = open(input_filename).read() | raw_data = open(input_filename).read() | ||||
input_data = json.loads(raw_data) | input_data = json.loads(raw_data) | ||||
failed_testcases = [] | failed_testcases = [] | ||||
for testObj in input_data: | for testObj in input_data: | ||||
try: | try: | ||||
bctest(testDir, testObj, buildenv.exeext) | bctest(testDir, testObj, buildenv) | ||||
logging.info("PASSED: " + testObj["description"]) | logging.info("PASSED: " + testObj["description"]) | ||||
except: | except: | ||||
logging.info("FAILED: " + testObj["description"]) | logging.info("FAILED: " + testObj["description"]) | ||||
failed_testcases.append(testObj["description"]) | failed_testcases.append(testObj["description"]) | ||||
if failed_testcases: | if failed_testcases: | ||||
logging.error( | logging.error( | ||||
"FAILED TESTCASES: [" + ", ".join(failed_testcases) + "]") | "FAILED TESTCASES: [" + ", ".join(failed_testcases) + "]") | ||||
sys.exit(1) | sys.exit(1) | ||||
else: | else: | ||||
sys.exit(0) | sys.exit(0) |