Move the code into functions. No behavior change.

Move almost all the code of this script into functions. There is no
intended behavior change. The goal of this commit is to make
subsequent improvements easier to follow.

A very large number of lines have been reintended. To see what's going
on, ignore whitespace differences (e.g. diff -w).

I followed the following rules:

* Minimize the amount of code that gets moved.
* Don't change anything to what gets executed or displayed.
* Almost all the code must end up in a function.
* One function does one thing. For most of the code, that's from one
  "cleanup" to the next.
* The test sequence functions (run_XXX) are independent.

The change mostly amounts to putting chunks of code into a function
and calling the functions in order. A few test runs are conditional;
in those cases the conditional is around the function call.
This commit is contained in:
Gilles Peskine 2018-11-27 15:58:47 +01:00
parent 556d7d9e3b
commit 8f07312124

View File

@ -55,6 +55,16 @@
# Notes for maintainers # Notes for maintainers
# --------------------- # ---------------------
# #
# The bulk of the code is organized into functions that follow one of the
# following naming conventions:
# * pre_XXX: things to do before running the tests, in order.
# * component_XXX: independent components. They can be run in any order.
# * component_check_XXX: quick tests that aren't worth parallelizing
# * component_build_XXX: build things but don't run them
# * component_test_XXX: build and test
# * post_XXX: things to do after running the tests.
# * other: miscellaneous support functions.
#
# The tests are roughly in order from fastest to slowest. This doesn't # The tests are roughly in order from fastest to slowest. This doesn't
# have to be exact, but in general you should add slower tests towards # have to be exact, but in general you should add slower tests towards
# the end and fast checks near the beginning. # the end and fast checks near the beginning.
@ -80,6 +90,7 @@
# Abort on errors (and uninitialised variables) # Abort on errors (and uninitialised variables)
set -eu set -eu
pre_check_environment () {
if [ "$( uname )" != "Linux" ]; then if [ "$( uname )" != "Linux" ]; then
echo "This script only works in Linux" >&2 echo "This script only works in Linux" >&2
exit 1 exit 1
@ -87,7 +98,9 @@ elif [ -d library -a -d include -a -d tests ]; then :; else
echo "Must be run from mbed TLS root" >&2 echo "Must be run from mbed TLS root" >&2
exit 1 exit 1
fi fi
}
pre_initialize_variables () {
CONFIG_H='include/mbedtls/config.h' CONFIG_H='include/mbedtls/config.h'
CONFIG_BAK="$CONFIG_H.bak" CONFIG_BAK="$CONFIG_H.bak"
@ -112,6 +125,7 @@ RUN_ARMCC=1
if [ -n "${MAKEFLAGS+set}" ]; then if [ -n "${MAKEFLAGS+set}" ]; then
export MAKEFLAGS="-j" export MAKEFLAGS="-j"
fi fi
}
usage() usage()
{ {
@ -197,7 +211,6 @@ msg()
current_section=$1 current_section=$1
} }
if [ $RUN_ARMCC -ne 0 ]; then
armc6_build_test() armc6_build_test()
{ {
FLAGS="$1" FLAGS="$1"
@ -207,7 +220,6 @@ if [ $RUN_ARMCC -ne 0 ]; then
WARNING_CFLAGS='-xc -std=c99' make lib WARNING_CFLAGS='-xc -std=c99' make lib
make clean make clean
} }
fi
err_msg() err_msg()
{ {
@ -232,6 +244,7 @@ check_headers_in_cpp () {
rm headers.txt rm headers.txt
} }
pre_parse_command_line () {
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--armcc) RUN_ARMCC=1;; --armcc) RUN_ARMCC=1;;
@ -264,7 +277,9 @@ while [ $# -gt 0 ]; do
esac esac
shift shift
done done
}
pre_check_git () {
if [ $FORCE -eq 1 ]; then if [ $FORCE -eq 1 ]; then
git checkout-index -f -q $CONFIG_H git checkout-index -f -q $CONFIG_H
cleanup cleanup
@ -284,9 +299,9 @@ else
exit 1 exit 1
fi fi
fi fi
}
build_status=0 pre_setup_keep_going () {
if [ $KEEP_GOING -eq 1 ]; then
failure_summary= failure_summary=
failure_count=0 failure_count=0
start_red= start_red=
@ -340,11 +355,8 @@ $text"
echo "Killed by SIG$1." echo "Killed by SIG$1."
fi fi
} }
else
record_status () {
"$@"
} }
fi
if_build_succeeded () { if_build_succeeded () {
if [ $build_status -eq 0 ]; then if [ $build_status -eq 0 ]; then
record_status "$@" record_status "$@"
@ -357,6 +369,7 @@ not() {
! "$@" ! "$@"
} }
pre_print_configuration () {
msg "info: $0 configuration" msg "info: $0 configuration"
echo "MEMORY: $MEMORY" echo "MEMORY: $MEMORY"
echo "FORCE: $FORCE" echo "FORCE: $FORCE"
@ -370,7 +383,9 @@ echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV" echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR" echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR" echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
}
pre_check_tools () {
ARMC5_CC="$ARMC5_BIN_DIR/armcc" ARMC5_CC="$ARMC5_BIN_DIR/armcc"
ARMC5_AR="$ARMC5_BIN_DIR/armar" ARMC5_AR="$ARMC5_BIN_DIR/armar"
ARMC6_CC="$ARMC6_BIN_DIR/armclang" ARMC6_CC="$ARMC6_BIN_DIR/armclang"
@ -395,7 +410,7 @@ check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
if [ $RUN_ARMCC -ne 0 ]; then if [ $RUN_ARMCC -ne 0 ]; then
check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR" check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
fi fi
}
################################################################ ################################################################
@ -413,32 +428,46 @@ fi
# #
# Indicative running times are given for reference. # Indicative running times are given for reference.
pre_print_tools () {
msg "info: output_env.sh" msg "info: output_env.sh"
OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \ OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \ GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \ GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
}
component_check_recursion () {
msg "test: recursion.pl" # < 1s msg "test: recursion.pl" # < 1s
record_status tests/scripts/recursion.pl library/*.c record_status tests/scripts/recursion.pl library/*.c
}
component_check_generated_files () {
msg "test: freshness of generated source files" # < 1s msg "test: freshness of generated source files" # < 1s
record_status tests/scripts/check-generated-files.sh record_status tests/scripts/check-generated-files.sh
}
component_check_doxy_blocks () {
msg "test: doxygen markup outside doxygen blocks" # < 1s msg "test: doxygen markup outside doxygen blocks" # < 1s
record_status tests/scripts/check-doxy-blocks.pl record_status tests/scripts/check-doxy-blocks.pl
}
component_check_files () {
msg "test: check-files.py" # < 1s msg "test: check-files.py" # < 1s
cleanup cleanup
record_status tests/scripts/check-files.py record_status tests/scripts/check-files.py
}
component_check_names () {
msg "test/build: declared and exported names" # < 3s msg "test/build: declared and exported names" # < 3s
cleanup cleanup
record_status tests/scripts/check-names.sh record_status tests/scripts/check-names.sh
}
component_check_doxygen_warnings () {
msg "test: doxygen warnings" # ~ 3s msg "test: doxygen warnings" # ~ 3s
cleanup cleanup
record_status tests/scripts/doxygen.sh record_status tests/scripts/doxygen.sh
}
@ -446,6 +475,7 @@ record_status tests/scripts/doxygen.sh
#### Build and test many configurations and targets #### Build and test many configurations and targets
################################################################ ################################################################
component_test_default_cmake_gcc_asan () {
msg "build: cmake, gcc, ASan" # ~ 1 min 50s msg "build: cmake, gcc, ASan" # ~ 1 min 50s
cleanup cleanup
CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
@ -465,7 +495,9 @@ make
msg "test: compat.sh (ASan build)" # ~ 6 min msg "test: compat.sh (ASan build)" # ~ 6 min
if_build_succeeded tests/compat.sh if_build_succeeded tests/compat.sh
}
component_test_sslv3 () {
msg "build: Default + SSLv3 (ASan build)" # ~ 6 min msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -482,7 +514,9 @@ if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
if_build_succeeded tests/ssl-opt.sh if_build_succeeded tests/ssl-opt.sh
}
component_test_no_renegotiation () {
msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -495,7 +529,9 @@ make test
msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
if_build_succeeded tests/ssl-opt.sh if_build_succeeded tests/ssl-opt.sh
}
component_test_rsa_no_crt () {
msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -511,7 +547,9 @@ if_build_succeeded tests/ssl-opt.sh -f RSA
msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
if_build_succeeded tests/compat.sh -t RSA if_build_succeeded tests/compat.sh -t RSA
}
component_test_small_ssl_out_content_len () {
msg "build: small SSL_OUT_CONTENT_LEN (ASan build)" msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -522,7 +560,9 @@ make
msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests" msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet" if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
}
component_test_small_ssl_in_content_len () {
msg "build: small SSL_IN_CONTENT_LEN (ASan build)" msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -533,7 +573,9 @@ make
msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests" msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
if_build_succeeded tests/ssl-opt.sh -f "Max fragment" if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
}
component_test_small_ssl_dtls_max_buffering () {
msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0" msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -543,7 +585,9 @@ make
msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test" msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg" if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
}
component_test_small_mbedtls_ssl_dtls_max_buffering () {
msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1" msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -553,7 +597,9 @@ make
msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test" msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket" if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
}
component_test_full_cmake_clang () {
msg "build: cmake, full config, clang" # ~ 50s msg "build: cmake, full config, clang" # ~ 50s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -573,7 +619,9 @@ if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_
msg "test: compat.sh ARIA + ChachaPoly" msg "test: compat.sh ARIA + ChachaPoly"
if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA' if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
}
component_build_deprecated () {
msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -591,23 +639,34 @@ scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
# Build with -O -Wextra to catch a maximum of issues. # Build with -O -Wextra to catch a maximum of issues.
make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
}
component_test_depends_curves () {
msg "test/build: curves.pl (gcc)" # ~ 4 min msg "test/build: curves.pl (gcc)" # ~ 4 min
cleanup cleanup
record_status tests/scripts/curves.pl record_status tests/scripts/curves.pl
}
component_test_depends_hashes () {
msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
cleanup cleanup
record_status tests/scripts/depends-hashes.pl record_status tests/scripts/depends-hashes.pl
}
component_test_depends_pkalgs () {
msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
cleanup cleanup
record_status tests/scripts/depends-pkalgs.pl record_status tests/scripts/depends-pkalgs.pl
}
component_build_key_exchanges () {
msg "test/build: key-exchanges (gcc)" # ~ 1 min msg "test/build: key-exchanges (gcc)" # ~ 1 min
cleanup cleanup
record_status tests/scripts/key-exchanges.pl record_status tests/scripts/key-exchanges.pl
}
component_build_default_make_gcc_and_cxx () {
msg "build: Unix make, -Os (gcc)" # ~ 30s msg "build: Unix make, -Os (gcc)" # ~ 30s
cleanup cleanup
make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
@ -617,7 +676,9 @@ record_status check_headers_in_cpp
msg "build: Unix make, incremental g++" msg "build: Unix make, incremental g++"
make TEST_CPP=1 make TEST_CPP=1
}
component_test_no_platform () {
# Full configuration build, without platform support, file IO and net sockets. # Full configuration build, without platform support, file IO and net sockets.
# This should catch missing mbedtls_printf definitions, and by disabling file # This should catch missing mbedtls_printf definitions, and by disabling file
# IO, it should catch missing '#include <stdio.h>' # IO, it should catch missing '#include <stdio.h>'
@ -640,7 +701,9 @@ scripts/config.pl unset MBEDTLS_FS_IO
# to re-enable platform integration features otherwise disabled in C99 builds # to re-enable platform integration features otherwise disabled in C99 builds
make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
}
component_build_no_std_function () {
# catch compile bugs in _uninit functions # catch compile bugs in _uninit functions
msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
cleanup cleanup
@ -649,21 +712,27 @@ scripts/config.pl full
scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
}
component_build_no_ssl_srv () {
msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
scripts/config.pl full scripts/config.pl full
scripts/config.pl unset MBEDTLS_SSL_SRV_C scripts/config.pl unset MBEDTLS_SSL_SRV_C
make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
}
component_build_no_ssl_cli () {
msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
scripts/config.pl full scripts/config.pl full
scripts/config.pl unset MBEDTLS_SSL_CLI_C scripts/config.pl unset MBEDTLS_SSL_CLI_C
make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
}
component_build_no_sockets () {
# Note, C99 compliance can also be tested with the sockets support disabled, # Note, C99 compliance can also be tested with the sockets support disabled,
# as that requires a POSIX platform (which isn't the same as C99). # as that requires a POSIX platform (which isn't the same as C99).
msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
@ -673,7 +742,9 @@ scripts/config.pl full
scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc. scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
}
component_test_no_max_fragment_length () {
# Run max fragment length tests with MFL disabled # Run max fragment length tests with MFL disabled
msg "build: default config except MFL extension (ASan build)" # ~ 30s msg "build: default config except MFL extension (ASan build)" # ~ 30s
cleanup cleanup
@ -684,7 +755,9 @@ make
msg "test: ssl-opt.sh, MFL-related tests" msg "test: ssl-opt.sh, MFL-related tests"
if_build_succeeded tests/ssl-opt.sh -f "Max fragment length" if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
}
component_test_no_max_fragment_length_small_ssl_out_content_len () {
msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)" msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -696,7 +769,9 @@ make
msg "test: MFL tests (disabled MFL extension case) & large packet tests" msg "test: MFL tests (disabled MFL extension case) & large packet tests"
if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer" if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
}
component_test_null_entropy () {
msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)" msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -711,7 +786,9 @@ make
msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)" msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
make test make test
}
component_test_platform_calloc_macro () {
msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)" msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -723,7 +800,9 @@ make
msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)" msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
make test make test
}
component_test_aes_fewer_tables () {
msg "build: default config with AES_FEWER_TABLES enabled" msg "build: default config with AES_FEWER_TABLES enabled"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -732,7 +811,9 @@ make CC=gcc CFLAGS='-Werror -Wall -Wextra'
msg "test: AES_FEWER_TABLES" msg "test: AES_FEWER_TABLES"
make test make test
}
component_test_aes_rom_tables () {
msg "build: default config with AES_ROM_TABLES enabled" msg "build: default config with AES_ROM_TABLES enabled"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -741,7 +822,9 @@ make CC=gcc CFLAGS='-Werror -Wall -Wextra'
msg "test: AES_ROM_TABLES" msg "test: AES_ROM_TABLES"
make test make test
}
component_test_aes_fewer_tables_and_rom_tables () {
msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled" msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -751,14 +834,15 @@ make CC=gcc CFLAGS='-Werror -Wall -Wextra'
msg "test: AES_FEWER_TABLES + AES_ROM_TABLES" msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
make test make test
}
if uname -a | grep -F Linux >/dev/null; then component_test_make_shared () {
msg "build/test: make shared" # ~ 40s msg "build/test: make shared" # ~ 40s
cleanup cleanup
make SHARED=1 all check make SHARED=1 all check
fi }
if uname -a | grep -F x86_64 >/dev/null; then component_test_m32_o0 () {
# Build once with -O0, to compile out the i386 specific inline assembly # Build once with -O0, to compile out the i386 specific inline assembly
msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
cleanup cleanup
@ -768,7 +852,9 @@ if uname -a | grep -F x86_64 >/dev/null; then
msg "test: i386, make, gcc -O0 (ASan build)" msg "test: i386, make, gcc -O0 (ASan build)"
make test make test
}
component_test_m32_o1 () {
# Build again with -O1, to compile in the i386 specific inline assembly # Build again with -O1, to compile in the i386 specific inline assembly
msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
cleanup cleanup
@ -778,7 +864,9 @@ if uname -a | grep -F x86_64 >/dev/null; then
msg "test: i386, make, gcc -O1 (ASan build)" msg "test: i386, make, gcc -O1 (ASan build)"
make test make test
}
component_test_mx32 () {
msg "build: 64-bit ILP32, make, gcc" # ~ 30s msg "build: 64-bit ILP32, make, gcc" # ~ 30s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -787,8 +875,9 @@ if uname -a | grep -F x86_64 >/dev/null; then
msg "test: 64-bit ILP32, make, gcc" msg "test: 64-bit ILP32, make, gcc"
make test make test
fi # x86_64 }
component_test_have_int32 () {
msg "build: gcc, force 32-bit bignum limbs" msg "build: gcc, force 32-bit bignum limbs"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -799,7 +888,9 @@ make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
msg "test: gcc, force 32-bit bignum limbs" msg "test: gcc, force 32-bit bignum limbs"
make test make test
}
component_test_have_int64 () {
msg "build: gcc, force 64-bit bignum limbs" msg "build: gcc, force 64-bit bignum limbs"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -810,8 +901,9 @@ make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
msg "test: gcc, force 64-bit bignum limbs" msg "test: gcc, force 64-bit bignum limbs"
make test make test
}
component_test_no_udbl_division () {
msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -822,8 +914,9 @@ make CFLAGS='-Werror -O1'
msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
make test make test
}
component_test_no_64bit_multiplication () {
msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -834,8 +927,9 @@ make CFLAGS='-Werror -O1'
msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
make test make test
}
component_build_arm_none_eabi_gcc () {
msg "build: arm-none-eabi-gcc, make" # ~ 10s msg "build: arm-none-eabi-gcc, make" # ~ 10s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -852,7 +946,9 @@ scripts/config.pl unset MBEDTLS_THREADING_C
scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
}
component_build_arm_none_eabi_gcc_no_udbl_division () {
msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -872,7 +968,9 @@ scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
echo "Checking that software 64-bit division is not required" echo "Checking that software 64-bit division is not required"
if_build_succeeded not grep __aeabi_uldiv library/*.o if_build_succeeded not grep __aeabi_uldiv library/*.o
}
component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -892,7 +990,9 @@ scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
echo "Checking that software 64-bit multiplication is not required" echo "Checking that software 64-bit multiplication is not required"
if_build_succeeded not grep __aeabi_lmul library/*.o if_build_succeeded not grep __aeabi_lmul library/*.o
}
component_build_armcc () {
msg "build: ARM Compiler 5, make" msg "build: ARM Compiler 5, make"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -932,7 +1032,9 @@ if [ $RUN_ARMCC -ne 0 ]; then
# ARM Compiler 6 - Target ARMv8-A - AArch64 # ARM Compiler 6 - Target ARMv8-A - AArch64
armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a" armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
fi fi
}
component_test_allow_sha1 () {
msg "build: allow SHA1 in certificates by default" msg "build: allow SHA1 in certificates by default"
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -941,7 +1043,9 @@ make CFLAGS='-Werror -Wall -Wextra'
msg "test: allow SHA1 in certificates by default" msg "test: allow SHA1 in certificates by default"
make test make test
if_build_succeeded tests/ssl-opt.sh -f SHA-1 if_build_succeeded tests/ssl-opt.sh -f SHA-1
}
component_test_rsa_no_crt () {
msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -951,7 +1055,9 @@ make
msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)" msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)"
make test make test
}
component_build_mingw () {
msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
cleanup cleanup
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 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
@ -964,10 +1070,9 @@ msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
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 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
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 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
make WINDOWS_BUILD=1 clean make WINDOWS_BUILD=1 clean
}
# MemSan currently only available on Linux 64 bits component_test_memsan () {
if uname -a | grep 'Linux.*x86_64' >/dev/null; then
msg "build: MSan (clang)" # ~ 1 min 20s msg "build: MSan (clang)" # ~ 1 min 20s
cleanup cleanup
cp "$CONFIG_H" "$CONFIG_BAK" cp "$CONFIG_H" "$CONFIG_BAK"
@ -987,9 +1092,9 @@ if uname -a | grep 'Linux.*x86_64' >/dev/null; then
msg "test: compat.sh (MSan)" # ~ 6 min 20s msg "test: compat.sh (MSan)" # ~ 6 min 20s
if_build_succeeded tests/compat.sh if_build_succeeded tests/compat.sh
fi fi
}
else # no MemSan component_test_memcheck () {
msg "build: Release (clang)" msg "build: Release (clang)"
cleanup cleanup
CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release . CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
@ -1011,9 +1116,9 @@ else # no MemSan
msg "test: compat.sh --memcheck (Release)" msg "test: compat.sh --memcheck (Release)"
if_build_succeeded tests/compat.sh --memcheck if_build_succeeded tests/compat.sh --memcheck
fi fi
}
fi # MemSan component_test_cmake_out_of_source () {
msg "build: cmake 'out-of-source' build" msg "build: cmake 'out-of-source' build"
cleanup cleanup
MBEDTLS_ROOT_DIR="$PWD" MBEDTLS_ROOT_DIR="$PWD"
@ -1038,7 +1143,9 @@ fi
cd "$MBEDTLS_ROOT_DIR" cd "$MBEDTLS_ROOT_DIR"
rm -rf "$OUT_OF_SOURCE_DIR" rm -rf "$OUT_OF_SOURCE_DIR"
unset MBEDTLS_ROOT_DIR unset MBEDTLS_ROOT_DIR
}
component_test_zeroize () {
# Test that the function mbedtls_platform_zeroize() is not optimized away by # Test that the function mbedtls_platform_zeroize() is not optimized away by
# different combinations of compilers and optimization flags by using an # different combinations of compilers and optimization flags by using an
# auxiliary GDB script. Unfortunately, GDB does not return error values to the # auxiliary GDB script. Unfortunately, GDB does not return error values to the
@ -1056,18 +1163,124 @@ for optimization_flag in -O2 -O3 -Ofast -Os; do
rm -f test_zeroize.log rm -f test_zeroize.log
done done
done done
}
component_check_python_files () {
msg "Lint: Python scripts" msg "Lint: Python scripts"
record_status tests/scripts/check-python-files.sh record_status tests/scripts/check-python-files.sh
}
component_check_generate_test_code () {
msg "uint test: generate_test_code.py" msg "uint test: generate_test_code.py"
record_status ./tests/scripts/test_generate_test_code.py record_status ./tests/scripts/test_generate_test_code.py
}
################################################################ ################################################################
#### Termination #### Termination
################################################################ ################################################################
post_report () {
msg "Done, cleaning up" msg "Done, cleaning up"
cleanup cleanup
final_report final_report
}
################################################################
#### Run all the things
################################################################
# Run one component. Currently trivial.
run_component () {
"$@"
}
# Preliminary setup
pre_check_environment
pre_initialize_variables
pre_parse_command_line "$@"
pre_check_git
build_status=0
if [ $KEEP_GOING -eq 1 ]; then
pre_setup_keep_going
else
record_status () {
"$@"
}
fi
pre_print_configuration
pre_check_tools
pre_print_tools
# Small things
run_component component_check_recursion
run_component component_check_generated_files
run_component component_check_doxy_blocks
run_component component_check_files
run_component component_check_names
run_component component_check_doxygen_warnings
# Test many different configurations
run_component component_test_default_cmake_gcc_asan
run_component component_test_sslv3
run_component component_test_no_renegotiation
run_component component_test_rsa_no_crt
run_component component_test_small_ssl_out_content_len
run_component component_test_small_ssl_in_content_len
run_component component_test_small_ssl_dtls_max_buffering
run_component component_test_small_mbedtls_ssl_dtls_max_buffering
run_component component_test_full_cmake_clang
run_component component_build_deprecated
run_component component_test_depends_curves
run_component component_test_depends_hashes
run_component component_test_depends_pkalgs
run_component component_build_key_exchanges
run_component component_build_default_make_gcc_and_cxx
run_component component_test_no_platform
run_component component_build_no_std_function
run_component component_build_no_ssl_srv
run_component component_build_no_ssl_cli
run_component component_build_no_sockets
run_component component_test_no_max_fragment_length
run_component component_test_no_max_fragment_length_small_ssl_out_content_len
run_component component_test_null_entropy
run_component component_test_platform_calloc_macro
run_component component_test_aes_fewer_tables
run_component component_test_aes_rom_tables
run_component component_test_aes_fewer_tables_and_rom_tables
if uname -a | grep -F Linux >/dev/null; then
run_component component_test_make_shared
fi
if uname -a | grep -F x86_64 >/dev/null; then
run_component component_test_m32_o0
run_component component_test_m32_o1
run_component component_test_mx32
fi
run_component component_test_have_int32
run_component component_test_have_int64
run_component component_test_no_udbl_division
run_component component_test_no_64bit_multiplication
run_component component_build_arm_none_eabi_gcc
run_component component_build_arm_none_eabi_gcc_no_udbl_division
run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
run_component component_build_armcc
run_component component_test_allow_sha1
run_component component_test_rsa_no_crt
run_component component_build_mingw
# MemSan currently only available on Linux 64 bits
if uname -a | grep 'Linux.*x86_64' >/dev/null; then
run_component component_test_memsan
else # no MemSan
run_component component_test_memcheck
fi
run_component component_test_cmake_out_of_source
# More small things
run_component component_test_zeroize
run_component component_check_python_files
run_component component_check_generate_test_code
# We're done.
post_report