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