blob: 7ee35d8eb67d14a24afcdc99948802a9785ad8f8 [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"
Minos Galanakis4a2a3512024-08-01 17:28:37 +010098 skip_all_except_given_suite test_suite_constant_time
99 cmake -D CMAKE_BUILD_TYPE:String=Release .
100 make clean
101 make
102 make memcheck
103}
104
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100105component_release_test_valgrind_constant_flow_no_asm () {
106 # This tests both (1) everything that valgrind's memcheck usually checks
107 # (heap buffer overflows, use of uninitialized memory, use-after-free,
108 # etc.) and (2) branches or memory access depending on secret values,
109 # which will be reported as uninitialized memory. To distinguish between
110 # secret and actually uninitialized:
111 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
112 # - or alternatively, build with debug info and manually run the offending
113 # test suite with valgrind --track-origins=yes, then check if the origin
114 # was TEST_CF_SECRET() or something else.
115 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM with constant flow testing"
116 scripts/config.py full
117 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
118 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
119 scripts/config.py unset MBEDTLS_AESNI_C
120 scripts/config.py unset MBEDTLS_HAVE_ASM
121 skip_suites_without_constant_flow
122 cmake -D CMAKE_BUILD_TYPE:String=Release .
123 make
124
125 # this only shows a summary of the results (how many of each type)
126 # details are left in Testing/<date>/DynamicAnalysis.xml
127 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM, valgrind + constant flow)"
128 make memcheck
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100129}
130
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100131component_release_test_valgrind_constant_flow_psa () {
132 # This tests both (1) everything that valgrind's memcheck usually checks
133 # (heap buffer overflows, use of uninitialized memory, use-after-free,
134 # etc.) and (2) branches or memory access depending on secret values,
135 # which will be reported as uninitialized memory. To distinguish between
136 # secret and actually uninitialized:
137 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
138 # - or alternatively, build with debug info and manually run the offending
139 # test suite with valgrind --track-origins=yes, then check if the origin
140 # was TEST_CF_SECRET() or something else.
141 msg "build: cmake release GCC, full config with constant flow testing"
142 scripts/config.py full
143 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
144 skip_suites_without_constant_flow
145 cmake -D CMAKE_BUILD_TYPE:String=Release .
146 make
147
148 # this only shows a summary of the results (how many of each type)
149 # details are left in Testing/<date>/DynamicAnalysis.xml
150 msg "test: some suites (valgrind + constant flow)"
151 make memcheck
152}
153
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100154component_release_test_valgrind_constant_flow_psa_no_asm () {
155 # This tests both (1) everything that valgrind's memcheck usually checks
156 # (heap buffer overflows, use of uninitialized memory, use-after-free,
157 # etc.) and (2) branches or memory access depending on secret values,
158 # which will be reported as uninitialized memory. To distinguish between
159 # secret and actually uninitialized:
160 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
161 # - or alternatively, build with debug info and manually run the offending
162 # test suite with valgrind --track-origins=yes, then check if the origin
163 # was TEST_CF_SECRET() or something else.
164 msg "build: cmake release GCC, full config minus MBEDTLS_HAVE_ASM with constant flow testing"
165 scripts/config.py full
166 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
167 scripts/config.py unset MBEDTLS_AESNI_C
168 scripts/config.py unset MBEDTLS_HAVE_ASM
169 skip_suites_without_constant_flow
170 cmake -D CMAKE_BUILD_TYPE:String=Release .
171 make
172
173 # this only shows a summary of the results (how many of each type)
174 # details are left in Testing/<date>/DynamicAnalysis.xml
175 msg "test: some suites (full minus MBEDTLS_HAVE_ASM, valgrind + constant flow)"
176 make memcheck
177}
178
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100179component_test_tsan () {
180 msg "build: TSan (clang)"
181 scripts/config.py full
182 scripts/config.py set MBEDTLS_THREADING_C
183 scripts/config.py set MBEDTLS_THREADING_PTHREAD
184 # Self-tests do not currently use multiple threads.
185 scripts/config.py unset MBEDTLS_SELF_TEST
186
187 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
188 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
189
190 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
191 make
192
193 msg "test: main suites (TSan)"
194 make test
195}
196
197component_test_memsan () {
198 msg "build: MSan (clang)" # ~ 1 min 20s
199 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Elena Uziunaite9af882d2024-07-02 10:52:13 +0100200 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100201 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
202 make
203
204 msg "test: main suites (MSan)" # ~ 10s
205 make test
206
207 msg "test: metatests (MSan)"
208 tests/scripts/run-metatests.sh any msan
209
210 msg "program demos (MSan)" # ~20s
211 tests/scripts/run_demos.py
212
213 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
214 tests/ssl-opt.sh
215
216 # Optional part(s)
217
218 if [ "$MEMORY" -gt 0 ]; then
219 msg "test: compat.sh (MSan)" # ~ 6 min 20s
220 tests/compat.sh
221 fi
222}
223
224component_release_test_valgrind () {
225 msg "build: Release (clang)"
226 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
227 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
228 make
229
230 msg "test: main suites, Valgrind (default config)"
231 make memcheck
232
233 # Optional parts (slow; currently broken on OS X because programs don't
234 # seem to receive signals under valgrind on OS X).
235 # These optional parts don't run on the CI.
236 if [ "$MEMORY" -gt 0 ]; then
237 msg "test: ssl-opt.sh --memcheck (default config)"
238 tests/ssl-opt.sh --memcheck
239 fi
240
241 if [ "$MEMORY" -gt 1 ]; then
242 msg "test: compat.sh --memcheck (default config)"
243 tests/compat.sh --memcheck
244 fi
245
246 if [ "$MEMORY" -gt 0 ]; then
247 msg "test: context-info.sh --memcheck (default config)"
248 tests/context-info.sh --memcheck
249 fi
250}
251
252component_release_test_valgrind_psa () {
253 msg "build: Release, full (clang)"
254 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
255 scripts/config.py full
256 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
257 make
258
259 msg "test: main suites, Valgrind (full config)"
260 make memcheck
261}