Skip to content

Commit 3a0d561

Browse files
authored
Merge pull request #1911 from mbedmicro/config-tests
Config tests, GCC flags, requirements.txt
2 parents 89c1bef + 5002c5b commit 3a0d561

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1510
-7
lines changed

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
colorama
2+
PrettyTable
23
pyserial
3-
prettytable
4-
Jinja2
54
IntelHex
65
mbed-ls
6+
mbed-greentea
77
project-generator>=0.8.11,<0.9.0
8+
Jinja2
89
junit-xml
910
requests
10-
pyYAML

tools/build_everything.py

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#! /usr/bin/env python
2+
"""
3+
mbed SDK
4+
Copyright (c) 2011-2013 ARM Limited
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
import sys
19+
from time import time
20+
from os.path import join, abspath, dirname, normpath
21+
from optparse import OptionParser
22+
import json
23+
24+
# Be sure that the tools directory is in the search path
25+
ROOT = abspath(join(dirname(__file__), ".."))
26+
sys.path.insert(0, ROOT)
27+
28+
from tools.build_api import build_library
29+
from tools.build_api import write_build_report
30+
from tools.targets import TARGET_MAP, TARGET_NAMES
31+
from tools.toolchains import TOOLCHAINS
32+
from tools.test_exporters import ReportExporter, ResultExporterType
33+
from tools.test_api import find_tests, build_tests, test_spec_from_test_builds
34+
from tools.build_release import OFFICIAL_MBED_LIBRARY_BUILD
35+
36+
if __name__ == '__main__':
37+
try:
38+
parser = OptionParser()
39+
40+
parser.add_option("--source", dest="source_dir",
41+
default=None, help="The source (input) directory (for sources other than tests). Defaults to current directory.", action="append")
42+
43+
parser.add_option("--build", dest="build_dir",
44+
default=None, help="The build (output) directory")
45+
46+
parser.add_option('-c', '--clean',
47+
dest='clean',
48+
metavar=False,
49+
action="store_true",
50+
help='Clean the build directory')
51+
52+
parser.add_option('-a', '--all', dest="all", default=False, action="store_true",
53+
help="Build every target (including unofficial targets) and with each of the supported toolchains")
54+
55+
parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true",
56+
help="Build using only the official toolchain for each target")
57+
58+
parser.add_option("-D", "",
59+
action="append",
60+
dest="macros",
61+
help="Add a macro definition")
62+
63+
parser.add_option("-j", "--jobs", type="int", dest="jobs",
64+
default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
65+
66+
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
67+
default=False, help="Verbose diagnostic output")
68+
69+
parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma")
70+
71+
parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
72+
73+
parser.add_option("", "--config", action="store_true", dest="list_config",
74+
default=False, help="List the platforms and toolchains in the release in JSON")
75+
76+
parser.add_option("", "--test-spec", dest="test_spec",
77+
default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool")
78+
79+
parser.add_option("", "--build-report-junit", dest="build_report_junit", help="Output the build results to an junit xml file")
80+
81+
parser.add_option("--continue-on-build-fail", action="store_true", dest="continue_on_build_fail",
82+
default=False, help="Continue trying to build all tests if a build failure occurs")
83+
84+
options, args = parser.parse_args()
85+
86+
# Get set of valid targets
87+
all_platforms = set(TARGET_NAMES)
88+
bad_platforms = set()
89+
platforms = set()
90+
if options.platforms != "":
91+
platforms = set(options.platforms.split(","))
92+
bad_platforms = platforms.difference(all_platforms)
93+
platforms = platforms.intersection(all_platforms)
94+
elif options.all:
95+
platforms = all_platforms
96+
else:
97+
platforms = set(x[0] for x in OFFICIAL_MBED_LIBRARY_BUILD)
98+
bad_platforms = platforms.difference(all_platforms)
99+
platforms = platforms.intersection(all_platforms)
100+
101+
for bad_platform in bad_platforms:
102+
print "Platform '%s' is not a valid platform. Skipping." % bad_platform
103+
104+
if options.platforms:
105+
print "Limiting build to the following platforms: %s" % ",".join(platforms)
106+
107+
# Get set of valid toolchains
108+
all_toolchains = set(TOOLCHAINS)
109+
bad_toolchains = set()
110+
toolchains = set()
111+
112+
if options.toolchains:
113+
toolchains = set(options.toolchains.split(","))
114+
bad_toolchains = toolchains.difference(all_toolchains)
115+
toolchains = toolchains.intersection(all_toolchains)
116+
else:
117+
toolchains = all_toolchains
118+
119+
for bad_toolchain in bad_toolchains:
120+
print "Toolchain '%s' is not a valid toolchain. Skipping." % bad_toolchain
121+
122+
if options.toolchains:
123+
print "Limiting build to the following toolchains: %s" % ",".join(toolchains)
124+
125+
build_config = {}
126+
127+
for platform in platforms:
128+
target = TARGET_MAP[platform]
129+
130+
if options.official_only:
131+
default_toolchain = getattr(target, 'default_toolchain', 'ARM')
132+
build_config[platform] = list(toolchains.intersection(set([default_toolchain])))
133+
else:
134+
build_config[platform] = list(toolchains.intersection(set(target.supported_toolchains)))
135+
136+
if options.list_config:
137+
print json.dumps(build_config, indent=4)
138+
sys.exit(0)
139+
140+
# Ensure build directory is set
141+
if not options.build_dir:
142+
print "[ERROR] You must specify a build path"
143+
sys.exit(1)
144+
145+
# Default base source path is the current directory
146+
base_source_paths = options.source_dir
147+
if not base_source_paths:
148+
base_source_paths = ['.']
149+
150+
all_tests = find_tests(base_source_paths[0])
151+
152+
start = time()
153+
build_report = {}
154+
build_properties = {}
155+
test_builds = {}
156+
total_build_success = True
157+
158+
for target_name, target_toolchains in build_config.iteritems():
159+
target = TARGET_MAP[target_name]
160+
161+
for target_toolchain in target_toolchains:
162+
library_build_success = True
163+
164+
try:
165+
build_directory = join(options.build_dir, target_name, target_toolchain)
166+
# Build sources
167+
build_library(base_source_paths, build_directory, target, target_toolchain,
168+
jobs=options.jobs,
169+
clean=options.clean,
170+
report=build_report,
171+
properties=build_properties,
172+
name="mbed-os",
173+
macros=options.macros,
174+
verbose=options.verbose,
175+
archive=False)
176+
except Exception, e:
177+
library_build_success = False
178+
print "Failed to build library"
179+
print e
180+
181+
if options.continue_on_build_fail or library_build_success:
182+
# Build all the tests
183+
test_build_success, test_build = build_tests(all_tests, [build_directory], build_directory, target, target_toolchain,
184+
clean=options.clean,
185+
report=build_report,
186+
properties=build_properties,
187+
macros=options.macros,
188+
verbose=options.verbose,
189+
jobs=options.jobs,
190+
continue_on_build_fail=options.continue_on_build_fail)
191+
192+
if not test_build_success:
193+
total_build_success = False
194+
print "Failed to build some tests, check build log for details"
195+
196+
test_builds.update(test_build)
197+
else:
198+
total_build_success = False
199+
break
200+
201+
# If a path to a test spec is provided, write it to a file
202+
if options.test_spec:
203+
test_spec_data = test_spec_from_test_builds(test_builds)
204+
205+
# Create the target dir for the test spec if necessary
206+
# mkdir will not create the dir if it already exists
207+
test_spec_dir = dirname(options.test_spec)
208+
if test_spec_dir:
209+
mkdir(test_spec_dir)
210+
211+
try:
212+
with open(options.test_spec, 'w') as f:
213+
f.write(json.dumps(test_spec_data, indent=2))
214+
except IOError, e:
215+
print "[ERROR] Error writing test spec to file"
216+
print e
217+
218+
# If a path to a JUnit build report spec is provided, write it to a file
219+
if options.build_report_junit:
220+
report_exporter = ReportExporter(ResultExporterType.JUNIT)
221+
report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
222+
223+
print "\n\nCompleted in: (%.2f)s" % (time() - start)
224+
225+
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
226+
status = print_report_exporter.report(build_report)
227+
228+
if status:
229+
sys.exit(0)
230+
else:
231+
sys.exit(1)
232+
233+
except KeyboardInterrupt, e:
234+
print "\n[CTRL+c] exit"
235+
except Exception,e:
236+
import traceback
237+
traceback.print_exc(file=sys.stdout)
238+
print "[ERROR] %s" % str(e)
239+
sys.exit(1)

tools/export/gcc_arm_common.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ CPU = {% block cpu %}{% for cf in cpu_flags %}{{cf|replace("-mfloat-abi=softfp",
3737
CC_FLAGS = {% block cc_flags %}$(CPU) -c -g -fno-common -fmessage-length=0 -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -MMD -MP{% endblock %}
3838
CC_SYMBOLS = {% block cc_symbols %}{% for s in symbols %}-D{{s}} {% endfor %}{% endblock %}
3939

40-
LD_FLAGS = {%- block ld_flags -%}
40+
LD_FLAGS = {%- block ld_flags -%} $(CPU) -Wl,--gc-sections --specs=nano.specs -Wl,--wrap,main -Wl,-Map=$(PROJECT).map,--cref -Wl,--wrap,_malloc_r -Wl,--wrap,_free_r -Wl,--wrap,_realloc_r
4141
{%- if "-mcpu=cortex-m0" in cpu_flags or "-mcpu=cortex-m0plus" in cpu_flags -%}
42-
{{ ' ' }}$(CPU) -Wl,--gc-sections --specs=nano.specs -Wl,--wrap,main -Wl,-Map=$(PROJECT).map,--cref
4342
#LD_FLAGS += -u _printf_float -u _scanf_float
4443
{%- else -%}
45-
{{ ' ' }}$(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main -Wl,-Map=$(PROJECT).map,--cref
44+
{{ ' ' }}-u _printf_float -u _scanf_float
4645
{%- endif -%}
4746
{% endblock %}
4847
LD_SYS_LIBS = {% block ld_sys_libs %}-lstdc++ -lsupc++ -lm -lc -lgcc -lnosys{% endblock %}

tools/test/config_test/config_test.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""
2+
mbed SDK
3+
Copyright (c) 2011-2016 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
18+
from tools.build_api import get_config
19+
from tools.config import ConfigException
20+
import os, sys
21+
22+
# Compare the output of config against a dictionary of known good results
23+
def compare_config(cfg, expected):
24+
try:
25+
for k in cfg:
26+
if cfg[k].value != expected[k]:
27+
return "'%s': expected '%s', got '%s'" % (k, expected[k], cfg[k].value)
28+
except KeyError:
29+
return "Unexpected key '%s' in configuration data" % k
30+
for k in expected:
31+
if k != "desc" and k != "expected_macros" and not k in cfg:
32+
return "Expected key '%s' was not found in configuration data" % k
33+
return ""
34+
35+
def test_tree(full_name, name):
36+
failed = 0
37+
sys.path.append(full_name)
38+
if "test_data" in sys.modules:
39+
del sys.modules["test_data"]
40+
import test_data
41+
for target, expected in test_data.expected_results.items():
42+
sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target))
43+
sys.stdout.flush()
44+
err_msg = None
45+
try:
46+
cfg, macros = get_config(full_name, target, "GCC_ARM")
47+
except ConfigException as e:
48+
err_msg = e.message
49+
if err_msg:
50+
if expected.has_key("exception_msg"):
51+
if err_msg.find(expected["exception_msg"]) == -1:
52+
print "FAILED!"
53+
sys.stderr.write(" Unexpected error message!\n")
54+
sys.stderr.write(" Expected: '%s'\n" % expected["exception_msg"])
55+
sys.stderr.write(" Got: '%s'\n" % err_msg)
56+
failed += 1
57+
else:
58+
print "OK"
59+
else:
60+
print "FAILED!"
61+
sys.stderr.write(" Error while getting configuration!\n")
62+
sys.stderr.write(" " + err_msg + "\n")
63+
failed += 1
64+
else:
65+
res = compare_config(cfg, expected)
66+
if res:
67+
print "FAILED!"
68+
sys.stdout.write(" " + res + "\n")
69+
failed += 1
70+
else:
71+
expected_macros = expected.get("expected_macros", None)
72+
if expected_macros is not None:
73+
if sorted(expected_macros) != sorted(macros):
74+
print "FAILED!"
75+
sys.stderr.write(" List of macros doesn't match\n")
76+
sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros)))
77+
sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros)))
78+
failed += 1
79+
else:
80+
print "OK"
81+
else:
82+
print "OK"
83+
sys.path.remove(full_name)
84+
return failed
85+
86+
failed = 0
87+
root_dir = os.path.abspath(os.path.dirname(__file__))
88+
tlist = sorted(os.listdir(root_dir), key = lambda e: int(e[4:]) if e.startswith('test') else -1)
89+
for test_name in tlist:
90+
full_name = os.path.join(root_dir, test_name)
91+
if os.path.isdir(full_name) and test_name.startswith('test'):
92+
failed += test_tree(full_name, test_name)
93+
sys.exit(failed)
94+

0 commit comments

Comments
 (0)