Skip to content

Commit 4443116

Browse files
committed
Merge pull request #137 from bridadan/continue-test-build-if-fail
Allowing test builds to continue if one test build fails
2 parents 2a456e5 + 6dbc960 commit 4443116

File tree

3 files changed

+79
-49
lines changed

3 files changed

+79
-49
lines changed

tools/build_api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from os import getcwd
2727
from time import time
2828

29-
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException
29+
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException, ToolException
3030
from tools.paths import MBED_TARGETS_PATH, MBED_LIBRARIES, MBED_API, MBED_HAL, MBED_COMMON
3131
from tools.targets import TARGET_NAMES, TARGET_MAP
3232
from tools.libraries import Library
@@ -306,7 +306,12 @@ def build_library(src_paths, build_path, target, toolchain_name,
306306
except Exception, e:
307307
if report != None:
308308
end = time()
309-
cur_result["result"] = "FAIL"
309+
310+
if isinstance(e, ToolException):
311+
cur_result["result"] = "FAIL"
312+
elif isinstance(e, NotSupportedException):
313+
cur_result["result"] = "NOT_SUPPORTED"
314+
310315
cur_result["elapsed_time"] = end - start
311316

312317
toolchain_output = toolchain.get_output()

tools/test.py

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -129,49 +129,63 @@
129129

130130
build_report = {}
131131
build_properties = {}
132-
133-
# Build sources
134-
lib_build_res = build_library(base_source_paths, options.build_dir, target, options.tool,
135-
options=options.options,
136-
jobs=options.jobs,
137-
clean=options.clean,
138-
report=build_report,
139-
properties=build_properties,
140-
name="mbed-os",
141-
macros=options.macros,
142-
archive=False)
143-
144-
# Build all the tests
145-
test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
146-
options=options.options,
147-
clean=options.clean,
148-
report=build_report,
149-
properties=build_properties,
150-
macros=options.macros,
151-
jobs=options.jobs)
152-
153-
# If a path to a test spec is provided, write it to a file
154-
if options.test_spec:
155-
test_spec_data = test_spec_from_test_build(test_build)
132+
133+
library_build_success = True
134+
try:
135+
# Build sources
136+
build_library(base_source_paths, options.build_dir, target, options.tool,
137+
options=options.options,
138+
jobs=options.jobs,
139+
clean=options.clean,
140+
report=build_report,
141+
properties=build_properties,
142+
name="mbed-os",
143+
macros=options.macros,
144+
archive=False)
145+
except Exception, e:
146+
library_build_success = False
147+
print "Failed to build library"
148+
print e
156149

157-
# Create the target dir for the test spec if necessary
158-
# mkdir will not create the dir if it already exists
159-
test_spec_dir = os.path.dirname(options.test_spec)
160-
if test_spec_dir:
161-
mkdir(test_spec_dir)
150+
if library_build_success:
151+
# Build all the tests
152+
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
153+
options=options.options,
154+
clean=options.clean,
155+
report=build_report,
156+
properties=build_properties,
157+
macros=options.macros,
158+
jobs=options.jobs)
159+
160+
if not test_build_success:
161+
print "Failed to build some tests, check build log for details"
162162

163-
try:
164-
with open(options.test_spec, 'w') as f:
165-
f.write(json.dumps(test_spec_data, indent=2))
166-
except IOError, e:
167-
print "[ERROR] Error writing test spec to file"
168-
print e
163+
# If a path to a test spec is provided, write it to a file
164+
if options.test_spec:
165+
test_spec_data = test_spec_from_test_build(test_build)
166+
167+
# Create the target dir for the test spec if necessary
168+
# mkdir will not create the dir if it already exists
169+
test_spec_dir = os.path.dirname(options.test_spec)
170+
if test_spec_dir:
171+
mkdir(test_spec_dir)
172+
173+
try:
174+
with open(options.test_spec, 'w') as f:
175+
f.write(json.dumps(test_spec_data, indent=2))
176+
except IOError, e:
177+
print "[ERROR] Error writing test spec to file"
178+
print e
169179

170180
# If a path to a JUnit build report spec is provided, write it to a file
171181
if options.build_report_junit:
172182
report_exporter = ReportExporter(ResultExporterType.JUNIT)
173183
report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
174-
sys.exit()
184+
185+
if library_build_success and test_build_success:
186+
sys.exit(0)
187+
else:
188+
sys.exit(1)
175189

176190
except KeyboardInterrupt, e:
177191
print "\n[CTRL+c] exit"

tools/test_api.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,10 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20292029
options=None, clean=False, notify=None, verbose=False, jobs=1,
20302030
macros=None, silent=False, report=None, properties=None):
20312031
"""Given the data structure from 'find_tests' and the typical build parameters,
2032-
build all the tests and return a test build data structure"""
2032+
build all the tests
2033+
2034+
Returns a tuple of the build result (True or False) followed by the test
2035+
build data structure"""
20332036

20342037
test_build = {
20352038
"platform": target.name,
@@ -2040,18 +2043,26 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20402043
"tests": {}
20412044
}
20422045

2046+
result = True
2047+
20432048
for test_name, test_path in tests.iteritems():
20442049
test_build_path = os.path.join(build_path, test_path)
20452050
src_path = base_source_paths + [test_path]
2046-
bin_file = build_project(src_path, test_build_path, target, toolchain_name,
2047-
options=options,
2048-
jobs=jobs,
2049-
clean=clean,
2050-
macros=macros,
2051-
name=test_name,
2052-
report=report,
2053-
properties=properties,
2054-
verbose=verbose)
2051+
2052+
try:
2053+
bin_file = build_project(src_path, test_build_path, target, toolchain_name,
2054+
options=options,
2055+
jobs=jobs,
2056+
clean=clean,
2057+
macros=macros,
2058+
name=test_name,
2059+
report=report,
2060+
properties=properties,
2061+
verbose=verbose)
2062+
2063+
except Exception, e:
2064+
result = False
2065+
continue
20552066

20562067
# If a clean build was carried out last time, disable it for the next build.
20572068
# Otherwise the previously built test will be deleted.
@@ -2075,7 +2086,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20752086
test_builds["%s-%s" % (target.name, toolchain_name)] = test_build
20762087

20772088

2078-
return test_builds
2089+
return result, test_builds
20792090

20802091

20812092
def test_spec_from_test_build(test_builds):

0 commit comments

Comments
 (0)