blob: aa936a20b8e08a79ffb1ad7f605775b902132ad3 [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
Minos Galanakis1ef3a662024-08-01 11:47:49 +0100113support_test_aesni_m32_clang () {
114 # clang >= 4 is required to build with target attributes
115 support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
116}
117
118component_test_aesni_m32_clang () {
119
120 scripts/config.py set MBEDTLS_AESNI_C
121 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
122 scripts/config.py set MBEDTLS_HAVE_ASM
123
124 # test the intrinsics implementation with clang
125 msg "AES tests, test intrinsics (clang)"
126 make clean
127 make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
128 # check that we built intrinsics - this should be used by default when supported by the compiler
129 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
130 grep -q "AES note: using AESNI" ./programs/test/selftest
131 grep -q "AES note: built-in implementation." ./programs/test/selftest
132 grep -q mbedtls_aesni_has_support ./programs/test/selftest
133}
134
Minos Galanakis8a980902024-07-26 17:41:03 +0100135component_build_zeroize_checks () {
136 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
137
138 scripts/config.py full
139
140 # Only compile - we're looking for sizeof-pointer-memaccess warnings
141 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
142}
143
Minos Galanakis07404d22024-08-01 11:44:57 +0100144component_build_arm_none_eabi_gcc () {
145 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
146 scripts/config.py baremetal
147 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
148
149 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
150 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
151 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
152 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
153}
154
155component_build_arm_linux_gnueabi_gcc_arm5vte () {
156 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
157 scripts/config.py baremetal
158 # Build for a target platform that's close to what Debian uses
159 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
160 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
161 # Build everything including programs, see for example
162 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
163 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'
164
165 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
166 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
167 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
168 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
169}
170
171support_build_arm_linux_gnueabi_gcc_arm5vte () {
172 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
173}
174
175component_build_arm_none_eabi_gcc_arm5vte () {
176 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
177 scripts/config.py baremetal
178 # This is an imperfect substitute for
179 # component_build_arm_linux_gnueabi_gcc_arm5vte
180 # in case the gcc-arm-linux-gnueabi toolchain is not available
181 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
182
183 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
184 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
185 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
186 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
187}
188
189component_build_arm_none_eabi_gcc_m0plus () {
190 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
191 scripts/config.py baremetal_size
192 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
193
194 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
195 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
196 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
197 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
198 for lib in library/*.a; do
199 echo "$lib:"
200 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
201 done
202}
203
204component_build_arm_none_eabi_gcc_no_udbl_division () {
205 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
206 scripts/config.py baremetal
207 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
208 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
209 echo "Checking that software 64-bit division is not required"
210 not grep __aeabi_uldiv library/*.o
211 not grep __aeabi_uldiv ${PSA_CORE_PATH}/*.o
212 not grep __aeabi_uldiv ${BUILTIN_SRC_PATH}/*.o
213}
214
215component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
216 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
217 scripts/config.py baremetal
218 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
219 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
220 echo "Checking that software 64-bit multiplication is not required"
221 not grep __aeabi_lmul library/*.o
222 not grep __aeabi_lmul ${PSA_CORE_PATH}/*.o
223 not grep __aeabi_lmul ${BUILTIN_SRC_PATH}/*.o
224}
225
226component_build_arm_clang_thumb () {
227 # ~ 30s
228
229 scripts/config.py baremetal
230
231 msg "build: clang thumb 2, make"
232 make clean
233 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
234
235 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
236 msg "build: clang thumb 1 -O0, make"
237 make clean
238 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
239
240 msg "build: clang thumb 1 -Os, make"
241 make clean
242 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
243}
244
245component_build_armcc () {
246 msg "build: ARM Compiler 5"
247 scripts/config.py baremetal
248 # armc[56] don't support SHA-512 intrinsics
249 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
250
251 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
252 scripts/config.py unset MBEDTLS_AESCE_C
253
254 # Stop armclang warning about feature detection for A64_CRYPTO.
255 # With this enabled, the library does build correctly under armclang,
256 # but in baremetal builds (as tested here), feature detection is
257 # unavailable, and the user is notified via a #warning. So enabling
258 # this feature would prevent us from building with -Werror on
259 # armclang. Tracked in #7198.
260 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
261
262 scripts/config.py set MBEDTLS_HAVE_ASM
263
264 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
265
266 msg "size: ARM Compiler 5"
267 "$ARMC5_FROMELF" -z library/*.o
268 "$ARMC5_FROMELF" -z ${PSA_CORE_PATH}/*.o
269 "$ARMC5_FROMELF" -z ${BUILTIN_SRC_PATH}/*.o
270
271 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
272
273 # ARM Compiler 6 - Target ARMv7-A
274 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
275
276 # ARM Compiler 6 - Target ARMv7-M
277 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
278
279 # ARM Compiler 6 - Target ARMv7-M+DSP
280 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
281
282 # ARM Compiler 6 - Target ARMv8-A - AArch32
283 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
284
285 # ARM Compiler 6 - Target ARMv8-M
286 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
287
288 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
289 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
290
291 # ARM Compiler 6 - Target Cortex-M0
292 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
293
294 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
295 #
296 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
297 # that we have in our CI
298 scripts/config.py set MBEDTLS_AESCE_C
299 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
300}
301
302support_build_armcc () {
303 armc5_cc="$ARMC5_BIN_DIR/armcc"
304 armc6_cc="$ARMC6_BIN_DIR/armclang"
305 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
306}