blob: 34954eaa0a6aa061ca7edf9c83916583e08d9ecd [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 Peskinea6901f42017-12-10 23:43:39 +0100119 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100120 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskinea6901f42017-12-10 23:43:39 +0100121 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
122 -s|--seed Integer seed value to use for this test run.
123
124Tool path options:
125 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
126 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
127 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
128 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
129 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
130 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
131EOF
Simon Butcherd7f19022016-10-14 09:49:48 +0100132}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100133
134# remove built files as well as the cmake cache/config
135cleanup()
136{
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100137 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200138
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200139 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000140 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200141 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
142 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200143
144 if [ -f "$CONFIG_BAK" ]; then
145 mv "$CONFIG_BAK" "$CONFIG_H"
146 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100147}
148
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100149# Executed on exit. May be redefined depending on command line options.
150final_report () {
151 :
152}
153
154fatal_signal () {
155 cleanup
156 final_report $1
157 trap - $1
158 kill -$1 $$
159}
160
161trap 'fatal_signal HUP' HUP
162trap 'fatal_signal INT' INT
163trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200164
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100165msg()
166{
167 echo ""
168 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100169 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000170 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100171 echo "******************************************************************"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100172 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100173}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100174
Simon Butcherd7f19022016-10-14 09:49:48 +0100175err_msg()
176{
177 echo "$1" >&2
178}
179
180check_tools()
181{
182 for TOOL in "$@"; do
183 if ! `hash "$TOOL" >/dev/null 2>&1`; then
184 err_msg "$TOOL not found!"
185 exit 1
186 fi
187 done
188}
189
190while [ $# -gt 0 ]; do
191 case "$1" in
Gilles Peskine7efa8cf2018-03-21 10:04:49 +0100192 --armcc) RUN_ARMCC=1;;
193 --force|-f) FORCE=1;;
194 --gnutls-cli) shift; GNUTLS_CLI="$1";;
195 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
196 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
197 --gnutls-serv) shift; GNUTLS_SERV="$1";;
198 --help|-h) usage; exit;;
199 --keep-going|-k) KEEP_GOING=1;;
200 --memory|-m) MEMORY=1;;
201 --no-armcc) RUN_ARMCC=0;;
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100202 --no-force) FORCE=0;;
203 --no-keep-going) KEEP_GOING=0;;
204 --no-memory) MEMORY=0;;
Gilles Peskine7efa8cf2018-03-21 10:04:49 +0100205 --openssl) shift; OPENSSL="$1";;
206 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
207 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100208 --random-seed) unset SEED;;
209 --release-test|-r) SEED=1;;
Gilles Peskine7efa8cf2018-03-21 10:04:49 +0100210 --seed|-s) shift; SEED="$1";;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100211 *)
212 echo >&2 "Unknown option: $1"
213 echo >&2 "Run $0 --help for usage."
214 exit 120
Simon Butcherd7f19022016-10-14 09:49:48 +0100215 ;;
216 esac
217 shift
218done
219
220if [ $FORCE -eq 1 ]; then
221 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
222 git checkout-index -f -q $CONFIG_H
223 cleanup
224else
225
226 if [ -d yotta/module ]; then
227 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
228 echo "You can either delete your work and retry, or force the test to overwrite the"
229 echo "test by rerunning the script as: $0 --force"
230 exit 1
231 fi
232
233 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
234 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
235 echo "You can either delete this directory manually, or force the test by rerunning"
236 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
237 exit 1
238 fi
239
240 if ! git diff-files --quiet include/mbedtls/config.h; then
Simon Butcherd7f19022016-10-14 09:49:48 +0100241 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
242 echo "You can either delete or preserve your work, or force the test by rerunning the"
243 echo "script as: $0 --force"
244 exit 1
245 fi
246fi
247
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100248build_status=0
249if [ $KEEP_GOING -eq 1 ]; then
250 failure_summary=
251 failure_count=0
252 start_red=
253 end_color=
254 if [ -t 1 ]; then
Gilles Peskine92deeaa2018-01-02 21:54:17 +0100255 case "${TERM:-}" in
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100256 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
257 start_red=$(printf '\033[31m')
258 end_color=$(printf '\033[0m')
259 ;;
260 esac
261 fi
262 record_status () {
263 if "$@"; then
264 last_status=0
265 else
266 last_status=$?
267 text="$current_section: $* -> $last_status"
268 failure_summary="$failure_summary
269$text"
270 failure_count=$((failure_count + 1))
271 echo "${start_red}^^^^$text^^^^${end_color}"
272 fi
273 }
274 make () {
275 case "$*" in
276 *test|*check)
277 if [ $build_status -eq 0 ]; then
278 record_status command make "$@"
279 else
280 echo "(skipped because the build failed)"
281 fi
282 ;;
283 *)
284 record_status command make "$@"
285 build_status=$last_status
286 ;;
287 esac
288 }
289 final_report () {
290 if [ $failure_count -gt 0 ]; then
291 echo
292 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
293 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
294 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
295 elif [ -z "${1-}" ]; then
296 echo "SUCCESS :)"
297 fi
298 if [ -n "${1-}" ]; then
299 echo "Killed by SIG$1."
300 fi
301 }
302else
303 record_status () {
304 "$@"
305 }
306fi
307if_build_succeeded () {
308 if [ $build_status -eq 0 ]; then
309 record_status "$@"
310 fi
311}
312
Simon Butcherd7f19022016-10-14 09:49:48 +0100313msg "info: $0 configuration"
314echo "MEMORY: $MEMORY"
315echo "FORCE: $FORCE"
316echo "SEED: ${SEED-"UNSET"}"
317echo "OPENSSL: $OPENSSL"
318echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
319echo "GNUTLS_CLI: $GNUTLS_CLI"
320echo "GNUTLS_SERV: $GNUTLS_SERV"
321echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
322echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
323
324# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
325# we just export the variables they require
326export OPENSSL_CMD="$OPENSSL"
327export GNUTLS_CLI="$GNUTLS_CLI"
328export GNUTLS_SERV="$GNUTLS_SERV"
329
330# Avoid passing --seed flag in every call to ssl-opt.sh
Gilles Peskine243bb4c2018-03-21 08:40:26 +0100331if [ -n "${SEED-}" ]; then
332 export SEED
333fi
Simon Butcherd7f19022016-10-14 09:49:48 +0100334
335# Make sure the tools we need are available.
336check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100337 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskineb9344e32017-12-19 18:24:31 +0100338 "arm-none-eabi-gcc"
339if [ $RUN_ARMCC -ne 0 ]; then
340 check_tools "armcc"
341fi
Simon Butcherd7f19022016-10-14 09:49:48 +0100342
Gilles Peskined7602c22017-12-21 15:59:21 +0100343
344
345################################################################
346#### Basic checks
347################################################################
348
Simon Butcherd7f19022016-10-14 09:49:48 +0100349#
350# Test Suites to be executed
351#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200352# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100353# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200354# and/or are more likely to fail than others (eg I use Clang most of the
355# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200356# 2. Minimize total running time, by avoiding useless rebuilds
357#
358# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100359
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100360msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200361tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100362
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000363msg "test: freshness of generated source files" # < 1s
364tests/scripts/check-generated-files.sh
365
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200366msg "test: doxygen markup outside doxygen blocks" # < 1s
367tests/scripts/check-doxy-blocks.pl
368
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200369msg "test/build: declared and exported names" # < 3s
370cleanup
371tests/scripts/check-names.sh
372
Gilles Peskined7602c22017-12-21 15:59:21 +0100373
374
375################################################################
376#### Build and test many configurations and targets
377################################################################
378
Simon Butcher73156352015-11-04 00:36:30 +0000379# Yotta not supported in 2.1 branch
380#msg "build: create and build yotta module" # ~ 30s
381#cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100382#record_status tests/scripts/yotta-build.sh
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200383
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100384msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100385cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100386CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100387make
388
Simon Butcherd7f19022016-10-14 09:49:48 +0100389msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100390make test
391programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200392
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100393msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100394if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200395
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100396msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100397if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200398
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200399msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
400make
401
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100402msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100403if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200404
Hanno Becker797c0842017-10-19 15:49:21 +0100405msg "build: default config except MFL extension (ASan build)" # ~ 30s
406cleanup
407cp "$CONFIG_H" "$CONFIG_BAK"
408scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
409CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
410make
411
412msg "test: ssl-opt.sh, MFL-related tests"
413tests/ssl-opt.sh -f "Max fragment length"
414
Simon Butcher02b8d482016-03-15 20:39:52 +0000415msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
416cleanup
417cp "$CONFIG_H" "$CONFIG_BAK"
418scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
419CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
420make
421
Simon Butcherd7f19022016-10-14 09:49:48 +0100422msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher02b8d482016-03-15 20:39:52 +0000423make test
424programs/test/selftest
425
426msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100427if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
428if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher02b8d482016-03-15 20:39:52 +0000429
430msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100431if_build_succeeded tests/ssl-opt.sh
Simon Butcher02b8d482016-03-15 20:39:52 +0000432
Hanno Becker4f9973e2017-10-24 11:56:28 +0100433msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
434cleanup
435cp "$CONFIG_H" "$CONFIG_BAK"
436scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
437CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
438make
439
440msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
441make test
442
443msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100444if_build_succeeded tests/ssl-opt.sh
Hanno Becker4f9973e2017-10-24 11:56:28 +0100445
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100446msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100447cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200448cp "$CONFIG_H" "$CONFIG_BAK"
449scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200450scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100451CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100452make
453
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100454msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200455make test
456
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100457msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100458if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200459
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100460msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100461if_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 +0200462
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200463msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100464cleanup
465cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100466if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100467
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200468msg "test/build: key-exchanges (gcc)" # ~ 1 min
469cleanup
470cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100471if_build_succeeded tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200472
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000473msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100474cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100475make CC=gcc CFLAGS='-Werror -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100476
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200477# this is meant to cath missing #define mbedtls_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000478# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100479msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000480cleanup
481cp "$CONFIG_H" "$CONFIG_BAK"
482scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200483scripts/config.pl unset MBEDTLS_PLATFORM_C
484scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100485scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
486scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
487scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
488scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200489scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
490scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100491make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000492
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100493# catch compile bugs in _uninit functions
494msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
495cleanup
496cp "$CONFIG_H" "$CONFIG_BAK"
497scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100498scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100499make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100500
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200501msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
502cleanup
503cp "$CONFIG_H" "$CONFIG_BAK"
504scripts/config.pl full
505scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100506make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200507
508msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
509cleanup
510cp "$CONFIG_H" "$CONFIG_BAK"
511scripts/config.pl full
512scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100513make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200514
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200515msg "build: full config except net.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200516cleanup
517cp "$CONFIG_H" "$CONFIG_BAK"
518scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200519scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
520scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100521make CC=gcc CFLAGS='-Werror -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200522
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200523if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100524 msg "build/test: make shared" # ~ 40s
525 cleanup
526 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200527fi
528
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000529if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100530 msg "build: i386, make, gcc" # ~ 30s
531 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100532 make CC=gcc CFLAGS='-Werror -m32'
Andres Amaya Garcia401441b2017-05-08 11:19:19 +0100533
534 msg "test: i386, make, gcc"
535 make test
536
537 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
538 cleanup
539 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
540
541 msg "test: 64-bit ILP32, make, gcc"
542 make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000543fi # x86_64
544
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000545msg "build: arm-none-eabi-gcc, make" # ~ 10s
546cleanup
547cp "$CONFIG_H" "$CONFIG_BAK"
548scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200549scripts/config.pl unset MBEDTLS_NET_C
550scripts/config.pl unset MBEDTLS_TIMING_C
551scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcherd7f19022016-10-14 09:49:48 +0100552scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000553# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
555scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
556scripts/config.pl unset MBEDTLS_THREADING_C
557scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
558scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100559make 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 +0000560
Gilles Peskineb9344e32017-12-19 18:24:31 +0100561if [ $RUN_ARMCC -ne 0 ]; then
562 msg "build: armcc, make"
563 cleanup
564 cp "$CONFIG_H" "$CONFIG_BAK"
565 scripts/config.pl full
566 scripts/config.pl unset MBEDTLS_NET_C
567 scripts/config.pl unset MBEDTLS_TIMING_C
568 scripts/config.pl unset MBEDTLS_FS_IO
569 scripts/config.pl unset MBEDTLS_HAVE_TIME
570 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
571 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
572 # following things are not in the default config
573 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
574 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
575 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
576 scripts/config.pl unset MBEDTLS_THREADING_C
577 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
578 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
579 make CC=armcc AR=armar WARNING_CFLAGS= lib
580fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100581
Gilles Peskineb49351d2017-05-12 15:26:58 +0200582msg "build: allow SHA1 in certificates by default"
583cleanup
584cp "$CONFIG_H" "$CONFIG_BAK"
585scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100586make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskineb49351d2017-05-12 15:26:58 +0200587msg "test: allow SHA1 in certificates by default"
588make test
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100589if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskineb49351d2017-05-12 15:26:58 +0200590
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100591if which i686-w64-mingw32-gcc >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100592 msg "build: cross-mingw64, make" # ~ 30s
593 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100594 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1
595 make WINDOWS_BUILD=1 clean
596 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1
597 make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100598fi
599
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000600# MemSan currently only available on Linux 64 bits
601if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000602
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100603 msg "build: MSan (clang)" # ~ 1 min 20s
604 cleanup
605 cp "$CONFIG_H" "$CONFIG_BAK"
606 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
607 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
608 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200609
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100610 msg "test: main suites (MSan)" # ~ 10s
611 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100612
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100613 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100614 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100615
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100616 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100617
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100618 if [ "$MEMORY" -gt 0 ]; then
619 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100620 if_build_succeeded tests/compat.sh
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100621 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100622
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000623else # no MemSan
624
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100625 msg "build: Release (clang)"
626 cleanup
627 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
628 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000629
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100630 msg "test: main suites valgrind (Release)"
631 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000632
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100633 # Optional part(s)
634 # Currently broken, programs don't seem to receive signals
635 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000636
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100637 if [ "$MEMORY" -gt 0 ]; then
638 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100639 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100640 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000641
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100642 if [ "$MEMORY" -gt 1 ]; then
643 msg "test: compat.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100644 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100645 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000646
647fi # MemSan
648
Simon Butcherd7f19022016-10-14 09:49:48 +0100649msg "build: cmake 'out-of-source' build"
650cleanup
651MBEDTLS_ROOT_DIR="$PWD"
652mkdir "$OUT_OF_SOURCE_DIR"
653cd "$OUT_OF_SOURCE_DIR"
654cmake "$MBEDTLS_ROOT_DIR"
655make
656
657msg "test: cmake 'out-of-source' build"
658make test
659cd "$MBEDTLS_ROOT_DIR"
660rm -rf "$OUT_OF_SOURCE_DIR"
661
Gilles Peskined7602c22017-12-21 15:59:21 +0100662
663
664################################################################
665#### Termination
666################################################################
667
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100668msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100669cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100670
671final_report