the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
31:182518299918
Parent:
25:aef6536015e3
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 31:182518299918 1 """Tests for the toolchain sub-system"""
screamer 25:aef6536015e3 2 import sys
screamer 25:aef6536015e3 3 import os
The Other Jimmy 31:182518299918 4 from string import printable
The Other Jimmy 31:182518299918 5 from copy import deepcopy
The Other Jimmy 31:182518299918 6 from mock import MagicMock, patch
The Other Jimmy 31:182518299918 7 from hypothesis import given
The Other Jimmy 31:182518299918 8 from hypothesis.strategies import text, lists, fixed_dictionaries
screamer 25:aef6536015e3 9
The Other Jimmy 31:182518299918 10 ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..",
The Other Jimmy 31:182518299918 11 ".."))
screamer 25:aef6536015e3 12 sys.path.insert(0, ROOT)
screamer 25:aef6536015e3 13
The Other Jimmy 31:182518299918 14 from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES,\
The Other Jimmy 31:182518299918 15 Resources
screamer 25:aef6536015e3 16 from tools.targets import TARGET_MAP
screamer 25:aef6536015e3 17
screamer 25:aef6536015e3 18 def test_instantiation():
The Other Jimmy 31:182518299918 19 """Test that all exported toolchain may be instantiated"""
The Other Jimmy 31:182518299918 20 for name, tc_class in TOOLCHAIN_CLASSES.items():
The Other Jimmy 31:182518299918 21 cls = tc_class(TARGET_MAP["K64F"])
The Other Jimmy 31:182518299918 22 assert name == cls.name or\
The Other Jimmy 31:182518299918 23 name == LEGACY_TOOLCHAIN_NAMES[cls.name]
The Other Jimmy 31:182518299918 24
The Other Jimmy 31:182518299918 25 ALPHABET = [char for char in printable if char not in [u'.', u'/']]
The Other Jimmy 31:182518299918 26
The Other Jimmy 31:182518299918 27 @given(fixed_dictionaries({
The Other Jimmy 31:182518299918 28 'common': lists(text()),
The Other Jimmy 31:182518299918 29 'c': lists(text()),
The Other Jimmy 31:182518299918 30 'cxx': lists(text()),
The Other Jimmy 31:182518299918 31 'asm': lists(text()),
The Other Jimmy 31:182518299918 32 'ld': lists(text())}),
The Other Jimmy 31:182518299918 33 lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
The Other Jimmy 31:182518299918 34 def test_toolchain_profile_c(profile, source_file):
The Other Jimmy 31:182518299918 35 """Test that the appropriate profile parameters are passed to the
The Other Jimmy 31:182518299918 36 C compiler"""
The Other Jimmy 31:182518299918 37 filename = deepcopy(source_file)
The Other Jimmy 31:182518299918 38 filename[-1] += ".c"
The Other Jimmy 31:182518299918 39 to_compile = os.path.join(*filename)
The Other Jimmy 31:182518299918 40 with patch('os.mkdir') as _mkdir:
The Other Jimmy 31:182518299918 41 for _, tc_class in TOOLCHAIN_CLASSES.items():
The Other Jimmy 31:182518299918 42 toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
The Other Jimmy 31:182518299918 43 toolchain.inc_md5 = ""
The Other Jimmy 31:182518299918 44 toolchain.build_dir = ""
The Other Jimmy 31:182518299918 45 compile_command = toolchain.compile_command(to_compile,
The Other Jimmy 31:182518299918 46 to_compile + ".o", [])
The Other Jimmy 31:182518299918 47 for parameter in profile['c'] + profile['common']:
The Other Jimmy 31:182518299918 48 assert any(parameter in cmd for cmd in compile_command), \
The Other Jimmy 31:182518299918 49 "Toolchain %s did not propigate arg %s" % (toolchain.name,
The Other Jimmy 31:182518299918 50 parameter)
The Other Jimmy 31:182518299918 51
The Other Jimmy 31:182518299918 52 @given(fixed_dictionaries({
The Other Jimmy 31:182518299918 53 'common': lists(text()),
The Other Jimmy 31:182518299918 54 'c': lists(text()),
The Other Jimmy 31:182518299918 55 'cxx': lists(text()),
The Other Jimmy 31:182518299918 56 'asm': lists(text()),
The Other Jimmy 31:182518299918 57 'ld': lists(text())}),
The Other Jimmy 31:182518299918 58 lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
The Other Jimmy 31:182518299918 59 def test_toolchain_profile_cpp(profile, source_file):
The Other Jimmy 31:182518299918 60 """Test that the appropriate profile parameters are passed to the
The Other Jimmy 31:182518299918 61 C++ compiler"""
The Other Jimmy 31:182518299918 62 filename = deepcopy(source_file)
The Other Jimmy 31:182518299918 63 filename[-1] += ".cpp"
The Other Jimmy 31:182518299918 64 to_compile = os.path.join(*filename)
The Other Jimmy 31:182518299918 65 with patch('os.mkdir') as _mkdir:
The Other Jimmy 31:182518299918 66 for _, tc_class in TOOLCHAIN_CLASSES.items():
The Other Jimmy 31:182518299918 67 toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
The Other Jimmy 31:182518299918 68 toolchain.inc_md5 = ""
The Other Jimmy 31:182518299918 69 toolchain.build_dir = ""
The Other Jimmy 31:182518299918 70 compile_command = toolchain.compile_command(to_compile,
The Other Jimmy 31:182518299918 71 to_compile + ".o", [])
The Other Jimmy 31:182518299918 72 for parameter in profile['cxx'] + profile['common']:
The Other Jimmy 31:182518299918 73 assert any(parameter in cmd for cmd in compile_command), \
The Other Jimmy 31:182518299918 74 "Toolchain %s did not propigate arg %s" % (toolchain.name,
The Other Jimmy 31:182518299918 75 parameter)
The Other Jimmy 31:182518299918 76
The Other Jimmy 31:182518299918 77 @given(fixed_dictionaries({
The Other Jimmy 31:182518299918 78 'common': lists(text()),
The Other Jimmy 31:182518299918 79 'c': lists(text()),
The Other Jimmy 31:182518299918 80 'cxx': lists(text()),
The Other Jimmy 31:182518299918 81 'asm': lists(text()),
The Other Jimmy 31:182518299918 82 'ld': lists(text())}),
The Other Jimmy 31:182518299918 83 lists(text(min_size=1, alphabet=ALPHABET), min_size=1))
The Other Jimmy 31:182518299918 84 def test_toolchain_profile_asm(profile, source_file):
The Other Jimmy 31:182518299918 85 """Test that the appropriate profile parameters are passed to the
The Other Jimmy 31:182518299918 86 Assembler"""
The Other Jimmy 31:182518299918 87 filename = deepcopy(source_file)
The Other Jimmy 31:182518299918 88 filename[-1] += ".s"
The Other Jimmy 31:182518299918 89 to_compile = os.path.join(*filename)
The Other Jimmy 31:182518299918 90 with patch('os.mkdir') as _mkdir:
The Other Jimmy 31:182518299918 91 for _, tc_class in TOOLCHAIN_CLASSES.items():
The Other Jimmy 31:182518299918 92 toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
The Other Jimmy 31:182518299918 93 toolchain.inc_md5 = ""
The Other Jimmy 31:182518299918 94 toolchain.build_dir = ""
The Other Jimmy 31:182518299918 95 compile_command = toolchain.compile_command(to_compile,
The Other Jimmy 31:182518299918 96 to_compile + ".o", [])
The Other Jimmy 31:182518299918 97 if not compile_command:
The Other Jimmy 31:182518299918 98 assert compile_command, to_compile
The Other Jimmy 31:182518299918 99 for parameter in profile['asm']:
The Other Jimmy 31:182518299918 100 assert any(parameter in cmd for cmd in compile_command), \
The Other Jimmy 31:182518299918 101 "Toolchain %s did not propigate arg %s" % (toolchain.name,
The Other Jimmy 31:182518299918 102 parameter)
The Other Jimmy 31:182518299918 103
screamer 25:aef6536015e3 104 for name, Class in TOOLCHAIN_CLASSES.items():
screamer 25:aef6536015e3 105 CLS = Class(TARGET_MAP["K64F"])
screamer 25:aef6536015e3 106 assert name == CLS.name or name == LEGACY_TOOLCHAIN_NAMES[CLS.name]
The Other Jimmy 31:182518299918 107
The Other Jimmy 31:182518299918 108
The Other Jimmy 31:182518299918 109 @given(lists(text(alphabet=ALPHABET, min_size=1), min_size=1))
The Other Jimmy 31:182518299918 110 def test_detect_duplicates(filenames):
The Other Jimmy 31:182518299918 111 c_sources = [os.path.join(name, "dupe.c") for name in filenames]
The Other Jimmy 31:182518299918 112 s_sources = [os.path.join(name, "dupe.s") for name in filenames]
The Other Jimmy 31:182518299918 113 cpp_sources = [os.path.join(name, "dupe.cpp") for name in filenames]
The Other Jimmy 31:182518299918 114 with MagicMock() as notify:
The Other Jimmy 31:182518299918 115 toolchain = TOOLCHAIN_CLASSES["ARM"](TARGET_MAP["K64F"], notify=notify)
The Other Jimmy 31:182518299918 116 res = Resources()
The Other Jimmy 31:182518299918 117 res.c_sources = c_sources
The Other Jimmy 31:182518299918 118 res.s_sources = s_sources
The Other Jimmy 31:182518299918 119 res.cpp_sources = cpp_sources
The Other Jimmy 31:182518299918 120 assert res.detect_duplicates(toolchain) == 1,\
The Other Jimmy 31:182518299918 121 "Not Enough duplicates found"
The Other Jimmy 31:182518299918 122
The Other Jimmy 31:182518299918 123 _, (notification, _), _ = notify.mock_calls[1]
The Other Jimmy 31:182518299918 124 assert "dupe.o" in notification["message"]
The Other Jimmy 31:182518299918 125 assert "dupe.s" in notification["message"]
The Other Jimmy 31:182518299918 126 assert "dupe.c" in notification["message"]
The Other Jimmy 31:182518299918 127 assert "dupe.cpp" in notification["message"]