Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 1 | # components-configuration.sh |
| 2 | # |
| 3 | # Copyright The Mbed TLS Contributors |
| 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 5 | |
Minos Galanakis | 609f749 | 2024-07-31 16:39:28 +0100 | [diff] [blame] | 6 | # This file contains test components that are executed by all.sh |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 7 | |
| 8 | ################################################################ |
| 9 | #### Configuration Testing |
| 10 | ################################################################ |
| 11 | |
Minos Galanakis | 31b7a0c | 2024-07-26 17:24:23 +0100 | [diff] [blame] | 12 | component_test_default_out_of_box () { |
| 13 | msg "build: make, default config (out-of-box)" # ~1min |
| 14 | make |
| 15 | # Disable fancy stuff |
| 16 | unset MBEDTLS_TEST_OUTCOME_FILE |
| 17 | |
| 18 | msg "test: main suites make, default config (out-of-box)" # ~10s |
| 19 | make test |
| 20 | |
| 21 | msg "selftest: make, default config (out-of-box)" # ~10s |
| 22 | programs/test/selftest |
| 23 | |
| 24 | msg "program demos: make, default config (out-of-box)" # ~10s |
| 25 | tests/scripts/run_demos.py |
| 26 | } |
| 27 | |
| 28 | component_test_default_cmake_gcc_asan () { |
| 29 | msg "build: cmake, gcc, ASan" # ~ 1 min 50s |
| 30 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 31 | make |
| 32 | |
| 33 | msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s |
| 34 | make test |
| 35 | |
| 36 | msg "program demos (ASan build)" # ~10s |
| 37 | tests/scripts/run_demos.py |
| 38 | |
| 39 | msg "test: selftest (ASan build)" # ~ 10s |
| 40 | programs/test/selftest |
| 41 | |
| 42 | msg "test: metatests (GCC, ASan build)" |
| 43 | tests/scripts/run-metatests.sh any asan poison |
| 44 | |
| 45 | msg "test: ssl-opt.sh (ASan build)" # ~ 1 min |
| 46 | tests/ssl-opt.sh |
| 47 | |
| 48 | msg "test: compat.sh (ASan build)" # ~ 6 min |
| 49 | tests/compat.sh |
| 50 | |
| 51 | msg "test: context-info.sh (ASan build)" # ~ 15 sec |
| 52 | tests/context-info.sh |
| 53 | } |
| 54 | |
| 55 | component_test_default_cmake_gcc_asan_new_bignum () { |
| 56 | msg "build: cmake, gcc, ASan" # ~ 1 min 50s |
| 57 | scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT |
| 58 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 59 | make |
| 60 | |
| 61 | msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s |
| 62 | make test |
| 63 | |
| 64 | msg "test: selftest (ASan build)" # ~ 10s |
| 65 | programs/test/selftest |
| 66 | |
| 67 | msg "test: ssl-opt.sh (ASan build)" # ~ 1 min |
| 68 | tests/ssl-opt.sh |
| 69 | |
| 70 | msg "test: compat.sh (ASan build)" # ~ 6 min |
| 71 | tests/compat.sh |
| 72 | |
| 73 | msg "test: context-info.sh (ASan build)" # ~ 15 sec |
| 74 | tests/context-info.sh |
| 75 | } |
| 76 | |
| 77 | component_test_full_cmake_gcc_asan () { |
| 78 | msg "build: full config, cmake, gcc, ASan" |
| 79 | scripts/config.py full |
| 80 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 81 | make |
| 82 | |
| 83 | msg "test: main suites (inc. selftests) (full config, ASan build)" |
| 84 | make test |
| 85 | |
| 86 | msg "test: selftest (full config, ASan build)" # ~ 10s |
| 87 | programs/test/selftest |
| 88 | |
| 89 | msg "test: ssl-opt.sh (full config, ASan build)" |
| 90 | tests/ssl-opt.sh |
| 91 | |
| 92 | # Note: the next two invocations cover all compat.sh test cases. |
| 93 | # We should use the same here and in basic-build-test.sh. |
| 94 | msg "test: compat.sh: default version (full config, ASan build)" |
| 95 | tests/compat.sh -e 'ARIA\|CHACHA' |
| 96 | |
| 97 | msg "test: compat.sh: next: ARIA, Chacha (full config, ASan build)" |
| 98 | env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA' |
| 99 | |
| 100 | msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec |
| 101 | tests/context-info.sh |
| 102 | } |
| 103 | |
| 104 | component_test_full_cmake_gcc_asan_new_bignum () { |
| 105 | msg "build: full config, cmake, gcc, ASan" |
| 106 | scripts/config.py full |
| 107 | scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT |
| 108 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 109 | make |
| 110 | |
| 111 | msg "test: main suites (inc. selftests) (full config, new bignum, ASan)" |
| 112 | make test |
| 113 | |
| 114 | msg "test: selftest (full config, new bignum, ASan)" # ~ 10s |
| 115 | programs/test/selftest |
| 116 | |
| 117 | msg "test: ssl-opt.sh (full config, new bignum, ASan)" |
| 118 | tests/ssl-opt.sh |
| 119 | |
| 120 | # Note: the next two invocations cover all compat.sh test cases. |
| 121 | # We should use the same here and in basic-build-test.sh. |
| 122 | msg "test: compat.sh: default version (full config, new bignum, ASan)" |
| 123 | tests/compat.sh -e 'ARIA\|CHACHA' |
| 124 | |
| 125 | msg "test: compat.sh: next: ARIA, Chacha (full config, new bignum, ASan)" |
| 126 | env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA' |
| 127 | |
| 128 | msg "test: context-info.sh (full config, new bignum, ASan)" # ~ 15 sec |
| 129 | tests/context-info.sh |
| 130 | } |
| 131 | |
Minos Galanakis | 31b7a0c | 2024-07-26 17:24:23 +0100 | [diff] [blame] | 132 | component_test_full_cmake_clang () { |
| 133 | msg "build: cmake, full config, clang" # ~ 50s |
| 134 | scripts/config.py full |
| 135 | CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 . |
| 136 | make |
| 137 | |
| 138 | msg "test: main suites (full config, clang)" # ~ 5s |
| 139 | make test |
| 140 | |
| 141 | msg "test: cpp_dummy_build (full config, clang)" # ~ 1s |
| 142 | programs/test/cpp_dummy_build |
| 143 | |
| 144 | msg "test: metatests (clang)" |
| 145 | tests/scripts/run-metatests.sh any pthread |
| 146 | |
| 147 | msg "program demos (full config, clang)" # ~10s |
| 148 | tests/scripts/run_demos.py |
| 149 | |
| 150 | msg "test: psa_constant_names (full config, clang)" # ~ 1s |
| 151 | tests/scripts/test_psa_constant_names.py |
| 152 | |
| 153 | msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s |
| 154 | tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private' |
| 155 | } |
| 156 | |
| 157 | component_test_default_no_deprecated () { |
| 158 | # Test that removing the deprecated features from the default |
| 159 | # configuration leaves something consistent. |
| 160 | msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s |
| 161 | scripts/config.py set MBEDTLS_DEPRECATED_REMOVED |
| 162 | make CFLAGS='-O -Werror -Wall -Wextra' |
| 163 | |
| 164 | msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s |
| 165 | make test |
| 166 | } |
| 167 | |
| 168 | component_test_full_no_deprecated () { |
| 169 | msg "build: make, full_no_deprecated config" # ~ 30s |
| 170 | scripts/config.py full_no_deprecated |
| 171 | make CFLAGS='-O -Werror -Wall -Wextra' |
| 172 | |
| 173 | msg "test: make, full_no_deprecated config" # ~ 5s |
| 174 | make test |
| 175 | |
| 176 | msg "test: ensure that X509 has no direct dependency on BIGNUM_C" |
| 177 | not grep mbedtls_mpi library/libmbedx509.a |
| 178 | } |
| 179 | |
| 180 | component_test_full_no_deprecated_deprecated_warning () { |
| 181 | # Test that there is nothing deprecated in "full_no_deprecated". |
| 182 | # A deprecated feature would trigger a warning (made fatal) from |
| 183 | # MBEDTLS_DEPRECATED_WARNING. |
| 184 | msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s |
| 185 | scripts/config.py full_no_deprecated |
| 186 | scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED |
| 187 | scripts/config.py set MBEDTLS_DEPRECATED_WARNING |
| 188 | make CFLAGS='-O -Werror -Wall -Wextra' |
| 189 | |
| 190 | msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s |
| 191 | make test |
| 192 | } |
| 193 | |
| 194 | component_test_full_deprecated_warning () { |
| 195 | # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes |
| 196 | # with only certain whitelisted types of warnings. |
| 197 | msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s |
| 198 | scripts/config.py full |
| 199 | scripts/config.py set MBEDTLS_DEPRECATED_WARNING |
| 200 | # Expect warnings from '#warning' directives in check_config.h. |
| 201 | # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to |
| 202 | # display #warning messages without them being treated as errors. |
| 203 | make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs |
| 204 | |
| 205 | msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s |
| 206 | # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features. |
| 207 | # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set. |
| 208 | # Expect warnings from '#warning' directives in check_config.h and |
| 209 | # from the use of deprecated functions in test suites. |
| 210 | make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests |
| 211 | |
| 212 | msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s |
| 213 | make test |
| 214 | |
| 215 | msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s |
| 216 | tests/scripts/run_demos.py |
| 217 | } |
| 218 | |
| 219 | component_build_baremetal () { |
| 220 | msg "build: make, baremetal config" |
| 221 | scripts/config.py baremetal |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame^] | 222 | make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/" |
Minos Galanakis | 31b7a0c | 2024-07-26 17:24:23 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | support_build_baremetal () { |
| 226 | # Older Glibc versions include time.h from other headers such as stdlib.h, |
| 227 | # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this |
| 228 | # problem, Ubuntu 18.04 is ok. |
| 229 | ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h |
| 230 | } |
| 231 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 232 | component_build_tfm () { |
Minos Galanakis | 31b7a0c | 2024-07-26 17:24:23 +0100 | [diff] [blame] | 233 | # Check that the TF-M configuration can build cleanly with various |
| 234 | # warning flags enabled. We don't build or run tests, since the |
| 235 | # TF-M configuration needs a TF-M platform. A tweaked version of |
| 236 | # the configuration that works on mainstream platforms is in |
| 237 | # configs/config-tfm.h, tested via test-ref-configs.pl. |
| 238 | cp configs/config-tfm.h "$CONFIG_H" |
| 239 | |
| 240 | msg "build: TF-M config, clang, armv7-m thumb2" |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame^] | 241 | make lib CC="clang" CFLAGS="--target=arm-linux-gnueabihf -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../framework/tests/include/spe" |
Minos Galanakis | 31b7a0c | 2024-07-26 17:24:23 +0100 | [diff] [blame] | 242 | |
| 243 | msg "build: TF-M config, gcc native build" |
| 244 | make clean |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame^] | 245 | make lib CC="gcc" CFLAGS="-Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wformat-signedness -Wlogical-op -I../framework/tests/include/spe" |
Minos Galanakis | 31b7a0c | 2024-07-26 17:24:23 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Minos Galanakis | 9ceb2c3 | 2024-08-01 12:28:19 +0100 | [diff] [blame] | 248 | component_test_malloc_0_null () { |
| 249 | msg "build: malloc(0) returns NULL (ASan+UBSan build)" |
| 250 | scripts/config.py full |
| 251 | make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 252 | |
| 253 | msg "test: malloc(0) returns NULL (ASan+UBSan build)" |
| 254 | make test |
| 255 | |
| 256 | msg "selftest: malloc(0) returns NULL (ASan+UBSan build)" |
| 257 | # Just the calloc selftest. "make test" ran the others as part of the |
| 258 | # test suites. |
| 259 | programs/test/selftest calloc |
| 260 | |
| 261 | msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)" |
| 262 | # Run a subset of the tests. The choice is a balance between coverage |
| 263 | # and time (including time indirectly wasted due to flaky tests). |
| 264 | # The current choice is to skip tests whose description includes |
| 265 | # "proxy", which is an approximation of skipping tests that use the |
| 266 | # UDP proxy, which tend to be slower and flakier. |
| 267 | tests/ssl-opt.sh -e 'proxy' |
| 268 | } |
| 269 | |
Minos Galanakis | 31b7a0c | 2024-07-26 17:24:23 +0100 | [diff] [blame] | 270 | component_test_no_platform () { |
| 271 | # Full configuration build, without platform support, file IO and net sockets. |
| 272 | # This should catch missing mbedtls_printf definitions, and by disabling file |
| 273 | # IO, it should catch missing '#include <stdio.h>' |
| 274 | msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s |
| 275 | scripts/config.py full_no_platform |
| 276 | scripts/config.py unset MBEDTLS_PLATFORM_C |
| 277 | scripts/config.py unset MBEDTLS_NET_C |
| 278 | scripts/config.py unset MBEDTLS_FS_IO |
| 279 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C |
| 280 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C |
| 281 | scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C |
| 282 | scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED |
| 283 | # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19, |
| 284 | # to re-enable platform integration features otherwise disabled in C99 builds |
| 285 | make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs |
| 286 | make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test |
| 287 | } |
| 288 | |
| 289 | component_build_mbedtls_config_file () { |
| 290 | msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s |
| 291 | scripts/config.py -w full_config.h full |
| 292 | echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H" |
| 293 | make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'" |
| 294 | # Make sure this feature is enabled. We'll disable it in the next phase. |
| 295 | programs/test/query_compile_time_config MBEDTLS_NIST_KW_C |
| 296 | make clean |
| 297 | |
| 298 | msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE" |
| 299 | # In the user config, disable one feature (for simplicity, pick a feature |
| 300 | # that nothing else depends on). |
| 301 | echo '#undef MBEDTLS_NIST_KW_C' >user_config.h |
| 302 | make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'" |
| 303 | not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C |
| 304 | |
| 305 | rm -f user_config.h full_config.h |
| 306 | } |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 307 | |
Minos Galanakis | 1c26ef5 | 2024-08-01 11:58:16 +0100 | [diff] [blame] | 308 | component_test_no_strings () { |
| 309 | msg "build: no strings" # ~10s |
| 310 | scripts/config.py full |
| 311 | # Disable options that activate a large amount of string constants. |
| 312 | scripts/config.py unset MBEDTLS_DEBUG_C |
| 313 | scripts/config.py unset MBEDTLS_ERROR_C |
| 314 | scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY |
| 315 | scripts/config.py unset MBEDTLS_VERSION_FEATURES |
| 316 | make CFLAGS='-Werror -Os' |
| 317 | |
| 318 | msg "test: no strings" # ~ 10s |
| 319 | make test |
Minos Galanakis | 9ceb2c3 | 2024-08-01 12:28:19 +0100 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | component_test_memory_buffer_allocator_backtrace () { |
| 323 | msg "build: default config with memory buffer allocator and backtrace enabled" |
| 324 | scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 325 | scripts/config.py set MBEDTLS_PLATFORM_MEMORY |
| 326 | scripts/config.py set MBEDTLS_MEMORY_BACKTRACE |
| 327 | scripts/config.py set MBEDTLS_MEMORY_DEBUG |
| 328 | cmake -DCMAKE_BUILD_TYPE:String=Release . |
| 329 | make |
| 330 | |
| 331 | msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE" |
| 332 | make test |
| 333 | } |
| 334 | |
| 335 | component_test_memory_buffer_allocator () { |
| 336 | msg "build: default config with memory buffer allocator" |
| 337 | scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 338 | scripts/config.py set MBEDTLS_PLATFORM_MEMORY |
| 339 | cmake -DCMAKE_BUILD_TYPE:String=Release . |
| 340 | make |
| 341 | |
| 342 | msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C" |
| 343 | make test |
| 344 | |
| 345 | msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C" |
| 346 | # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out. |
| 347 | tests/ssl-opt.sh -e '^DTLS proxy' |
| 348 | } |