Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
test/toolchains/api.py@35:da9c89f8be7d, 2017-02-15 (annotated)
- Committer:
- The Other Jimmy
- Date:
- Wed Feb 15 13:53:18 2017 -0600
- Revision:
- 35:da9c89f8be7d
- Parent:
- 31:8ea194f6145b
Update tools to mbed-os 5.3.5
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| The Other Jimmy |
31:8ea194f6145b | 1 | """Tests for the toolchain sub-system""" |
| screamer | 25:aef6536015e3 | 2 | import sys |
| screamer | 25:aef6536015e3 | 3 | import os |
| The Other Jimmy |
31:8ea194f6145b | 4 | from string import printable |
| The Other Jimmy |
31:8ea194f6145b | 5 | from copy import deepcopy |
| The Other Jimmy |
31:8ea194f6145b | 6 | from mock import MagicMock, patch |
| The Other Jimmy |
31:8ea194f6145b | 7 | from hypothesis import given |
| The Other Jimmy |
31:8ea194f6145b | 8 | from hypothesis.strategies import text, lists, fixed_dictionaries |
| screamer | 25:aef6536015e3 | 9 | |
| The Other Jimmy |
31:8ea194f6145b | 10 | ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", |
| The Other Jimmy |
31:8ea194f6145b | 11 | "..")) |
| screamer | 25:aef6536015e3 | 12 | sys.path.insert(0, ROOT) |
| screamer | 25:aef6536015e3 | 13 | |
| The Other Jimmy |
31:8ea194f6145b | 14 | from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES,\ |
| The Other Jimmy |
31:8ea194f6145b | 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:8ea194f6145b | 19 | """Test that all exported toolchain may be instantiated""" |
| The Other Jimmy |
31:8ea194f6145b | 20 | for name, tc_class in TOOLCHAIN_CLASSES.items(): |
| The Other Jimmy |
31:8ea194f6145b | 21 | cls = tc_class(TARGET_MAP["K64F"]) |
| The Other Jimmy |
31:8ea194f6145b | 22 | assert name == cls.name or\ |
| The Other Jimmy |
31:8ea194f6145b | 23 | name == LEGACY_TOOLCHAIN_NAMES[cls.name] |
| The Other Jimmy |
31:8ea194f6145b | 24 | |
| The Other Jimmy |
31:8ea194f6145b | 25 | ALPHABET = [char for char in printable if char not in [u'.', u'/']] |
| The Other Jimmy |
31:8ea194f6145b | 26 | |
| The Other Jimmy |
31:8ea194f6145b | 27 | @given(fixed_dictionaries({ |
| The Other Jimmy |
31:8ea194f6145b | 28 | 'common': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 29 | 'c': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 30 | 'cxx': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 31 | 'asm': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 32 | 'ld': lists(text())}), |
| The Other Jimmy |
31:8ea194f6145b | 33 | lists(text(min_size=1, alphabet=ALPHABET), min_size=1)) |
| The Other Jimmy |
31:8ea194f6145b | 34 | def test_toolchain_profile_c(profile, source_file): |
| The Other Jimmy |
31:8ea194f6145b | 35 | """Test that the appropriate profile parameters are passed to the |
| The Other Jimmy |
31:8ea194f6145b | 36 | C compiler""" |
| The Other Jimmy |
31:8ea194f6145b | 37 | filename = deepcopy(source_file) |
| The Other Jimmy |
31:8ea194f6145b | 38 | filename[-1] += ".c" |
| The Other Jimmy |
31:8ea194f6145b | 39 | to_compile = os.path.join(*filename) |
| The Other Jimmy |
31:8ea194f6145b | 40 | with patch('os.mkdir') as _mkdir: |
| The Other Jimmy |
31:8ea194f6145b | 41 | for _, tc_class in TOOLCHAIN_CLASSES.items(): |
| The Other Jimmy |
31:8ea194f6145b | 42 | toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile) |
| The Other Jimmy |
31:8ea194f6145b | 43 | toolchain.inc_md5 = "" |
| The Other Jimmy |
31:8ea194f6145b | 44 | toolchain.build_dir = "" |
| The Other Jimmy |
31:8ea194f6145b | 45 | compile_command = toolchain.compile_command(to_compile, |
| The Other Jimmy |
31:8ea194f6145b | 46 | to_compile + ".o", []) |
| The Other Jimmy |
31:8ea194f6145b | 47 | for parameter in profile['c'] + profile['common']: |
| The Other Jimmy |
31:8ea194f6145b | 48 | assert any(parameter in cmd for cmd in compile_command), \ |
| The Other Jimmy |
31:8ea194f6145b | 49 | "Toolchain %s did not propigate arg %s" % (toolchain.name, |
| The Other Jimmy |
31:8ea194f6145b | 50 | parameter) |
| The Other Jimmy |
31:8ea194f6145b | 51 | |
| The Other Jimmy |
31:8ea194f6145b | 52 | @given(fixed_dictionaries({ |
| The Other Jimmy |
31:8ea194f6145b | 53 | 'common': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 54 | 'c': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 55 | 'cxx': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 56 | 'asm': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 57 | 'ld': lists(text())}), |
| The Other Jimmy |
31:8ea194f6145b | 58 | lists(text(min_size=1, alphabet=ALPHABET), min_size=1)) |
| The Other Jimmy |
31:8ea194f6145b | 59 | def test_toolchain_profile_cpp(profile, source_file): |
| The Other Jimmy |
31:8ea194f6145b | 60 | """Test that the appropriate profile parameters are passed to the |
| The Other Jimmy |
31:8ea194f6145b | 61 | C++ compiler""" |
| The Other Jimmy |
31:8ea194f6145b | 62 | filename = deepcopy(source_file) |
| The Other Jimmy |
31:8ea194f6145b | 63 | filename[-1] += ".cpp" |
| The Other Jimmy |
31:8ea194f6145b | 64 | to_compile = os.path.join(*filename) |
| The Other Jimmy |
31:8ea194f6145b | 65 | with patch('os.mkdir') as _mkdir: |
| The Other Jimmy |
31:8ea194f6145b | 66 | for _, tc_class in TOOLCHAIN_CLASSES.items(): |
| The Other Jimmy |
31:8ea194f6145b | 67 | toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile) |
| The Other Jimmy |
31:8ea194f6145b | 68 | toolchain.inc_md5 = "" |
| The Other Jimmy |
31:8ea194f6145b | 69 | toolchain.build_dir = "" |
| The Other Jimmy |
31:8ea194f6145b | 70 | compile_command = toolchain.compile_command(to_compile, |
| The Other Jimmy |
31:8ea194f6145b | 71 | to_compile + ".o", []) |
| The Other Jimmy |
31:8ea194f6145b | 72 | for parameter in profile['cxx'] + profile['common']: |
| The Other Jimmy |
31:8ea194f6145b | 73 | assert any(parameter in cmd for cmd in compile_command), \ |
| The Other Jimmy |
31:8ea194f6145b | 74 | "Toolchain %s did not propigate arg %s" % (toolchain.name, |
| The Other Jimmy |
31:8ea194f6145b | 75 | parameter) |
| The Other Jimmy |
31:8ea194f6145b | 76 | |
| The Other Jimmy |
31:8ea194f6145b | 77 | @given(fixed_dictionaries({ |
| The Other Jimmy |
31:8ea194f6145b | 78 | 'common': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 79 | 'c': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 80 | 'cxx': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 81 | 'asm': lists(text()), |
| The Other Jimmy |
31:8ea194f6145b | 82 | 'ld': lists(text())}), |
| The Other Jimmy |
31:8ea194f6145b | 83 | lists(text(min_size=1, alphabet=ALPHABET), min_size=1)) |
| The Other Jimmy |
31:8ea194f6145b | 84 | def test_toolchain_profile_asm(profile, source_file): |
| The Other Jimmy |
31:8ea194f6145b | 85 | """Test that the appropriate profile parameters are passed to the |
| The Other Jimmy |
31:8ea194f6145b | 86 | Assembler""" |
| The Other Jimmy |
31:8ea194f6145b | 87 | filename = deepcopy(source_file) |
| The Other Jimmy |
31:8ea194f6145b | 88 | filename[-1] += ".s" |
| The Other Jimmy |
31:8ea194f6145b | 89 | to_compile = os.path.join(*filename) |
| The Other Jimmy |
31:8ea194f6145b | 90 | with patch('os.mkdir') as _mkdir: |
| The Other Jimmy |
31:8ea194f6145b | 91 | for _, tc_class in TOOLCHAIN_CLASSES.items(): |
| The Other Jimmy |
31:8ea194f6145b | 92 | toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile) |
| The Other Jimmy |
31:8ea194f6145b | 93 | toolchain.inc_md5 = "" |
| The Other Jimmy |
31:8ea194f6145b | 94 | toolchain.build_dir = "" |
| The Other Jimmy |
31:8ea194f6145b | 95 | compile_command = toolchain.compile_command(to_compile, |
| The Other Jimmy |
31:8ea194f6145b | 96 | to_compile + ".o", []) |
| The Other Jimmy |
31:8ea194f6145b | 97 | if not compile_command: |
| The Other Jimmy |
31:8ea194f6145b | 98 | assert compile_command, to_compile |
| The Other Jimmy |
31:8ea194f6145b | 99 | for parameter in profile['asm']: |
| The Other Jimmy |
31:8ea194f6145b | 100 | assert any(parameter in cmd for cmd in compile_command), \ |
| The Other Jimmy |
31:8ea194f6145b | 101 | "Toolchain %s did not propigate arg %s" % (toolchain.name, |
| The Other Jimmy |
31:8ea194f6145b | 102 | parameter) |
| The Other Jimmy |
31:8ea194f6145b | 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:8ea194f6145b | 107 | |
| The Other Jimmy |
31:8ea194f6145b | 108 | |
| The Other Jimmy |
31:8ea194f6145b | 109 | @given(lists(text(alphabet=ALPHABET, min_size=1), min_size=1)) |
| The Other Jimmy |
31:8ea194f6145b | 110 | def test_detect_duplicates(filenames): |
| The Other Jimmy |
31:8ea194f6145b | 111 | c_sources = [os.path.join(name, "dupe.c") for name in filenames] |
| The Other Jimmy |
31:8ea194f6145b | 112 | s_sources = [os.path.join(name, "dupe.s") for name in filenames] |
| The Other Jimmy |
31:8ea194f6145b | 113 | cpp_sources = [os.path.join(name, "dupe.cpp") for name in filenames] |
| The Other Jimmy |
31:8ea194f6145b | 114 | with MagicMock() as notify: |
| The Other Jimmy |
31:8ea194f6145b | 115 | toolchain = TOOLCHAIN_CLASSES["ARM"](TARGET_MAP["K64F"], notify=notify) |
| The Other Jimmy |
31:8ea194f6145b | 116 | res = Resources() |
| The Other Jimmy |
31:8ea194f6145b | 117 | res.c_sources = c_sources |
| The Other Jimmy |
31:8ea194f6145b | 118 | res.s_sources = s_sources |
| The Other Jimmy |
31:8ea194f6145b | 119 | res.cpp_sources = cpp_sources |
| The Other Jimmy |
31:8ea194f6145b | 120 | assert res.detect_duplicates(toolchain) == 1,\ |
| The Other Jimmy |
31:8ea194f6145b | 121 | "Not Enough duplicates found" |
| The Other Jimmy |
31:8ea194f6145b | 122 | |
| The Other Jimmy |
31:8ea194f6145b | 123 | _, (notification, _), _ = notify.mock_calls[1] |
| The Other Jimmy |
31:8ea194f6145b | 124 | assert "dupe.o" in notification["message"] |
| The Other Jimmy |
31:8ea194f6145b | 125 | assert "dupe.s" in notification["message"] |
| The Other Jimmy |
31:8ea194f6145b | 126 | assert "dupe.c" in notification["message"] |
| The Other Jimmy |
31:8ea194f6145b | 127 | assert "dupe.cpp" in notification["message"] |