blob: a97ee5724303fd9e81d4f947886a074fdf6fa462 [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# components-platform.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
Minos Galanakis609f7492024-07-31 16:39:28 +01006# This file contains test components that are executed by all.sh
Minos Galanakis6aab5b72024-07-25 14:24:37 +01007
8################################################################
9#### Platform Testing
10################################################################
11
Minos Galanakis8a980902024-07-26 17:41:03 +010012component_test_malloc_0_null () {
13 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
14 scripts/config.py full
15 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
16
17 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
18 make test
19
20 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
21 # Just the calloc selftest. "make test" ran the others as part of the
22 # test suites.
23 programs/test/selftest calloc
24
25 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
26 # Run a subset of the tests. The choice is a balance between coverage
27 # and time (including time indirectly wasted due to flaky tests).
28 # The current choice is to skip tests whose description includes
29 # "proxy", which is an approximation of skipping tests that use the
30 # UDP proxy, which tend to be slower and flakier.
31 tests/ssl-opt.sh -e 'proxy'
32}
33
34component_test_m32_no_asm () {
35 # Build without assembly, so as to use portable C code (in a 32-bit
36 # build) and not the i386-specific inline assembly.
37 #
38 # Note that we require gcc, because clang Asan builds fail to link for
39 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
40 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
41 scripts/config.py full
42 scripts/config.py unset MBEDTLS_HAVE_ASM
43 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
44 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
45
46 msg "test: i386, make, gcc, no asm (ASan build)"
47 make test
48}
49
50support_test_m32_no_asm () {
51 case $(uname -m) in
52 amd64|x86_64) true;;
53 *) false;;
54 esac
55}
56
57component_test_m32_o2 () {
58 # Build with optimization, to use the i386 specific inline assembly
59 # and go faster for tests.
60 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
61 scripts/config.py full
62 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
63 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
64
65 msg "test: i386, make, gcc -O2 (ASan build)"
66 make test
67
68 msg "test ssl-opt.sh, i386, make, gcc-O2"
69 tests/ssl-opt.sh
70}
71
72support_test_m32_o2 () {
73 support_test_m32_no_asm "$@"
74}
75
76component_test_m32_everest () {
77 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
78 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
79 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
80 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
81
82 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
83 make test
84
85 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
86 tests/ssl-opt.sh -f ECDH
87
88 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
89 # Exclude some symmetric ciphers that are redundant here to gain time.
90 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
91}
92
93support_test_m32_everest () {
94 support_test_m32_no_asm "$@"
95}
96
97component_test_mx32 () {
98 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
99 scripts/config.py full
100 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
101
102 msg "test: 64-bit ILP32, make, gcc"
103 make test
104}
105
106support_test_mx32 () {
107 case $(uname -m) in
108 amd64|x86_64) true;;
109 *) false;;
110 esac
111}
112
113component_build_zeroize_checks () {
114 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
115
116 scripts/config.py full
117
118 # Only compile - we're looking for sizeof-pointer-memaccess warnings
119 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
120}
121
Minos Galanakis07404d22024-08-01 11:44:57 +0100122component_build_arm_none_eabi_gcc () {
123 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
124 scripts/config.py baremetal
125 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -O1' lib
126
127 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
128 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
129 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
130 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
131}
132
133component_build_arm_linux_gnueabi_gcc_arm5vte () {
134 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
135 scripts/config.py baremetal
136 # Build for a target platform that's close to what Debian uses
137 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
138 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
139 # Build everything including programs, see for example
140 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
141 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te'
142
143 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
144 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
145 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
146 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
147}
148
149support_build_arm_linux_gnueabi_gcc_arm5vte () {
150 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
151}
152
153component_build_arm_none_eabi_gcc_arm5vte () {
154 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
155 scripts/config.py baremetal
156 # This is an imperfect substitute for
157 # component_build_arm_linux_gnueabi_gcc_arm5vte
158 # in case the gcc-arm-linux-gnueabi toolchain is not available
159 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-std=c99 -Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
160
161 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
162 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
163 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
164 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
165}
166
167component_build_arm_none_eabi_gcc_m0plus () {
168 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
169 scripts/config.py baremetal_size
170 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
171
172 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
173 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
174 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
175 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
176 for lib in library/*.a; do
177 echo "$lib:"
178 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
179 done
180}
181
182component_build_arm_none_eabi_gcc_no_udbl_division () {
183 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
184 scripts/config.py baremetal
185 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
186 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra' lib
187 echo "Checking that software 64-bit division is not required"
188 not grep __aeabi_uldiv library/*.o
189 not grep __aeabi_uldiv ${PSA_CORE_PATH}/*.o
190 not grep __aeabi_uldiv ${BUILTIN_SRC_PATH}/*.o
191}
192
193component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
194 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
195 scripts/config.py baremetal
196 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
197 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -O1 -march=armv6-m -mthumb' lib
198 echo "Checking that software 64-bit multiplication is not required"
199 not grep __aeabi_lmul library/*.o
200 not grep __aeabi_lmul ${PSA_CORE_PATH}/*.o
201 not grep __aeabi_lmul ${BUILTIN_SRC_PATH}/*.o
202}
203
204component_build_arm_clang_thumb () {
205 # ~ 30s
206
207 scripts/config.py baremetal
208
209 msg "build: clang thumb 2, make"
210 make clean
211 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
212
213 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
214 msg "build: clang thumb 1 -O0, make"
215 make clean
216 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
217
218 msg "build: clang thumb 1 -Os, make"
219 make clean
220 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
221}
222
223component_build_armcc () {
224 msg "build: ARM Compiler 5"
225 scripts/config.py baremetal
226 # armc[56] don't support SHA-512 intrinsics
227 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
228
229 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
230 scripts/config.py unset MBEDTLS_AESCE_C
231
232 # Stop armclang warning about feature detection for A64_CRYPTO.
233 # With this enabled, the library does build correctly under armclang,
234 # but in baremetal builds (as tested here), feature detection is
235 # unavailable, and the user is notified via a #warning. So enabling
236 # this feature would prevent us from building with -Werror on
237 # armclang. Tracked in #7198.
238 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
239
240 scripts/config.py set MBEDTLS_HAVE_ASM
241
242 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
243
244 msg "size: ARM Compiler 5"
245 "$ARMC5_FROMELF" -z library/*.o
246 "$ARMC5_FROMELF" -z ${PSA_CORE_PATH}/*.o
247 "$ARMC5_FROMELF" -z ${BUILTIN_SRC_PATH}/*.o
248
249 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
250
251 # ARM Compiler 6 - Target ARMv7-A
252 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
253
254 # ARM Compiler 6 - Target ARMv7-M
255 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
256
257 # ARM Compiler 6 - Target ARMv7-M+DSP
258 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
259
260 # ARM Compiler 6 - Target ARMv8-A - AArch32
261 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
262
263 # ARM Compiler 6 - Target ARMv8-M
264 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
265
266 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
267 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
268
269 # ARM Compiler 6 - Target Cortex-M0
270 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
271
272 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
273 #
274 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
275 # that we have in our CI
276 scripts/config.py set MBEDTLS_AESCE_C
277 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
278}
279
280support_build_armcc () {
281 armc5_cc="$ARMC5_BIN_DIR/armcc"
282 armc6_cc="$ARMC6_BIN_DIR/armclang"
283 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
284}