blob: d797bf227db5b6ccf387ab5a53c1cde8528cddff [file] [log] [blame]
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001#!/bin/sh
2
Simon Butcher123fb022016-10-15 22:18:05 +01003# all.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01004#
Simon Butcher123fb022016-10-15 22:18:05 +01005# This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01006#
Gilles Peskinee8be5e22017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher123fb022016-10-15 22:18:05 +010015# Purpose
Gilles Peskinee8be5e22017-12-21 15:59:21 +010016# -------
Simon Butcher123fb022016-10-15 22:18:05 +010017#
18# To run all tests possible or available on the platform.
19#
Gilles Peskinee8be5e22017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
Simon Butcher123fb022016-10-15 22:18:05 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskinee8be5e22017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/polarssl/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 Butcher123fb022016-10-15 22:18:05 +010030#
Gilles Peskinee8be5e22017-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 Butcher123fb022016-10-15 22:18:05 +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 Butcher123fb022016-10-15 22:18:05 +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é-Gonnarde73b2632014-07-12 04:00:00 +020087CONFIG_H='include/polarssl/config.h'
88CONFIG_BAK="$CONFIG_H.bak"
89
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010090MEMORY=0
Simon Butcher123fb022016-10-15 22:18:05 +010091FORCE=0
Gilles Peskineded50da2017-12-11 00:01:40 +010092KEEP_GOING=0
Simon Butcher123fb022016-10-15 22:18:05 +010093RELEASE=0
Gilles Peskine273ac902017-12-19 18:24:31 +010094RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010095
Simon Butcher123fb022016-10-15 22:18:05 +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 Peskine4d4872a2017-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 Peskineded50da2017-12-11 00:01:40 +0100113 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100114 -m|--memory Additional optional memory tests.
Gilles Peskine273ac902017-12-19 18:24:31 +0100115 --armcc Run ARM Compiler builds (on by default).
116 --no-armcc Skip ARM Compiler builds.
Gilles Peskine4d4872a2017-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 Butcher123fb022016-10-15 22:18:05 +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 Peskineded50da2017-12-11 00:01:40 +0100134 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200135
Manuel Pégourié-Gonnard76c99a02014-12-11 10:33:43 +0100136 find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard897a5952014-03-25 13:23:04 +0100137 rm -f include/Makefile include/polarssl/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200138 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
139 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200140
141 if [ -f "$CONFIG_BAK" ]; then
142 mv "$CONFIG_BAK" "$CONFIG_H"
143 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100144}
145
Gilles Peskineded50da2017-12-11 00:01:40 +0100146# Executed on exit. May be redefined depending on command line options.
147final_report () {
148 :
149}
150
151fatal_signal () {
152 cleanup
153 final_report $1
154 trap - $1
155 kill -$1 $$
156}
157
158trap 'fatal_signal HUP' HUP
159trap 'fatal_signal INT' INT
160trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200161
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100162msg()
163{
164 echo ""
165 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100166 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000167 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100168 echo "******************************************************************"
Gilles Peskineded50da2017-12-11 00:01:40 +0100169 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100170}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100171
Simon Butcher123fb022016-10-15 22:18:05 +0100172err_msg()
173{
174 echo "$1" >&2
175}
176
177check_tools()
178{
179 for TOOL in "$@"; do
180 if ! `hash "$TOOL" >/dev/null 2>&1`; then
181 err_msg "$TOOL not found!"
182 exit 1
183 fi
184 done
185}
186
187while [ $# -gt 0 ]; do
188 case "$1" in
Gilles Peskine273ac902017-12-19 18:24:31 +0100189 --armcc)
190 RUN_ARMCC=1
191 ;;
Simon Butcher123fb022016-10-15 22:18:05 +0100192 --force|-f)
193 FORCE=1
194 ;;
Simon Butcher123fb022016-10-15 22:18:05 +0100195 --gnutls-cli)
196 shift
197 GNUTLS_CLI="$1"
198 ;;
Simon Butcher123fb022016-10-15 22:18:05 +0100199 --gnutls-legacy-cli)
200 shift
201 GNUTLS_LEGACY_CLI="$1"
202 ;;
203 --gnutls-legacy-serv)
204 shift
205 GNUTLS_LEGACY_SERV="$1"
206 ;;
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100207 --gnutls-serv)
208 shift
209 GNUTLS_SERV="$1"
210 ;;
211 --help|-h)
Simon Butcher123fb022016-10-15 22:18:05 +0100212 usage
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100213 exit
214 ;;
Gilles Peskineded50da2017-12-11 00:01:40 +0100215 --keep-going|-k)
216 KEEP_GOING=1
217 ;;
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100218 --memory|-m)
219 MEMORY=1
220 ;;
Gilles Peskine273ac902017-12-19 18:24:31 +0100221 --no-armcc)
222 RUN_ARMCC=0
223 ;;
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100224 --openssl)
225 shift
226 OPENSSL="$1"
227 ;;
228 --openssl-legacy)
229 shift
230 OPENSSL_LEGACY="$1"
231 ;;
232 --out-of-source-dir)
233 shift
234 OUT_OF_SOURCE_DIR="$1"
235 ;;
236 --release-test|-r)
237 RELEASE=1
238 ;;
239 --seed|-s)
240 shift
241 SEED="$1"
242 ;;
243 *)
244 echo >&2 "Unknown option: $1"
245 echo >&2 "Run $0 --help for usage."
246 exit 120
Simon Butcher123fb022016-10-15 22:18:05 +0100247 ;;
248 esac
249 shift
250done
251
252if [ $FORCE -eq 1 ]; then
253 git checkout-index -f -q $CONFIG_H
254 cleanup
255else
256
257 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
258 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
259 echo "You can either delete this directory manually, or force the test by rerunning"
260 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
261 exit 1
262 fi
263
264 if ! git diff-files --quiet include/polarssl/config.h; then
Simon Butcher123fb022016-10-15 22:18:05 +0100265 err_msg "Warning - the configuration file 'include/polarssl/config.h' has been edited. "
266 echo "You can either delete or preserve your work, or force the test by rerunning the"
267 echo "script as: $0 --force"
268 exit 1
269 fi
270fi
271
Gilles Peskineded50da2017-12-11 00:01:40 +0100272build_status=0
273if [ $KEEP_GOING -eq 1 ]; then
274 failure_summary=
275 failure_count=0
276 start_red=
277 end_color=
278 if [ -t 1 ]; then
279 case "$TERM" in
280 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
281 start_red=$(printf '\033[31m')
282 end_color=$(printf '\033[0m')
283 ;;
284 esac
285 fi
286 record_status () {
287 if "$@"; then
288 last_status=0
289 else
290 last_status=$?
291 text="$current_section: $* -> $last_status"
292 failure_summary="$failure_summary
293$text"
294 failure_count=$((failure_count + 1))
295 echo "${start_red}^^^^$text^^^^${end_color}"
296 fi
297 }
298 make () {
299 case "$*" in
300 *test|*check)
301 if [ $build_status -eq 0 ]; then
302 record_status command make "$@"
303 else
304 echo "(skipped because the build failed)"
305 fi
306 ;;
307 *)
308 record_status command make "$@"
309 build_status=$last_status
310 ;;
311 esac
312 }
313 final_report () {
314 if [ $failure_count -gt 0 ]; then
315 echo
316 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
317 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
318 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
319 elif [ -z "${1-}" ]; then
320 echo "SUCCESS :)"
321 fi
322 if [ -n "${1-}" ]; then
323 echo "Killed by SIG$1."
324 fi
325 }
326else
327 record_status () {
328 "$@"
329 }
330fi
331if_build_succeeded () {
332 if [ $build_status -eq 0 ]; then
333 record_status "$@"
334 fi
335}
336
Simon Butcher123fb022016-10-15 22:18:05 +0100337if [ $RELEASE -eq 1 ]; then
338 # Fix the seed value to 1 to ensure that the tests are deterministic.
339 SEED=1
340fi
341
342msg "info: $0 configuration"
343echo "MEMORY: $MEMORY"
344echo "FORCE: $FORCE"
345echo "SEED: ${SEED-"UNSET"}"
346echo "OPENSSL: $OPENSSL"
347echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
348echo "GNUTLS_CLI: $GNUTLS_CLI"
349echo "GNUTLS_SERV: $GNUTLS_SERV"
350echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
351echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
352
353# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
354# we just export the variables they require
355export OPENSSL_CMD="$OPENSSL"
356export GNUTLS_CLI="$GNUTLS_CLI"
357export GNUTLS_SERV="$GNUTLS_SERV"
358
359# Avoid passing --seed flag in every call to ssl-opt.sh
360[ ! -z ${SEED+set} ] && export SEED
361
362# Make sure the tools we need are available.
363check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100364 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskine273ac902017-12-19 18:24:31 +0100365 "arm-none-eabi-gcc"
366if [ $RUN_ARMCC -ne 0 ]; then
367 check_tools "armcc"
368fi
Simon Butcher123fb022016-10-15 22:18:05 +0100369
Gilles Peskinee8be5e22017-12-21 15:59:21 +0100370
371
372################################################################
373#### Basic checks
374################################################################
375
Simon Butcher123fb022016-10-15 22:18:05 +0100376#
377# Test Suites to be executed
378#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200379# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100380# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200381# and/or are more likely to fail than others (eg I use Clang most of the
382# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200383# 2. Minimize total running time, by avoiding useless rebuilds
384#
385# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100386
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100387msg "test: recursion.pl" # < 1s
388scripts/recursion.pl library/*.c
389
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000390msg "test: freshness of generated source files" # < 1s
391tests/scripts/check-generated-files.sh
392
Gilles Peskinee8be5e22017-12-21 15:59:21 +0100393
394
395################################################################
396#### Build and test many configurations and targets
397################################################################
398
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100399msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100400cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100401CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100402make
403
Simon Butcher123fb022016-10-15 22:18:05 +0100404msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100405make test
406programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200407
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100408msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100409if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200410
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100411msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskineded50da2017-12-11 00:01:40 +0100412if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200413
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200414msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
415make
416
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100417msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100418if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200419
Janos Follath4dfecab2016-03-14 13:40:43 +0000420msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
421cleanup
422cp "$CONFIG_H" "$CONFIG_BAK"
423scripts/config.pl set POLARSSL_SSL_PROTO_SSL3
424CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
425make
426
Simon Butcher123fb022016-10-15 22:18:05 +0100427msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Janos Follath4dfecab2016-03-14 13:40:43 +0000428make test
429programs/test/selftest
430
431msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100432if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2'
433if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Janos Follath4dfecab2016-03-14 13:40:43 +0000434
435msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100436if_build_succeeded tests/ssl-opt.sh
Janos Follath4dfecab2016-03-14 13:40:43 +0000437
Hanno Beckerbe812f62017-10-25 09:49:13 +0100438msg "build: Default + POLARSSL_SSL_DISABLE_RENEGOTIATION (ASan build)" # ~ 6 min
439cleanup
440cp "$CONFIG_H" "$CONFIG_BAK"
441scripts/config.pl set POLARSSL_SSL_DISABLE_RENEGOTIATION
442CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
443make
444
445msg "test: POLARSSL_SSL_DISABLE_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
446make test
447
448msg "test: POLARSSL_SSL_DISABLE_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100449if_build_succeeded tests/ssl-opt.sh
Hanno Beckerbe812f62017-10-25 09:49:13 +0100450
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100451msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100452cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200453cp "$CONFIG_H" "$CONFIG_BAK"
454scripts/config.pl full
455scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard4d9e36a2015-09-02 10:10:32 +0200456scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
457scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100458CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100459make
460
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100461msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200462make test
463
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100464msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskineded50da2017-12-11 00:01:40 +0100465if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200466
Simon Butcher123fb022016-10-15 22:18:05 +0100467msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100468if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3'
Simon Butcher123fb022016-10-15 22:18:05 +0100469
470msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100471cleanup
472cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskineded50da2017-12-11 00:01:40 +0100473if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100474
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 Peskineded50da2017-12-11 00:01:40 +0100477make CC=gcc CFLAGS='-Werror -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100478
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000479# this is meant to cath missing #define polarssl_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
485scripts/config.pl unset POLARSSL_PLATFORM_C
Manuel Pégourié-Gonnard6ca40762015-02-13 15:57:35 +0000486scripts/config.pl unset POLARSSL_PLATFORM_MEMORY
Manuel Pégourié-Gonnard721e6bb2015-06-03 13:38:20 +0100487scripts/config.pl unset POLARSSL_PLATFORM_PRINTF_ALT
488scripts/config.pl unset POLARSSL_PLATFORM_FPRINTF_ALT
489scripts/config.pl unset POLARSSL_PLATFORM_SNPRINTF_ALT
490scripts/config.pl unset POLARSSL_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000491scripts/config.pl unset POLARSSL_MEMORY_C
492scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000493scripts/config.pl unset POLARSSL_FS_IO
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200494scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
495scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Gilles Peskineded50da2017-12-11 00:01:40 +0100496make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000497
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100498# catch compile bugs in _uninit functions
499msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
500cleanup
501cp "$CONFIG_H" "$CONFIG_BAK"
502scripts/config.pl full
503scripts/config.pl set POLARSSL_PLATFORM_NO_STD_FUNCTIONS
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200504scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
505scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Gilles Peskineded50da2017-12-11 00:01:40 +0100506make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100507
Simon Butcher123fb022016-10-15 22:18:05 +0100508msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
509cleanup
510cp "$CONFIG_H" "$CONFIG_BAK"
511scripts/config.pl full
512scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
513scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
514scripts/config.pl unset POLARSSL_SSL_SRV_C
Gilles Peskineded50da2017-12-11 00:01:40 +0100515make CC=gcc CFLAGS='-Werror -O0'
Simon Butcher123fb022016-10-15 22:18:05 +0100516
517msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
518cleanup
519cp "$CONFIG_H" "$CONFIG_BAK"
520scripts/config.pl full
521scripts/config.pl unset POLARSSL_SSL_CLI_C
522scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
523scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Gilles Peskineded50da2017-12-11 00:01:40 +0100524make CC=gcc CFLAGS='-Werror -O0'
Simon Butcher123fb022016-10-15 22:18:05 +0100525
Manuel Pégourié-Gonnard1b1254f2015-08-10 11:56:06 +0200526if uname -a | grep -F Linux >/dev/null; then
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100527 msg "build/test: make shared" # ~ 40s
528 cleanup
529 make SHARED=1 all check
Manuel Pégourié-Gonnard1b1254f2015-08-10 11:56:06 +0200530fi
531
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000532if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100533 msg "build: i386, make, gcc" # ~ 30s
534 cleanup
Gilles Peskineded50da2017-12-11 00:01:40 +0100535 make CC=gcc CFLAGS='-Werror -m32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000536fi # x86_64
537
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000538msg "build: arm-none-eabi-gcc, make" # ~ 10s
539cleanup
540cp "$CONFIG_H" "$CONFIG_BAK"
541scripts/config.pl full
542scripts/config.pl unset POLARSSL_NET_C
543scripts/config.pl unset POLARSSL_TIMING_C
544scripts/config.pl unset POLARSSL_FS_IO
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200545scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
546scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Simon Butcher123fb022016-10-15 22:18:05 +0100547scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000548# following things are not in the default config
549scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
550scripts/config.pl unset POLARSSL_THREADING_PTHREAD
551scripts/config.pl unset POLARSSL_THREADING_C
552scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
553scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskineded50da2017-12-11 00:01:40 +0100554make 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 +0000555
Gilles Peskine273ac902017-12-19 18:24:31 +0100556if [ $RUN_ARMCC -ne 0 ]; then
557 msg "build: armcc, make"
558 cleanup
559 cp "$CONFIG_H" "$CONFIG_BAK"
560 scripts/config.pl full
561 scripts/config.pl unset POLARSSL_NET_C
562 scripts/config.pl unset POLARSSL_TIMING_C
563 scripts/config.pl unset POLARSSL_FS_IO
564 scripts/config.pl unset POLARSSL_HAVE_TIME
565 scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
566 scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
567 scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY
568 # following things are not in the default config
569 scripts/config.pl unset POLARSSL_DEPRECATED_WARNING
570 scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
571 scripts/config.pl unset POLARSSL_THREADING_PTHREAD
572 scripts/config.pl unset POLARSSL_THREADING_C
573 scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
574 scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
575 make CC=armcc AR=armar WARNING_CFLAGS= lib
576fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100577
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100578if which i686-w64-mingw32-gcc >/dev/null; then
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100579 msg "build: cross-mingw64, make" # ~ 30s
580 cleanup
Gilles Peskineded50da2017-12-11 00:01:40 +0100581 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1
582 make WINDOWS_BUILD=1 clean
583 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1
584 make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100585fi
586
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000587# MemSan currently only available on Linux 64 bits
588if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000589
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100590 msg "build: MSan (clang)" # ~ 1 min 20s
591 cleanup
592 cp "$CONFIG_H" "$CONFIG_BAK"
593 scripts/config.pl unset POLARSSL_AESNI_C # memsan doesn't grok asm
594 scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY # memsan vs getrandom()
595 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
596 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200597
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100598 msg "test: main suites (MSan)" # ~ 10s
599 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100600
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100601 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100602 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100603
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100604 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100605
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100606 if [ "$MEMORY" -gt 0 ]; then
607 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskineded50da2017-12-11 00:01:40 +0100608 if_build_succeeded tests/compat.sh
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100609 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100610
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000611else # no MemSan
612
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100613 msg "build: Release (clang)"
614 cleanup
615 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
616 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000617
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100618 msg "test: main suites valgrind (Release)"
619 make test
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000620
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100621 # Optional part(s)
622 # Currently broken, programs don't seem to receive signals
623 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000624
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100625 if [ "$MEMORY" -gt 0 ]; then
626 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskineded50da2017-12-11 00:01:40 +0100627 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100628 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000629
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100630 if [ "$MEMORY" -gt 1 ]; then
631 msg "test: compat.sh --memcheck (Release)"
Gilles Peskineded50da2017-12-11 00:01:40 +0100632 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100633 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000634
635fi # MemSan
636
Simon Butcher123fb022016-10-15 22:18:05 +0100637msg "build: cmake 'out-of-source' build"
638cleanup
639MBEDTLS_ROOT_DIR="$PWD"
640mkdir "$OUT_OF_SOURCE_DIR"
641cd "$OUT_OF_SOURCE_DIR"
642cmake "$MBEDTLS_ROOT_DIR"
643make
644
645msg "test: cmake 'out-of-source' build"
646make test
647cd "$MBEDTLS_ROOT_DIR"
648rm -rf "$OUT_OF_SOURCE_DIR"
649
Gilles Peskinee8be5e22017-12-21 15:59:21 +0100650
651
652################################################################
653#### Termination
654################################################################
655
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100656msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100657cleanup
658
Gilles Peskineded50da2017-12-11 00:01:40 +0100659final_report