blob: 348d15329f27f92e97f59568f5749849320ccc83 [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#
Simon Butcher123fb022016-10-15 22:18:05 +01007# Copyright (c) 2014-2016, ARM Limited, All Rights Reserved
8#
9# Purpose
10#
11# To run all tests possible or available on the platform.
12#
13# Warning: the test is destructive. It includes various build modes and
14# configurations, and can and will arbitrarily change the current CMake
15# configuration. After this script has been run, the CMake cache will be lost
16# and CMake will no longer be initialised.
17#
18# The script assumes the presence of gcc and clang (recent enough for using
19# ASan with gcc and MemSan with clang, or valgrind) are available, as well as
20# cmake and a "good" find.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010021
Simon Butcher123fb022016-10-15 22:18:05 +010022# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010023set -eu
24
25if [ -d library -a -d include -a -d tests ]; then :; else
Simon Butcher123fb022016-10-15 22:18:05 +010026 err_msg "Must be run from mbed TLS root"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010027 exit 1
28fi
29
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020030CONFIG_H='include/polarssl/config.h'
31CONFIG_BAK="$CONFIG_H.bak"
32
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010033MEMORY=0
Simon Butcher123fb022016-10-15 22:18:05 +010034FORCE=0
Gilles Peskineded50da2017-12-11 00:01:40 +010035KEEP_GOING=0
Simon Butcher123fb022016-10-15 22:18:05 +010036RELEASE=0
Gilles Peskine273ac902017-12-19 18:24:31 +010037RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010038
Simon Butcher123fb022016-10-15 22:18:05 +010039# Default commands, can be overriden by the environment
40: ${OPENSSL:="openssl"}
41: ${OPENSSL_LEGACY:="$OPENSSL"}
42: ${GNUTLS_CLI:="gnutls-cli"}
43: ${GNUTLS_SERV:="gnutls-serv"}
44: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
45: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
46: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
47
48usage()
49{
Gilles Peskine4d4872a2017-12-10 23:43:39 +010050 cat <<EOF
51Usage: $0 [OPTION]...
52 -h|--help Print this help.
53
54General options:
55 -f|--force Force the tests to overwrite any modified files.
Gilles Peskineded50da2017-12-11 00:01:40 +010056 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine4d4872a2017-12-10 23:43:39 +010057 -m|--memory Additional optional memory tests.
Gilles Peskine273ac902017-12-19 18:24:31 +010058 --armcc Run ARM Compiler builds (on by default).
59 --no-armcc Skip ARM Compiler builds.
Gilles Peskine4d4872a2017-12-10 23:43:39 +010060 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
61 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
62 -s|--seed Integer seed value to use for this test run.
63
64Tool path options:
65 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
66 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
67 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
68 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
69 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
70 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
71EOF
Simon Butcher123fb022016-10-15 22:18:05 +010072}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010073
74# remove built files as well as the cmake cache/config
75cleanup()
76{
Gilles Peskineded50da2017-12-11 00:01:40 +010077 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020078
Manuel Pégourié-Gonnard76c99a02014-12-11 10:33:43 +010079 find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard897a5952014-03-25 13:23:04 +010080 rm -f include/Makefile include/polarssl/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +020081 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
82 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020083
84 if [ -f "$CONFIG_BAK" ]; then
85 mv "$CONFIG_BAK" "$CONFIG_H"
86 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010087}
88
Gilles Peskineded50da2017-12-11 00:01:40 +010089# Executed on exit. May be redefined depending on command line options.
90final_report () {
91 :
92}
93
94fatal_signal () {
95 cleanup
96 final_report $1
97 trap - $1
98 kill -$1 $$
99}
100
101trap 'fatal_signal HUP' HUP
102trap 'fatal_signal INT' INT
103trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200104
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100105msg()
106{
107 echo ""
108 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100109 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000110 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100111 echo "******************************************************************"
Gilles Peskineded50da2017-12-11 00:01:40 +0100112 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100113}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Simon Butcher123fb022016-10-15 22:18:05 +0100115err_msg()
116{
117 echo "$1" >&2
118}
119
120check_tools()
121{
122 for TOOL in "$@"; do
123 if ! `hash "$TOOL" >/dev/null 2>&1`; then
124 err_msg "$TOOL not found!"
125 exit 1
126 fi
127 done
128}
129
130while [ $# -gt 0 ]; do
131 case "$1" in
Gilles Peskine273ac902017-12-19 18:24:31 +0100132 --armcc)
133 RUN_ARMCC=1
134 ;;
Simon Butcher123fb022016-10-15 22:18:05 +0100135 --force|-f)
136 FORCE=1
137 ;;
Simon Butcher123fb022016-10-15 22:18:05 +0100138 --gnutls-cli)
139 shift
140 GNUTLS_CLI="$1"
141 ;;
Simon Butcher123fb022016-10-15 22:18:05 +0100142 --gnutls-legacy-cli)
143 shift
144 GNUTLS_LEGACY_CLI="$1"
145 ;;
146 --gnutls-legacy-serv)
147 shift
148 GNUTLS_LEGACY_SERV="$1"
149 ;;
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100150 --gnutls-serv)
151 shift
152 GNUTLS_SERV="$1"
153 ;;
154 --help|-h)
Simon Butcher123fb022016-10-15 22:18:05 +0100155 usage
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100156 exit
157 ;;
Gilles Peskineded50da2017-12-11 00:01:40 +0100158 --keep-going|-k)
159 KEEP_GOING=1
160 ;;
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100161 --memory|-m)
162 MEMORY=1
163 ;;
Gilles Peskine273ac902017-12-19 18:24:31 +0100164 --no-armcc)
165 RUN_ARMCC=0
166 ;;
Gilles Peskine4d4872a2017-12-10 23:43:39 +0100167 --openssl)
168 shift
169 OPENSSL="$1"
170 ;;
171 --openssl-legacy)
172 shift
173 OPENSSL_LEGACY="$1"
174 ;;
175 --out-of-source-dir)
176 shift
177 OUT_OF_SOURCE_DIR="$1"
178 ;;
179 --release-test|-r)
180 RELEASE=1
181 ;;
182 --seed|-s)
183 shift
184 SEED="$1"
185 ;;
186 *)
187 echo >&2 "Unknown option: $1"
188 echo >&2 "Run $0 --help for usage."
189 exit 120
Simon Butcher123fb022016-10-15 22:18:05 +0100190 ;;
191 esac
192 shift
193done
194
195if [ $FORCE -eq 1 ]; then
196 git checkout-index -f -q $CONFIG_H
197 cleanup
198else
199
200 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
201 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
202 echo "You can either delete this directory manually, or force the test by rerunning"
203 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
204 exit 1
205 fi
206
207 if ! git diff-files --quiet include/polarssl/config.h; then
Simon Butcher123fb022016-10-15 22:18:05 +0100208 err_msg "Warning - the configuration file 'include/polarssl/config.h' has been edited. "
209 echo "You can either delete or preserve your work, or force the test by rerunning the"
210 echo "script as: $0 --force"
211 exit 1
212 fi
213fi
214
Gilles Peskineded50da2017-12-11 00:01:40 +0100215build_status=0
216if [ $KEEP_GOING -eq 1 ]; then
217 failure_summary=
218 failure_count=0
219 start_red=
220 end_color=
221 if [ -t 1 ]; then
222 case "$TERM" in
223 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
224 start_red=$(printf '\033[31m')
225 end_color=$(printf '\033[0m')
226 ;;
227 esac
228 fi
229 record_status () {
230 if "$@"; then
231 last_status=0
232 else
233 last_status=$?
234 text="$current_section: $* -> $last_status"
235 failure_summary="$failure_summary
236$text"
237 failure_count=$((failure_count + 1))
238 echo "${start_red}^^^^$text^^^^${end_color}"
239 fi
240 }
241 make () {
242 case "$*" in
243 *test|*check)
244 if [ $build_status -eq 0 ]; then
245 record_status command make "$@"
246 else
247 echo "(skipped because the build failed)"
248 fi
249 ;;
250 *)
251 record_status command make "$@"
252 build_status=$last_status
253 ;;
254 esac
255 }
256 final_report () {
257 if [ $failure_count -gt 0 ]; then
258 echo
259 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
260 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
261 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
262 elif [ -z "${1-}" ]; then
263 echo "SUCCESS :)"
264 fi
265 if [ -n "${1-}" ]; then
266 echo "Killed by SIG$1."
267 fi
268 }
269else
270 record_status () {
271 "$@"
272 }
273fi
274if_build_succeeded () {
275 if [ $build_status -eq 0 ]; then
276 record_status "$@"
277 fi
278}
279
Simon Butcher123fb022016-10-15 22:18:05 +0100280if [ $RELEASE -eq 1 ]; then
281 # Fix the seed value to 1 to ensure that the tests are deterministic.
282 SEED=1
283fi
284
285msg "info: $0 configuration"
286echo "MEMORY: $MEMORY"
287echo "FORCE: $FORCE"
288echo "SEED: ${SEED-"UNSET"}"
289echo "OPENSSL: $OPENSSL"
290echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
291echo "GNUTLS_CLI: $GNUTLS_CLI"
292echo "GNUTLS_SERV: $GNUTLS_SERV"
293echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
294echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
295
296# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
297# we just export the variables they require
298export OPENSSL_CMD="$OPENSSL"
299export GNUTLS_CLI="$GNUTLS_CLI"
300export GNUTLS_SERV="$GNUTLS_SERV"
301
302# Avoid passing --seed flag in every call to ssl-opt.sh
303[ ! -z ${SEED+set} ] && export SEED
304
305# Make sure the tools we need are available.
306check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100307 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskine273ac902017-12-19 18:24:31 +0100308 "arm-none-eabi-gcc"
309if [ $RUN_ARMCC -ne 0 ]; then
310 check_tools "armcc"
311fi
Simon Butcher123fb022016-10-15 22:18:05 +0100312
313#
314# Test Suites to be executed
315#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200316# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100317# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200318# and/or are more likely to fail than others (eg I use Clang most of the
319# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200320# 2. Minimize total running time, by avoiding useless rebuilds
321#
322# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100323
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100324msg "test: recursion.pl" # < 1s
325scripts/recursion.pl library/*.c
326
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000327msg "test: freshness of generated source files" # < 1s
328tests/scripts/check-generated-files.sh
329
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100330msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100331cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100332CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100333make
334
Simon Butcher123fb022016-10-15 22:18:05 +0100335msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100336make test
337programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200338
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100339msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100340if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200341
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100342msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskineded50da2017-12-11 00:01:40 +0100343if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200344
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200345msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
346make
347
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100348msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100349if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200350
Janos Follath4dfecab2016-03-14 13:40:43 +0000351msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
352cleanup
353cp "$CONFIG_H" "$CONFIG_BAK"
354scripts/config.pl set POLARSSL_SSL_PROTO_SSL3
355CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
356make
357
Simon Butcher123fb022016-10-15 22:18:05 +0100358msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Janos Follath4dfecab2016-03-14 13:40:43 +0000359make test
360programs/test/selftest
361
362msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100363if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2'
364if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Janos Follath4dfecab2016-03-14 13:40:43 +0000365
366msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100367if_build_succeeded tests/ssl-opt.sh
Janos Follath4dfecab2016-03-14 13:40:43 +0000368
Hanno Beckerbe812f62017-10-25 09:49:13 +0100369msg "build: Default + POLARSSL_SSL_DISABLE_RENEGOTIATION (ASan build)" # ~ 6 min
370cleanup
371cp "$CONFIG_H" "$CONFIG_BAK"
372scripts/config.pl set POLARSSL_SSL_DISABLE_RENEGOTIATION
373CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
374make
375
376msg "test: POLARSSL_SSL_DISABLE_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
377make test
378
379msg "test: POLARSSL_SSL_DISABLE_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100380if_build_succeeded tests/ssl-opt.sh
Hanno Beckerbe812f62017-10-25 09:49:13 +0100381
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100382msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100383cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200384cp "$CONFIG_H" "$CONFIG_BAK"
385scripts/config.pl full
386scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard4d9e36a2015-09-02 10:10:32 +0200387scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
388scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100389CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100390make
391
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100392msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200393make test
394
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100395msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskineded50da2017-12-11 00:01:40 +0100396if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200397
Simon Butcher123fb022016-10-15 22:18:05 +0100398msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100399if_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 +0100400
401msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100402cleanup
403cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskineded50da2017-12-11 00:01:40 +0100404if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100405
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000406msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100407cleanup
Gilles Peskineded50da2017-12-11 00:01:40 +0100408make CC=gcc CFLAGS='-Werror -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100409
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000410# this is meant to cath missing #define polarssl_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000411# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100412msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000413cleanup
414cp "$CONFIG_H" "$CONFIG_BAK"
415scripts/config.pl full
416scripts/config.pl unset POLARSSL_PLATFORM_C
Manuel Pégourié-Gonnard6ca40762015-02-13 15:57:35 +0000417scripts/config.pl unset POLARSSL_PLATFORM_MEMORY
Manuel Pégourié-Gonnard721e6bb2015-06-03 13:38:20 +0100418scripts/config.pl unset POLARSSL_PLATFORM_PRINTF_ALT
419scripts/config.pl unset POLARSSL_PLATFORM_FPRINTF_ALT
420scripts/config.pl unset POLARSSL_PLATFORM_SNPRINTF_ALT
421scripts/config.pl unset POLARSSL_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000422scripts/config.pl unset POLARSSL_MEMORY_C
423scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000424scripts/config.pl unset POLARSSL_FS_IO
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200425scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
426scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Gilles Peskineded50da2017-12-11 00:01:40 +0100427make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000428
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100429# catch compile bugs in _uninit functions
430msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
431cleanup
432cp "$CONFIG_H" "$CONFIG_BAK"
433scripts/config.pl full
434scripts/config.pl set POLARSSL_PLATFORM_NO_STD_FUNCTIONS
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200435scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
436scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Gilles Peskineded50da2017-12-11 00:01:40 +0100437make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100438
Simon Butcher123fb022016-10-15 22:18:05 +0100439msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
440cleanup
441cp "$CONFIG_H" "$CONFIG_BAK"
442scripts/config.pl full
443scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
444scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
445scripts/config.pl unset POLARSSL_SSL_SRV_C
Gilles Peskineded50da2017-12-11 00:01:40 +0100446make CC=gcc CFLAGS='-Werror -O0'
Simon Butcher123fb022016-10-15 22:18:05 +0100447
448msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
449cleanup
450cp "$CONFIG_H" "$CONFIG_BAK"
451scripts/config.pl full
452scripts/config.pl unset POLARSSL_SSL_CLI_C
453scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
454scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Gilles Peskineded50da2017-12-11 00:01:40 +0100455make CC=gcc CFLAGS='-Werror -O0'
Simon Butcher123fb022016-10-15 22:18:05 +0100456
Manuel Pégourié-Gonnard1b1254f2015-08-10 11:56:06 +0200457if uname -a | grep -F Linux >/dev/null; then
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100458 msg "build/test: make shared" # ~ 40s
459 cleanup
460 make SHARED=1 all check
Manuel Pégourié-Gonnard1b1254f2015-08-10 11:56:06 +0200461fi
462
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000463if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100464 msg "build: i386, make, gcc" # ~ 30s
465 cleanup
Gilles Peskineded50da2017-12-11 00:01:40 +0100466 make CC=gcc CFLAGS='-Werror -m32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000467fi # x86_64
468
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000469msg "build: arm-none-eabi-gcc, make" # ~ 10s
470cleanup
471cp "$CONFIG_H" "$CONFIG_BAK"
472scripts/config.pl full
473scripts/config.pl unset POLARSSL_NET_C
474scripts/config.pl unset POLARSSL_TIMING_C
475scripts/config.pl unset POLARSSL_FS_IO
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200476scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
477scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Simon Butcher123fb022016-10-15 22:18:05 +0100478scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000479# following things are not in the default config
480scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
481scripts/config.pl unset POLARSSL_THREADING_PTHREAD
482scripts/config.pl unset POLARSSL_THREADING_C
483scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
484scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskineded50da2017-12-11 00:01:40 +0100485make 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 +0000486
Gilles Peskine273ac902017-12-19 18:24:31 +0100487if [ $RUN_ARMCC -ne 0 ]; then
488 msg "build: armcc, make"
489 cleanup
490 cp "$CONFIG_H" "$CONFIG_BAK"
491 scripts/config.pl full
492 scripts/config.pl unset POLARSSL_NET_C
493 scripts/config.pl unset POLARSSL_TIMING_C
494 scripts/config.pl unset POLARSSL_FS_IO
495 scripts/config.pl unset POLARSSL_HAVE_TIME
496 scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
497 scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
498 scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY
499 # following things are not in the default config
500 scripts/config.pl unset POLARSSL_DEPRECATED_WARNING
501 scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
502 scripts/config.pl unset POLARSSL_THREADING_PTHREAD
503 scripts/config.pl unset POLARSSL_THREADING_C
504 scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
505 scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
506 make CC=armcc AR=armar WARNING_CFLAGS= lib
507fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100508
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100509if which i686-w64-mingw32-gcc >/dev/null; then
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100510 msg "build: cross-mingw64, make" # ~ 30s
511 cleanup
Gilles Peskineded50da2017-12-11 00:01:40 +0100512 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1
513 make WINDOWS_BUILD=1 clean
514 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1
515 make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100516fi
517
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000518# MemSan currently only available on Linux 64 bits
519if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000520
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100521 msg "build: MSan (clang)" # ~ 1 min 20s
522 cleanup
523 cp "$CONFIG_H" "$CONFIG_BAK"
524 scripts/config.pl unset POLARSSL_AESNI_C # memsan doesn't grok asm
525 scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY # memsan vs getrandom()
526 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
527 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200528
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100529 msg "test: main suites (MSan)" # ~ 10s
530 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100531
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100532 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskineded50da2017-12-11 00:01:40 +0100533 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100534
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100535 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100536
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100537 if [ "$MEMORY" -gt 0 ]; then
538 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskineded50da2017-12-11 00:01:40 +0100539 if_build_succeeded tests/compat.sh
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100540 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100541
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000542else # no MemSan
543
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100544 msg "build: Release (clang)"
545 cleanup
546 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
547 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000548
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100549 msg "test: main suites valgrind (Release)"
550 make test
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000551
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100552 # Optional part(s)
553 # Currently broken, programs don't seem to receive signals
554 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000555
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100556 if [ "$MEMORY" -gt 0 ]; then
557 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskineded50da2017-12-11 00:01:40 +0100558 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100559 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000560
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100561 if [ "$MEMORY" -gt 1 ]; then
562 msg "test: compat.sh --memcheck (Release)"
Gilles Peskineded50da2017-12-11 00:01:40 +0100563 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskinefb18b6c2017-12-20 14:00:06 +0100564 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000565
566fi # MemSan
567
Simon Butcher123fb022016-10-15 22:18:05 +0100568msg "build: cmake 'out-of-source' build"
569cleanup
570MBEDTLS_ROOT_DIR="$PWD"
571mkdir "$OUT_OF_SOURCE_DIR"
572cd "$OUT_OF_SOURCE_DIR"
573cmake "$MBEDTLS_ROOT_DIR"
574make
575
576msg "test: cmake 'out-of-source' build"
577make test
578cd "$MBEDTLS_ROOT_DIR"
579rm -rf "$OUT_OF_SOURCE_DIR"
580
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100581msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100582cleanup
583
Gilles Peskineded50da2017-12-11 00:01:40 +0100584final_report