all.sh: don't insist on Linux; always run Valgrind

Don't bail out of all.sh if the OS isn't Linux. We only expect
everything to pass on a recent Linux x86_64, but it's useful to call
all.sh to run some components on any platform.

In all.sh, always run both MemorySanitizer and Valgrind. Valgrind is
slower than ASan and MSan but finds some things that they don't.

Run MSan unconditionally, not just on Linux/x86_64. MSan is supported
on some other OSes and CPUs these days.

Use `all.sh --except test_memsan` if you want to omit MSan because it
isn't supported on your platform. Use `all.sh --except test_memcheck`
if you want to omit Valgrind because it's too slow.

Portability: ecognize amd64 (FreeBSD arch string) as well as x86_64
(Linux arch string) for `uname -m`. The `make` utility must still
be GNU make.
This commit is contained in:
Gilles Peskine 2019-01-08 23:19:08 +01:00
parent 4e7b323fd8
commit 770ad7e2c9

View file

@ -81,10 +81,7 @@
set -eu set -eu
pre_check_environment () { pre_check_environment () {
if [ "$( uname )" != "Linux" ]; then if [ -d library -a -d include -a -d tests ]; then :; else
echo "This script only works in Linux" >&2
exit 1
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
@ -737,47 +734,42 @@ component_test_platform_calloc_macro () {
} }
component_test_make_shared () { component_test_make_shared () {
if uname -a | grep -F Linux >/dev/null; then msg "build/test: make shared" # ~ 40s
msg "build/test: make shared" # ~ 40s make SHARED=1 all check
make SHARED=1 all check
fi
} }
component_test_m32_o0 () { case $(uname -m) in
if uname -a | grep -F x86_64 >/dev/null; then amd64|x86_64)
# Build once with -O0, to compile out the i386 specific inline assembly component_test_m32_o0 () {
msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s # Build once with -O0, to compile out the i386 specific inline assembly
scripts/config.pl full msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' scripts/config.pl full
make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
msg "test: i386, make, gcc -O0 (ASan build)" msg "test: i386, make, gcc -O0 (ASan build)"
make test make test
fi # x86_64 }
}
component_test_m32_o1 () { component_test_m32_o1 () {
if uname -a | grep -F x86_64 >/dev/null; then # 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 scripts/config.pl full
scripts/config.pl full make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
msg "test: i386, make, gcc -O1 (ASan build)" msg "test: i386, make, gcc -O1 (ASan build)"
make test make test
fi # x86_64 }
}
component_test_mx32 () { component_test_mx32 () {
if uname -a | grep -F x86_64 >/dev/null; then msg "build: 64-bit ILP32, make, gcc" # ~ 30s
msg "build: 64-bit ILP32, make, gcc" # ~ 30s scripts/config.pl full
scripts/config.pl full make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
msg "test: 64-bit ILP32, make, gcc" msg "test: 64-bit ILP32, make, gcc"
make test make test
fi # x86_64 }
} ;;
esac
component_test_have_int32 () { component_test_have_int32 () {
msg "build: gcc, force 32-bit bignum limbs" msg "build: gcc, force 32-bit bignum limbs"
@ -902,53 +894,46 @@ component_build_mingw () {
} }
component_test_memsan () { component_test_memsan () {
# MemSan currently only available on Linux 64 bits msg "build: MSan (clang)" # ~ 1 min 20s
if uname -a | grep 'Linux.*x86_64' >/dev/null; then scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
msg "build: MSan (clang)" # ~ 1 min 20s CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm make
CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
make
msg "test: main suites (MSan)" # ~ 10s msg "test: main suites (MSan)" # ~ 10s
make test make test
msg "test: ssl-opt.sh (MSan)" # ~ 1 min msg "test: ssl-opt.sh (MSan)" # ~ 1 min
if_build_succeeded tests/ssl-opt.sh if_build_succeeded tests/ssl-opt.sh
# Optional part(s) # Optional part(s)
if [ "$MEMORY" -gt 0 ]; then if [ "$MEMORY" -gt 0 ]; 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 fi
} }
component_test_memcheck () { component_test_memcheck () {
# Only run if MemSan is not available msg "build: Release (clang)"
if ! uname -a | grep 'Linux.*x86_64' >/dev/null; then CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
msg "build: Release (clang)" make
CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
make
msg "test: main suites valgrind (Release)" msg "test: main suites valgrind (Release)"
make memcheck make memcheck
# Optional part(s) # Optional part(s)
# Currently broken, programs don't seem to receive signals # Currently broken, programs don't seem to receive signals
# under valgrind on OS X # under valgrind on OS X
if [ "$MEMORY" -gt 0 ]; then if [ "$MEMORY" -gt 0 ]; then
msg "test: ssl-opt.sh --memcheck (Release)" msg "test: ssl-opt.sh --memcheck (Release)"
if_build_succeeded tests/ssl-opt.sh --memcheck if_build_succeeded tests/ssl-opt.sh --memcheck
fi fi
if [ "$MEMORY" -gt 1 ]; then if [ "$MEMORY" -gt 1 ]; then
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 () { component_test_cmake_out_of_source () {