blob: 454d1407f6bad8c9d763666465a0912c232d2eda [file] [log] [blame]
Minos Galanakis6aab5b72024-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
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#### Sanitizer Testing
10################################################################
11
Minos Galanakise280ff82024-07-26 17:42:50 +010012skip_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
David Horstmann5b93d972024-10-31 15:36:05 +000015 # secret from macros or functions inside framework/tests/include or framework/tests/src.
Minos Galanakise280ff82024-07-26 17:42:50 +010016 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 git -C tf-psa-crypto/tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
21 sed 's/test_suite_//; s/\.function$//' |
22 tr '\n' ,)
23 export SKIP_TEST_SUITES
24}
25
26skip_all_except_given_suite () {
27 # Skip all but the given test suite
28 SKIP_TEST_SUITES=$(
29 ls -1 tests/suites/test_suite_*.function |
30 grep -v $1.function |
31 sed 's/tests.suites.test_suite_//; s/\.function$//' |
32 tr '\n' ,),$(
33 ls -1 tf-psa-crypto/tests/suites/test_suite_*.function |
34 grep -v $1.function |
35 sed 's/tf-psa-crypto.tests.suites.test_suite_//; s/\.function$//' |
36 tr '\n' ,)
37 export SKIP_TEST_SUITES
38}
39
Minos Galanakise280ff82024-07-26 17:42:50 +010040component_test_memsan_constant_flow_psa () {
41 # This tests both (1) accesses to undefined memory, and (2) branches or
42 # memory access depending on secret values. To distinguish between those:
43 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
44 # - or alternatively, change the build type to MemSanDbg, which enables
45 # origin tracking and nicer stack traces (which are useful for debugging
46 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
47 msg "build: cmake MSan (clang), full config with constant flow testing"
48 scripts/config.py full
49 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
50 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Elena Uziunaite969e9e12024-07-01 16:55:19 +010051 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakisc6e58aa2024-11-06 20:13:31 +000052 CC=clang cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=MemSan .
Minos Galanakise280ff82024-07-26 17:42:50 +010053 make
54
55 msg "test: main suites (Msan + constant flow)"
56 make test
57}
58
Elena Uziunaiteaff61f32024-07-02 15:52:03 +010059component_release_test_valgrind_constant_flow_no_asm () {
60 # This tests both (1) everything that valgrind's memcheck usually checks
61 # (heap buffer overflows, use of uninitialized memory, use-after-free,
62 # etc.) and (2) branches or memory access depending on secret values,
63 # which will be reported as uninitialized memory. To distinguish between
64 # secret and actually uninitialized:
65 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
66 # - or alternatively, build with debug info and manually run the offending
67 # test suite with valgrind --track-origins=yes, then check if the origin
68 # was TEST_CF_SECRET() or something else.
69 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM with constant flow testing"
70 scripts/config.py full
71 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Elena Uziunaiteaff61f32024-07-02 15:52:03 +010072 scripts/config.py unset MBEDTLS_AESNI_C
73 scripts/config.py unset MBEDTLS_HAVE_ASM
74 skip_suites_without_constant_flow
75 cmake -D CMAKE_BUILD_TYPE:String=Release .
76 make
77
78 # this only shows a summary of the results (how many of each type)
79 # details are left in Testing/<date>/DynamicAnalysis.xml
80 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM, valgrind + constant flow)"
81 make memcheck
Elena Uziunaiteaff61f32024-07-02 15:52:03 +010082}
83
Minos Galanakise280ff82024-07-26 17:42:50 +010084component_release_test_valgrind_constant_flow_psa () {
85 # This tests both (1) everything that valgrind's memcheck usually checks
86 # (heap buffer overflows, use of uninitialized memory, use-after-free,
87 # etc.) and (2) branches or memory access depending on secret values,
88 # which will be reported as uninitialized memory. To distinguish between
89 # secret and actually uninitialized:
90 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
91 # - or alternatively, build with debug info and manually run the offending
92 # test suite with valgrind --track-origins=yes, then check if the origin
93 # was TEST_CF_SECRET() or something else.
94 msg "build: cmake release GCC, full config with constant flow testing"
95 scripts/config.py full
96 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
97 skip_suites_without_constant_flow
98 cmake -D CMAKE_BUILD_TYPE:String=Release .
99 make
100
101 # this only shows a summary of the results (how many of each type)
102 # details are left in Testing/<date>/DynamicAnalysis.xml
103 msg "test: some suites (valgrind + constant flow)"
104 make memcheck
105}
106
107component_test_tsan () {
108 msg "build: TSan (clang)"
109 scripts/config.py full
110 scripts/config.py set MBEDTLS_THREADING_C
111 scripts/config.py set MBEDTLS_THREADING_PTHREAD
112 # Self-tests do not currently use multiple threads.
113 scripts/config.py unset MBEDTLS_SELF_TEST
Paul Elliott28c62902024-12-03 18:07:02 +0000114 # Interruptible ECC tests are not thread safe
115 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Minos Galanakise280ff82024-07-26 17:42:50 +0100116
117 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
118 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
119
120 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
121 make
122
123 msg "test: main suites (TSan)"
124 make test
125}
126
127component_test_memsan () {
128 msg "build: MSan (clang)" # ~ 1 min 20s
129 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Elena Uziunaitedcb5d832024-07-02 10:52:13 +0100130 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakise280ff82024-07-26 17:42:50 +0100131 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
132 make
133
134 msg "test: main suites (MSan)" # ~ 10s
135 make test
136
137 msg "test: metatests (MSan)"
138 tests/scripts/run-metatests.sh any msan
139
140 msg "program demos (MSan)" # ~20s
141 tests/scripts/run_demos.py
142
143 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
144 tests/ssl-opt.sh
145
146 # Optional part(s)
147
148 if [ "$MEMORY" -gt 0 ]; then
149 msg "test: compat.sh (MSan)" # ~ 6 min 20s
150 tests/compat.sh
151 fi
152}
153
154component_release_test_valgrind () {
155 msg "build: Release (clang)"
156 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
157 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
158 make
159
160 msg "test: main suites, Valgrind (default config)"
161 make memcheck
162
163 # Optional parts (slow; currently broken on OS X because programs don't
164 # seem to receive signals under valgrind on OS X).
165 # These optional parts don't run on the CI.
166 if [ "$MEMORY" -gt 0 ]; then
167 msg "test: ssl-opt.sh --memcheck (default config)"
168 tests/ssl-opt.sh --memcheck
169 fi
170
171 if [ "$MEMORY" -gt 1 ]; then
172 msg "test: compat.sh --memcheck (default config)"
173 tests/compat.sh --memcheck
174 fi
175
176 if [ "$MEMORY" -gt 0 ]; then
177 msg "test: context-info.sh --memcheck (default config)"
178 tests/context-info.sh --memcheck
179 fi
180}
181
182component_release_test_valgrind_psa () {
183 msg "build: Release, full (clang)"
184 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
185 scripts/config.py full
186 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
187 make
188
189 msg "test: main suites, Valgrind (full config)"
190 make memcheck
191}
192