From f95c1764faa8218c95b1f03b4d0cf7a1ad60f1e2 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 10 Nov 2016 17:25:58 +0000 Subject: [PATCH 1/5] Make the test builds much stricter for warnings Tighten up the test options in all.sh, test-ref-configs.pl and curves.pl to ensure the builds are strict for all warnings, warnings are treated as errors, and that wherever possible builds are strict to the C99 standard. (Note that builds that use the Unix sockets API cannot be). --- tests/scripts/all.sh | 53 ++++++++++++++++++------------- tests/scripts/curves.pl | 3 +- tests/scripts/test-ref-configs.pl | 16 +++++++--- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 6b3396059d..5a764e73c6 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -285,16 +285,16 @@ OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3' msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min tests/ssl-opt.sh -msg "build: cmake, full config, clang" # ~ 50s +msg "build: cmake, full config, clang, C99" # ~ 50s cleanup cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests -CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check . -make +CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On . +CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic' make msg "test: main suites (full config)" # ~ 5s -make test +CFLAGS='-Werror -Wall -Wextra' make test msg "test: ssl-opt.sh default (full config)" # ~ 1s tests/ssl-opt.sh -f Default @@ -314,15 +314,17 @@ tests/scripts/key-exchanges.pl msg "build: Unix make, -Os (gcc)" # ~ 30s cleanup -CC=gcc CFLAGS='-Werror -Os' make +CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' make -# this is meant to cath missing #define mbedtls_printf etc -# disable fsio to catch some more missing #include -msg "build: full config except platform/fsio, make, gcc" # ~ 30s +# Full configuration build, without platform support, file IO and net sockets. +# This should catch missing mbedtls_printf definitions, and by disabling file +# IO, it should catch missing '#include ' +msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s cleanup cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full scripts/config.pl unset MBEDTLS_PLATFORM_C +scripts/config.pl unset MBEDTLS_NET_C scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT @@ -332,7 +334,8 @@ scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.pl unset MBEDTLS_FS_IO -CC=gcc CFLAGS='-Werror -O0' make +CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0' make lib programs +CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make test # catch compile bugs in _uninit functions msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s @@ -341,29 +344,31 @@ cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED -CC=gcc CFLAGS='-Werror -O0' make +CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s cleanup cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full scripts/config.pl unset MBEDTLS_SSL_SRV_C -CC=gcc CFLAGS='-Werror -O0' make +CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s cleanup cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full scripts/config.pl unset MBEDTLS_SSL_CLI_C -CC=gcc CFLAGS='-Werror -O0' make +CC=gcc CFLAGS='-Werror -Wall -Werror -O0' make +# 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). msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s cleanup cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc. scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux -CC=gcc CFLAGS='-Werror -O0 -std=c99 -pedantic' make lib +CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' make lib msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)" cleanup @@ -389,7 +394,7 @@ fi if uname -a | grep -F x86_64 >/dev/null; then msg "build: i386, make, gcc" # ~ 30s cleanup -CC=gcc CFLAGS='-Werror -m32' make +CC=gcc CFLAGS='-Werror -Wall -Wextra -m32' make fi # x86_64 msg "build: arm-none-eabi-gcc, make" # ~ 10s @@ -407,7 +412,7 @@ scripts/config.pl unset MBEDTLS_THREADING_PTHREAD scripts/config.pl unset MBEDTLS_THREADING_C scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit -CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS=-Werror make lib +CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' make lib msg "build: armcc, make" cleanup @@ -428,15 +433,19 @@ scripts/config.pl unset MBEDTLS_THREADING_C 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_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME -CC=armcc AR=armar WARNING_CFLAGS= make lib +CC=armcc AR=armar WARNING_CFLAGS='--strict --c99' make lib if which i686-w64-mingw32-gcc >/dev/null; then -msg "build: cross-mingw64, make" # ~ 30s -cleanup -CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 make -WINDOWS_BUILD=1 make clean -CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1 make -WINDOWS_BUILD=1 make clean + msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s + cleanup + CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 make lib programs + CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 make test + WINDOWS_BUILD=1 make clean + + msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s + CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS'=-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make lib programs + CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS'=-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make test + WINDOWS_BUILD=1 make clean fi # MemSan currently only available on Linux 64 bits diff --git a/tests/scripts/curves.pl b/tests/scripts/curves.pl index 85eb7e6514..bd13f52cce 100755 --- a/tests/scripts/curves.pl +++ b/tests/scripts/curves.pl @@ -49,7 +49,8 @@ for my $curve (@curves) { system( "scripts/config.pl unset $curve" ) and abort "Failed to disable $curve\n"; - system( "make lib" ) and abort "Failed to build lib: $curve\n"; + system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) + and abort "Failed to build lib: $curve\n"; system( "cd tests && make" ) and abort "Failed to build tests: $curve\n"; system( "make test" ) and abort "Failed test suite: $curve\n"; diff --git a/tests/scripts/test-ref-configs.pl b/tests/scripts/test-ref-configs.pl index 8f4738cb45..a9a89f1ced 100755 --- a/tests/scripts/test-ref-configs.pl +++ b/tests/scripts/test-ref-configs.pl @@ -1,9 +1,15 @@ #!/usr/bin/perl -# test standard configurations: -# - build -# - run test suite -# - run compat.sh +# test-ref-configs.pl +# +# This file is part of mbed TLS (https://tls.mbed.org) +# +# Copyright (c) 2013-2016, ARM Limited, All Rights Reserved +# +# Purpose +# +# For each reference configuration file in the configs directory, build the +# configuration, run the test suites and compat.sh # # Usage: tests/scripts/test-ref-configs.pl [config-name [...]] @@ -63,7 +69,7 @@ while( my ($conf, $data) = each %configs ) { system( "cp configs/$conf $config_h" ) and abort "Failed to activate $conf\n"; - system( "make CFLAGS='-Os -Werror'" ) and abort "Failed to build: $conf\n"; + system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n"; system( "make test" ) and abort "Failed test suite: $conf\n"; my $compat = $data->{'compat'}; From 097618b4c6184516e723225984fb9ee56ad456d3 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 10 Nov 2016 17:28:55 +0000 Subject: [PATCH 2/5] Fix compiler warning in debug.c --- library/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/debug.c b/library/debug.c index a9cd814be4..f9229b3606 100644 --- a/library/debug.c +++ b/library/debug.c @@ -71,7 +71,7 @@ static inline void debug_send_line( const mbedtls_ssl_context *ssl, int level, */ #if defined(MBEDTLS_THREADING_C) char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */ - mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", ssl, str ); + mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str ); ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr ); #else ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str ); From 532c94dcb77126002e770b0a7a6baca8cdf3526e Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 10 Nov 2016 17:30:18 +0000 Subject: [PATCH 3/5] Fix formatting issues in net_sockets.c --- library/net_sockets.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/net_sockets.c b/library/net_sockets.c index 6a013e979c..80be6ec6a4 100644 --- a/library/net_sockets.c +++ b/library/net_sockets.c @@ -133,7 +133,8 @@ void mbedtls_net_init( mbedtls_net_context *ctx ) /* * Initiate a TCP connection with host:port and the given protocol */ -int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto ) +int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, + const char *port, int proto ) { int ret; struct addrinfo hints, *addr_list, *cur; @@ -322,7 +323,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, { /* TCP: actual accept() */ ret = client_ctx->fd = (int) accept( bind_ctx->fd, - (struct sockaddr *) &client_addr, &n ); + (struct sockaddr *) &client_addr, &n ); } else { From 91aef338329652da9f2e5ad2be9d7f11fd51882b Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 17 Nov 2016 09:20:50 +0000 Subject: [PATCH 4/5] Fix mingw test build to avoid executing the tests Changed the mingw build target to avoid building mingw test suites and then attempting to run them which was failing on Linux. --- tests/scripts/all.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 5a764e73c6..1228270745 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -439,12 +439,14 @@ if which i686-w64-mingw32-gcc >/dev/null; then msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s cleanup CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 make lib programs - CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 make test + + # note Make tests only builds the tests, but doesn't run them + CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 make tests WINDOWS_BUILD=1 make clean msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s - CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS'=-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make lib programs - CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS'=-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make test + CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make lib programs + CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make tests WINDOWS_BUILD=1 make clean fi From 002bc6262b3c73bf847f99d997a7960976813ce2 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 17 Nov 2016 09:27:45 +0000 Subject: [PATCH 5/5] Make mingw test build a requirement of all.sh Changed the mingw test build to be a required test of the all.sh script. --- tests/scripts/all.sh | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 1228270745..6e24909617 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -209,7 +209,7 @@ export GNUTLS_SERV="$GNUTLS_SERV" # Make sure the tools we need are available. check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \ "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \ - "arm-none-eabi-gcc" "armcc" + "arm-none-eabi-gcc" "armcc" "i686-w64-mingw32-gcc" # # Test Suites to be executed @@ -435,20 +435,18 @@ scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME CC=armcc AR=armar WARNING_CFLAGS='--strict --c99' make lib -if which i686-w64-mingw32-gcc >/dev/null; then - msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s - cleanup - CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 make lib programs +msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s +cleanup +CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 make lib programs - # note Make tests only builds the tests, but doesn't run them - CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 make tests - WINDOWS_BUILD=1 make clean +# note Make tests only builds the tests, but doesn't run them +CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 make tests +WINDOWS_BUILD=1 make clean - msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s - CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make lib programs - CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make tests - WINDOWS_BUILD=1 make clean -fi +msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s +CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make lib programs +CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 make tests +WINDOWS_BUILD=1 make clean # MemSan currently only available on Linux 64 bits if uname -a | grep 'Linux.*x86_64' >/dev/null; then