blob: 96b33a15ec23882f80945731594de8137ed69584 [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
Simon Butcherd7f19022016-10-14 09:49:48 +010093RELEASE=0
Gilles Peskineb9344e32017-12-19 18:24:31 +010094RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010095
Simon Butcherd7f19022016-10-14 09:49:48 +010096# Default commands, can be overriden by the environment
97: ${OPENSSL:="openssl"}
98: ${OPENSSL_LEGACY:="$OPENSSL"}
99: ${GNUTLS_CLI:="gnutls-cli"}
100: ${GNUTLS_SERV:="gnutls-serv"}
101: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
102: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
103: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
104
105usage()
106{
Gilles Peskinea6901f42017-12-10 23:43:39 +0100107 cat <<EOF
108Usage: $0 [OPTION]...
109 -h|--help Print this help.
110
111General options:
112 -f|--force Force the tests to overwrite any modified files.
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100113 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskinea6901f42017-12-10 23:43:39 +0100114 -m|--memory Additional optional memory tests.
Gilles Peskineb9344e32017-12-19 18:24:31 +0100115 --armcc Run ARM Compiler builds (on by default).
116 --no-armcc Skip ARM Compiler builds.
Gilles Peskinea6901f42017-12-10 23:43:39 +0100117 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
118 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
119 -s|--seed Integer seed value to use for this test run.
120
121Tool path options:
122 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
123 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
124 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
125 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
126 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
127 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
128EOF
Simon Butcherd7f19022016-10-14 09:49:48 +0100129}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100130
131# remove built files as well as the cmake cache/config
132cleanup()
133{
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100134 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200135
Gilles Peskine341ea252018-03-21 12:15:06 +0100136 # Remove CMake artefacts
137 find . -name .git -prune -o -name yotta -prune -o \
138 -iname CMakeFiles -exec rm -rf {} \+ -o \
139 \( -iname cmake_install.cmake -o \
140 -iname CTestTestfile.cmake -o \
141 -iname CMakeCache.txt \) -exec rm {} \+
142 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000143 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200144 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
145 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200146
147 if [ -f "$CONFIG_BAK" ]; then
148 mv "$CONFIG_BAK" "$CONFIG_H"
149 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100150}
151
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100152# Executed on exit. May be redefined depending on command line options.
153final_report () {
154 :
155}
156
157fatal_signal () {
158 cleanup
159 final_report $1
160 trap - $1
161 kill -$1 $$
162}
163
164trap 'fatal_signal HUP' HUP
165trap 'fatal_signal INT' INT
166trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200167
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100168msg()
169{
170 echo ""
171 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100172 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000173 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100174 echo "******************************************************************"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100175 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100176}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100177
Simon Butcherd7f19022016-10-14 09:49:48 +0100178err_msg()
179{
180 echo "$1" >&2
181}
182
183check_tools()
184{
185 for TOOL in "$@"; do
186 if ! `hash "$TOOL" >/dev/null 2>&1`; then
187 err_msg "$TOOL not found!"
188 exit 1
189 fi
190 done
191}
192
193while [ $# -gt 0 ]; do
194 case "$1" in
Gilles Peskineb9344e32017-12-19 18:24:31 +0100195 --armcc)
196 RUN_ARMCC=1
197 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +0100198 --force|-f)
199 FORCE=1
200 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +0100201 --gnutls-cli)
202 shift
203 GNUTLS_CLI="$1"
204 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +0100205 --gnutls-legacy-cli)
206 shift
207 GNUTLS_LEGACY_CLI="$1"
208 ;;
209 --gnutls-legacy-serv)
210 shift
211 GNUTLS_LEGACY_SERV="$1"
212 ;;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100213 --gnutls-serv)
214 shift
215 GNUTLS_SERV="$1"
216 ;;
217 --help|-h)
Simon Butcherd7f19022016-10-14 09:49:48 +0100218 usage
Gilles Peskinea6901f42017-12-10 23:43:39 +0100219 exit
220 ;;
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100221 --keep-going|-k)
222 KEEP_GOING=1
223 ;;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100224 --memory|-m)
225 MEMORY=1
226 ;;
Gilles Peskineb9344e32017-12-19 18:24:31 +0100227 --no-armcc)
228 RUN_ARMCC=0
229 ;;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100230 --openssl)
231 shift
232 OPENSSL="$1"
233 ;;
234 --openssl-legacy)
235 shift
236 OPENSSL_LEGACY="$1"
237 ;;
238 --out-of-source-dir)
239 shift
240 OUT_OF_SOURCE_DIR="$1"
241 ;;
242 --release-test|-r)
243 RELEASE=1
244 ;;
245 --seed|-s)
246 shift
247 SEED="$1"
248 ;;
249 *)
250 echo >&2 "Unknown option: $1"
251 echo >&2 "Run $0 --help for usage."
252 exit 120
Simon Butcherd7f19022016-10-14 09:49:48 +0100253 ;;
254 esac
255 shift
256done
257
258if [ $FORCE -eq 1 ]; then
259 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
260 git checkout-index -f -q $CONFIG_H
261 cleanup
262else
263
264 if [ -d yotta/module ]; then
265 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
266 echo "You can either delete your work and retry, or force the test to overwrite the"
267 echo "test by rerunning the script as: $0 --force"
268 exit 1
269 fi
270
271 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
272 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
273 echo "You can either delete this directory manually, or force the test by rerunning"
274 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
275 exit 1
276 fi
277
278 if ! git diff-files --quiet include/mbedtls/config.h; then
Simon Butcherd7f19022016-10-14 09:49:48 +0100279 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
280 echo "You can either delete or preserve your work, or force the test by rerunning the"
281 echo "script as: $0 --force"
282 exit 1
283 fi
284fi
285
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100286build_status=0
287if [ $KEEP_GOING -eq 1 ]; then
288 failure_summary=
289 failure_count=0
290 start_red=
291 end_color=
292 if [ -t 1 ]; then
Gilles Peskine92deeaa2018-01-02 21:54:17 +0100293 case "${TERM:-}" in
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100294 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
295 start_red=$(printf '\033[31m')
296 end_color=$(printf '\033[0m')
297 ;;
298 esac
299 fi
300 record_status () {
301 if "$@"; then
302 last_status=0
303 else
304 last_status=$?
305 text="$current_section: $* -> $last_status"
306 failure_summary="$failure_summary
307$text"
308 failure_count=$((failure_count + 1))
309 echo "${start_red}^^^^$text^^^^${end_color}"
310 fi
311 }
312 make () {
313 case "$*" in
314 *test|*check)
315 if [ $build_status -eq 0 ]; then
316 record_status command make "$@"
317 else
318 echo "(skipped because the build failed)"
319 fi
320 ;;
321 *)
322 record_status command make "$@"
323 build_status=$last_status
324 ;;
325 esac
326 }
327 final_report () {
328 if [ $failure_count -gt 0 ]; then
329 echo
330 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
331 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
332 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
333 elif [ -z "${1-}" ]; then
334 echo "SUCCESS :)"
335 fi
336 if [ -n "${1-}" ]; then
337 echo "Killed by SIG$1."
338 fi
339 }
340else
341 record_status () {
342 "$@"
343 }
344fi
345if_build_succeeded () {
346 if [ $build_status -eq 0 ]; then
347 record_status "$@"
348 fi
349}
350
Simon Butcherd7f19022016-10-14 09:49:48 +0100351if [ $RELEASE -eq 1 ]; then
352 # Fix the seed value to 1 to ensure that the tests are deterministic.
353 SEED=1
354fi
355
356msg "info: $0 configuration"
357echo "MEMORY: $MEMORY"
358echo "FORCE: $FORCE"
359echo "SEED: ${SEED-"UNSET"}"
360echo "OPENSSL: $OPENSSL"
361echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
362echo "GNUTLS_CLI: $GNUTLS_CLI"
363echo "GNUTLS_SERV: $GNUTLS_SERV"
364echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
365echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
366
367# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
368# we just export the variables they require
369export OPENSSL_CMD="$OPENSSL"
370export GNUTLS_CLI="$GNUTLS_CLI"
371export GNUTLS_SERV="$GNUTLS_SERV"
372
373# Avoid passing --seed flag in every call to ssl-opt.sh
374[ ! -z ${SEED+set} ] && export SEED
375
376# Make sure the tools we need are available.
377check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100378 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskineb9344e32017-12-19 18:24:31 +0100379 "arm-none-eabi-gcc"
380if [ $RUN_ARMCC -ne 0 ]; then
381 check_tools "armcc"
382fi
Simon Butcherd7f19022016-10-14 09:49:48 +0100383
Gilles Peskined7602c22017-12-21 15:59:21 +0100384
385
386################################################################
387#### Basic checks
388################################################################
389
Simon Butcherd7f19022016-10-14 09:49:48 +0100390#
391# Test Suites to be executed
392#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200393# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100394# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200395# and/or are more likely to fail than others (eg I use Clang most of the
396# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200397# 2. Minimize total running time, by avoiding useless rebuilds
398#
399# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100400
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100401msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200402tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100403
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000404msg "test: freshness of generated source files" # < 1s
405tests/scripts/check-generated-files.sh
406
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200407msg "test: doxygen markup outside doxygen blocks" # < 1s
408tests/scripts/check-doxy-blocks.pl
409
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200410msg "test/build: declared and exported names" # < 3s
411cleanup
412tests/scripts/check-names.sh
413
Gilles Peskined7602c22017-12-21 15:59:21 +0100414
415
416################################################################
417#### Build and test many configurations and targets
418################################################################
419
Simon Butcher73156352015-11-04 00:36:30 +0000420# Yotta not supported in 2.1 branch
421#msg "build: create and build yotta module" # ~ 30s
422#cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100423#record_status tests/scripts/yotta-build.sh
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200424
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100425msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100426cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100427CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100428make
429
Simon Butcherd7f19022016-10-14 09:49:48 +0100430msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100431make test
432programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200433
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100434msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100435if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200436
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100437msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100438if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200439
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200440msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
441make
442
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100443msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100444if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200445
Hanno Becker797c0842017-10-19 15:49:21 +0100446msg "build: default config except MFL extension (ASan build)" # ~ 30s
447cleanup
448cp "$CONFIG_H" "$CONFIG_BAK"
449scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
450CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
451make
452
453msg "test: ssl-opt.sh, MFL-related tests"
454tests/ssl-opt.sh -f "Max fragment length"
455
Simon Butcher02b8d482016-03-15 20:39:52 +0000456msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
457cleanup
458cp "$CONFIG_H" "$CONFIG_BAK"
459scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
460CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
461make
462
Simon Butcherd7f19022016-10-14 09:49:48 +0100463msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher02b8d482016-03-15 20:39:52 +0000464make test
465programs/test/selftest
466
467msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100468if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
469if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher02b8d482016-03-15 20:39:52 +0000470
471msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100472if_build_succeeded tests/ssl-opt.sh
Simon Butcher02b8d482016-03-15 20:39:52 +0000473
Hanno Becker4f9973e2017-10-24 11:56:28 +0100474msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
475cleanup
476cp "$CONFIG_H" "$CONFIG_BAK"
477scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
478CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
479make
480
481msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
482make test
483
484msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100485if_build_succeeded tests/ssl-opt.sh
Hanno Becker4f9973e2017-10-24 11:56:28 +0100486
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100487msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100488cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200489cp "$CONFIG_H" "$CONFIG_BAK"
490scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200491scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100492CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100493make
494
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100495msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200496make test
497
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100498msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100499if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200500
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100501msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100502if_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 +0200503
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200504msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100505cleanup
506cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100507if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100508
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200509msg "test/build: key-exchanges (gcc)" # ~ 1 min
510cleanup
511cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100512if_build_succeeded tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200513
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000514msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100515cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100516make CC=gcc CFLAGS='-Werror -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100517
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200518# this is meant to cath missing #define mbedtls_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000519# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100520msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000521cleanup
522cp "$CONFIG_H" "$CONFIG_BAK"
523scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200524scripts/config.pl unset MBEDTLS_PLATFORM_C
525scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100526scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
527scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
528scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
529scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200530scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
531scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100532make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000533
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100534# catch compile bugs in _uninit functions
535msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
536cleanup
537cp "$CONFIG_H" "$CONFIG_BAK"
538scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100539scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100540make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100541
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200542msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
543cleanup
544cp "$CONFIG_H" "$CONFIG_BAK"
545scripts/config.pl full
546scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100547make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200548
549msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
550cleanup
551cp "$CONFIG_H" "$CONFIG_BAK"
552scripts/config.pl full
553scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100554make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200555
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200556msg "build: full config except net.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200557cleanup
558cp "$CONFIG_H" "$CONFIG_BAK"
559scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200560scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
561scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100562make CC=gcc CFLAGS='-Werror -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200563
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200564if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100565 msg "build/test: make shared" # ~ 40s
566 cleanup
567 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200568fi
569
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000570if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100571 msg "build: i386, make, gcc" # ~ 30s
572 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100573 make CC=gcc CFLAGS='-Werror -m32'
Andres Amaya Garcia401441b2017-05-08 11:19:19 +0100574
575 msg "test: i386, make, gcc"
576 make test
577
578 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
579 cleanup
580 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
581
582 msg "test: 64-bit ILP32, make, gcc"
583 make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000584fi # x86_64
585
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000586msg "build: arm-none-eabi-gcc, make" # ~ 10s
587cleanup
588cp "$CONFIG_H" "$CONFIG_BAK"
589scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590scripts/config.pl unset MBEDTLS_NET_C
591scripts/config.pl unset MBEDTLS_TIMING_C
592scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcherd7f19022016-10-14 09:49:48 +0100593scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000594# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
596scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
597scripts/config.pl unset MBEDTLS_THREADING_C
598scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
599scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100600make 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 +0000601
Gilles Peskineb9344e32017-12-19 18:24:31 +0100602if [ $RUN_ARMCC -ne 0 ]; then
603 msg "build: armcc, make"
604 cleanup
605 cp "$CONFIG_H" "$CONFIG_BAK"
606 scripts/config.pl full
607 scripts/config.pl unset MBEDTLS_NET_C
608 scripts/config.pl unset MBEDTLS_TIMING_C
609 scripts/config.pl unset MBEDTLS_FS_IO
610 scripts/config.pl unset MBEDTLS_HAVE_TIME
611 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
612 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
613 # following things are not in the default config
614 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
615 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
616 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
617 scripts/config.pl unset MBEDTLS_THREADING_C
618 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
619 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
620 make CC=armcc AR=armar WARNING_CFLAGS= lib
621fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100622
Gilles Peskineb49351d2017-05-12 15:26:58 +0200623msg "build: allow SHA1 in certificates by default"
624cleanup
625cp "$CONFIG_H" "$CONFIG_BAK"
626scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100627make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskineb49351d2017-05-12 15:26:58 +0200628msg "test: allow SHA1 in certificates by default"
629make test
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100630if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskineb49351d2017-05-12 15:26:58 +0200631
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100632if which i686-w64-mingw32-gcc >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100633 msg "build: cross-mingw64, make" # ~ 30s
634 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100635 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1
636 make WINDOWS_BUILD=1 clean
637 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1
638 make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100639fi
640
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000641# MemSan currently only available on Linux 64 bits
642if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000643
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100644 msg "build: MSan (clang)" # ~ 1 min 20s
645 cleanup
646 cp "$CONFIG_H" "$CONFIG_BAK"
647 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
648 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
649 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200650
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100651 msg "test: main suites (MSan)" # ~ 10s
652 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100653
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100654 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100655 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100656
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100657 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100658
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100659 if [ "$MEMORY" -gt 0 ]; then
660 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100661 if_build_succeeded tests/compat.sh
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100662 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100663
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000664else # no MemSan
665
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100666 msg "build: Release (clang)"
667 cleanup
668 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
669 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000670
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100671 msg "test: main suites valgrind (Release)"
672 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000673
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100674 # Optional part(s)
675 # Currently broken, programs don't seem to receive signals
676 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000677
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100678 if [ "$MEMORY" -gt 0 ]; then
679 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100680 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100681 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000682
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100683 if [ "$MEMORY" -gt 1 ]; then
684 msg "test: compat.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100685 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100686 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000687
688fi # MemSan
689
Simon Butcherd7f19022016-10-14 09:49:48 +0100690msg "build: cmake 'out-of-source' build"
691cleanup
692MBEDTLS_ROOT_DIR="$PWD"
693mkdir "$OUT_OF_SOURCE_DIR"
694cd "$OUT_OF_SOURCE_DIR"
695cmake "$MBEDTLS_ROOT_DIR"
696make
697
698msg "test: cmake 'out-of-source' build"
699make test
700cd "$MBEDTLS_ROOT_DIR"
701rm -rf "$OUT_OF_SOURCE_DIR"
702
Gilles Peskined7602c22017-12-21 15:59:21 +0100703
704
705################################################################
706#### Termination
707################################################################
708
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100709msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100710cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100711
712final_report