Skip to content

Commit 9b92105

Browse files
committed
Replace small with std C lib if not supported by a target's toolchain
Display a post-build warning indicating to the user that the standard C library was used instead of the small C library if the former is not supported.
1 parent 62b8121 commit 9b92105

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

tools/test/toolchains/test_toolchains.py

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ def test_arm_c_lib_std_exception(self):
8383

8484

8585
def test_arm_c_lib_small_exception(self):
86-
"""Test that an exception is raised if the small C library is not supported for a target on the ARM toolchain."""
86+
"""Test that an exception is raised if the small and std C library are not supported for a target on the ARM toolchain."""
8787
mock_target = mock.MagicMock()
8888
mock_target.core = "Cortex-M4"
8989
mock_target.c_lib = "small"
9090
del mock_target.default_lib
91-
mock_target.supported_c_libs = {"arm": ["std"]}
91+
mock_target.supported_c_libs = {"arm": [""]}
9292
mock_target.default_toolchain = "ARM"
9393
mock_target.supported_toolchains = ["ARM", "uARM", "ARMC5"]
9494
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
@@ -97,6 +97,27 @@ def test_arm_c_lib_small_exception(self):
9797
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
9898
ARMC6(mock_target)
9999

100+
def test_arm_small_c_lib_swap_std_lib(self):
101+
"""Test that no exception is raised when small c lib is not supported but std lib is supported."""
102+
mock_target = mock.MagicMock()
103+
mock_target.core = "Cortex-M4"
104+
mock_target.c_lib = "small"
105+
del mock_target.default_lib
106+
mock_target.supported_c_libs = {"arm": ["std"]}
107+
mock_target.supported_toolchains = ["ARM", "uARM", "ARMC5"]
108+
109+
mock_target.default_toolchain = "ARM"
110+
try:
111+
ARM_STD(mock_target)
112+
except NotSupportedException:
113+
self.fail(UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib))
114+
115+
mock_target.default_toolchain = "ARMC6"
116+
try:
117+
ARMC6(mock_target)
118+
except NotSupportedException:
119+
self.fail(UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib))
120+
100121
class TestGccToolchain(TestCase):
101122
"""Test the GCC class."""
102123

@@ -147,25 +168,39 @@ def test_gcc_arm_c_lib_std_exception(self):
147168
"""Test that an exception is raised if the std C library is not supported for a target on the GCC_ARM toolchain."""
148169
mock_target = mock.MagicMock()
149170
mock_target.core = "Cortex-M4"
150-
mock_target.default_toolchain = "ARM"
171+
mock_target.default_toolchain = "GCC_ARM"
151172
mock_target.c_lib = "std"
152173
del mock_target.default_lib
153-
mock_target.supported_c_libs = {"arm": ["small"]}
174+
mock_target.supported_c_libs = {"gcc_arm": ["small"]}
154175
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
155176
GCC_ARM(mock_target)
156177

157178
def test_gcc_arm_c_lib_small_exception(self):
158-
"""Test that an exception is raised if the small C library is not supported for a target on the GCC_ARM toolchain."""
179+
"""Test that an exception is raised if the small and std C library are not supported for a target on the GCC_ARM toolchain."""
159180
mock_target = mock.MagicMock()
160181
mock_target.core = "Cortex-M4"
161182
mock_target.c_lib = "small"
162183
del mock_target.default_lib
163-
mock_target.supported_c_libs = {"arm": ["std"]}
164-
mock_target.default_toolchain = "ARM"
165-
mock_target.supported_toolchains = ["ARM", "uARM", "ARMC5"]
184+
mock_target.supported_c_libs = {"gcc_arm": [""]}
185+
mock_target.default_toolchain = "GCC_ARM"
186+
mock_target.supported_toolchains = ["GCC_ARM"]
166187
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
167188
GCC_ARM(mock_target)
168189

190+
def test_gcc_arm_small_c_lib_swap_std_lib(self):
191+
"""Test that no exception is raised when small c lib is not supported but std lib is supported."""
192+
mock_target = mock.MagicMock()
193+
mock_target.core = "Cortex-M4"
194+
mock_target.supported_c_libs = {"gcc_arm": ["std"]}
195+
mock_target.c_lib = "small"
196+
del mock_target.default_lib
197+
mock_target.supported_toolchains = ["GCC_ARM"]
198+
mock_target.is_TrustZone_secure_target = False
199+
mock_target.default_toolchain = "GCC_ARM"
200+
try:
201+
GCC_ARM(mock_target)
202+
except NotSupportedException:
203+
self.fail(UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib))
169204
class TestIarToolchain(TestCase):
170205
"""Test the IAR class."""
171206

@@ -210,12 +245,26 @@ def test_iar_c_lib_std_exception(self):
210245
IAR(mock_target)
211246

212247
def test_iar_c_lib_small_exception(self):
213-
"""Test that an exception is raised if the small C library is not supported for a target on the IAR toolchain."""
248+
"""Test that an exception is raised if the small and std C library are not supported for a target on the IAR toolchain."""
214249
mock_target = mock.MagicMock()
215250
mock_target.core = "Cortex-M4"
216251
mock_target.c_lib = "small"
217252
del mock_target.default_lib
218-
mock_target.supported_c_libs = {"iar": ["std"]}
253+
mock_target.supported_c_libs = {"iar": [""]}
219254
mock_target.supported_toolchains = ["IAR"]
220255
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
221256
IAR(mock_target)
257+
258+
def test_iar_small_c_lib_swap_std_lib(self):
259+
"""Test that no exception is raised when small c lib is not supported but std lib is supported."""
260+
mock_target = mock.MagicMock()
261+
mock_target.core = "Cortex-M4"
262+
mock_target.supported_c_libs = {"iar": ["std"]}
263+
mock_target.c_lib = "small"
264+
del mock_target.default_lib
265+
mock_target.supported_toolchains = ["IAR"]
266+
mock_target.is_TrustZone_secure_target = False
267+
try:
268+
IAR(mock_target)
269+
except NotSupportedException:
270+
self.fail(UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib))

0 commit comments

Comments
 (0)