5 # This file is part of mbed TLS (https://tls.mbed.org)
7 # Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
11 ################################################################
13 ################################################################
18 # To run all tests possible or available on the platform.
23 # Warning: the test is destructive. It includes various build modes and
24 # configurations, and can and will arbitrarily change the current CMake
25 # configuration. The following files must be committed into git:
26 # * include/mbedtls/config.h
27 # * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28 # After running this script, the CMake cache will be lost and CMake
29 # will no longer be initialised.
31 # The script assumes the presence of a number of tools:
32 # * Basic Unix tools (Windows users note: a Unix-style find must be before
33 # the Windows find in the PATH)
37 # * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
39 # * arm-gcc and mingw-gcc
40 # * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
41 # * OpenSSL and GnuTLS command line tools, recent enough for the
42 # interoperability tests. If they don't support SSLv3 then a legacy
43 # version of these tools must be present as well (search for LEGACY
45 # See the invocation of check_tools below for details.
47 # This script must be invoked from the toplevel directory of a git
48 # working copy of Mbed TLS.
50 # Note that the output is not saved. You may want to run
51 # script -c tests/scripts/all.sh
53 # tests/scripts/all.sh >all.log 2>&1
55 # Notes for maintainers
56 # ---------------------
58 # The bulk of the code is organized into functions that follow one of the
59 # following naming conventions:
60 # * pre_XXX: things to do before running the tests, in order.
61 # * component_XXX: independent components. They can be run in any order.
62 # * component_check_XXX: quick tests that aren't worth parallelizing.
63 # * component_build_XXX: build things but don't run them.
64 # * component_test_XXX: build and test.
65 # * support_XXX: if support_XXX exists and returns false then
66 # component_XXX is not run by default.
67 # * post_XXX: things to do after running the tests.
68 # * other: miscellaneous support functions.
70 # Each component must start by invoking `msg` with a short informative message.
72 # The framework performs some cleanup tasks after each component. This
73 # means that components can assume that the working directory is in a
74 # cleaned-up state, and don't need to perform the cleanup themselves.
76 # * Restore `include/mbedtks/config.h` from a backup made before running
78 # * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
79 # `tests/Makefile` from git. This cleans up after an in-tree use of
82 # Any command that is expected to fail must be protected so that the
83 # script keeps running in --keep-going mode despite `set -e`. In keep-going
84 # mode, if a protected command fails, this is logged as a failure and the
85 # script will exit with a failure status once it has run all components.
86 # Commands can be protected in any of the following ways:
87 # * `make` is a function which runs the `make` command with protection.
88 # Note that you must write `make VAR=value`, not `VAR=value make`,
89 # because the `VAR=value make` syntax doesn't work with functions.
90 # * Put `report_status` before the command to protect it.
91 # * Put `if_build_successful` before a command. This protects it, and
92 # additionally skips it if a prior invocation of `make` in the same
95 # The tests are roughly in order from fastest to slowest. This doesn't
96 # have to be exact, but in general you should add slower tests towards
97 # the end and fast checks near the beginning.
101 ################################################################
102 #### Initialization and command line parsing
103 ################################################################
105 # Abort on errors (and uninitialised variables)
108 pre_check_environment () {
109 if [ -d library -a -d include -a -d tests ]; then :; else
110 echo "Must be run from mbed TLS root" >&2
115 pre_initialize_variables () {
116 CONFIG_H='include/mbedtls/config.h'
117 CONFIG_BAK="$CONFIG_H.bak"
123 # Default commands, can be overridden by the environment
124 : ${OPENSSL:="openssl"}
125 : ${OPENSSL_LEGACY:="$OPENSSL"}
126 : ${OPENSSL_NEXT:="$OPENSSL"}
127 : ${GNUTLS_CLI:="gnutls-cli"}
128 : ${GNUTLS_SERV:="gnutls-serv"}
129 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
130 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
131 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
132 : ${ARMC5_BIN_DIR:=/usr/bin}
133 : ${ARMC6_BIN_DIR:=/usr/bin}
135 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
136 if [ -z "${MAKEFLAGS+set}" ]; then
137 export MAKEFLAGS="-j"
140 # Gather the list of available components. These are the functions
141 # defined in this script whose name starts with "component_".
142 # Parse the script with sed, because in sh there is no way to list
144 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
146 # Exclude components that are not supported on this platform.
147 SUPPORTED_COMPONENTS=
148 for component in $ALL_COMPONENTS; do
149 case $(type "support_$component" 2>&1) in
151 if ! support_$component; then continue; fi;;
153 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
157 # Test whether the component $1 is included in the command line patterns.
158 is_component_included()
161 for pattern in $COMMAND_LINE_COMPONENTS; do
163 case ${1#component_} in $pattern) return 0;; esac
172 Usage: $0 [OPTION]... [COMPONENT]...
173 Run mbedtls release validation tests.
174 By default, run all tests. With one or more COMPONENT, run only those.
175 COMPONENT can be the name of a component or a shell wildcard pattern.
179 Run all sanity checks.
180 $0 --no-armcc --except test_memsan
181 Run everything except builds that require armcc and MemSan.
184 -h|--help Print this help and exit.
185 --list-all-components List all available test components and exit.
186 --list-components List components supported on this platform and exit.
189 -f|--force Force the tests to overwrite any modified files.
190 -k|--keep-going Run all tests and report errors at the end.
191 -m|--memory Additional optional memory tests.
192 --armcc Run ARM Compiler builds (on by default).
193 --except Exclude the COMPONENTs listed on the command line,
194 instead of running only those.
195 --no-armcc Skip ARM Compiler builds.
196 --no-force Refuse to overwrite modified files (default).
197 --no-keep-going Stop at the first error (default).
198 --no-memory No additional memory tests (default).
199 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
200 --random-seed Use a random seed value for randomized tests (default).
201 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
202 -s|--seed Integer seed value to use for this test run.
205 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
206 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
207 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
208 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
209 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
210 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
211 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
212 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
213 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
217 # remove built files as well as the cmake cache/config
220 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
221 cd "$MBEDTLS_ROOT_DIR"
229 # Remove CMake artefacts
230 find . -name .git -prune -o \
231 -iname CMakeFiles -exec rm -rf {} \+ -o \
232 \( -iname cmake_install.cmake -o \
233 -iname CTestTestfile.cmake -o \
234 -iname CMakeCache.txt \) -exec rm {} \+
235 # Recover files overwritten by in-tree CMake builds
236 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
237 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
238 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
240 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
241 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
242 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
245 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
246 rm -rf programs/test/cmake_subproject/build
247 rm -f programs/test/cmake_subproject/Makefile
248 rm -f programs/test/cmake_subproject/cmake_subproject
250 if [ -f "$CONFIG_BAK" ]; then
251 mv "$CONFIG_BAK" "$CONFIG_H"
255 # Executed on exit. May be redefined depending on command line options.
267 trap 'fatal_signal HUP' HUP
268 trap 'fatal_signal INT' INT
269 trap 'fatal_signal TERM' TERM
273 if [ -n "${current_component:-}" ]; then
274 current_section="${current_component#component_}: $1"
279 echo "******************************************************************"
280 echo "* $current_section "
282 echo "******************************************************************"
289 msg "build: ARM Compiler 6 ($FLAGS), make"
290 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
291 WARNING_CFLAGS='-xc -std=c99' make lib
303 if ! `type "$TOOL" >/dev/null 2>&1`; then
304 err_msg "$TOOL not found!"
310 check_headers_in_cpp () {
311 ls include/mbedtls | grep "\.h$" >headers.txt
312 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
318 pre_parse_command_line () {
319 COMMAND_LINE_COMPONENTS=
323 while [ $# -gt 0 ]; do
326 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
327 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
328 --except) all_except=1;;
329 --force|-f) FORCE=1;;
330 --gnutls-cli) shift; GNUTLS_CLI="$1";;
331 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
332 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
333 --gnutls-serv) shift; GNUTLS_SERV="$1";;
334 --help|-h) usage; exit;;
335 --keep-going|-k) KEEP_GOING=1;;
336 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
337 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
338 --memory|-m) MEMORY=1;;
339 --no-armcc) no_armcc=1;;
340 --no-force) FORCE=0;;
341 --no-keep-going) KEEP_GOING=0;;
342 --no-memory) MEMORY=0;;
343 --openssl) shift; OPENSSL="$1";;
344 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
345 --openssl-next) shift; OPENSSL_NEXT="$1";;
346 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
347 --random-seed) unset SEED;;
348 --release-test|-r) SEED=1;;
349 --seed|-s) shift; SEED="$1";;
351 echo >&2 "Unknown option: $1"
352 echo >&2 "Run $0 --help for usage."
355 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
360 # With no list of components, run everything.
361 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
365 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
366 # Ignore it if components are listed explicitly on the command line.
367 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
368 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
371 # Build the list of components to run.
373 for component in $SUPPORTED_COMPONENTS; do
374 if is_component_included "$component"; [ $? -eq $all_except ]; then
375 RUN_COMPONENTS="$RUN_COMPONENTS $component"
384 if [ $FORCE -eq 1 ]; then
385 rm -rf "$OUT_OF_SOURCE_DIR"
386 git checkout-index -f -q $CONFIG_H
390 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
391 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
392 echo "You can either delete this directory manually, or force the test by rerunning"
393 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
397 if ! git diff --quiet include/mbedtls/config.h; then
398 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
399 echo "You can either delete or preserve your work, or force the test by rerunning the"
400 echo "script as: $0 --force"
404 if ! [ -f crypto/Makefile ]; then
405 echo "Please initialize the crypto submodule" >&2
410 pre_check_seedfile () {
411 if [ ! -f "./tests/seedfile" ]; then
412 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
414 if [ ! -f "./crypto/tests/seedfile" ]; then
415 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
419 pre_setup_keep_going () {
426 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
427 start_red=$(printf '\033[31m')
428 end_color=$(printf '\033[0m')
437 text="$current_section: $* -> $last_status"
438 failure_summary="$failure_summary
440 failure_count=$((failure_count + 1))
441 echo "${start_red}^^^^$text^^^^${end_color}"
447 if [ $build_status -eq 0 ]; then
448 record_status command make "$@"
450 echo "(skipped because the build failed)"
454 record_status command make "$@"
455 build_status=$last_status
460 if [ $failure_count -gt 0 ]; then
462 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
463 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
464 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
466 elif [ -z "${1-}" ]; then
469 if [ -n "${1-}" ]; then
470 echo "Killed by SIG$1."
475 if_build_succeeded () {
476 if [ $build_status -eq 0 ]; then
481 # to be used instead of ! for commands run with
482 # record_status or if_build_succeeded
487 pre_print_configuration () {
488 msg "info: $0 configuration"
489 echo "MEMORY: $MEMORY"
491 echo "SEED: ${SEED-"UNSET"}"
492 echo "OPENSSL: $OPENSSL"
493 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
494 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
495 echo "GNUTLS_CLI: $GNUTLS_CLI"
496 echo "GNUTLS_SERV: $GNUTLS_SERV"
497 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
498 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
499 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
500 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
503 # Make sure the tools we need are available.
505 # Build the list of variables to pass to output_env.sh.
508 case " $RUN_COMPONENTS " in
509 # Require OpenSSL and GnuTLS if running any tests (as opposed to
510 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
511 # is a good enough approximation in practice.
513 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
514 # and ssl-opt.sh, we just export the variables they require.
515 export OPENSSL_CMD="$OPENSSL"
516 export GNUTLS_CLI="$GNUTLS_CLI"
517 export GNUTLS_SERV="$GNUTLS_SERV"
518 # Avoid passing --seed flag in every call to ssl-opt.sh
519 if [ -n "${SEED-}" ]; then
522 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
523 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
524 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
525 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
526 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
527 "$GNUTLS_CLI" "$GNUTLS_SERV" \
528 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
532 case " $RUN_COMPONENTS " in
533 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
536 case " $RUN_COMPONENTS " in
537 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
540 case " $RUN_COMPONENTS " in
541 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
544 case " $RUN_COMPONENTS " in
545 *" test_zeroize "*) check_tools "gdb";;
548 case " $RUN_COMPONENTS " in
550 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
551 ARMC5_AR="$ARMC5_BIN_DIR/armar"
552 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
553 ARMC6_AR="$ARMC6_BIN_DIR/armar"
554 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
557 msg "info: output_env.sh"
558 case $RUN_COMPONENTS in
560 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
561 *) set "$@" RUN_ARMCC=0;;
563 "$@" scripts/output_env.sh
568 ################################################################
570 ################################################################
573 # Test Suites to be executed
575 # The test ordering tries to optimize for the following criteria:
576 # 1. Catch possible problems early, by running first tests that run quickly
577 # and/or are more likely to fail than others (eg I use Clang most of the
578 # time, so start with a GCC build).
579 # 2. Minimize total running time, by avoiding useless rebuilds
581 # Indicative running times are given for reference.
583 component_check_recursion () {
584 msg "test: recursion.pl" # < 1s
585 record_status tests/scripts/recursion.pl library/*.c
588 component_check_generated_files () {
589 msg "test: freshness of generated source files" # < 1s
590 record_status tests/scripts/check-generated-files.sh
593 component_check_doxy_blocks () {
594 msg "test: doxygen markup outside doxygen blocks" # < 1s
595 record_status tests/scripts/check-doxy-blocks.pl
598 component_check_files () {
599 msg "test: check-files.py" # < 1s
600 record_status tests/scripts/check-files.py
603 component_check_names () {
604 msg "test/build: declared and exported names" # < 3s
605 record_status tests/scripts/check-names.sh -v
608 component_check_doxygen_warnings () {
609 msg "test: doxygen warnings" # ~ 3s
610 record_status tests/scripts/doxygen.sh
615 ################################################################
616 #### Build and test many configurations and targets
617 ################################################################
619 component_test_default_out_of_box () {
620 msg "build: make, default config (out-of-box)" # ~1min
623 msg "test: main suites make, default config (out-of-box)" # ~10s
626 msg "selftest: make, default config (out-of-box)" # ~10s
627 programs/test/selftest
630 component_test_default_cmake_gcc_asan () {
631 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
632 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
635 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
638 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
639 if_build_succeeded tests/ssl-opt.sh
641 msg "test: compat.sh (ASan build)" # ~ 6 min
642 if_build_succeeded tests/compat.sh
645 component_test_ref_configs () {
646 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
647 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
648 record_status tests/scripts/test-ref-configs.pl
651 component_test_sslv3 () {
652 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
653 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
654 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
657 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
660 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
661 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
662 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
664 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
665 if_build_succeeded tests/ssl-opt.sh
668 component_test_no_renegotiation () {
669 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
670 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
671 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
674 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
677 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
678 if_build_succeeded tests/ssl-opt.sh
681 component_test_rsa_no_crt () {
682 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
683 scripts/config.pl set MBEDTLS_RSA_NO_CRT
684 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
687 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
690 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
691 if_build_succeeded tests/ssl-opt.sh -f RSA
693 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
694 if_build_succeeded tests/compat.sh -t RSA
697 component_test_small_ssl_out_content_len () {
698 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
699 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
700 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
701 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
704 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
705 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
708 component_test_small_ssl_in_content_len () {
709 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
710 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
711 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
712 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
715 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
716 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
719 component_test_small_ssl_dtls_max_buffering () {
720 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
721 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
722 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
725 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
726 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
729 component_test_small_mbedtls_ssl_dtls_max_buffering () {
730 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
731 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
732 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
735 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
736 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
739 component_test_full_cmake_clang () {
740 msg "build: cmake, full config, clang" # ~ 50s
741 scripts/config.pl full
742 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
743 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
746 msg "test: main suites (full config)" # ~ 5s
749 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
750 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
752 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
753 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
755 msg "test: compat.sh ARIA + ChachaPoly"
756 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
759 component_build_deprecated () {
760 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
761 scripts/config.pl full
762 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
763 # Build with -O -Wextra to catch a maximum of issues.
764 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
765 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
767 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
768 # No cleanup, just tweak the configuration and rebuild
770 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
771 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
772 # Build with -O -Wextra to catch a maximum of issues.
773 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
774 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
777 component_test_depends_curves () {
778 msg "test/build: curves.pl (gcc)" # ~ 4 min
779 record_status tests/scripts/curves.pl
782 component_test_depends_hashes () {
783 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
784 record_status tests/scripts/depends-hashes.pl
787 component_test_depends_pkalgs () {
788 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
789 record_status tests/scripts/depends-pkalgs.pl
792 component_build_key_exchanges () {
793 msg "test/build: key-exchanges (gcc)" # ~ 1 min
794 record_status tests/scripts/key-exchanges.pl
797 component_build_default_make_gcc_and_cxx () {
798 msg "build: Unix make, -Os (gcc)" # ~ 30s
799 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
801 msg "test: verify header list in cpp_dummy_build.cpp"
802 record_status check_headers_in_cpp
804 msg "build: Unix make, incremental g++"
808 component_test_no_use_psa_crypto_full_cmake_asan() {
809 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
810 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
811 scripts/config.pl full
812 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
813 scripts/config.pl unset MBEDTLS_ECP_RESTARTABLE # restartable ECC not supported through PSA
814 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
815 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
816 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
817 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
818 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
821 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
824 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
825 if_build_succeeded tests/ssl-opt.sh
827 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
828 if_build_succeeded tests/compat.sh
830 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
831 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
833 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
834 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
836 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
837 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
840 component_test_check_params_without_platform () {
841 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
842 scripts/config.pl full # includes CHECK_PARAMS
843 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
844 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
845 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
846 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
847 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
848 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
849 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
850 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
851 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
852 scripts/config.pl unset MBEDTLS_PLATFORM_C
853 make CC=gcc CFLAGS='-Werror -O1' all test
856 component_test_check_params_silent () {
857 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
858 scripts/config.pl full # includes CHECK_PARAMS
859 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
860 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
861 make CC=gcc CFLAGS='-Werror -O1' all test
864 component_test_no_platform () {
865 # Full configuration build, without platform support, file IO and net sockets.
866 # This should catch missing mbedtls_printf definitions, and by disabling file
867 # IO, it should catch missing '#include <stdio.h>'
868 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
869 scripts/config.pl full
870 scripts/config.pl unset MBEDTLS_PLATFORM_C
871 scripts/config.pl unset MBEDTLS_NET_C
872 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
873 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
874 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
875 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
876 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
877 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
878 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
879 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
880 scripts/config.pl unset MBEDTLS_FS_IO
881 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
882 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
883 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
884 # to re-enable platform integration features otherwise disabled in C99 builds
885 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
886 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
889 component_build_no_std_function () {
890 # catch compile bugs in _uninit functions
891 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
892 scripts/config.pl full
893 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
894 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
895 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
898 component_build_no_ssl_srv () {
899 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
900 scripts/config.pl full
901 scripts/config.pl unset MBEDTLS_SSL_SRV_C
902 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
905 component_build_no_ssl_cli () {
906 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
907 scripts/config.pl full
908 scripts/config.pl unset MBEDTLS_SSL_CLI_C
909 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
912 component_build_no_sockets () {
913 # Note, C99 compliance can also be tested with the sockets support disabled,
914 # as that requires a POSIX platform (which isn't the same as C99).
915 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
916 scripts/config.pl full
917 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
918 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
919 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
922 component_test_no_max_fragment_length () {
923 # Run max fragment length tests with MFL disabled
924 msg "build: default config except MFL extension (ASan build)" # ~ 30s
925 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
926 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
929 msg "test: ssl-opt.sh, MFL-related tests"
930 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
933 component_test_asan_remove_peer_certificate () {
934 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
935 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
936 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
939 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
942 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
943 if_build_succeeded tests/ssl-opt.sh
945 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
946 if_build_succeeded tests/compat.sh
949 component_test_no_max_fragment_length_small_ssl_out_content_len () {
950 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
951 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
952 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
953 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
954 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
957 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
958 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
961 component_test_when_no_ciphersuites_have_mac () {
962 msg "build: when no ciphersuites have MAC"
963 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
964 scripts/config.pl unset MBEDTLS_ARC4_C
965 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
968 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
971 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
972 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
975 component_test_null_entropy () {
976 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
977 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
978 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
979 scripts/config.pl set MBEDTLS_ENTROPY_C
980 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
981 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
982 scripts/config.pl unset MBEDTLS_HAVEGE_C
983 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
986 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
990 component_test_platform_calloc_macro () {
991 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
992 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
993 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
994 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
995 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
998 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1002 component_test_make_shared () {
1003 msg "build/test: make shared" # ~ 40s
1004 make SHARED=1 all check -j1
1007 component_test_m32_o0 () {
1008 # Build once with -O0, to compile out the i386 specific inline assembly
1009 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1010 scripts/config.pl full
1011 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
1013 msg "test: i386, make, gcc -O0 (ASan build)"
1016 support_test_m32_o0 () {
1023 component_test_m32_o1 () {
1024 # Build again with -O1, to compile in the i386 specific inline assembly
1025 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1026 scripts/config.pl full
1027 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
1028 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1029 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
1030 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
1032 msg "test: i386, make, gcc -O1 (ASan build)"
1035 msg "test ssl-opt.sh, i386, make, gcc-O1"
1036 if_build_succeeded tests/ssl-opt.sh
1038 support_test_m32_o1 () {
1039 support_test_m32_o0 "$@"
1042 component_test_mx32 () {
1043 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1044 scripts/config.pl full
1045 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
1047 msg "test: 64-bit ILP32, make, gcc"
1050 support_test_mx32 () {
1052 amd64|x86_64) true;;
1057 component_build_arm_none_eabi_gcc () {
1058 msg "build: arm-none-eabi-gcc, make" # ~ 10s
1059 scripts/config.pl full
1060 scripts/config.pl unset MBEDTLS_NET_C
1061 scripts/config.pl unset MBEDTLS_TIMING_C
1062 scripts/config.pl unset MBEDTLS_FS_IO
1063 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1064 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1065 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1066 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
1067 # following things are not in the default config
1068 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1069 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1070 scripts/config.pl unset MBEDTLS_THREADING_C
1071 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1072 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1073 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1076 component_build_arm_none_eabi_gcc_no_udbl_division () {
1077 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
1078 scripts/config.pl full
1079 scripts/config.pl unset MBEDTLS_NET_C
1080 scripts/config.pl unset MBEDTLS_TIMING_C
1081 scripts/config.pl unset MBEDTLS_FS_IO
1082 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1083 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1084 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1085 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
1086 # following things are not in the default config
1087 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1088 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1089 scripts/config.pl unset MBEDTLS_THREADING_C
1090 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1091 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1092 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1093 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1094 echo "Checking that software 64-bit division is not required"
1095 if_build_succeeded not grep __aeabi_uldiv library/*.o
1098 component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1099 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
1100 scripts/config.pl full
1101 scripts/config.pl unset MBEDTLS_NET_C
1102 scripts/config.pl unset MBEDTLS_TIMING_C
1103 scripts/config.pl unset MBEDTLS_FS_IO
1104 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1105 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1106 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
1107 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1108 # following things are not in the default config
1109 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1110 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1111 scripts/config.pl unset MBEDTLS_THREADING_C
1112 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1113 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1114 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1115 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1116 echo "Checking that software 64-bit multiplication is not required"
1117 if_build_succeeded not grep __aeabi_lmul library/*.o
1120 component_build_armcc () {
1121 msg "build: ARM Compiler 5, make"
1122 scripts/config.pl full
1123 scripts/config.pl unset MBEDTLS_NET_C
1124 scripts/config.pl unset MBEDTLS_TIMING_C
1125 scripts/config.pl unset MBEDTLS_FS_IO
1126 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1127 scripts/config.pl unset MBEDTLS_HAVE_TIME
1128 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1129 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1130 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1131 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
1132 # following things are not in the default config
1133 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1134 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1135 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1136 scripts/config.pl unset MBEDTLS_THREADING_C
1137 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1138 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1139 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
1141 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1144 # ARM Compiler 6 - Target ARMv7-A
1145 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
1147 # ARM Compiler 6 - Target ARMv7-M
1148 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
1150 # ARM Compiler 6 - Target ARMv8-A - AArch32
1151 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
1153 # ARM Compiler 6 - Target ARMv8-M
1154 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
1156 # ARM Compiler 6 - Target ARMv8-A - AArch64
1157 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1160 component_test_allow_sha1 () {
1161 msg "build: allow SHA1 in certificates by default"
1162 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1163 make CFLAGS='-Werror -Wall -Wextra'
1164 msg "test: allow SHA1 in certificates by default"
1166 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1169 component_build_mingw () {
1170 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
1171 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs -j1
1173 # note Make tests only builds the tests, but doesn't run them
1174 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests -j1
1175 make WINDOWS_BUILD=1 clean
1177 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1178 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs -j1
1179 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests -j1
1180 make WINDOWS_BUILD=1 clean
1182 support_build_mingw() {
1183 case $(i686-w64-mingw32-gcc -dumpversion) in
1189 component_test_memsan () {
1190 msg "build: MSan (clang)" # ~ 1 min 20s
1191 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1192 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1195 msg "test: main suites (MSan)" # ~ 10s
1198 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1199 if_build_succeeded tests/ssl-opt.sh
1203 if [ "$MEMORY" -gt 0 ]; then
1204 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1205 if_build_succeeded tests/compat.sh
1209 component_test_valgrind () {
1210 msg "build: Release (clang)"
1211 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1214 msg "test: main suites valgrind (Release)"
1217 # Optional parts (slow; currently broken on OS X because programs don't
1218 # seem to receive signals under valgrind on OS X).
1219 if [ "$MEMORY" -gt 0 ]; then
1220 msg "test: ssl-opt.sh --memcheck (Release)"
1221 if_build_succeeded tests/ssl-opt.sh --memcheck
1224 if [ "$MEMORY" -gt 1 ]; then
1225 msg "test: compat.sh --memcheck (Release)"
1226 if_build_succeeded tests/compat.sh --memcheck
1230 component_test_cmake_out_of_source () {
1231 msg "build: cmake 'out-of-source' build"
1232 MBEDTLS_ROOT_DIR="$PWD"
1233 mkdir "$OUT_OF_SOURCE_DIR"
1234 cd "$OUT_OF_SOURCE_DIR"
1235 cmake "$MBEDTLS_ROOT_DIR"
1238 msg "test: cmake 'out-of-source' build"
1240 # Test an SSL option that requires an auxiliary script in test/scripts/.
1241 # Also ensure that there are no error messages such as
1242 # "No such file or directory", which would indicate that some required
1243 # file is missing (ssl-opt.sh tolerates the absence of some files so
1244 # may exit with status 0 but emit errors).
1245 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1246 if [ -s ssl-opt.err ]; then
1248 record_status [ ! -s ssl-opt.err ]
1251 cd "$MBEDTLS_ROOT_DIR"
1252 rm -rf "$OUT_OF_SOURCE_DIR"
1253 unset MBEDTLS_ROOT_DIR
1256 component_test_cmake_as_subdirectory () {
1257 msg "build: cmake 'as-subdirectory' build"
1258 MBEDTLS_ROOT_DIR="$PWD"
1260 cd programs/test/cmake_subproject
1263 if_build_succeeded ./cmake_subproject
1265 cd "$MBEDTLS_ROOT_DIR"
1266 unset MBEDTLS_ROOT_DIR
1269 component_test_zeroize () {
1270 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1271 # different combinations of compilers and optimization flags by using an
1272 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1273 # system in all cases that the script fails, so we must manually search the
1274 # output to check whether the pass string is present and no failure strings
1277 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1278 # about a spurious message if Gdb tries and fails, so suppress that.
1280 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1281 gdb_disable_aslr='set disable-randomization off'
1284 for optimization_flag in -O2 -O3 -Ofast -Os; do
1285 for compiler in clang gcc; do
1286 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1287 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
1288 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
1289 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1290 if_build_succeeded not grep -i "error" test_zeroize.log
1291 rm -f test_zeroize.log
1296 unset gdb_disable_aslr
1299 support_check_python_files () {
1300 type pylint3 >/dev/null 2>/dev/null
1302 component_check_python_files () {
1303 msg "Lint: Python scripts"
1304 record_status tests/scripts/check-python-files.sh
1307 component_check_generate_test_code () {
1308 msg "uint test: generate_test_code.py"
1309 record_status ./tests/scripts/test_generate_test_code.py
1312 ################################################################
1314 ################################################################
1317 msg "Done, cleaning up"
1325 ################################################################
1326 #### Run all the things
1327 ################################################################
1329 # Run one component and clean up afterwards.
1331 # Back up the configuration in case the component modifies it.
1332 # The cleanup function will restore it.
1333 cp -p "$CONFIG_H" "$CONFIG_BAK"
1334 current_component="$1"
1340 pre_check_environment
1341 pre_initialize_variables
1342 pre_parse_command_line "$@"
1348 if [ $KEEP_GOING -eq 1 ]; then
1349 pre_setup_keep_going
1355 pre_print_configuration
1359 # Run the requested tests.
1360 for component in $RUN_COMPONENTS; do
1361 run_component "component_$component"