blob: 5c9ea8d3df4bddead8f081db842c37e6522deecd [file] [log] [blame]
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001#!/bin/sh
2
Simon Butcherd7f19022016-10-14 09:49:48 +01003# all.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01004#
Simon Butcherd7f19022016-10-14 09:49:48 +01005# This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01006#
Gilles Peskined7602c22017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcherd7f19022016-10-14 09:49:48 +010015# Purpose
Gilles Peskined7602c22017-12-21 15:59:21 +010016# -------
Simon Butcherd7f19022016-10-14 09:49:48 +010017#
18# To run all tests possible or available on the platform.
19#
Gilles Peskined7602c22017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
Simon Butcherd7f19022016-10-14 09:49:48 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskined7602c22017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Simon Butcherd7f19022016-10-14 09:49:48 +010030#
Gilles Peskined7602c22017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
38# * arm-gcc and mingw-gcc
39# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
40# * OpenSSL and GnuTLS command line tools, recent enough for the
41# interoperability tests. If they don't support SSLv3 then a legacy
42# version of these tools must be present as well (search for LEGACY
43# below).
44# See the invocation of check_tools below for details.
45#
46# This script must be invoked from the toplevel directory of a git
47# working copy of Mbed TLS.
48#
49# Note that the output is not saved. You may want to run
50# script -c tests/scripts/all.sh
51# or
52# tests/scripts/all.sh >all.log 2>&1
53#
54# Notes for maintainers
55# ---------------------
56#
57# The tests are roughly in order from fastest to slowest. This doesn't
58# have to be exact, but in general you should add slower tests towards
59# the end and fast checks near the beginning.
60#
61# Sanity checks have the following form:
62# 1. msg "short description of what is about to be done"
63# 2. run sanity check (failure stops the script)
64#
65# Build or build-and-test steps have the following form:
66# 1. msg "short description of what is about to be done"
67# 2. cleanup
68# 3. preparation (config.pl, cmake, ...) (failure stops the script)
69# 4. make
70# 5. Run tests if relevant. All tests must be prefixed with
71# if_build_successful for the sake of --keep-going.
72
73
74
75################################################################
76#### Initialization and command line parsing
77################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010078
Simon Butcherd7f19022016-10-14 09:49:48 +010079# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010080set -eu
81
82if [ -d library -a -d include -a -d tests ]; then :; else
Simon Butcherd7f19022016-10-14 09:49:48 +010083 err_msg "Must be run from mbed TLS root"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010084 exit 1
85fi
86
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000087CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020088CONFIG_BAK="$CONFIG_H.bak"
89
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010090MEMORY=0
Simon Butcherd7f19022016-10-14 09:49:48 +010091FORCE=0
Gilles Peskinea8bf9862017-12-11 00:01:40 +010092KEEP_GOING=0
Gilles Peskineb9344e32017-12-19 18:24:31 +010093RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010094
Simon Butcherd7f19022016-10-14 09:49:48 +010095# Default commands, can be overriden by the environment
96: ${OPENSSL:="openssl"}
97: ${OPENSSL_LEGACY:="$OPENSSL"}
98: ${GNUTLS_CLI:="gnutls-cli"}
99: ${GNUTLS_SERV:="gnutls-serv"}
100: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
101: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
102: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
103
104usage()
105{
Gilles Peskinea6901f42017-12-10 23:43:39 +0100106 cat <<EOF
107Usage: $0 [OPTION]...
108 -h|--help Print this help.
109
110General options:
111 -f|--force Force the tests to overwrite any modified files.
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100112 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskinea6901f42017-12-10 23:43:39 +0100113 -m|--memory Additional optional memory tests.
Gilles Peskineb9344e32017-12-19 18:24:31 +0100114 --armcc Run ARM Compiler builds (on by default).
115 --no-armcc Skip ARM Compiler builds.
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100116 --no-force Refuse to overwrite modified files (default).
117 --no-keep-going Stop at the first error (default).
118 --no-memory No additional memory tests (default).
Gilles Peskine32d92932018-03-21 10:14:05 +0100119 --no-yotta Ignored for compatibility with other Mbed TLS versions.
Gilles Peskinea6901f42017-12-10 23:43:39 +0100120 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100121 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskinea6901f42017-12-10 23:43:39 +0100122 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
123 -s|--seed Integer seed value to use for this test run.
124
125Tool path options:
126 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
127 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
128 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
129 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
130 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
131 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
132EOF
Simon Butcherd7f19022016-10-14 09:49:48 +0100133}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100134
135# remove built files as well as the cmake cache/config
136cleanup()
137{
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100138 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200139
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200140 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000141 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200142 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
143 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200144
145 if [ -f "$CONFIG_BAK" ]; then
146 mv "$CONFIG_BAK" "$CONFIG_H"
147 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100148}
149
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100150# Executed on exit. May be redefined depending on command line options.
151final_report () {
152 :
153}
154
155fatal_signal () {
156 cleanup
157 final_report $1
158 trap - $1
159 kill -$1 $$
160}
161
162trap 'fatal_signal HUP' HUP
163trap 'fatal_signal INT' INT
164trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200165
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100166msg()
167{
168 echo ""
169 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100170 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000171 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100172 echo "******************************************************************"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100173 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100174}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100175
Simon Butcherd7f19022016-10-14 09:49:48 +0100176err_msg()
177{
178 echo "$1" >&2
179}
180
181check_tools()
182{
183 for TOOL in "$@"; do
184 if ! `hash "$TOOL" >/dev/null 2>&1`; then
185 err_msg "$TOOL not found!"
186 exit 1
187 fi
188 done
189}
190
191while [ $# -gt 0 ]; do
192 case "$1" in
Gilles Peskine7efa8cf2018-03-21 10:04:49 +0100193 --armcc) RUN_ARMCC=1;;
194 --force|-f) FORCE=1;;
195 --gnutls-cli) shift; GNUTLS_CLI="$1";;
196 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
197 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
198 --gnutls-serv) shift; GNUTLS_SERV="$1";;
199 --help|-h) usage; exit;;
200 --keep-going|-k) KEEP_GOING=1;;
201 --memory|-m) MEMORY=1;;
202 --no-armcc) RUN_ARMCC=0;;
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100203 --no-force) FORCE=0;;
204 --no-keep-going) KEEP_GOING=0;;
205 --no-memory) MEMORY=0;;
Gilles Peskine32d92932018-03-21 10:14:05 +0100206 --no-yotta) :;; # No Yotta support anyway, so just ignore --no-yotta
Gilles Peskine7efa8cf2018-03-21 10:04:49 +0100207 --openssl) shift; OPENSSL="$1";;
208 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
209 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100210 --random-seed) unset SEED;;
211 --release-test|-r) SEED=1;;
Gilles Peskine7efa8cf2018-03-21 10:04:49 +0100212 --seed|-s) shift; SEED="$1";;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100213 *)
214 echo >&2 "Unknown option: $1"
215 echo >&2 "Run $0 --help for usage."
216 exit 120
Simon Butcherd7f19022016-10-14 09:49:48 +0100217 ;;
218 esac
219 shift
220done
221
222if [ $FORCE -eq 1 ]; then
223 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
224 git checkout-index -f -q $CONFIG_H
225 cleanup
226else
227
228 if [ -d yotta/module ]; then
229 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
230 echo "You can either delete your work and retry, or force the test to overwrite the"
231 echo "test by rerunning the script as: $0 --force"
232 exit 1
233 fi
234
235 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
236 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
237 echo "You can either delete this directory manually, or force the test by rerunning"
238 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
239 exit 1
240 fi
241
242 if ! git diff-files --quiet include/mbedtls/config.h; then
Simon Butcherd7f19022016-10-14 09:49:48 +0100243 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
244 echo "You can either delete or preserve your work, or force the test by rerunning the"
245 echo "script as: $0 --force"
246 exit 1
247 fi
248fi
249
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100250build_status=0
251if [ $KEEP_GOING -eq 1 ]; then
252 failure_summary=
253 failure_count=0
254 start_red=
255 end_color=
256 if [ -t 1 ]; then
Gilles Peskine92deeaa2018-01-02 21:54:17 +0100257 case "${TERM:-}" in
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100258 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
259 start_red=$(printf '\033[31m')
260 end_color=$(printf '\033[0m')
261 ;;
262 esac
263 fi
264 record_status () {
265 if "$@"; then
266 last_status=0
267 else
268 last_status=$?
269 text="$current_section: $* -> $last_status"
270 failure_summary="$failure_summary
271$text"
272 failure_count=$((failure_count + 1))
273 echo "${start_red}^^^^$text^^^^${end_color}"
274 fi
275 }
276 make () {
277 case "$*" in
278 *test|*check)
279 if [ $build_status -eq 0 ]; then
280 record_status command make "$@"
281 else
282 echo "(skipped because the build failed)"
283 fi
284 ;;
285 *)
286 record_status command make "$@"
287 build_status=$last_status
288 ;;
289 esac
290 }
291 final_report () {
292 if [ $failure_count -gt 0 ]; then
293 echo
294 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
295 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
296 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
297 elif [ -z "${1-}" ]; then
298 echo "SUCCESS :)"
299 fi
300 if [ -n "${1-}" ]; then
301 echo "Killed by SIG$1."
302 fi
303 }
304else
305 record_status () {
306 "$@"
307 }
308fi
309if_build_succeeded () {
310 if [ $build_status -eq 0 ]; then
311 record_status "$@"
312 fi
313}
314
Simon Butcherd7f19022016-10-14 09:49:48 +0100315msg "info: $0 configuration"
316echo "MEMORY: $MEMORY"
317echo "FORCE: $FORCE"
318echo "SEED: ${SEED-"UNSET"}"
319echo "OPENSSL: $OPENSSL"
320echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
321echo "GNUTLS_CLI: $GNUTLS_CLI"
322echo "GNUTLS_SERV: $GNUTLS_SERV"
323echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
324echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
325
326# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
327# we just export the variables they require
328export OPENSSL_CMD="$OPENSSL"
329export GNUTLS_CLI="$GNUTLS_CLI"
330export GNUTLS_SERV="$GNUTLS_SERV"
331
332# Avoid passing --seed flag in every call to ssl-opt.sh
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100333if [ -n "${SEED-}" ]; then
334 export SEED
335fi
Simon Butcherd7f19022016-10-14 09:49:48 +0100336
337# Make sure the tools we need are available.
338check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100339 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskineb9344e32017-12-19 18:24:31 +0100340 "arm-none-eabi-gcc"
341if [ $RUN_ARMCC -ne 0 ]; then
342 check_tools "armcc"
343fi
Simon Butcherd7f19022016-10-14 09:49:48 +0100344
Gilles Peskined7602c22017-12-21 15:59:21 +0100345
346
347################################################################
348#### Basic checks
349################################################################
350
Simon Butcherd7f19022016-10-14 09:49:48 +0100351#
352# Test Suites to be executed
353#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200354# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100355# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200356# and/or are more likely to fail than others (eg I use Clang most of the
357# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200358# 2. Minimize total running time, by avoiding useless rebuilds
359#
360# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100361
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100362msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200363tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100364
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000365msg "test: freshness of generated source files" # < 1s
366tests/scripts/check-generated-files.sh
367
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200368msg "test: doxygen markup outside doxygen blocks" # < 1s
369tests/scripts/check-doxy-blocks.pl
370
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200371msg "test/build: declared and exported names" # < 3s
372cleanup
373tests/scripts/check-names.sh
374
Gilles Peskined7602c22017-12-21 15:59:21 +0100375
376
377################################################################
378#### Build and test many configurations and targets
379################################################################
380
Simon Butcher73156352015-11-04 00:36:30 +0000381# Yotta not supported in 2.1 branch
382#msg "build: create and build yotta module" # ~ 30s
383#cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100384#record_status tests/scripts/yotta-build.sh
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200385
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100386msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100387cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100388CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100389make
390
Simon Butcherd7f19022016-10-14 09:49:48 +0100391msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100392make test
393programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200394
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100395msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100396if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200397
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100398msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100399if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200400
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200401msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
402make
403
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100404msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100405if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200406
Hanno Becker797c0842017-10-19 15:49:21 +0100407msg "build: default config except MFL extension (ASan build)" # ~ 30s
408cleanup
409cp "$CONFIG_H" "$CONFIG_BAK"
410scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
411CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
412make
413
414msg "test: ssl-opt.sh, MFL-related tests"
415tests/ssl-opt.sh -f "Max fragment length"
416
Simon Butcher02b8d482016-03-15 20:39:52 +0000417msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
418cleanup
419cp "$CONFIG_H" "$CONFIG_BAK"
420scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
421CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
422make
423
Simon Butcherd7f19022016-10-14 09:49:48 +0100424msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher02b8d482016-03-15 20:39:52 +0000425make test
426programs/test/selftest
427
428msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100429if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
430if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher02b8d482016-03-15 20:39:52 +0000431
432msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100433if_build_succeeded tests/ssl-opt.sh
Simon Butcher02b8d482016-03-15 20:39:52 +0000434
Hanno Becker4f9973e2017-10-24 11:56:28 +0100435msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
436cleanup
437cp "$CONFIG_H" "$CONFIG_BAK"
438scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
439CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
440make
441
442msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
443make test
444
445msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100446if_build_succeeded tests/ssl-opt.sh
Hanno Becker4f9973e2017-10-24 11:56:28 +0100447
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100448msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100449cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200450cp "$CONFIG_H" "$CONFIG_BAK"
451scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200452scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100453CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100454make
455
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100456msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200457make test
458
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100459msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100460if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200461
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100462msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100463if_build_succeeded env OPENSSL_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 +0200464
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200465msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100466cleanup
467cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100468if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100469
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200470msg "test/build: key-exchanges (gcc)" # ~ 1 min
471cleanup
472cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100473if_build_succeeded tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200474
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000475msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100476cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100477make CC=gcc CFLAGS='-Werror -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100478
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200479# this is meant to cath missing #define mbedtls_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000480# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100481msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000482cleanup
483cp "$CONFIG_H" "$CONFIG_BAK"
484scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200485scripts/config.pl unset MBEDTLS_PLATFORM_C
486scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100487scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
488scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
489scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
490scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200491scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
492scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100493make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000494
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100495# catch compile bugs in _uninit functions
496msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
497cleanup
498cp "$CONFIG_H" "$CONFIG_BAK"
499scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100500scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100501make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100502
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200503msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
504cleanup
505cp "$CONFIG_H" "$CONFIG_BAK"
506scripts/config.pl full
507scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100508make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200509
510msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
511cleanup
512cp "$CONFIG_H" "$CONFIG_BAK"
513scripts/config.pl full
514scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100515make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200516
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200517msg "build: full config except net.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200518cleanup
519cp "$CONFIG_H" "$CONFIG_BAK"
520scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200521scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
522scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100523make CC=gcc CFLAGS='-Werror -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200524
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200525if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100526 msg "build/test: make shared" # ~ 40s
527 cleanup
528 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200529fi
530
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000531if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100532 msg "build: i386, make, gcc" # ~ 30s
533 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100534 make CC=gcc CFLAGS='-Werror -m32'
Andres Amaya Garcia401441b2017-05-08 11:19:19 +0100535
536 msg "test: i386, make, gcc"
537 make test
538
539 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
540 cleanup
541 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
542
543 msg "test: 64-bit ILP32, make, gcc"
544 make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000545fi # x86_64
546
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000547msg "build: arm-none-eabi-gcc, make" # ~ 10s
548cleanup
549cp "$CONFIG_H" "$CONFIG_BAK"
550scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551scripts/config.pl unset MBEDTLS_NET_C
552scripts/config.pl unset MBEDTLS_TIMING_C
553scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcherd7f19022016-10-14 09:49:48 +0100554scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000555# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
557scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
558scripts/config.pl unset MBEDTLS_THREADING_C
559scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
560scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100561make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS=-Werror lib
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000562
Gilles Peskineb9344e32017-12-19 18:24:31 +0100563if [ $RUN_ARMCC -ne 0 ]; then
564 msg "build: armcc, make"
565 cleanup
566 cp "$CONFIG_H" "$CONFIG_BAK"
567 scripts/config.pl full
568 scripts/config.pl unset MBEDTLS_NET_C
569 scripts/config.pl unset MBEDTLS_TIMING_C
570 scripts/config.pl unset MBEDTLS_FS_IO
571 scripts/config.pl unset MBEDTLS_HAVE_TIME
572 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
573 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
574 # following things are not in the default config
575 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
576 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
577 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
578 scripts/config.pl unset MBEDTLS_THREADING_C
579 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
580 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
581 make CC=armcc AR=armar WARNING_CFLAGS= lib
582fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100583
Gilles Peskineb49351d2017-05-12 15:26:58 +0200584msg "build: allow SHA1 in certificates by default"
585cleanup
586cp "$CONFIG_H" "$CONFIG_BAK"
587scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100588make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskineb49351d2017-05-12 15:26:58 +0200589msg "test: allow SHA1 in certificates by default"
590make test
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100591if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskineb49351d2017-05-12 15:26:58 +0200592
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100593if which i686-w64-mingw32-gcc >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100594 msg "build: cross-mingw64, make" # ~ 30s
595 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100596 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1
597 make WINDOWS_BUILD=1 clean
598 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1
599 make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100600fi
601
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000602# MemSan currently only available on Linux 64 bits
603if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000604
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100605 msg "build: MSan (clang)" # ~ 1 min 20s
606 cleanup
607 cp "$CONFIG_H" "$CONFIG_BAK"
608 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
609 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
610 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200611
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100612 msg "test: main suites (MSan)" # ~ 10s
613 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100614
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100615 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100616 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100617
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100618 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100619
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100620 if [ "$MEMORY" -gt 0 ]; then
621 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100622 if_build_succeeded tests/compat.sh
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100623 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100624
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000625else # no MemSan
626
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100627 msg "build: Release (clang)"
628 cleanup
629 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
630 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000631
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100632 msg "test: main suites valgrind (Release)"
633 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000634
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100635 # Optional part(s)
636 # Currently broken, programs don't seem to receive signals
637 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000638
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100639 if [ "$MEMORY" -gt 0 ]; then
640 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100641 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100642 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000643
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100644 if [ "$MEMORY" -gt 1 ]; then
645 msg "test: compat.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100646 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100647 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000648
649fi # MemSan
650
Simon Butcherd7f19022016-10-14 09:49:48 +0100651msg "build: cmake 'out-of-source' build"
652cleanup
653MBEDTLS_ROOT_DIR="$PWD"
654mkdir "$OUT_OF_SOURCE_DIR"
655cd "$OUT_OF_SOURCE_DIR"
656cmake "$MBEDTLS_ROOT_DIR"
657make
658
659msg "test: cmake 'out-of-source' build"
660make test
661cd "$MBEDTLS_ROOT_DIR"
662rm -rf "$OUT_OF_SOURCE_DIR"
663
Gilles Peskined7602c22017-12-21 15:59:21 +0100664
665
666################################################################
667#### Termination
668################################################################
669
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100670msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100671cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100672
673final_report