Fix style of implementation of toolchain profiles

pull/2802/head
Jimmy Brisson 2016-09-27 18:36:30 -05:00
parent c86ad6646d
commit 73e811a9a0
2 changed files with 49 additions and 29 deletions

View File

@ -84,7 +84,14 @@ def get_default_options_parser(add_clean=True, add_options=True,
def extract_profile(parser, options, toolchain):
profile = { 'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []}
"""Extract a Toolchain profile from parsed options
Positional arguments:
parser - parser used to parse the command line arguments
options - The parsed command line arguments
toolchain - the toolchain that the profile should be extracted for
"""
profile = {'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []}
filenames = options.profile or [join(dirname(__file__), "profiles",
"default.json")]
for filename in filenames:

View File

@ -1,3 +1,4 @@
"""Tests for the toolchain sub-system"""
import sys
import os
from string import printable
@ -5,16 +6,19 @@ from copy import deepcopy
from hypothesis import given
from hypothesis.strategies import text, lists, fixed_dictionaries
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..",
".."))
sys.path.insert(0, ROOT)
from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES
from tools.targets import TARGET_MAP
def test_instantiation():
for name, Class in TOOLCHAIN_CLASSES.items():
CLS = Class(TARGET_MAP["K64F"])
assert name == CLS.name or name == LEGACY_TOOLCHAIN_NAMES[CLS.name]
"""Test that all exported toolchain may be instantiated"""
for name, tc_class in TOOLCHAIN_CLASSES.items():
cls = tc_class(TARGET_MAP["K64F"])
assert name == cls.name or\
name == LEGACY_TOOLCHAIN_NAMES[cls.name]
ALPHABET = [char for char in printable if char not in [u'.', u'/']]
@ -24,20 +28,23 @@ ALPHABET = [char for char in printable if char not in [u'.', u'/']]
'cxx': lists(text()),
'asm': lists(text()),
'ld': lists(text())}),
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
)
lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
def test_toolchain_profile_c(profile, source_file):
"""Test that the appropriate profile parameters are passed to the
C compiler"""
filename = deepcopy(source_file)
filename[-1] += ".c"
to_compile = os.path.join(*filename)
for name, Class in TOOLCHAIN_CLASSES.items():
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
CLS.inc_md5 = ""
CLS.build_dir = ""
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
for _, tc_class in TOOLCHAIN_CLASSES.items():
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
toolchain.inc_md5 = ""
toolchain.build_dir = ""
compile_command = toolchain.compile_command(to_compile,
to_compile + ".o", [])
for parameter in profile['c'] + profile['common']:
assert any(parameter in cmd for cmd in compile_command), \
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
"Toolchain %s did not propigate arg %s" % (toolchain.name,
parameter)
@given(fixed_dictionaries({
'common': lists(text()),
@ -45,20 +52,23 @@ def test_toolchain_profile_c(profile, source_file):
'cxx': lists(text()),
'asm': lists(text()),
'ld': lists(text())}),
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
)
lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
def test_toolchain_profile_cpp(profile, source_file):
"""Test that the appropriate profile parameters are passed to the
C++ compiler"""
filename = deepcopy(source_file)
filename[-1] += ".cpp"
to_compile = os.path.join(*filename)
for name, Class in TOOLCHAIN_CLASSES.items():
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
CLS.inc_md5 = ""
CLS.build_dir = ""
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
for _, tc_class in TOOLCHAIN_CLASSES.items():
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
toolchain.inc_md5 = ""
toolchain.build_dir = ""
compile_command = toolchain.compile_command(to_compile,
to_compile + ".o", [])
for parameter in profile['cxx'] + profile['common']:
assert any(parameter in cmd for cmd in compile_command), \
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
"Toolchain %s did not propigate arg %s" % (toolchain.name,
parameter)
@given(fixed_dictionaries({
'common': lists(text()),
@ -66,20 +76,23 @@ def test_toolchain_profile_cpp(profile, source_file):
'cxx': lists(text()),
'asm': lists(text()),
'ld': lists(text())}),
lists(text(min_size=1, alphabet=ALPHABET), min_size=1)
)
lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
def test_toolchain_profile_asm(profile, source_file):
"""Test that the appropriate profile parameters are passed to the
Assembler"""
filename = deepcopy(source_file)
filename[-1] += ".s"
to_compile = os.path.join(*filename)
for name, Class in TOOLCHAIN_CLASSES.items():
CLS = Class(TARGET_MAP["K64F"], build_profile=profile)
CLS.inc_md5 = ""
CLS.build_dir = ""
compile_command = CLS.compile_command(to_compile, to_compile + ".o", [])
for _, tc_class in TOOLCHAIN_CLASSES.items():
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
toolchain.inc_md5 = ""
toolchain.build_dir = ""
compile_command = toolchain.compile_command(to_compile,
to_compile + ".o", [])
if not compile_command:
assert compile_command, to_compile
for parameter in profile['asm']:
assert any(parameter in cmd for cmd in compile_command), \
"Toolchain %s did not propigate arg %s" % (CLS.name, parameter)
"Toolchain %s did not propigate arg %s" % (toolchain.name,
parameter)