Skip to content

Commit 24418b4

Browse files
Merge pull request #5182 from theotherjimmy/test-flags-assumptions
tools/toolhains - Test for flag passing in constructor
2 parents b6b9daa + b9b4bb5 commit 24418b4

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

tools/test/toolchains/api_test.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sys.path.insert(0, ROOT)
1313

1414
from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES,\
15-
Resources, TOOLCHAIN_PATHS
15+
Resources, TOOLCHAIN_PATHS, mbedToolchain
1616
from tools.targets import TARGET_MAP
1717

1818
def test_instantiation():
@@ -43,11 +43,15 @@ def test_toolchain_profile_c(profile, source_file):
4343
toolchain.inc_md5 = ""
4444
toolchain.build_dir = ""
4545
toolchain.config = MagicMock(app_config_location=None)
46+
for parameter in profile['c'] + profile['common']:
47+
assert any(parameter in cmd for cmd in toolchain.cc), \
48+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
49+
parameter)
4650
compile_command = toolchain.compile_command(to_compile,
4751
to_compile + ".o", [])
4852
for parameter in profile['c'] + profile['common']:
4953
assert any(parameter in cmd for cmd in compile_command), \
50-
"Toolchain %s did not propigate arg %s" % (toolchain.name,
54+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
5155
parameter)
5256

5357
@given(fixed_dictionaries({
@@ -69,11 +73,15 @@ def test_toolchain_profile_cpp(profile, source_file):
6973
toolchain.inc_md5 = ""
7074
toolchain.build_dir = ""
7175
toolchain.config = MagicMock(app_config_location=None)
76+
for parameter in profile['cxx'] + profile['common']:
77+
assert any(parameter in cmd for cmd in toolchain.cppc), \
78+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
79+
parameter)
7280
compile_command = toolchain.compile_command(to_compile,
7381
to_compile + ".o", [])
7482
for parameter in profile['cxx'] + profile['common']:
7583
assert any(parameter in cmd for cmd in compile_command), \
76-
"Toolchain %s did not propigate arg %s" % (toolchain.name,
84+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
7785
parameter)
7886

7987
@given(fixed_dictionaries({
@@ -94,14 +102,55 @@ def test_toolchain_profile_asm(profile, source_file):
94102
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
95103
toolchain.inc_md5 = ""
96104
toolchain.build_dir = ""
105+
for parameter in profile['asm']:
106+
assert any(parameter in cmd for cmd in toolchain.asm), \
107+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
108+
parameter)
97109
compile_command = toolchain.compile_command(to_compile,
98110
to_compile + ".o", [])
99111
if not compile_command:
100112
assert compile_command, to_compile
101113
for parameter in profile['asm']:
102114
assert any(parameter in cmd for cmd in compile_command), \
103-
"Toolchain %s did not propigate arg %s" % (toolchain.name,
104-
parameter)
115+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
116+
parameter)
117+
118+
for name, Class in TOOLCHAIN_CLASSES.items():
119+
CLS = Class(TARGET_MAP["K64F"])
120+
assert name == CLS.name or name == LEGACY_TOOLCHAIN_NAMES[CLS.name]
121+
122+
@given(fixed_dictionaries({
123+
'common': lists(text()),
124+
'c': lists(text()),
125+
'cxx': lists(text()),
126+
'asm': lists(text()),
127+
'ld': lists(text(min_size=1))}),
128+
lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
129+
def test_toolchain_profile_ld(profile, source_file):
130+
"""Test that the appropriate profile parameters are passed to the
131+
Linker"""
132+
filename = deepcopy(source_file)
133+
filename[-1] += ".o"
134+
to_compile = os.path.join(*filename)
135+
with patch('os.mkdir') as _mkdir,\
136+
patch('tools.toolchains.mbedToolchain.default_cmd') as _dflt_cmd:
137+
for _, tc_class in TOOLCHAIN_CLASSES.items():
138+
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
139+
toolchain.RESPONSE_FILES = False
140+
toolchain.inc_md5 = ""
141+
toolchain.build_dir = ""
142+
for parameter in profile['ld']:
143+
assert any(parameter in cmd for cmd in toolchain.ld), \
144+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
145+
parameter)
146+
toolchain.link(to_compile + ".elf", [to_compile], [], [], None)
147+
compile_cmd = _dflt_cmd.call_args_list
148+
if not compile_cmd:
149+
assert compile_cmd, to_compile
150+
for parameter in profile['ld']:
151+
assert any(parameter in cmd[0][0] for cmd in compile_cmd), \
152+
"Toolchain %s did not propagate arg %s" % (toolchain.name,
153+
parameter)
105154

106155
for name, Class in TOOLCHAIN_CLASSES.items():
107156
CLS = Class(TARGET_MAP["K64F"])

tools/toolchains/iar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(self, target, notify=None, macros=None,
8484
self.cc += self.flags["common"] + c_flags_cmd + self.flags["c"]
8585
self.cppc += self.flags["common"] + c_flags_cmd + cxx_flags_cmd + self.flags["cxx"]
8686

87-
self.ld = [join(IAR_BIN, "ilinkarm")]
87+
self.ld = [join(IAR_BIN, "ilinkarm")] + self.flags['ld']
8888
self.ar = join(IAR_BIN, "iarchive")
8989
self.elf2bin = join(IAR_BIN, "ielftool")
9090

@@ -186,7 +186,7 @@ def compile_cpp(self, source, object, includes):
186186
def link(self, output, objects, libraries, lib_dirs, mem_map):
187187
# Build linker command
188188
map_file = splitext(output)[0] + ".map"
189-
cmd = self.ld + [ "-o", output, "--map=%s" % map_file] + objects + libraries + self.flags['ld']
189+
cmd = self.ld + [ "-o", output, "--map=%s" % map_file] + objects + libraries
190190

191191
if mem_map:
192192
cmd.extend(["--config", mem_map])

0 commit comments

Comments
 (0)