blob: 5a764e73c69d5af07f9354a9af11e867d7a8a1c6 [file] [log] [blame]
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001#!/bin/sh
2
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Simon Butcher3ea7f522016-03-07 23:22:10 +00007# Copyright (c) 2014-2016, ARM Limited, All Rights Reserved
8#
9# Purpose
10#
SimonB2e23c822016-04-16 21:54:39 +010011# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010012#
SimonB2e23c822016-04-16 21:54:39 +010013# Warning: the test is destructive. It includes various build modes and
14# configurations, and can and will arbitrarily change the current CMake
15# configuration. After this script has been run, the CMake cache will be lost
16# and CMake will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010017#
SimonB2e23c822016-04-16 21:54:39 +010018# The script assumes the presence of gcc and clang (recent enough for using
19# ASan with gcc and MemSan with clang, or valgrind) are available, as well as
20# cmake and a "good" find.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010021
SimonB2e23c822016-04-16 21:54:39 +010022# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010023set -eu
24
25if [ -d library -a -d include -a -d tests ]; then :; else
Andres AGd9eba4b2016-08-26 14:42:14 +010026 err_msg "Must be run from mbed TLS root"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010027 exit 1
28fi
29
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000030CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020031CONFIG_BAK="$CONFIG_H.bak"
32
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010033MEMORY=0
SimonB2e23c822016-04-16 21:54:39 +010034FORCE=0
Andres AG7770ea82016-10-10 15:46:20 +010035RELEASE=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010036
Andres AGd9eba4b2016-08-26 14:42:14 +010037# Default commands, can be overriden by the environment
38: ${OPENSSL:="openssl"}
39: ${OPENSSL_LEGACY:="$OPENSSL"}
40: ${GNUTLS_CLI:="gnutls-cli"}
41: ${GNUTLS_SERV:="gnutls-serv"}
42: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
43: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
Andres AGdc192212016-08-31 17:33:13 +010044: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
45
Simon Butcher41eeccf2016-09-07 00:07:09 +010046usage()
SimonB2e23c822016-04-16 21:54:39 +010047{
Andres AGd9eba4b2016-08-26 14:42:14 +010048 printf "Usage: $0\n"
49 printf " -h|--help\t\tPrint this help.\n"
50 printf " -m|--memory\t\tAdditional optional memory tests.\n"
51 printf " -f|--force\t\tForce the tests to overwrite any modified files.\n"
Andres AG7770ea82016-10-10 15:46:20 +010052 printf " -s|--seed\t\tInteger seed value to use for this test run.\n"
53 printf " -r|--release-test\t\tRun this script in release mode. This fixes the seed value to 1.\n"
Simon Butcher41eeccf2016-09-07 00:07:09 +010054 printf " --out-of-source-dir=<path>\t\tDirectory used for CMake out-of-source build tests."
Andres AGd9eba4b2016-08-26 14:42:14 +010055 printf " --openssl=<OpenSSL_path>\t\tPath to OpenSSL executable to use for most tests.\n"
56 printf " --openssl-legacy=<OpenSSL_path>\t\tPath to OpenSSL executable to use for legacy tests e.g. SSLv3.\n"
57 printf " --gnutls-cli=<GnuTLS_cli_path>\t\tPath to GnuTLS client executable to use for most tests.\n"
58 printf " --gnutls-serv=<GnuTLS_serv_path>\t\tPath to GnuTLS server executable to use for most tests.\n"
59 printf " --gnutls-legacy-cli=<GnuTLS_cli_path>\t\tPath to GnuTLS client executable to use for legacy tests.\n"
60 printf " --gnutls-legacy-serv=<GnuTLS_serv_path>\t\tPath to GnuTLS server executable to use for legacy tests.\n"
SimonB2e23c822016-04-16 21:54:39 +010061}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010062
63# remove built files as well as the cmake cache/config
64cleanup()
65{
66 make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020067
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +020068 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +020070 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
71 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020072
73 if [ -f "$CONFIG_BAK" ]; then
74 mv "$CONFIG_BAK" "$CONFIG_H"
75 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010076}
77
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020078trap cleanup INT TERM HUP
79
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010080msg()
81{
82 echo ""
83 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010084 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +000085 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010086 echo "******************************************************************"
87}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010088
Andres AGd9eba4b2016-08-26 14:42:14 +010089err_msg()
90{
91 echo "$1" >&2
92}
93
94check_tools()
95{
96 for TOOL in "$@"; do
97 if ! `hash "$TOOL" >/dev/null 2>&1`; then
98 err_msg "$TOOL not found!"
99 exit 1
100 fi
101 done
102}
103
SimonB2e23c822016-04-16 21:54:39 +0100104while [ $# -gt 0 ]; do
105 case "$1" in
106 --memory|-m*)
107 MEMORY=${1#-m}
108 ;;
SimonB2e23c822016-04-16 21:54:39 +0100109 --force|-f)
110 FORCE=1
111 ;;
Andres AG7770ea82016-10-10 15:46:20 +0100112 --seed|-s)
113 shift
114 SEED="$1"
115 ;;
116 --release-test|-r)
117 RELEASE=1
118 ;;
Andres AGdc192212016-08-31 17:33:13 +0100119 --out-of-source-dir)
120 shift
121 OUT_OF_SOURCE_DIR="$1"
122 ;;
Andres AGd9eba4b2016-08-26 14:42:14 +0100123 --openssl)
124 shift
125 OPENSSL="$1"
126 ;;
127 --openssl-legacy)
128 shift
129 OPENSSL_LEGACY="$1"
130 ;;
131 --gnutls-cli)
132 shift
133 GNUTLS_CLI="$1"
134 ;;
135 --gnutls-serv)
136 shift
137 GNUTLS_SERV="$1"
138 ;;
139 --gnutls-legacy-cli)
140 shift
141 GNUTLS_LEGACY_CLI="$1"
142 ;;
143 --gnutls-legacy-serv)
144 shift
145 GNUTLS_LEGACY_SERV="$1"
146 ;;
SimonB2e23c822016-04-16 21:54:39 +0100147 --help|-h|*)
Andres AGd9eba4b2016-08-26 14:42:14 +0100148 usage
SimonB2e23c822016-04-16 21:54:39 +0100149 exit 1
150 ;;
151 esac
152 shift
153done
154
155if [ $FORCE -eq 1 ]; then
Andres AGdc192212016-08-31 17:33:13 +0100156 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
SimonB2e23c822016-04-16 21:54:39 +0100157 git checkout-index -f -q $CONFIG_H
158 cleanup
159else
160
161 if [ -d yotta/module ]; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100162 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
SimonB2e23c822016-04-16 21:54:39 +0100163 echo "You can either delete your work and retry, or force the test to overwrite the"
164 echo "test by rerunning the script as: $0 --force"
165 exit 1
166 fi
167
Andres AGdc192212016-08-31 17:33:13 +0100168 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
169 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
170 echo "You can either delete this directory manually, or force the test by rerunning"
171 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
172 exit 1
173 fi
174
SimonB2e23c822016-04-16 21:54:39 +0100175 if ! git diff-files --quiet include/mbedtls/config.h; then
176 echo $?
Andres AGd9eba4b2016-08-26 14:42:14 +0100177 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
SimonB2e23c822016-04-16 21:54:39 +0100178 echo "You can either delete or preserve your work, or force the test by rerunning the"
179 echo "script as: $0 --force"
180 exit 1
181 fi
182fi
183
Andres AG7770ea82016-10-10 15:46:20 +0100184if [ $RELEASE -eq 1 ]; then
185 # Fix the seed value to 1 to ensure that the tests are deterministic.
186 SEED=1
187fi
188
Andres AGd9eba4b2016-08-26 14:42:14 +0100189msg "info: $0 configuration"
190echo "MEMORY: $MEMORY"
191echo "FORCE: $FORCE"
Andres AG7770ea82016-10-10 15:46:20 +0100192echo "SEED: ${SEED-"UNSET"}"
Andres AGd9eba4b2016-08-26 14:42:14 +0100193echo "OPENSSL: $OPENSSL"
194echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
195echo "GNUTLS_CLI: $GNUTLS_CLI"
196echo "GNUTLS_SERV: $GNUTLS_SERV"
197echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
198echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
199
Andres AGb2fdd042016-09-22 14:17:46 +0100200# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
201# we just export the variables they require
202export OPENSSL_CMD="$OPENSSL"
203export GNUTLS_CLI="$GNUTLS_CLI"
204export GNUTLS_SERV="$GNUTLS_SERV"
205
Andres AG7770ea82016-10-10 15:46:20 +0100206# Avoid passing --seed flag in every call to ssl-opt.sh
207[ ! -z ${SEED+set} ] && export SEED
208
Andres AGd9eba4b2016-08-26 14:42:14 +0100209# Make sure the tools we need are available.
210check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
211 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
212 "arm-none-eabi-gcc" "armcc"
213
SimonB2e23c822016-04-16 21:54:39 +0100214#
215# Test Suites to be executed
216#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200217# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100218# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200219# and/or are more likely to fail than others (eg I use Clang most of the
220# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200221# 2. Minimize total running time, by avoiding useless rebuilds
222#
223# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100224
Janos Follathb72c6782016-07-19 14:54:17 +0100225msg "info: output_env.sh"
Andres AGd9eba4b2016-08-26 14:42:14 +0100226OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
227 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
228 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100229
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100230msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200231tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100232
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000233msg "test: freshness of generated source files" # < 1s
234tests/scripts/check-generated-files.sh
235
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200236msg "test: doxygen markup outside doxygen blocks" # < 1s
237tests/scripts/check-doxy-blocks.pl
238
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200239msg "test/build: declared and exported names" # < 3s
240cleanup
241tests/scripts/check-names.sh
242
Andres AGd9eba4b2016-08-26 14:42:14 +0100243msg "test: doxygen warnings" # ~ 3s
244cleanup
245tests/scripts/doxygen.sh
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100246
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200247msg "build: create and build yotta module" # ~ 30s
248cleanup
249tests/scripts/yotta-build.sh
250
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100251msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100252cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100253CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100254make
255
Simon Butcher8e3afc72016-09-15 17:13:08 +0100256msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100257make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200258
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100259msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100260tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200261
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100262msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200263tests/scripts/test-ref-configs.pl
264
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200265msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
266make
267
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100268msg "test: compat.sh (ASan build)" # ~ 6 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100269tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200270
Simon Butcher3ea7f522016-03-07 23:22:10 +0000271msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
272cleanup
Simon Butcherf413b6f2016-03-14 22:32:42 +0000273cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcher3ea7f522016-03-07 23:22:10 +0000274scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
275CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
276make
277
Simon Butcher8e3afc72016-09-15 17:13:08 +0100278msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher3ea7f522016-03-07 23:22:10 +0000279make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000280
281msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Andres AGd9eba4b2016-08-26 14:42:14 +0100282tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
283OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000284
285msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
286tests/ssl-opt.sh
287
Simon Butcherf95c1762016-11-10 17:25:58 +0000288msg "build: cmake, full config, clang, C99" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100289cleanup
Janos Follath35d48cb2016-04-22 14:45:00 +0100290cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200291scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Simon Butcherf95c1762016-11-10 17:25:58 +0000293CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
294CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic' make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100295
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100296msg "test: main suites (full config)" # ~ 5s
Simon Butcherf95c1762016-11-10 17:25:58 +0000297CFLAGS='-Werror -Wall -Wextra' make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200298
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100299msg "test: ssl-opt.sh default (full config)" # ~ 1s
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100300tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200301
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100302msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Andres AGd9eba4b2016-08-26 14:42:14 +0100303OPENSSL_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'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200304
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200305msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100306cleanup
307cmake -D CMAKE_BUILD_TYPE:String=Debug .
308tests/scripts/curves.pl
309
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200310msg "test/build: key-exchanges (gcc)" # ~ 1 min
311cleanup
312cmake -D CMAKE_BUILD_TYPE:String=Check .
313tests/scripts/key-exchanges.pl
314
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000315msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100316cleanup
Simon Butcherf95c1762016-11-10 17:25:58 +0000317CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100318
Simon Butcherf95c1762016-11-10 17:25:58 +0000319# Full configuration build, without platform support, file IO and net sockets.
320# This should catch missing mbedtls_printf definitions, and by disabling file
321# IO, it should catch missing '#include <stdio.h>'
322msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000323cleanup
324cp "$CONFIG_H" "$CONFIG_BAK"
325scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326scripts/config.pl unset MBEDTLS_PLATFORM_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000327scripts/config.pl unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100329scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
330scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
331scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Simon Butcherb9283432016-07-13 11:02:41 +0100332scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100333scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Simon Butcher284b4c92016-06-26 13:10:00 +0100334scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200335scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
336scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcherf95c1762016-11-10 17:25:58 +0000337CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0' make lib programs
338CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make test
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000339
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100340# catch compile bugs in _uninit functions
341msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
342cleanup
343cp "$CONFIG_H" "$CONFIG_BAK"
344scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100345scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Simon Butchereebf1b92016-06-27 01:42:39 +0100346scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherf95c1762016-11-10 17:25:58 +0000347CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100348
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200349msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
350cleanup
351cp "$CONFIG_H" "$CONFIG_BAK"
352scripts/config.pl full
353scripts/config.pl unset MBEDTLS_SSL_SRV_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000354CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200355
356msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
357cleanup
358cp "$CONFIG_H" "$CONFIG_BAK"
359scripts/config.pl full
360scripts/config.pl unset MBEDTLS_SSL_CLI_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000361CC=gcc CFLAGS='-Werror -Wall -Werror -O0' make
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200362
Simon Butcherf95c1762016-11-10 17:25:58 +0000363# Note, C99 compliance can also be tested with the sockets support disabled,
364# as that requires a POSIX platform (which isn't the same as C99).
Andres AG788aa4a2016-09-14 14:32:09 +0100365msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200366cleanup
367cp "$CONFIG_H" "$CONFIG_BAK"
368scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200369scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
370scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Simon Butcherf95c1762016-11-10 17:25:58 +0000371CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' make lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200372
Simon Butcherab5df402016-06-11 02:31:21 +0100373msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100374cleanup
375cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcherab5df402016-06-11 02:31:21 +0100376scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
Janos Follath06c54002016-06-09 13:57:40 +0100377scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
378scripts/config.pl set MBEDTLS_ENTROPY_C
379scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
380scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
381scripts/config.pl unset MBEDTLS_HAVEGE_C
Simon Butchereebf1b92016-06-27 01:42:39 +0100382CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
Janos Follath06c54002016-06-09 13:57:40 +0100383make
384
Simon Butcher8e3afc72016-09-15 17:13:08 +0100385msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100386make test
Janos Follath06c54002016-06-09 13:57:40 +0100387
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200388if uname -a | grep -F Linux >/dev/null; then
389msg "build/test: make shared" # ~ 40s
390cleanup
391make SHARED=1 all check
392fi
393
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000394if uname -a | grep -F x86_64 >/dev/null; then
395msg "build: i386, make, gcc" # ~ 30s
396cleanup
Simon Butcherf95c1762016-11-10 17:25:58 +0000397CC=gcc CFLAGS='-Werror -Wall -Wextra -m32' make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000398fi # x86_64
399
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000400msg "build: arm-none-eabi-gcc, make" # ~ 10s
401cleanup
402cp "$CONFIG_H" "$CONFIG_BAK"
403scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200404scripts/config.pl unset MBEDTLS_NET_C
405scripts/config.pl unset MBEDTLS_TIMING_C
406scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchereebf1b92016-06-27 01:42:39 +0100407scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherbc6a4862016-03-07 17:35:59 +0000408scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000409# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200410scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
411scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
412scripts/config.pl unset MBEDTLS_THREADING_C
413scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
414scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcherf95c1762016-11-10 17:25:58 +0000415CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' make lib
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000416
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100417msg "build: armcc, make"
418cleanup
419cp "$CONFIG_H" "$CONFIG_BAK"
420scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200421scripts/config.pl unset MBEDTLS_NET_C
422scripts/config.pl unset MBEDTLS_TIMING_C
423scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher1c719652016-06-27 19:02:12 +0100424scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200425scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200426scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherbc6a4862016-03-07 17:35:59 +0000427scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100428# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200429scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
430scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
431scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
432scripts/config.pl unset MBEDTLS_THREADING_C
433scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
434scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcher4df5eaf2016-08-24 22:58:31 +0300435scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Simon Butcherf95c1762016-11-10 17:25:58 +0000436CC=armcc AR=armar WARNING_CFLAGS='--strict --c99' make lib
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100437
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100438if which i686-w64-mingw32-gcc >/dev/null; then
Simon Butcherf95c1762016-11-10 17:25:58 +0000439 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
440 cleanup
441 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
442 CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 make test
443 WINDOWS_BUILD=1 make clean
444
445 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
446 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
447 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
448 WINDOWS_BUILD=1 make clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100449fi
450
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000451# MemSan currently only available on Linux 64 bits
452if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000453
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100454msg "build: MSan (clang)" # ~ 1 min 20s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100455cleanup
456cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100458CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
459make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200460
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100461msg "test: main suites (MSan)" # ~ 10s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100462make test
463
464msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100465tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100466
467# Optional part(s)
468
469if [ "$MEMORY" -gt 0 ]; then
470 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100471 tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200472fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100473
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000474else # no MemSan
475
476msg "build: Release (clang)"
477cleanup
478CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
479make
480
481msg "test: main suites valgrind (Release)"
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +0200482make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000483
484# Optional part(s)
485# Currently broken, programs don't seem to receive signals
486# under valgrind on OS X
487
488if [ "$MEMORY" -gt 0 ]; then
489 msg "test: ssl-opt.sh --memcheck (Release)"
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100490 tests/ssl-opt.sh --memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000491fi
492
493if [ "$MEMORY" -gt 1 ]; then
494 msg "test: compat.sh --memcheck (Release)"
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100495 tests/compat.sh --memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000496fi
497
498fi # MemSan
499
Andres AGdc192212016-08-31 17:33:13 +0100500msg "build: cmake 'out-of-source' build"
501cleanup
502MBEDTLS_ROOT_DIR="$PWD"
503mkdir "$OUT_OF_SOURCE_DIR"
504cd "$OUT_OF_SOURCE_DIR"
505cmake "$MBEDTLS_ROOT_DIR"
506make
507
508msg "test: cmake 'out-of-source' build"
509make test
510cd "$MBEDTLS_ROOT_DIR"
511rm -rf "$OUT_OF_SOURCE_DIR"
512
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100513msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100514cleanup
515