Skip to content

Commit fd04ea2

Browse files
committed
Added property based regression test to travis
1 parent d88852d commit fd04ea2

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ install:
1919
- sudo pip install jinja2
2020
- sudo pip install pytest
2121
- sudo pip install pylint
22+
- sudo pip install hypothesis

tools/test/toolchains/api.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import sys
22
import os
3+
from string import printable
4+
from copy import deepcopy
5+
from hypothesis import given
6+
from hypothesis.strategies import text, lists, fixed_dictionaries
37

48
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
59
sys.path.insert(0, ROOT)
@@ -11,3 +15,71 @@ def test_instantiation():
1115
for name, Class in TOOLCHAIN_CLASSES.items():
1216
CLS = Class(TARGET_MAP["K64F"])
1317
assert name == CLS.name or name == LEGACY_TOOLCHAIN_NAMES[CLS.name]
18+
19+
ALPHABET = [char for char in printable if char not in [u'.', u'/']]
20+
21+
@given(fixed_dictionaries({
22+
'common': lists(text()),
23+
'c': lists(text()),
24+
'cxx': lists(text()),
25+
'asm': lists(text()),
26+
'ld': lists(text())}),
27+
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
28+
)
29+
def test_toolchain_profile_c(profile, source_file):
30+
filename = deepcopy(source_file)
31+
filename[-1] += ".c"
32+
to_compile = os.path.join(*filename)
33+
for name, Class in TOOLCHAIN_CLASSES.items():
34+
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
35+
CLS.inc_md5 = ""
36+
CLS.build_dir = ""
37+
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
38+
for parameter in profile['c'] + profile['common']:
39+
assert any(parameter in cmd for cmd in compile_command), \
40+
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
41+
42+
@given(fixed_dictionaries({
43+
'common': lists(text()),
44+
'c': lists(text()),
45+
'cxx': lists(text()),
46+
'asm': lists(text()),
47+
'ld': lists(text())}),
48+
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
49+
)
50+
def test_toolchain_profile_cpp(profile, source_file):
51+
filename = deepcopy(source_file)
52+
filename[-1] += ".cpp"
53+
to_compile = os.path.join(*filename)
54+
for name, Class in TOOLCHAIN_CLASSES.items():
55+
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
56+
CLS.inc_md5 = ""
57+
CLS.build_dir = ""
58+
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
59+
for parameter in profile['cxx'] + profile['common']:
60+
assert any(parameter in cmd for cmd in compile_command), \
61+
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
62+
63+
@given(fixed_dictionaries({
64+
'common': lists(text()),
65+
'c': lists(text()),
66+
'cxx': lists(text()),
67+
'asm': lists(text()),
68+
'ld': lists(text())}),
69+
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
70+
)
71+
def test_toolchain_profile_asm(profile, source_file):
72+
filename = deepcopy(source_file)
73+
filename[-1] += ".s"
74+
to_compile = os.path.join(*filename)
75+
for name, Class in TOOLCHAIN_CLASSES.items():
76+
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
77+
CLS.inc_md5 = ""
78+
CLS.build_dir = ""
79+
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
80+
if not compile_command:
81+
assert compile_command, to_compile
82+
for parameter in profile['asm']:
83+
assert any(parameter in cmd for cmd in compile_command), \
84+
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
85+

tools/toolchains/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ class mbedToolchain:
217217

218218
__metaclass__ = ABCMeta
219219

220+
profile_template = {'common':[], 'c':[], 'cxx':[], 'asm':[], 'ld':[]}
221+
220222
def __init__(self, target, notify=None, macros=None, silent=False, extra_verbose=False, build_profile=None):
221223
self.target = target
222224
self.name = self.__class__.__name__
@@ -225,7 +227,7 @@ def __init__(self, target, notify=None, macros=None, silent=False, extra_verbose
225227
self.hook = hooks.Hook(target, self)
226228

227229
# Toolchain flags
228-
self.flags = deepcopy(build_profile)
230+
self.flags = deepcopy(build_profile or self.profile_template)
229231

230232
# User-defined macros
231233
self.macros = macros or []

0 commit comments

Comments
 (0)