blob: 4e43976a298fd9f142b464492b356efbfe97176a [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_m32_no_asm () {
13 # Build without assembly, so as to use portable C code (in a 32-bit
14 # build) and not the i386-specific inline assembly.
15 #
16 # Note that we require gcc, because clang Asan builds fail to link for
17 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
18 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
19 scripts/config.py full
20 scripts/config.py unset MBEDTLS_HAVE_ASM
21 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
22 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
23
24 msg "test: i386, make, gcc, no asm (ASan build)"
25 make test
26}
27
28support_test_m32_no_asm () {
29 case $(uname -m) in
30 amd64|x86_64) true;;
31 *) false;;
32 esac
33}
34
35component_test_m32_o2 () {
36 # Build with optimization, to use the i386 specific inline assembly
37 # and go faster for tests.
38 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
39 scripts/config.py full
40 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
41 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
42
43 msg "test: i386, make, gcc -O2 (ASan build)"
44 make test
45
46 msg "test ssl-opt.sh, i386, make, gcc-O2"
47 tests/ssl-opt.sh
48}
49
50support_test_m32_o2 () {
51 support_test_m32_no_asm "$@"
52}
53
54component_test_m32_everest () {
55 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
56 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
57 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
58 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
59
60 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
61 make test
62
63 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
64 tests/ssl-opt.sh -f ECDH
65
66 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
67 # Exclude some symmetric ciphers that are redundant here to gain time.
68 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
69}
70
71support_test_m32_everest () {
72 support_test_m32_no_asm "$@"
73}
74
75component_test_mx32 () {
76 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
77 scripts/config.py full
78 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
79
80 msg "test: 64-bit ILP32, make, gcc"
81 make test
82}
83
84support_test_mx32 () {
85 case $(uname -m) in
86 amd64|x86_64) true;;
87 *) false;;
88 esac
89}
90
Minos Galanakisb5891d52024-08-01 11:55:33 +010091support_test_aesni () {
92 # Check that gcc targets x86_64 (we can build AESNI), and check for
93 # AESNI support on the host (we can run AESNI).
94 #
95 # The name of this function is possibly slightly misleading, but needs to align
96 # with the name of the corresponding test, component_test_aesni.
97 #
98 # In principle 32-bit x86 can support AESNI, but our implementation does not
99 # support 32-bit x86, so we check for x86-64.
100 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
101 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
102 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
103 (lscpu | grep -qw aes)
104}
105
106component_test_aesni () { # ~ 60s
107 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
108 # fallback. It also tests the logic that is used to select which implementation(s) to build.
109 #
110 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
111 # AESNI detection will fallback to the plain C implementation, so the tests will instead
112 # exercise the plain C impl).
113
114 msg "build: default config with different AES implementations"
115 scripts/config.py set MBEDTLS_AESNI_C
116 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
117 scripts/config.py set MBEDTLS_HAVE_ASM
118
119 # test the intrinsics implementation
120 msg "AES tests, test intrinsics"
121 make clean
122 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
123 # check that we built intrinsics - this should be used by default when supported by the compiler
124 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
125
126 # test the asm implementation
127 msg "AES tests, test assembly"
128 make clean
129 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
130 # check that we built assembly - this should be built if the compiler does not support intrinsics
131 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
132
133 # test the plain C implementation
134 scripts/config.py unset MBEDTLS_AESNI_C
135 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
136 msg "AES tests, plain C"
137 make clean
138 make CC=gcc CFLAGS='-O2 -Werror'
139 # check that there is no AESNI code present
140 ./programs/test/selftest aes | not grep -q "AESNI code"
141 not grep -q "AES note: using AESNI" ./programs/test/selftest
142 grep -q "AES note: built-in implementation." ./programs/test/selftest
143
144 # test the intrinsics implementation
145 scripts/config.py set MBEDTLS_AESNI_C
146 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
147 msg "AES tests, test AESNI only"
148 make clean
149 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
150 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
151 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
152 grep -q "AES note: using AESNI" ./programs/test/selftest
153 not grep -q "AES note: built-in implementation." ./programs/test/selftest
154}
155
156support_test_aesni_m32 () {
157 support_test_m32_no_asm && (lscpu | grep -qw aes)
158}
159
160component_test_aesni_m32 () { # ~ 60s
161 # This tests are duplicated from component_test_aesni for i386 target
162 #
163 # AESNI intrinsic code supports i386 and assembly code does not support it.
164
165 msg "build: default config with different AES implementations"
166 scripts/config.py set MBEDTLS_AESNI_C
167 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
168 scripts/config.py set MBEDTLS_HAVE_ASM
169
170 # test the intrinsics implementation with gcc
171 msg "AES tests, test intrinsics (gcc)"
172 make clean
173 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
174 # check that we built intrinsics - this should be used by default when supported by the compiler
175 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
176 grep -q "AES note: using AESNI" ./programs/test/selftest
177 grep -q "AES note: built-in implementation." ./programs/test/selftest
178 grep -q mbedtls_aesni_has_support ./programs/test/selftest
179
180 scripts/config.py set MBEDTLS_AESNI_C
181 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
182 msg "AES tests, test AESNI only"
183 make clean
184 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
185 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
186 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
187 grep -q "AES note: using AESNI" ./programs/test/selftest
188 not grep -q "AES note: built-in implementation." ./programs/test/selftest
189 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
190}
191
Minos Galanakis1ef3a662024-08-01 11:47:49 +0100192support_test_aesni_m32_clang () {
193 # clang >= 4 is required to build with target attributes
194 support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
195}
196
197component_test_aesni_m32_clang () {
198
199 scripts/config.py set MBEDTLS_AESNI_C
200 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
201 scripts/config.py set MBEDTLS_HAVE_ASM
202
203 # test the intrinsics implementation with clang
204 msg "AES tests, test intrinsics (clang)"
205 make clean
206 make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
207 # check that we built intrinsics - this should be used by default when supported by the compiler
208 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
209 grep -q "AES note: using AESNI" ./programs/test/selftest
210 grep -q "AES note: built-in implementation." ./programs/test/selftest
211 grep -q mbedtls_aesni_has_support ./programs/test/selftest
212}
213
Minos Galanakisb5891d52024-08-01 11:55:33 +0100214support_build_aes_armce () {
215 # clang >= 11 is required to build with AES extensions
216 [[ $(clang_version) -ge 11 ]]
217}
218
219component_build_aes_armce () {
220 # Test variations of AES with Armv8 crypto extensions
221 scripts/config.py set MBEDTLS_AESCE_C
222 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
223
224 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200225 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
Minos Galanakisb5891d52024-08-01 11:55:33 +0100226 msg "clang, test aarch64 crypto instructions built"
Gilles Peskine8bea95d2024-06-19 14:16:05 +0200227 grep -E 'aes[a-z]+\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100228
229 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200230 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
231 msg "clang, test A32 crypto instructions built"
232 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100233
234 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200235 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
Minos Galanakisb5891d52024-08-01 11:55:33 +0100236 msg "clang, test T32 crypto instructions built"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200237 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100238
Minos Galanakisb5891d52024-08-01 11:55:33 +0100239 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200240
241 msg "MBEDTLS_AES_USE_both, clang, aarch64"
242 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
243 msg "clang, test aarch64 crypto instructions built"
244 grep -E 'aes[a-z]+\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
245
246 msg "MBEDTLS_AES_USE_both, clang, arm"
247 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
248 msg "clang, test A32 crypto instructions built"
249 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
250
251 msg "MBEDTLS_AES_USE_both, clang, thumb"
252 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
253 msg "clang, test T32 crypto instructions built"
254 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
255
Minos Galanakisb5891d52024-08-01 11:55:33 +0100256 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200257
258 msg "no MBEDTLS_AESCE_C, clang, aarch64"
259 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
Minos Galanakisb5891d52024-08-01 11:55:33 +0100260 msg "clang, test aarch64 crypto instructions not built"
Gilles Peskine8bea95d2024-06-19 14:16:05 +0200261 not grep -E 'aes[a-z]+\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200262
263 msg "no MBEDTLS_AESCE_C, clang, arm"
264 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72 -marm"
265 msg "clang, test A32 crypto instructions not built"
266 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
267
268 msg "no MBEDTLS_AESCE_C, clang, thumb"
269 make -B library/../${BUILTIN_SRC_PATH}/aesce.o library/../${BUILTIN_SRC_PATH}/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32 -mthumb"
270 msg "clang, test T32 crypto instructions not built"
271 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' ${BUILTIN_SRC_PATH}/aesce.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100272}
273
274support_build_sha_armce () {
275 # clang >= 4 is required to build with SHA extensions
276 [[ $(clang_version) -ge 4 ]]
277}
278
279component_build_sha_armce () {
280 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
281
Minos Galanakisb5891d52024-08-01 11:55:33 +0100282 # Test variations of SHA256 Armv8 crypto extensions
283 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
284 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200285 make -B library/../${BUILTIN_SRC_PATH}/sha256.o library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
286 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, test aarch64 crypto instructions built"
287 grep -E 'sha256[a-z0-9]+\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
288
Minos Galanakisb5891d52024-08-01 11:55:33 +0100289 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200290 make -B library/../${BUILTIN_SRC_PATH}/sha256.o library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
291 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, test A32 crypto instructions built"
292 grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100293 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
294
295
296 # test the deprecated form of the config option
297 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
298 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200299 make -B library/../${BUILTIN_SRC_PATH}/sha256.o library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
300 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, test T32 crypto instructions built"
301 grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100302 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
303
304 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
305 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200306 make -B library/../${BUILTIN_SRC_PATH}/sha256.o library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
307 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, test aarch64 crypto instructions built"
308 grep -E 'sha256[a-z0-9]+\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100309 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
310
311
312 # test the deprecated form of the config option
313 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
314 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200315 make -B library/../${BUILTIN_SRC_PATH}/sha256.o library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
316
Minos Galanakisb5891d52024-08-01 11:55:33 +0100317 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200318 make -B library/../${BUILTIN_SRC_PATH}/sha256.o library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
319 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, test T32 crypto instructions built"
320 grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100321 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
322
Minos Galanakisb5891d52024-08-01 11:55:33 +0100323 # examine the disassembly for absence of SHA instructions
324 msg "clang, test A32 crypto instructions not built"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200325 make -B library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72 -marm"
Gilles Peskine8bea95d2024-06-19 14:16:05 +0200326 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100327
328 msg "clang, test T32 crypto instructions not built"
Gilles Peskine59aea4e2024-06-19 19:58:38 +0200329 make -B library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32 -mthumb"
Gilles Peskine8bea95d2024-06-19 14:16:05 +0200330 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100331
332 msg "clang, test aarch64 crypto instructions not built"
Gilles Peskine8bea95d2024-06-19 14:16:05 +0200333 make -B library/../${BUILTIN_SRC_PATH}/sha256.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
334 not grep -E 'sha256[a-z0-9]+\s+[qv]' ${BUILTIN_SRC_PATH}/sha256.s
Minos Galanakisb5891d52024-08-01 11:55:33 +0100335}
336
Bence Szépkúti1524b9c2024-07-11 09:50:45 +0100337component_test_arm_linux_gnueabi_gcc_arm5vte () {
338 # Mimic Debian armel port
339 msg "test: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, default config"
340 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1'
341
342 msg "test: main suites make, default config (out-of-box)" # ~10s
343 make test
344
345 msg "selftest: make, default config (out-of-box)" # ~10s
346 programs/test/selftest
347
348 msg "program demos: make, default config (out-of-box)" # ~10s
349 tests/scripts/run_demos.py
350}
351
352support_test_arm_linux_gnueabi_gcc_arm5vte () {
353 can_run_arm_linux_gnueabi
354}
355
356component_test_arm_linux_gnueabi_gcc_thumb_1 () {
357 # The hard float ABI is not implemented for Thumb 1, so use gnueabi
358 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
359 msg "test: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -O0, thumb 1, default config"
360 make clean
361 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -O0 -mcpu=arm1136j-s -mthumb'
362
363 msg "test: main suites make, default config (out-of-box)" # ~10s
364 make test
365
366 msg "selftest: make, default config (out-of-box)" # ~10s
367 programs/test/selftest
368
369 msg "program demos: make, default config (out-of-box)" # ~10s
370 tests/scripts/run_demos.py
371
372 msg "test: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -Os, thumb 1, default config"
373 make clean
374 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -Os -mcpu=arm1136j-s -mthumb'
375
376 msg "test: main suites make, default config (out-of-box)" # ~10s
377 make test
378
379 msg "selftest: make, default config (out-of-box)" # ~10s
380 programs/test/selftest
381
382 msg "program demos: make, default config (out-of-box)" # ~10s
383 tests/scripts/run_demos.py
384}
385
386support_test_arm_linux_gnueabi_gcc_thumb_1 () {
387 can_run_arm_linux_gnueabi
388}
389
390component_test_arm_linux_gnueabihf_gcc_armv7 () {
391 msg "test: ${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc -O2, A32, default config"
392 make clean
393 make CC="${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -O2 -march=armv7-a -marm'
394
395 msg "test: main suites make, default config (out-of-box)" # ~10s
396 make test
397
398 msg "selftest: make, default config (out-of-box)" # ~10s
399 programs/test/selftest
400
401 msg "program demos: make, default config (out-of-box)" # ~10s
402 tests/scripts/run_demos.py
403}
404
405support_test_arm_linux_gnueabihf_gcc_armv7 () {
406 can_run_arm_linux_gnueabihf
407}
408
409component_test_arm_linux_gnueabihf_gcc_thumb_2 () {
410 msg "test: ${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc -Os, thumb 2, default config"
411 make clean
412 make CC="${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -Os -march=armv7-a -mthumb'
413
414 msg "test: main suites make, default config (out-of-box)" # ~10s
415 make test
416
417 msg "selftest: make, default config (out-of-box)" # ~10s
418 programs/test/selftest
419
420 msg "program demos: make, default config (out-of-box)" # ~10s
421 tests/scripts/run_demos.py
422}
423
424support_test_arm_linux_gnueabihf_gcc_thumb_2 () {
425 can_run_arm_linux_gnueabihf
426}
427
Minos Galanakis07404d22024-08-01 11:44:57 +0100428component_build_arm_none_eabi_gcc () {
429 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
430 scripts/config.py baremetal
431 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
432
433 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
434 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
435 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
436 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
437}
438
439component_build_arm_linux_gnueabi_gcc_arm5vte () {
440 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
441 scripts/config.py baremetal
442 # Build for a target platform that's close to what Debian uses
443 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
444 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
445 # Build everything including programs, see for example
446 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
447 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'
448
449 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
450 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
451 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
452 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
453}
454
455support_build_arm_linux_gnueabi_gcc_arm5vte () {
456 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
457}
458
459component_build_arm_none_eabi_gcc_arm5vte () {
460 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
461 scripts/config.py baremetal
462 # This is an imperfect substitute for
463 # component_build_arm_linux_gnueabi_gcc_arm5vte
464 # in case the gcc-arm-linux-gnueabi toolchain is not available
465 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
466
467 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
468 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
469 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
470 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
471}
472
473component_build_arm_none_eabi_gcc_m0plus () {
474 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
475 scripts/config.py baremetal_size
476 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
477
478 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
479 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
480 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${PSA_CORE_PATH}/*.o
481 ${ARM_NONE_EABI_GCC_PREFIX}size -t ${BUILTIN_SRC_PATH}/*.o
482 for lib in library/*.a; do
483 echo "$lib:"
484 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
485 done
486}
487
488component_build_arm_none_eabi_gcc_no_udbl_division () {
489 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
490 scripts/config.py baremetal
491 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
492 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
493 echo "Checking that software 64-bit division is not required"
494 not grep __aeabi_uldiv library/*.o
495 not grep __aeabi_uldiv ${PSA_CORE_PATH}/*.o
496 not grep __aeabi_uldiv ${BUILTIN_SRC_PATH}/*.o
497}
498
499component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
500 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
501 scripts/config.py baremetal
502 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
503 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
504 echo "Checking that software 64-bit multiplication is not required"
505 not grep __aeabi_lmul library/*.o
506 not grep __aeabi_lmul ${PSA_CORE_PATH}/*.o
507 not grep __aeabi_lmul ${BUILTIN_SRC_PATH}/*.o
508}
509
510component_build_arm_clang_thumb () {
511 # ~ 30s
512
513 scripts/config.py baremetal
514
515 msg "build: clang thumb 2, make"
516 make clean
517 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
518
519 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
520 msg "build: clang thumb 1 -O0, make"
521 make clean
522 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
523
524 msg "build: clang thumb 1 -Os, make"
525 make clean
526 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
527}
528
529component_build_armcc () {
530 msg "build: ARM Compiler 5"
531 scripts/config.py baremetal
532 # armc[56] don't support SHA-512 intrinsics
533 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
534
535 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
536 scripts/config.py unset MBEDTLS_AESCE_C
537
538 # Stop armclang warning about feature detection for A64_CRYPTO.
539 # With this enabled, the library does build correctly under armclang,
540 # but in baremetal builds (as tested here), feature detection is
541 # unavailable, and the user is notified via a #warning. So enabling
542 # this feature would prevent us from building with -Werror on
543 # armclang. Tracked in #7198.
544 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
545
546 scripts/config.py set MBEDTLS_HAVE_ASM
547
548 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
549
550 msg "size: ARM Compiler 5"
551 "$ARMC5_FROMELF" -z library/*.o
552 "$ARMC5_FROMELF" -z ${PSA_CORE_PATH}/*.o
553 "$ARMC5_FROMELF" -z ${BUILTIN_SRC_PATH}/*.o
554
555 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
556
557 # ARM Compiler 6 - Target ARMv7-A
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200558 helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Minos Galanakis07404d22024-08-01 11:44:57 +0100559
560 # ARM Compiler 6 - Target ARMv7-M
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200561 helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
Minos Galanakis07404d22024-08-01 11:44:57 +0100562
563 # ARM Compiler 6 - Target ARMv7-M+DSP
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200564 helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Minos Galanakis07404d22024-08-01 11:44:57 +0100565
566 # ARM Compiler 6 - Target ARMv8-A - AArch32
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200567 helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Minos Galanakis07404d22024-08-01 11:44:57 +0100568
569 # ARM Compiler 6 - Target ARMv8-M
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200570 helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Minos Galanakis07404d22024-08-01 11:44:57 +0100571
572 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200573 helper_armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
Minos Galanakis07404d22024-08-01 11:44:57 +0100574
575 # ARM Compiler 6 - Target Cortex-M0
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200576 helper_armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Minos Galanakis07404d22024-08-01 11:44:57 +0100577
578 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
579 #
580 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
581 # that we have in our CI
582 scripts/config.py set MBEDTLS_AESCE_C
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +0200583 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
Minos Galanakis07404d22024-08-01 11:44:57 +0100584}
585
586support_build_armcc () {
587 armc5_cc="$ARMC5_BIN_DIR/armcc"
588 armc6_cc="$ARMC6_BIN_DIR/armclang"
589 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Minos Galanakisbf47cf72024-08-01 12:35:25 +0100590}