Skip to content

Commit 78ca3e4

Browse files
authored
Merge pull request #1925 from bridadan/tools-improvements
Tools improvements
2 parents 71ffe89 + 1bcd643 commit 78ca3e4

File tree

4 files changed

+76
-92
lines changed

4 files changed

+76
-92
lines changed

tools/build_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,6 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False, clean
521521
if toolchain_output:
522522
cur_result["output"] += toolchain_output
523523

524-
cur_result["output"] += str(e)
525-
526524
add_result_to_report(report, cur_result)
527525

528526
# Let Exception propagate

tools/test.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys
2222
import os
2323
import json
24+
import fnmatch
2425

2526
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
2627
sys.path.insert(0, ROOT)
@@ -29,7 +30,7 @@
2930
from tools.options import get_default_options_parser
3031
from tools.build_api import build_project, build_library
3132
from tools.targets import TARGET_MAP
32-
from tools.utils import mkdir
33+
from tools.utils import mkdir, ToolException, NotSupportedException
3334
from tools.test_exporters import ReportExporter, ResultExporterType
3435

3536
if __name__ == '__main__':
@@ -102,11 +103,13 @@
102103
# Filter tests by name if specified
103104
if options.names:
104105
all_names = options.names.split(",")
106+
all_names = [x.lower() for x in all_names]
105107

106-
all_tests_keys = all_tests.keys()
107108
for name in all_names:
108-
if name in all_tests_keys:
109-
tests[name] = all_tests[name]
109+
if any(fnmatch.fnmatch(testname, name) for testname in all_tests):
110+
for testname, test in all_tests.items():
111+
if fnmatch.fnmatch(testname, name):
112+
tests[testname] = test
110113
else:
111114
print "[Warning] Test with name '%s' was not found in the available tests" % (name)
112115
else:
@@ -134,7 +137,7 @@
134137
build_report = {}
135138
build_properties = {}
136139

