Skip to content

Commit f622c59

Browse files
committed
Handling exceptions throughout test flow
1 parent 6796025 commit f622c59

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

tools/test.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from tools.options import get_default_options_parser
3131
from tools.build_api import build_project, build_library
3232
from tools.targets import TARGET_MAP
33-
from tools.utils import mkdir
33+
from tools.utils import mkdir, ToolException, NotSupportedException
3434
from tools.test_exporters import ReportExporter, ResultExporterType
3535

3636
if __name__ == '__main__':
@@ -137,7 +137,7 @@
137137
build_report = {}
138138
build_properties = {}
139139

140-
library_build_success = True
140+
library_build_success = False
141141
try:
142142
# Build sources
143143
build_library(base_source_paths, options.build_dir, target, options.tool,
@@ -150,11 +150,21 @@
150150
macros=options.macros,
151151
verbose=options.verbose,
152152
archive=False)
153+
154+
library_build_success = True
155+
except ToolException, e:
156+
# ToolException output is handled by the build log
157+
pass
158+
except NotSupportedException, e:
159+
# NotSupportedException is handled by the build log
160+
pass
153161
except Exception, e:
154-
library_build_success = False
162+
# Some other exception occurred, print the error message
163+
print e
164+
165+
if not library_build_success:
155166
print "Failed to build library"
156-
157-
if library_build_success:
167+
else:
158168
# Build all the tests
159169
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
160170
options=options.options,

tools/test_api.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20642064
for test_name, test_path in tests.iteritems():
20652065
test_build_path = os.path.join(build_path, test_path)
20662066
src_path = base_source_paths + [test_path]
2067-
2067+
bin_file = None
20682068
try:
20692069
bin_file = build_project(src_path, test_build_path, target, toolchain_name,
20702070
options=options,
@@ -2091,17 +2091,18 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20912091
clean = False
20922092

20932093
# Normalize the path
2094-
bin_file = os.path.normpath(bin_file)
2095-
2096-
test_build['tests'][test_name] = {
2097-
"binaries": [
2098-
{
2099-
"path": bin_file
2100-
}
2101-
]
2102-
}
2103-
2104-
print 'Image: %s'% bin_file
2094+
if bin_file:
2095+
bin_file = os.path.normpath(bin_file)
2096+
2097+
test_build['tests'][test_name] = {
2098+
"binaries": [
2099+
{
2100+
"path": bin_file
2101+
}
2102+
]
2103+
}
2104+
2105+
print 'Image: %s'% bin_file
21052106

21062107
test_builds = {}
21072108
test_builds["%s-%s" % (target.name, toolchain_name)] = test_build

tools/test_exporters.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,18 @@ def exporter_print(self, test_result_ext, print_log_for_failures=False):
324324
for test_runner in test_runs:
325325
#test_run = test_result_ext[target][toolchain][test][test_run_number][0]
326326
test_run = test_runner[0]
327-
328-
if test_run["result"] == "FAIL":
329-
failures.append(test_run)
330-
elif test_run["result"] == "SKIP" or test_run["result"] == "NOT_SUPPORTED":
331-
skips.append(test_run)
332-
elif test_run["result"] == "OK":
333-
successes.append(test_run)
327+
328+
if "result" in test_run:
329+
if test_run["result"] == "FAIL":
330+
failures.append(test_run)
331+
elif test_run["result"] == "SKIP" or test_run["result"] == "NOT_SUPPORTED":
332+
skips.append(test_run)
333+
elif test_run["result"] == "OK":
334+
successes.append(test_run)
335+
else:
336+
raise Exception("Unhandled result type: %s" % (test_run["result"]))
334337
else:
335-
raise Exception("Unhandled result type: %s" % (test_run["result"]))
338+
raise Exception("'test_run' did not have a 'result' value")
336339

337340
if successes:
338341
print "\n\nBuild successes:"

0 commit comments

Comments
 (0)