Handling exceptions throughout test flow

pull/1925/head
Brian Daniels 2016-06-13 23:14:34 +01:00
parent 6796025e78
commit f622c591e8
3 changed files with 40 additions and 26 deletions

View File

@ -30,7 +30,7 @@ from tools.test_api import test_path_to_name, find_tests, print_tests, build_tes
from tools.options import get_default_options_parser from tools.options import get_default_options_parser
from tools.build_api import build_project, build_library from tools.build_api import build_project, build_library
from tools.targets import TARGET_MAP from tools.targets import TARGET_MAP
from tools.utils import mkdir from tools.utils import mkdir, ToolException, NotSupportedException
from tools.test_exporters import ReportExporter, ResultExporterType from tools.test_exporters import ReportExporter, ResultExporterType
if __name__ == '__main__': if __name__ == '__main__':
@ -137,7 +137,7 @@ if __name__ == '__main__':
build_report = {} build_report = {}
build_properties = {} build_properties = {}
library_build_success = True library_build_success = False
try: try:
# Build sources # Build sources
build_library(base_source_paths, options.build_dir, target, options.tool, build_library(base_source_paths, options.build_dir, target, options.tool,
@ -150,11 +150,21 @@ if __name__ == '__main__':
macros=options.macros, macros=options.macros,
verbose=options.verbose, verbose=options.verbose,
archive=False) archive=False)
except Exception, e:
library_build_success = False
print "Failed to build library"
if library_build_success: library_build_success = True
except ToolException, e:
# ToolException output is handled by the build log
pass
except NotSupportedException, e:
# NotSupportedException is handled by the build log
pass
except Exception, e:
# Some other exception occurred, print the error message
print e
if not library_build_success:
print "Failed to build library"
else:
# Build all the tests # Build all the tests
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool, test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
options=options.options, options=options.options,

View File

@ -2064,7 +2064,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
for test_name, test_path in tests.iteritems(): for test_name, test_path in tests.iteritems():
test_build_path = os.path.join(build_path, test_path) test_build_path = os.path.join(build_path, test_path)
src_path = base_source_paths + [test_path] src_path = base_source_paths + [test_path]
bin_file = None
try: try:
bin_file = build_project(src_path, test_build_path, target, toolchain_name, bin_file = build_project(src_path, test_build_path, target, toolchain_name,
options=options, options=options,
@ -2091,17 +2091,18 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
clean = False clean = False
# Normalize the path # Normalize the path
bin_file = os.path.normpath(bin_file) if bin_file:
bin_file = os.path.normpath(bin_file)
test_build['tests'][test_name] = {
"binaries": [ test_build['tests'][test_name] = {
{ "binaries": [
"path": bin_file {
} "path": bin_file
] }
} ]
}
print 'Image: %s'% bin_file
print 'Image: %s'% bin_file
test_builds = {} test_builds = {}
test_builds["%s-%s" % (target.name, toolchain_name)] = test_build test_builds["%s-%s" % (target.name, toolchain_name)] = test_build

View File

@ -324,15 +324,18 @@ class ReportExporter():
for test_runner in test_runs: for test_runner in test_runs:
#test_run = test_result_ext[target][toolchain][test][test_run_number][0] #test_run = test_result_ext[target][toolchain][test][test_run_number][0]
test_run = test_runner[0] test_run = test_runner[0]
if test_run["result"] == "FAIL": if "result" in test_run:
failures.append(test_run) if test_run["result"] == "FAIL":
elif test_run["result"] == "SKIP" or test_run["result"] == "NOT_SUPPORTED": failures.append(test_run)
skips.append(test_run) elif test_run["result"] == "SKIP" or test_run["result"] == "NOT_SUPPORTED":
elif test_run["result"] == "OK": skips.append(test_run)
successes.append(test_run) elif test_run["result"] == "OK":
successes.append(test_run)
else:
raise Exception("Unhandled result type: %s" % (test_run["result"]))
else: else:
raise Exception("Unhandled result type: %s" % (test_run["result"])) raise Exception("'test_run' did not have a 'result' value")
if successes: if successes:
print "\n\nBuild successes:" print "\n\nBuild successes:"