137-
library_build_success = True
140+
library_build_success = False
138141
try:
139142
# Build sources
140143
build_library(base_source_paths, options.build_dir, target, options.tool,
@@ -147,11 +150,21 @@
147150
macros=options.macros,
148151
verbose=options.verbose,
149152
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
150161
except Exception, e:
151-
library_build_success = False
162+
# Some other exception occurred, print the error message
163+
print e
164+
165+
if not library_build_success:
152166
print "Failed to build library"
153-
154-
if library_build_success:
167+
else:
155168
# Build all the tests
156169
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
157170
options=options.options,

tools/test_api.py

Lines changed: 44 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,76 +1961,44 @@ def test_path_to_name(path):
19611961
name_parts.insert(0, tail)
19621962
head, tail = os.path.split(head)
19631963

1964-
return "-".join(name_parts)
1964+
return "-".join(name_parts).lower()
19651965

19661966
def find_tests(base_dir):
19671967
"""Given any directory, walk through the subdirectories and find all tests"""
19681968

1969-
def is_subdir(path, directory):
1970-
path = os.path.realpath(path)
1971-
directory = os.path.realpath(directory)
1972-
relative = os.path.relpath(path, directory)
1973-
return not (relative.startswith(os.pardir + os.sep) and relative.startswith(os.pardir))
1974-
1975-
def find_tests_in_tests_directory(directory):
1969+
def find_test_in_directory(directory, tests_path):
19761970
"""Given a 'TESTS' directory, return a dictionary of test names and test paths.
19771971
The formate of the dictionary is {"test-name": "./path/to/test"}"""
1978-
tests = {}
1979-
1980-
for d in os.listdir(directory):
1981-
# dir name host_tests is reserved for host python scripts.
1982-
if d != "host_tests":
1983-
# Loop on test case directories
1984-
for td in os.listdir(os.path.join(directory, d)):
1985-
# Add test case to the results if it is a directory and not "host_tests"
1986-
if td != "host_tests":
1987-
test_case_path = os.path.join(directory, d, td)
1988-
if os.path.isdir(test_case_path):
1989-
tests[test_path_to_name(test_case_path)] = test_case_path
1972+
test = None
1973+
if tests_path in directory:
1974+
head, test_case_directory = os.path.split(directory)
1975+
if test_case_directory != tests_path and test_case_directory != "host_tests":
1976+
head, test_group_directory = os.path.split(head)
1977+
if test_group_directory != tests_path and test_case_directory != "host_tests":
1978+
test = {
1979+
"name": test_path_to_name(directory),
1980+
"path": directory
1981+
}
19901982

1991-
return tests
1992-
1983+
return test
1984+
19931985
tests_path = 'TESTS'
1986+
tests = {}
1987+
dirs = scan_for_source_paths(base_dir)
19941988

1995-
# Determine if "base_dir" is already a "TESTS" directory
1996-
_, top_folder = os.path.split(base_dir)
1989+
for directory in dirs:
1990+
test = find_test_in_directory(directory, tests_path)
1991+
if test:
1992+
tests[test['name']] = test['path']
19971993

1998-
if top_folder == tests_path:
1999-
# Already pointing at a "TESTS" directory
2000-
return find_tests_in_tests_directory(base_dir)
2001-
else:
2002-
# Not pointing at a "TESTS" directory, so go find one!
2003-
tests = {}
2004-
2005-
dirs = scan_for_source_paths(base_dir)
2006-
2007-
test_and_sub_dirs = [x for x in dirs if tests_path in x]
2008-
test_dirs = []
2009-
for potential_test_dir in test_and_sub_dirs:
2010-
good_to_add = True
2011-
if test_dirs:
2012-
for test_dir in test_dirs:
2013-
if is_subdir(potential_test_dir, test_dir):
2014-
good_to_add = False
2015-
break
2016-
2017-
if good_to_add:
2018-
test_dirs.append(potential_test_dir)
2019-
2020-
# Only look at valid paths
2021-
for path in test_dirs:
2022-
# Get the tests inside of the "TESTS" directory
2023-
new_tests = find_tests_in_tests_directory(path)
2024-
if new_tests:
2025-
tests.update(new_tests)
2026-
2027-
return tests
1994+
return tests
20281995

2029-
def print_tests(tests, format="list"):
1996+
def print_tests(tests, format="list", sort=True):
20301997
"""Given a dictionary of tests (as returned from "find_tests"), print them
20311998
in the specified format"""
20321999
if format == "list":
2033-
for test_name, test_path in tests.iteritems():
2000+
for test_name in sorted(tests.keys()):
2001+
test_path = tests[test_name]
20342002
print "Test Case:"
20352003
print " Name: %s" % test_name
20362004
print " Path: %s" % test_path
@@ -2064,7 +2032,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20642032
for test_name, test_path in tests.iteritems():
20652033
test_build_path = os.path.join(build_path, test_path)
20662034
src_path = base_source_paths + [test_path]
2067-
2035+
bin_file = None
20682036
try:
20692037
bin_file = build_project(src_path, test_build_path, target, toolchain_name,
20702038
options=options,
@@ -2077,30 +2045,32 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20772045
verbose=verbose)
20782046

20792047
except Exception, e:
2080-
result = False
2081-
2082-
if continue_on_build_fail:
2083-
continue
2084-
else:
2085-
break
2048+
if not isinstance(e, NotSupportedException):
2049+
result = False
2050+
2051+
if continue_on_build_fail:
2052+
continue
2053+
else:
2054+
break
20862055

20872056
# If a clean build was carried out last time, disable it for the next build.
20882057
# Otherwise the previously built test will be deleted.
20892058
if clean:
20902059
clean = False
20912060

20922061
# Normalize the path
2093-
bin_file = os.path.normpath(bin_file)
2094-
2095-
test_build['tests'][test_name] = {
2096-
"binaries": [
2097-
{
2098-
"path": bin_file
2099-
}
2100-
]
2101-
}
2102-
2103-
print 'Image: %s'% bin_file
2062+
if bin_file:
2063+
bin_file = os.path.normpath(bin_file)
2064+
2065+
test_build['tests'][test_name] = {
2066+
"binaries": [
2067+
{
2068+
"path": bin_file
2069+
}
2070+
]
2071+
}
2072+
2073+
print 'Image: %s'% bin_file
21042074

21052075
test_builds = {}
21062076
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)