blob: 0b3c99f70a1d6fc60af4a4eaea9a6ce091bfd790 [file] [log] [blame]
Minos Galanakis77711192024-07-25 14:24:37 +01001# components-sanitizers.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
6# This file contains test components that are executed by all.sh
7
8################################################################
9#### Sanitizer Testing
10################################################################
Minos Galanakis4a2a3512024-08-01 17:28:37 +010011
12skip_suites_without_constant_flow () {
13 # Skip the test suites that don't have any constant-flow annotations.
14 # This will need to be adjusted if we ever start declaring things as
15 # secret from macros or functions inside tests/include or tests/src.
16 SKIP_TEST_SUITES=$(
17 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
18 sed 's/test_suite_//; s/\.function$//' |
19 tr '\n' ,)
20 export SKIP_TEST_SUITES
21}
22
23skip_all_except_given_suite () {
24 # Skip all but the given test suite
25 SKIP_TEST_SUITES=$(
26 ls -1 tests/suites/test_suite_*.function |
27 grep -v $1.function |
28 sed 's/tests.suites.test_suite_//; s/\.function$//' |
29 tr '\n' ,)
30 export SKIP_TEST_SUITES
31}
32
33component_test_memsan_constant_flow () {
34 # This tests both (1) accesses to undefined memory, and (2) branches or
35 # memory access depending on secret values. To distinguish between those:
36 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
37 # - or alternatively, change the build type to MemSanDbg, which enables
38 # origin tracking and nicer stack traces (which are useful for debugging
39 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
40 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
41 scripts/config.py full
42 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
43 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
44 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Elena Uziunaitecd2ae322024-07-01 16:55:19 +010045 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakis4a2a3512024-08-01 17:28:37 +010046 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
47 make
48
49 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
50 make test
51}
52
53component_test_memsan_constant_flow_psa () {
54 # This tests both (1) accesses to undefined memory, and (2) branches or
55 # memory access depending on secret values. To distinguish between those:
56 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
57 # - or alternatively, change the build type to MemSanDbg, which enables
58 # origin tracking and nicer stack traces (which are useful for debugging
59 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
60 msg "build: cmake MSan (clang), full config with constant flow testing"
61 scripts/config.py full
62 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
63 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Elena Uziunaitecd2ae322024-07-01 16:55:19 +010064 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakis4a2a3512024-08-01 17:28:37 +010065 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
66 make
67
68 msg "test: main suites (Msan + constant flow)"
69 make test
70}
71
72component_release_test_valgrind_constant_flow () {
73 # This tests both (1) everything that valgrind's memcheck usually checks
74 # (heap buffer overflows, use of uninitialized memory, use-after-free,
75 # etc.) and (2) branches or memory access depending on secret values,
76 # which will be reported as uninitialized memory. To distinguish between
77 # secret and actually uninitialized:
78 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
79 # - or alternatively, build with debug info and manually run the offending
80 # test suite with valgrind --track-origins=yes, then check if the origin
81 # was TEST_CF_SECRET() or something else.
82 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
83 scripts/config.py full
84 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
85 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
86 skip_suites_without_constant_flow
87 cmake -D CMAKE_BUILD_TYPE:String=Release .
88 make
89
90 # this only shows a summary of the results (how many of each type)
91 # details are left in Testing/<date>/DynamicAnalysis.xml
92 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
93 make memcheck
94
95 # Test asm path in constant time module - by default, it will test the plain C
96 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
97 msg "test: valgrind asm constant_time"
98 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
99 skip_all_except_given_suite test_suite_constant_time
100 cmake -D CMAKE_BUILD_TYPE:String=Release .
101 make clean
102 make
103 make memcheck
104}
105
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100106component_release_test_valgrind_constant_flow_no_asm () {
107 # This tests both (1) everything that valgrind's memcheck usually checks
108 # (heap buffer overflows, use of uninitialized memory, use-after-free,
109 # etc.) and (2) branches or memory access depending on secret values,
110 # which will be reported as uninitialized memory. To distinguish between
111 # secret and actually uninitialized:
112 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
113 # - or alternatively, build with debug info and manually run the offending
114 # test suite with valgrind --track-origins=yes, then check if the origin
115 # was TEST_CF_SECRET() or something else.
116 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM with constant flow testing"
117 scripts/config.py full
118 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
119 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
120 scripts/config.py unset MBEDTLS_AESNI_C
121 scripts/config.py unset MBEDTLS_HAVE_ASM
122 skip_suites_without_constant_flow
123 cmake -D CMAKE_BUILD_TYPE:String=Release .
124 make
125
126 # this only shows a summary of the results (how many of each type)
127 # details are left in Testing/<date>/DynamicAnalysis.xml
128 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM, valgrind + constant flow)"
129 make memcheck
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100130}
131
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100132component_release_test_valgrind_constant_flow_psa () {
133 # This tests both (1) everything that valgrind's memcheck usually checks
134 # (heap buffer overflows, use of uninitialized memory, use-after-free,
135 # etc.) and (2) branches or memory access depending on secret values,
136 # which will be reported as uninitialized memory. To distinguish between
137 # secret and actually uninitialized:
138 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
139 # - or alternatively, build with debug info and manually run the offending
140 # test suite with valgrind --track-origins=yes, then check if the origin
141 # was TEST_CF_SECRET() or something else.
142 msg "build: cmake release GCC, full config with constant flow testing"
143 scripts/config.py full
144 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
145 skip_suites_without_constant_flow
146 cmake -D CMAKE_BUILD_TYPE:String=Release .
147 make
148
149 # this only shows a summary of the results (how many of each type)
150 # details are left in Testing/<date>/DynamicAnalysis.xml
151 msg "test: some suites (valgrind + constant flow)"
152 make memcheck
153}
154
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100155component_release_test_valgrind_constant_flow_psa_no_asm () {
156 # This tests both (1) everything that valgrind's memcheck usually checks
157 # (heap buffer overflows, use of uninitialized memory, use-after-free,
158 # etc.) and (2) branches or memory access depending on secret values,
159 # which will be reported as uninitialized memory. To distinguish between
160 # secret and actually uninitialized:
161 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
162 # - or alternatively, build with debug info and manually run the offending
163 # test suite with valgrind --track-origins=yes, then check if the origin
164 # was TEST_CF_SECRET() or something else.
165 msg "build: cmake release GCC, full config minus MBEDTLS_HAVE_ASM with constant flow testing"
166 scripts/config.py full
167 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
168 scripts/config.py unset MBEDTLS_AESNI_C
169 scripts/config.py unset MBEDTLS_HAVE_ASM
170 skip_suites_without_constant_flow
171 cmake -D CMAKE_BUILD_TYPE:String=Release .
172 make
173
174 # this only shows a summary of the results (how many of each type)
175 # details are left in Testing/<date>/DynamicAnalysis.xml
176 msg "test: some suites (full minus MBEDTLS_HAVE_ASM, valgrind + constant flow)"
177 make memcheck
178}
179
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100180component_test_tsan () {
181 msg "build: TSan (clang)"
182 scripts/config.py full
183 scripts/config.py set MBEDTLS_THREADING_C
184 scripts/config.py set MBEDTLS_THREADING_PTHREAD
185 # Self-tests do not currently use multiple threads.
186 scripts/config.py unset MBEDTLS_SELF_TEST
187
188 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
189 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
190
191 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
192 make
193
194 msg "test: main suites (TSan)"
195 make test
196}
197
198component_test_memsan () {
199 msg "build: MSan (clang)" # ~ 1 min 20s
200 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Elena Uziunaite9af882d2024-07-02 10:52:13 +0100201 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100202 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
203 make
204
205 msg "test: main suites (MSan)" # ~ 10s
206 make test
207
208 msg "test: metatests (MSan)"
209 tests/scripts/run-metatests.sh any msan
210
211 msg "program demos (MSan)" # ~20s
212 tests/scripts/run_demos.py
213
214 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
215 tests/ssl-opt.sh
216
217 # Optional part(s)
218
219 if [ "$MEMORY" -gt 0 ]; then
220 msg "test: compat.sh (MSan)" # ~ 6 min 20s
221 tests/compat.sh
222 fi
223}
224
225component_release_test_valgrind () {
226 msg "build: Release (clang)"
227 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
228 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
229 make
230
231 msg "test: main suites, Valgrind (default config)"
232 make memcheck
233
234 # Optional parts (slow; currently broken on OS X because programs don't
235 # seem to receive signals under valgrind on OS X).
236 # These optional parts don't run on the CI.
237 if [ "$MEMORY" -gt 0 ]; then
238 msg "test: ssl-opt.sh --memcheck (default config)"
239 tests/ssl-opt.sh --memcheck
240 fi
241
242 if [ "$MEMORY" -gt 1 ]; then
243 msg "test: compat.sh --memcheck (default config)"
244 tests/compat.sh --memcheck
245 fi
246
247 if [ "$MEMORY" -gt 0 ]; then
248 msg "test: context-info.sh --memcheck (default config)"
249 tests/context-info.sh --memcheck
250 fi
251}
252
253component_release_test_valgrind_psa () {
254 msg "build: Release, full (clang)"
255 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
256 scripts/config.py full
257 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
258 make
259
260 msg "test: main suites, Valgrind (full config)"
261 make memcheck
262}