blob: bc600e88dc9a5bc35d4888db72da0cfca565e236 [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#
Simon Butcherd7f19022016-10-14 09:49:48 +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 Butcherd7f19022016-10-14 09:49:48 +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 Butcherd7f19022016-10-14 09:49:48 +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é-Gonnard7f809972015-03-09 17:05:11 +000030CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020031CONFIG_BAK="$CONFIG_H.bak"
32
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010033MEMORY=0
Simon Butcherd7f19022016-10-14 09:49:48 +010034FORCE=0
Gilles Peskinea8bf9862017-12-11 00:01:40 +010035KEEP_GOING=0
Simon Butcherd7f19022016-10-14 09:49:48 +010036RELEASE=0
Gilles Peskineb9344e32017-12-19 18:24:31 +010037RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010038
Simon Butcherd7f19022016-10-14 09:49:48 +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 Peskinea6901f42017-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 Peskinea8bf9862017-12-11 00:01:40 +010056 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskinea6901f42017-12-10 23:43:39 +010057 -m|--memory Additional optional memory tests.
Gilles Peskineb9344e32017-12-19 18:24:31 +010058 --armcc Run ARM Compiler builds (on by default).
59 --no-armcc Skip ARM Compiler builds.
Gilles Peskinea6901f42017-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 Butcherd7f19022016-10-14 09:49:48 +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 Peskinea8bf9862017-12-11 00:01:40 +010077 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020078
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +020079 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000080 rm -f include/Makefile include/mbedtls/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 Peskinea8bf9862017-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 Peskinea8bf9862017-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 Butcherd7f19022016-10-14 09:49:48 +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 Peskineb9344e32017-12-19 18:24:31 +0100132 --armcc)
133 RUN_ARMCC=1
134 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +0100135 --force|-f)
136 FORCE=1
137 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +0100138 --gnutls-cli)
139 shift
140 GNUTLS_CLI="$1"
141 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +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 Peskinea6901f42017-12-10 23:43:39 +0100150 --gnutls-serv)
151 shift
152 GNUTLS_SERV="$1"
153 ;;
154 --help|-h)
Simon Butcherd7f19022016-10-14 09:49:48 +0100155 usage
Gilles Peskinea6901f42017-12-10 23:43:39 +0100156 exit
157 ;;
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100158 --keep-going|-k)
159 KEEP_GOING=1
160 ;;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100161 --memory|-m)
162 MEMORY=1
163 ;;
Gilles Peskineb9344e32017-12-19 18:24:31 +0100164 --no-armcc)
165 RUN_ARMCC=0
166 ;;
Gilles Peskinea6901f42017-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 Butcherd7f19022016-10-14 09:49:48 +0100190 ;;
191 esac
192 shift
193done
194
195if [ $FORCE -eq 1 ]; then
196 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
197 git checkout-index -f -q $CONFIG_H
198 cleanup
199else
200
201 if [ -d yotta/module ]; then
202 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
203 echo "You can either delete your work and retry, or force the test to overwrite the"
204 echo "test by rerunning the script as: $0 --force"
205 exit 1
206 fi
207
208 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
209 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
210 echo "You can either delete this directory manually, or force the test by rerunning"
211 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
212 exit 1
213 fi
214
215 if ! git diff-files --quiet include/mbedtls/config.h; then
Simon Butcherd7f19022016-10-14 09:49:48 +0100216 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
217 echo "You can either delete or preserve your work, or force the test by rerunning the"
218 echo "script as: $0 --force"
219 exit 1
220 fi
221fi
222
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100223build_status=0
224if [ $KEEP_GOING -eq 1 ]; then
225 failure_summary=
226 failure_count=0
227 start_red=
228 end_color=
229 if [ -t 1 ]; then
230 case "$TERM" in
231 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
232 start_red=$(printf '\033[31m')
233 end_color=$(printf '\033[0m')
234 ;;
235 esac
236 fi
237 record_status () {
238 if "$@"; then
239 last_status=0
240 else
241 last_status=$?
242 text="$current_section: $* -> $last_status"
243 failure_summary="$failure_summary
244$text"
245 failure_count=$((failure_count + 1))
246 echo "${start_red}^^^^$text^^^^${end_color}"
247 fi
248 }
249 make () {
250 case "$*" in
251 *test|*check)
252 if [ $build_status -eq 0 ]; then
253 record_status command make "$@"
254 else
255 echo "(skipped because the build failed)"
256 fi
257 ;;
258 *)
259 record_status command make "$@"
260 build_status=$last_status
261 ;;
262 esac
263 }
264 final_report () {
265 if [ $failure_count -gt 0 ]; then
266 echo
267 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
268 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
269 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
270 elif [ -z "${1-}" ]; then
271 echo "SUCCESS :)"
272 fi
273 if [ -n "${1-}" ]; then
274 echo "Killed by SIG$1."
275 fi
276 }
277else
278 record_status () {
279 "$@"
280 }
281fi
282if_build_succeeded () {
283 if [ $build_status -eq 0 ]; then
284 record_status "$@"
285 fi
286}
287
Simon Butcherd7f19022016-10-14 09:49:48 +0100288if [ $RELEASE -eq 1 ]; then
289 # Fix the seed value to 1 to ensure that the tests are deterministic.
290 SEED=1
291fi
292
293msg "info: $0 configuration"
294echo "MEMORY: $MEMORY"
295echo "FORCE: $FORCE"
296echo "SEED: ${SEED-"UNSET"}"
297echo "OPENSSL: $OPENSSL"
298echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
299echo "GNUTLS_CLI: $GNUTLS_CLI"
300echo "GNUTLS_SERV: $GNUTLS_SERV"
301echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
302echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
303
304# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
305# we just export the variables they require
306export OPENSSL_CMD="$OPENSSL"
307export GNUTLS_CLI="$GNUTLS_CLI"
308export GNUTLS_SERV="$GNUTLS_SERV"
309
310# Avoid passing --seed flag in every call to ssl-opt.sh
311[ ! -z ${SEED+set} ] && export SEED
312
313# Make sure the tools we need are available.
314check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100315 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskineb9344e32017-12-19 18:24:31 +0100316 "arm-none-eabi-gcc"
317if [ $RUN_ARMCC -ne 0 ]; then
318 check_tools "armcc"
319fi
Simon Butcherd7f19022016-10-14 09:49:48 +0100320
321#
322# Test Suites to be executed
323#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200324# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100325# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200326# and/or are more likely to fail than others (eg I use Clang most of the
327# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200328# 2. Minimize total running time, by avoiding useless rebuilds
329#
330# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100331
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100332msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200333tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100334
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000335msg "test: freshness of generated source files" # < 1s
336tests/scripts/check-generated-files.sh
337
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200338msg "test: doxygen markup outside doxygen blocks" # < 1s
339tests/scripts/check-doxy-blocks.pl
340
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200341msg "test/build: declared and exported names" # < 3s
342cleanup
343tests/scripts/check-names.sh
344
Simon Butcher73156352015-11-04 00:36:30 +0000345# Yotta not supported in 2.1 branch
346#msg "build: create and build yotta module" # ~ 30s
347#cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100348#record_status tests/scripts/yotta-build.sh
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200349
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100350msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100351cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100352CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100353make
354
Simon Butcherd7f19022016-10-14 09:49:48 +0100355msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100356make test
357programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200358
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100359msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100360if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200361
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100362msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100363if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200364
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200365msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
366make
367
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100368msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100369if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200370
Hanno Becker797c0842017-10-19 15:49:21 +0100371msg "build: default config except MFL extension (ASan build)" # ~ 30s
372cleanup
373cp "$CONFIG_H" "$CONFIG_BAK"
374scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
375CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
376make
377
378msg "test: ssl-opt.sh, MFL-related tests"
379tests/ssl-opt.sh -f "Max fragment length"
380
Simon Butcher02b8d482016-03-15 20:39:52 +0000381msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
382cleanup
383cp "$CONFIG_H" "$CONFIG_BAK"
384scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
385CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
386make
387
Simon Butcherd7f19022016-10-14 09:49:48 +0100388msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher02b8d482016-03-15 20:39:52 +0000389make test
390programs/test/selftest
391
392msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100393if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
394if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher02b8d482016-03-15 20:39:52 +0000395
396msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100397if_build_succeeded tests/ssl-opt.sh
Simon Butcher02b8d482016-03-15 20:39:52 +0000398
Hanno Becker4f9973e2017-10-24 11:56:28 +0100399msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
400cleanup
401cp "$CONFIG_H" "$CONFIG_BAK"
402scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
403CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
404make
405
406msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
407make test
408
409msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100410if_build_succeeded tests/ssl-opt.sh
Hanno Becker4f9973e2017-10-24 11:56:28 +0100411
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100412msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100413cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200414cp "$CONFIG_H" "$CONFIG_BAK"
415scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200416scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100417CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100418make
419
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100420msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200421make test
422
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100423msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100424if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200425
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100426msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100427if_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 +0200428
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200429msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100430cleanup
431cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100432if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100433
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200434msg "test/build: key-exchanges (gcc)" # ~ 1 min
435cleanup
436cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100437if_build_succeeded tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200438
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000439msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100440cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100441make CC=gcc CFLAGS='-Werror -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100442
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200443# this is meant to cath missing #define mbedtls_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000444# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100445msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000446cleanup
447cp "$CONFIG_H" "$CONFIG_BAK"
448scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200449scripts/config.pl unset MBEDTLS_PLATFORM_C
450scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100451scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
452scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
453scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
454scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200455scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
456scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100457make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000458
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100459# catch compile bugs in _uninit functions
460msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
461cleanup
462cp "$CONFIG_H" "$CONFIG_BAK"
463scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100464scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100465make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100466
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200467msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
468cleanup
469cp "$CONFIG_H" "$CONFIG_BAK"
470scripts/config.pl full
471scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100472make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200473
474msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
475cleanup
476cp "$CONFIG_H" "$CONFIG_BAK"
477scripts/config.pl full
478scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100479make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200480
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200481msg "build: full config except net.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200482cleanup
483cp "$CONFIG_H" "$CONFIG_BAK"
484scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200485scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
486scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100487make CC=gcc CFLAGS='-Werror -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200488
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200489if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100490 msg "build/test: make shared" # ~ 40s
491 cleanup
492 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200493fi
494
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000495if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100496 msg "build: i386, make, gcc" # ~ 30s
497 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100498 make CC=gcc CFLAGS='-Werror -m32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000499fi # x86_64
500
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000501msg "build: arm-none-eabi-gcc, make" # ~ 10s
502cleanup
503cp "$CONFIG_H" "$CONFIG_BAK"
504scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200505scripts/config.pl unset MBEDTLS_NET_C
506scripts/config.pl unset MBEDTLS_TIMING_C
507scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcherd7f19022016-10-14 09:49:48 +0100508scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000509# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200510scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
511scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
512scripts/config.pl unset MBEDTLS_THREADING_C
513scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
514scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100515make 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 +0000516
Gilles Peskineb9344e32017-12-19 18:24:31 +0100517if [ $RUN_ARMCC -ne 0 ]; then
518 msg "build: armcc, make"
519 cleanup
520 cp "$CONFIG_H" "$CONFIG_BAK"
521 scripts/config.pl full
522 scripts/config.pl unset MBEDTLS_NET_C
523 scripts/config.pl unset MBEDTLS_TIMING_C
524 scripts/config.pl unset MBEDTLS_FS_IO
525 scripts/config.pl unset MBEDTLS_HAVE_TIME
526 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
527 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
528 # following things are not in the default config
529 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
530 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
531 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
532 scripts/config.pl unset MBEDTLS_THREADING_C
533 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
534 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
535 make CC=armcc AR=armar WARNING_CFLAGS= lib
536fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100537
Gilles Peskineb49351d2017-05-12 15:26:58 +0200538msg "build: allow SHA1 in certificates by default"
539cleanup
540cp "$CONFIG_H" "$CONFIG_BAK"
541scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100542make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskineb49351d2017-05-12 15:26:58 +0200543msg "test: allow SHA1 in certificates by default"
544make test
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100545if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskineb49351d2017-05-12 15:26:58 +0200546
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100547if which i686-w64-mingw32-gcc >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100548 msg "build: cross-mingw64, make" # ~ 30s
549 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100550 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1
551 make WINDOWS_BUILD=1 clean
552 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1
553 make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100554fi
555
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000556# MemSan currently only available on Linux 64 bits
557if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000558
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100559 msg "build: MSan (clang)" # ~ 1 min 20s
560 cleanup
561 cp "$CONFIG_H" "$CONFIG_BAK"
562 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
563 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
564 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200565
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100566 msg "test: main suites (MSan)" # ~ 10s
567 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100568
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100569 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100570 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100571
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100572 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100573
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100574 if [ "$MEMORY" -gt 0 ]; then
575 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100576 if_build_succeeded tests/compat.sh
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100577 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100578
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000579else # no MemSan
580
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100581 msg "build: Release (clang)"
582 cleanup
583 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
584 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000585
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100586 msg "test: main suites valgrind (Release)"
587 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000588
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100589 # Optional part(s)
590 # Currently broken, programs don't seem to receive signals
591 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000592
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100593 if [ "$MEMORY" -gt 0 ]; then
594 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100595 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100596 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000597
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100598 if [ "$MEMORY" -gt 1 ]; then
599 msg "test: compat.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100600 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100601 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000602
603fi # MemSan
604
Simon Butcherd7f19022016-10-14 09:49:48 +0100605msg "build: cmake 'out-of-source' build"
606cleanup
607MBEDTLS_ROOT_DIR="$PWD"
608mkdir "$OUT_OF_SOURCE_DIR"
609cd "$OUT_OF_SOURCE_DIR"
610cmake "$MBEDTLS_ROOT_DIR"
611make
612
613msg "test: cmake 'out-of-source' build"
614make test
615cd "$MBEDTLS_ROOT_DIR"
616rm -rf "$OUT_OF_SOURCE_DIR"
617
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100618msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100619cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100620
621final_report