Skip to content

Tools: Check for toolchain and core support for Arm Compilers #5317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tools/test/toolchains/arm_support_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Tests for the arm toolchain supported checks"""
import sys
import os
from string import printable
from copy import deepcopy
from mock import MagicMock, patch
from hypothesis import given, settings
from hypothesis.strategies import text, lists, sampled_from

ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..",
".."))
sys.path.insert(0, ROOT)

from tools.toolchains.arm import ARM_STD, ARM_MICRO, ARMC6
from tools.utils import NotSupportedException

ARMC5_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD"]
ARMC6_CORES = ARMC5_CORES + ["Cortex-M23", "Cortex-M23-NS",
"Cortex-M33", "CortexM33-NS"]

CORE_SUF_ALPHA = ["MDFNS02347-+"]

@given(lists(sampled_from(["ARM", "uARM", "GCC_ARM", "ARMC6", "IAR", "GARBAGE"])),
text(alphabet=CORE_SUF_ALPHA))
def test_arm_std(supported_toolchains, core):
mock_target = MagicMock()
mock_target.core = "Cortex-" + core
mock_target.supported_toolchains = supported_toolchains
try:
ARM_STD(mock_target)
assert "ARM" in supported_toolchains
assert mock_target.core in ARMC5_CORES
except NotSupportedException:
assert "ARM" not in supported_toolchains or mock_target.core not in ARMC5_CORES


@given(lists(sampled_from(["ARM", "uARM", "GCC_ARM", "ARMC6", "IAR", "GARBAGE"])),
text(alphabet=CORE_SUF_ALPHA))
def test_arm_micro(supported_toolchains, core):
mock_target = MagicMock()
mock_target.core = "Cortex-" + core
mock_target.supported_toolchains = supported_toolchains
try:
ARM_MICRO(mock_target)
assert "ARM" in supported_toolchains or "uARM" in supported_toolchains
assert mock_target.core in ARMC5_CORES
except NotSupportedException:
assert ("ARM" not in supported_toolchains and "uARM" not in supported_toolchains)\
or mock_target.core not in ARMC5_CORES


@given(lists(sampled_from(["ARM", "uARM", "GCC_ARM", "ARMC6", "IAR", "GARBAGE"])),
text(alphabet=CORE_SUF_ALPHA))
def test_armc6(supported_toolchains, core):
mock_target = MagicMock()
mock_target.core = "Cortex-" + core
mock_target.supported_toolchains = supported_toolchains
try:
ARMC6(mock_target)
assert "ARM" in supported_toolchains or "ARMC6" in supported_toolchains
assert mock_target.core in ARMC6_CORES
except NotSupportedException:
assert ("ARM" not in supported_toolchains and "ARMC6" not in supported_toolchains)\
or mock_target.core not in ARMC6_CORES
33 changes: 29 additions & 4 deletions tools/toolchains/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ARM(mbedToolchain):
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
SHEBANG = "#! armcc -E"
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD"]

@staticmethod
def check_executable():
Expand All @@ -48,9 +50,9 @@ def __init__(self, target, notify=None, macros=None,
build_dir=build_dir,
extra_verbose=extra_verbose,
build_profile=build_profile)

if "ARM" not in target.supported_toolchains:
raise NotSupportedException("ARM compiler support is required for ARM build")
if target.core not in self.SUPPORTED_CORES:
raise NotSupportedException(
"this compiler does not support the core %s" % target.core)

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


class ARM_STD(ARM):
pass
def __init__(self, target, notify=None, macros=None,
silent=False, extra_verbose=False, build_profile=None,
build_dir=None):
ARM.__init__(self, target, notify, macros, silent,
build_dir=build_dir, extra_verbose=extra_verbose,
build_profile=build_profile)
if "ARM" not in target.supported_toolchains:
raise NotSupportedException("ARM compiler support is required for ARM build")


class ARM_MICRO(ARM):
PATCHED_LIBRARY = False
def __init__(self, target, notify=None, macros=None,
silent=False, extra_verbose=False, build_profile=None,
build_dir=None):
ARM.__init__(self, target, notify, macros, silent,
build_dir=build_dir, extra_verbose=extra_verbose,
build_profile=build_profile)
if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
raise NotSupportedException("ARM/uARM compiler support is required for ARM build")

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

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

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