blob: e16c1b5f997b3382c8bb266ce18a658e657b85ba [file] [log] [blame]
Andres AG7f08d7a2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
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
Andres AGb9d3db62016-07-12 16:54:33 +010025if [ "$( uname )" != "Linux" ]; then
26 echo "This script only works in Linux" >&2
27 exit 1
28elif [ -d library -a -d include -a -d tests ]; then :; else
29 echo "Must be run from mbed TLS root" >&2
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010030 exit 1
31fi
32
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000033CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020034CONFIG_BAK="$CONFIG_H.bak"
35
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010036MEMORY=0
SimonB2e23c822016-04-16 21:54:39 +010037FORCE=0
Andres AG7770ea82016-10-10 15:46:20 +010038RELEASE=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010039
Andres AGd9eba4b2016-08-26 14:42:14 +010040# Default commands, can be overriden by the environment
41: ${OPENSSL:="openssl"}
42: ${OPENSSL_LEGACY:="$OPENSSL"}
43: ${GNUTLS_CLI:="gnutls-cli"}
44: ${GNUTLS_SERV:="gnutls-serv"}
45: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
46: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
Andres AGdc192212016-08-31 17:33:13 +010047: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
Andres AG9e3fba02016-09-27 15:05:15 +010048: ${ARMC5_BIN_DIR:=/usr/bin}
49: ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +010050
Andres AGb9d3db62016-07-12 16:54:33 +010051# if MAKEFLAGS is not set add the -j option to speed up invocations of make
52if [ -n "${MAKEFLAGS+set}" ]; then
53 export MAKEFLAGS="-j"
54fi
55
Simon Butcher41eeccf2016-09-07 00:07:09 +010056usage()
SimonB2e23c822016-04-16 21:54:39 +010057{
Andres AGd9eba4b2016-08-26 14:42:14 +010058 printf "Usage: $0\n"
59 printf " -h|--help\t\tPrint this help.\n"
60 printf " -m|--memory\t\tAdditional optional memory tests.\n"
61 printf " -f|--force\t\tForce the tests to overwrite any modified files.\n"
Andres AG7770ea82016-10-10 15:46:20 +010062 printf " -s|--seed\t\tInteger seed value to use for this test run.\n"
63 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 +010064 printf " --out-of-source-dir=<path>\t\tDirectory used for CMake out-of-source build tests."
Andres AGd9eba4b2016-08-26 14:42:14 +010065 printf " --openssl=<OpenSSL_path>\t\tPath to OpenSSL executable to use for most tests.\n"
66 printf " --openssl-legacy=<OpenSSL_path>\t\tPath to OpenSSL executable to use for legacy tests e.g. SSLv3.\n"
67 printf " --gnutls-cli=<GnuTLS_cli_path>\t\tPath to GnuTLS client executable to use for most tests.\n"
68 printf " --gnutls-serv=<GnuTLS_serv_path>\t\tPath to GnuTLS server executable to use for most tests.\n"
69 printf " --gnutls-legacy-cli=<GnuTLS_cli_path>\t\tPath to GnuTLS client executable to use for legacy tests.\n"
70 printf " --gnutls-legacy-serv=<GnuTLS_serv_path>\t\tPath to GnuTLS server executable to use for legacy tests.\n"
Andres AG9e3fba02016-09-27 15:05:15 +010071 printf " --armc5-bin-dir=<ARMC5_bin_dir_path>\t\tPath to the ARM Compiler 5 bin directory.\n"
72 printf " --armc6-bin-dir=<ARMC6_bin_dir_path>\t\tPath to the ARM Compiler 6 bin directory.\n"
SimonB2e23c822016-04-16 21:54:39 +010073}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010074
75# remove built files as well as the cmake cache/config
76cleanup()
77{
78 make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020079
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +020080 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +020082 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
83 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020084
85 if [ -f "$CONFIG_BAK" ]; then
86 mv "$CONFIG_BAK" "$CONFIG_H"
87 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010088}
89
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020090trap cleanup INT TERM HUP
91
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010092msg()
93{
94 echo ""
95 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010096 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +000097 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010098 echo "******************************************************************"
99}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100100
Andres AGd9eba4b2016-08-26 14:42:14 +0100101err_msg()
102{
103 echo "$1" >&2
104}
105
106check_tools()
107{
108 for TOOL in "$@"; do
109 if ! `hash "$TOOL" >/dev/null 2>&1`; then
110 err_msg "$TOOL not found!"
111 exit 1
112 fi
113 done
114}
115
SimonB2e23c822016-04-16 21:54:39 +0100116while [ $# -gt 0 ]; do
117 case "$1" in
118 --memory|-m*)
119 MEMORY=${1#-m}
120 ;;
SimonB2e23c822016-04-16 21:54:39 +0100121 --force|-f)
122 FORCE=1
123 ;;
Andres AG7770ea82016-10-10 15:46:20 +0100124 --seed|-s)
125 shift
126 SEED="$1"
127 ;;
128 --release-test|-r)
129 RELEASE=1
130 ;;
Andres AGdc192212016-08-31 17:33:13 +0100131 --out-of-source-dir)
132 shift
133 OUT_OF_SOURCE_DIR="$1"
134 ;;
Andres AGd9eba4b2016-08-26 14:42:14 +0100135 --openssl)
136 shift
137 OPENSSL="$1"
138 ;;
139 --openssl-legacy)
140 shift
141 OPENSSL_LEGACY="$1"
142 ;;
143 --gnutls-cli)
144 shift
145 GNUTLS_CLI="$1"
146 ;;
147 --gnutls-serv)
148 shift
149 GNUTLS_SERV="$1"
150 ;;
151 --gnutls-legacy-cli)
152 shift
153 GNUTLS_LEGACY_CLI="$1"
154 ;;
155 --gnutls-legacy-serv)
156 shift
157 GNUTLS_LEGACY_SERV="$1"
158 ;;
Andres AG9e3fba02016-09-27 15:05:15 +0100159 --armc5-bin-dir)
160 shift
161 ARMC5_BIN_DIR="$1"
162 ;;
163 --armc6-bin-dir)
164 shift
165 ARMC6_BIN_DIR="$1"
166 ;;
SimonB2e23c822016-04-16 21:54:39 +0100167 --help|-h|*)
Andres AGd9eba4b2016-08-26 14:42:14 +0100168 usage
SimonB2e23c822016-04-16 21:54:39 +0100169 exit 1
170 ;;
171 esac
172 shift
173done
174
175if [ $FORCE -eq 1 ]; then
Andres AGdc192212016-08-31 17:33:13 +0100176 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
SimonB2e23c822016-04-16 21:54:39 +0100177 git checkout-index -f -q $CONFIG_H
178 cleanup
179else
180
181 if [ -d yotta/module ]; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100182 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
SimonB2e23c822016-04-16 21:54:39 +0100183 echo "You can either delete your work and retry, or force the test to overwrite the"
184 echo "test by rerunning the script as: $0 --force"
185 exit 1
186 fi
187
Andres AGdc192212016-08-31 17:33:13 +0100188 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
189 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
190 echo "You can either delete this directory manually, or force the test by rerunning"
191 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
192 exit 1
193 fi
194
SimonB2e23c822016-04-16 21:54:39 +0100195 if ! git diff-files --quiet include/mbedtls/config.h; then
196 echo $?
Andres AGd9eba4b2016-08-26 14:42:14 +0100197 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
SimonB2e23c822016-04-16 21:54:39 +0100198 echo "You can either delete or preserve your work, or force the test by rerunning the"
199 echo "script as: $0 --force"
200 exit 1
201 fi
202fi
203
Andres AG7770ea82016-10-10 15:46:20 +0100204if [ $RELEASE -eq 1 ]; then
205 # Fix the seed value to 1 to ensure that the tests are deterministic.
206 SEED=1
207fi
208
Andres AGd9eba4b2016-08-26 14:42:14 +0100209msg "info: $0 configuration"
210echo "MEMORY: $MEMORY"
211echo "FORCE: $FORCE"
Andres AG7770ea82016-10-10 15:46:20 +0100212echo "SEED: ${SEED-"UNSET"}"
Andres AGd9eba4b2016-08-26 14:42:14 +0100213echo "OPENSSL: $OPENSSL"
214echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
215echo "GNUTLS_CLI: $GNUTLS_CLI"
216echo "GNUTLS_SERV: $GNUTLS_SERV"
217echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
218echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
Andres AG9e3fba02016-09-27 15:05:15 +0100219echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
220echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
221
222ARMC5_CC="$ARMC5_BIN_DIR/armcc"
223ARMC5_AR="$ARMC5_BIN_DIR/armar"
224ARMC6_CC="$ARMC6_BIN_DIR/armclang"
225ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100226
Andres AGb2fdd042016-09-22 14:17:46 +0100227# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
228# we just export the variables they require
229export OPENSSL_CMD="$OPENSSL"
230export GNUTLS_CLI="$GNUTLS_CLI"
231export GNUTLS_SERV="$GNUTLS_SERV"
232
Andres AG7770ea82016-10-10 15:46:20 +0100233# Avoid passing --seed flag in every call to ssl-opt.sh
234[ ! -z ${SEED+set} ] && export SEED
235
Andres AGd9eba4b2016-08-26 14:42:14 +0100236# Make sure the tools we need are available.
237check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
238 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Andres AG9e3fba02016-09-27 15:05:15 +0100239 "arm-none-eabi-gcc" "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR" \
240 "i686-w64-mingw32-gcc"
Andres AGd9eba4b2016-08-26 14:42:14 +0100241
SimonB2e23c822016-04-16 21:54:39 +0100242#
243# Test Suites to be executed
244#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200245# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100246# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200247# and/or are more likely to fail than others (eg I use Clang most of the
248# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200249# 2. Minimize total running time, by avoiding useless rebuilds
250#
251# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100252
Janos Follathb72c6782016-07-19 14:54:17 +0100253msg "info: output_env.sh"
Andres AGd9eba4b2016-08-26 14:42:14 +0100254OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
255 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
Andres AG9e3fba02016-09-27 15:05:15 +0100256 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
257 ARMC6_CC="$ARMC6_CC" scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100258
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100259msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200260tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100261
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000262msg "test: freshness of generated source files" # < 1s
263tests/scripts/check-generated-files.sh
264
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200265msg "test: doxygen markup outside doxygen blocks" # < 1s
266tests/scripts/check-doxy-blocks.pl
267
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200268msg "test/build: declared and exported names" # < 3s
269cleanup
270tests/scripts/check-names.sh
271
Andres AGd9eba4b2016-08-26 14:42:14 +0100272msg "test: doxygen warnings" # ~ 3s
273cleanup
274tests/scripts/doxygen.sh
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100275
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200276msg "build: create and build yotta module" # ~ 30s
277cleanup
278tests/scripts/yotta-build.sh
279
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100280msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100281cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100282CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100283make
284
Simon Butcher8e3afc72016-09-15 17:13:08 +0100285msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100286make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200287
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100288msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100289tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200290
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100291msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200292tests/scripts/test-ref-configs.pl
293
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200294msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
295make
296
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100297msg "test: compat.sh (ASan build)" # ~ 6 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100298tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200299
Simon Butcher3ea7f522016-03-07 23:22:10 +0000300msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
301cleanup
Simon Butcherf413b6f2016-03-14 22:32:42 +0000302cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcher3ea7f522016-03-07 23:22:10 +0000303scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
304CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
305make
306
Simon Butcher8e3afc72016-09-15 17:13:08 +0100307msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher3ea7f522016-03-07 23:22:10 +0000308make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000309
310msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Andres AGd9eba4b2016-08-26 14:42:14 +0100311tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
312OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000313
314msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
315tests/ssl-opt.sh
316
Simon Butcher9510cc12016-11-10 17:25:58 +0000317msg "build: cmake, full config, clang, C99" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100318cleanup
Janos Follath35d48cb2016-04-22 14:45:00 +0100319cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200320scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Simon Butcher9510cc12016-11-10 17:25:58 +0000322CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
323CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic' make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100324
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100325msg "test: main suites (full config)" # ~ 5s
Simon Butcher9510cc12016-11-10 17:25:58 +0000326CFLAGS='-Werror -Wall -Wextra' make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200327
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100328msg "test: ssl-opt.sh default (full config)" # ~ 1s
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100329tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200330
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100331msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Andres AGd9eba4b2016-08-26 14:42:14 +0100332OPENSSL_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 +0200333
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200334msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100335cleanup
336cmake -D CMAKE_BUILD_TYPE:String=Debug .
337tests/scripts/curves.pl
338
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200339msg "test/build: key-exchanges (gcc)" # ~ 1 min
340cleanup
341cmake -D CMAKE_BUILD_TYPE:String=Check .
342tests/scripts/key-exchanges.pl
343
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000344msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100345cleanup
Simon Butcher9510cc12016-11-10 17:25:58 +0000346CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100347
Simon Butcher9510cc12016-11-10 17:25:58 +0000348# Full configuration build, without platform support, file IO and net sockets.
349# This should catch missing mbedtls_printf definitions, and by disabling file
350# IO, it should catch missing '#include <stdio.h>'
351msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000352cleanup
353cp "$CONFIG_H" "$CONFIG_BAK"
354scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200355scripts/config.pl unset MBEDTLS_PLATFORM_C
Simon Butcher9510cc12016-11-10 17:25:58 +0000356scripts/config.pl unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200357scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100358scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
359scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
360scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Simon Butcherb9283432016-07-13 11:02:41 +0100361scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100362scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Simon Butcher284b4c92016-06-26 13:10:00 +0100363scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200364scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
365scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher9510cc12016-11-10 17:25:58 +0000366CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0' make lib programs
367CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make test
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000368
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100369# catch compile bugs in _uninit functions
370msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
371cleanup
372cp "$CONFIG_H" "$CONFIG_BAK"
373scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100374scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Simon Butchereebf1b92016-06-27 01:42:39 +0100375scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcher9510cc12016-11-10 17:25:58 +0000376CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100377
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200378msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
379cleanup
380cp "$CONFIG_H" "$CONFIG_BAK"
381scripts/config.pl full
382scripts/config.pl unset MBEDTLS_SSL_SRV_C
Simon Butcher9510cc12016-11-10 17:25:58 +0000383CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' make
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200384
385msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
386cleanup
387cp "$CONFIG_H" "$CONFIG_BAK"
388scripts/config.pl full
389scripts/config.pl unset MBEDTLS_SSL_CLI_C
Simon Butcher9510cc12016-11-10 17:25:58 +0000390CC=gcc CFLAGS='-Werror -Wall -Werror -O0' make
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200391
Simon Butcher9510cc12016-11-10 17:25:58 +0000392# Note, C99 compliance can also be tested with the sockets support disabled,
393# as that requires a POSIX platform (which isn't the same as C99).
Andres AG788aa4a2016-09-14 14:32:09 +0100394msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200395cleanup
396cp "$CONFIG_H" "$CONFIG_BAK"
397scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200398scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
399scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Simon Butcher9510cc12016-11-10 17:25:58 +0000400CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' make lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200401
Simon Butcherab5df402016-06-11 02:31:21 +0100402msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100403cleanup
404cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcherab5df402016-06-11 02:31:21 +0100405scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
Janos Follath06c54002016-06-09 13:57:40 +0100406scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
407scripts/config.pl set MBEDTLS_ENTROPY_C
408scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
409scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
410scripts/config.pl unset MBEDTLS_HAVEGE_C
Simon Butchereebf1b92016-06-27 01:42:39 +0100411CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
Janos Follath06c54002016-06-09 13:57:40 +0100412make
413
Simon Butcher8e3afc72016-09-15 17:13:08 +0100414msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100415make test
Janos Follath06c54002016-06-09 13:57:40 +0100416
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200417if uname -a | grep -F Linux >/dev/null; then
418msg "build/test: make shared" # ~ 40s
419cleanup
420make SHARED=1 all check
421fi
422
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000423if uname -a | grep -F x86_64 >/dev/null; then
424msg "build: i386, make, gcc" # ~ 30s
425cleanup
Simon Butcher9510cc12016-11-10 17:25:58 +0000426CC=gcc CFLAGS='-Werror -Wall -Wextra -m32' make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000427fi # x86_64
428
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000429msg "build: arm-none-eabi-gcc, make" # ~ 10s
430cleanup
431cp "$CONFIG_H" "$CONFIG_BAK"
432scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200433scripts/config.pl unset MBEDTLS_NET_C
434scripts/config.pl unset MBEDTLS_TIMING_C
435scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchereebf1b92016-06-27 01:42:39 +0100436scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherbc6a4862016-03-07 17:35:59 +0000437scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000438# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200439scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
440scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
441scripts/config.pl unset MBEDTLS_THREADING_C
442scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
443scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcher9510cc12016-11-10 17:25:58 +0000444CC=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 +0000445
Andres AG9e3fba02016-09-27 15:05:15 +0100446msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100447cleanup
448cp "$CONFIG_H" "$CONFIG_BAK"
449scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200450scripts/config.pl unset MBEDTLS_NET_C
451scripts/config.pl unset MBEDTLS_TIMING_C
452scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher1c719652016-06-27 19:02:12 +0100453scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200454scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200455scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherbc6a4862016-03-07 17:35:59 +0000456scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100457# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200458scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
459scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
460scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
461scripts/config.pl unset MBEDTLS_THREADING_C
462scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
463scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcher4df5eaf2016-08-24 22:58:31 +0300464scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Andres AG9e3fba02016-09-27 15:05:15 +0100465
466CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' make lib
467make clean
468
469msg "build: ARM Compiler 6 (arm-arm-none-eabi), make"
470ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" \
471 CFLAGS="--target=arm-arm-none-eabi" WARNING_CFLAGS= make lib
472make clean
473
474msg "build: ARM Compiler 6 (aarch64-arm-none-eabi), make"
475ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" \
476 CFLAGS="--target=aarch64-arm-none-eabi" WARNING_CFLAGS= make lib
477make clean
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100478
Simon Butcher1e6f5ac2016-11-17 09:27:45 +0000479msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
480cleanup
481CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 make lib programs
Simon Butcher4ae4fdc2016-11-17 09:20:50 +0000482
Simon Butcher1e6f5ac2016-11-17 09:27:45 +0000483# note Make tests only builds the tests, but doesn't run them
484CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 make tests
485WINDOWS_BUILD=1 make clean
Simon Butcher9510cc12016-11-10 17:25:58 +0000486
Simon Butcher1e6f5ac2016-11-17 09:27:45 +0000487msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
488CC=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
489CC=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
490WINDOWS_BUILD=1 make clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100491
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000492# MemSan currently only available on Linux 64 bits
493if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000494
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100495msg "build: MSan (clang)" # ~ 1 min 20s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100496cleanup
497cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200498scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100499CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
500make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200501
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100502msg "test: main suites (MSan)" # ~ 10s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100503make test
504
505msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100506tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100507
508# Optional part(s)
509
510if [ "$MEMORY" -gt 0 ]; then
511 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100512 tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200513fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100514
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000515else # no MemSan
516
517msg "build: Release (clang)"
518cleanup
519CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
520make
521
522msg "test: main suites valgrind (Release)"
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +0200523make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000524
525# Optional part(s)
526# Currently broken, programs don't seem to receive signals
527# under valgrind on OS X
528
529if [ "$MEMORY" -gt 0 ]; then
530 msg "test: ssl-opt.sh --memcheck (Release)"
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100531 tests/ssl-opt.sh --memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000532fi
533
534if [ "$MEMORY" -gt 1 ]; then
535 msg "test: compat.sh --memcheck (Release)"
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100536 tests/compat.sh --memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000537fi
538
539fi # MemSan
540
Andres AGdc192212016-08-31 17:33:13 +0100541msg "build: cmake 'out-of-source' build"
542cleanup
543MBEDTLS_ROOT_DIR="$PWD"
544mkdir "$OUT_OF_SOURCE_DIR"
545cd "$OUT_OF_SOURCE_DIR"
546cmake "$MBEDTLS_ROOT_DIR"
547make
548
549msg "test: cmake 'out-of-source' build"
550make test
551cd "$MBEDTLS_ROOT_DIR"
552rm -rf "$OUT_OF_SOURCE_DIR"
553
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100554msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100555cleanup
556