Skip to content

Commit ab8a8de

Browse files
Merge pull request #5317 from theotherjimmy/fix-arm-supported-check
Tools: Check for toolchain and core support for Arm Compilers
2 parents d2b7620 + b0fc103 commit ab8a8de

File tree

2 files changed

+94
-4
lines changed

2 files changed

+94
-4
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Tests for the arm toolchain supported checks"""
2+
import sys
3+
import os
4+
from string import printable
5+
from copy import deepcopy
6+
from mock import MagicMock, patch
7+
from hypothesis import given, settings
8+
from hypothesis.strategies import text, lists, sampled_from
9+
10+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..",
11+
".."))
12+
sys.path.insert(0, ROOT)
13+
14+
from tools.toolchains.arm import ARM_STD, ARM_MICRO, ARMC6
15+
from tools.utils import NotSupportedException
16+
17+
ARMC5_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
18+
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD"]
19+
ARMC6_CORES = ARMC5_CORES + ["Cortex-M23", "Cortex-M23-NS",
20+
"Cortex-M33", "CortexM33-NS"]
21+
22+
CORE_SUF_ALPHA = ["MDFNS02347-+"]
23+
24+
@given(lists(sampled_from(["ARM", "uARM", "GCC_ARM", "ARMC6", "IAR", "GARBAGE"])),
25+
text(alphabet=CORE_SUF_ALPHA))
26+
def test_arm_std(supported_toolchains, core):
27+
mock_target = MagicMock()
28+
mock_target.core = "Cortex-" + core
29+
mock_target.supported_toolchains = supported_toolchains
30+
try:
31+
ARM_STD(mock_target)
32+
assert "ARM" in supported_toolchains
33+
assert mock_target.core in ARMC5_CORES
34+
except NotSupportedException:
35+
assert "ARM" not in supported_toolchains or mock_target.core not in ARMC5_CORES
36+
37+
38+
@given(lists(sampled_from(["ARM", "uARM", "GCC_ARM", "ARMC6", "IAR", "GARBAGE"])),
39+
text(alphabet=CORE_SUF_ALPHA))
40+
def test_arm_micro(supported_toolchains, core):
41+
mock_target = MagicMock()
42+
mock_target.core = "Cortex-" + core
43+
mock_target.supported_toolchains = supported_toolchains
44+
try:
45+
ARM_MICRO(mock_target)
46+
assert "ARM" in supported_toolchains or "uARM" in supported_toolchains
47+
assert mock_target.core in ARMC5_CORES
48+
except NotSupportedException:
49+
assert ("ARM" not in supported_toolchains and "uARM" not in supported_toolchains)\
50+
or mock_target.core not in ARMC5_CORES
51+
52+
53+
@given(lists(sampled_from(["ARM", "uARM", "GCC_ARM", "ARMC6", "IAR", "GARBAGE"])),
54+
text(alphabet=CORE_SUF_ALPHA))
55+
def test_armc6(supported_toolchains, core):
56+
mock_target = MagicMock()
57+
mock_target.core = "Cortex-" + core
58+
mock_target.supported_toolchains = supported_toolchains
59+
try:
60+
ARMC6(mock_target)
61+
assert "ARM" in supported_toolchains or "ARMC6" in supported_toolchains
62+
assert mock_target.core in ARMC6_CORES
63+
except NotSupportedException:
64+
assert ("ARM" not in supported_toolchains and "ARMC6" not in supported_toolchains)\
65+
or mock_target.core not in ARMC6_CORES

tools/toolchains/arm.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class ARM(mbedToolchain):
3333
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
3434
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
3535
SHEBANG = "#! armcc -E"
36+
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
37+
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD"]
3638

3739
@staticmethod
3840
def check_executable():
@@ -48,9 +50,9 @@ def __init__(self, target, notify=None, macros=None,
4850
build_dir=build_dir,
4951
extra_verbose=extra_verbose,
5052
build_profile=build_profile)
51-
52-
if "ARM" not in target.supported_toolchains:
53-
raise NotSupportedException("ARM compiler support is required for ARM build")
53+
if target.core not in self.SUPPORTED_CORES:
54+
raise NotSupportedException(
55+
"this compiler does not support the core %s" % target.core)
5456

5557
if target.core == "Cortex-M0+":
5658
cpu = "Cortex-M0"
@@ -265,19 +267,42 @@ def redirect_symbol(source, sync, build_dir):
265267

266268

267269
class ARM_STD(ARM):
268-
pass
270+
def __init__(self, target, notify=None, macros=None,
271+
silent=False, extra_verbose=False, build_profile=None,
272+
build_dir=None):
273+
ARM.__init__(self, target, notify, macros, silent,
274+
build_dir=build_dir, extra_verbose=extra_verbose,
275+
build_profile=build_profile)
276+
if "ARM" not in target.supported_toolchains:
277+
raise NotSupportedException("ARM compiler support is required for ARM build")
278+
269279

270280
class ARM_MICRO(ARM):
271281
PATCHED_LIBRARY = False
282+
def __init__(self, target, notify=None, macros=None,
283+
silent=False, extra_verbose=False, build_profile=None,
284+
build_dir=None):
285+
ARM.__init__(self, target, notify, macros, silent,
286+
build_dir=build_dir, extra_verbose=extra_verbose,
287+
build_profile=build_profile)
288+
if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
289+
raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
272290

273291
class ARMC6(ARM_STD):
274292
SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c"
293+
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
294+
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
295+
"Cortex-M23", "Cortex-M23-NS", "Cortex-M33",
296+
"CortexM33-NS"]
275297
@staticmethod
276298
def check_executable():
277299
return mbedToolchain.generic_check_executable("ARMC6", "armclang", 1)
278300

279301
def __init__(self, target, *args, **kwargs):
280302
mbedToolchain.__init__(self, target, *args, **kwargs)
303+
if target.core not in self.SUPPORTED_CORES:
304+
raise NotSupportedException(
305+
"this compiler does not support the core %s" % target.core)
281306

282307
if not set(("ARM", "ARMC6")).intersection(set(target.supported_toolchains)):
283308
raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build")

0 commit comments

Comments
 (0)