blob: c46ae9ac8cf8518426e0bf4459b6918e15192fdc [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
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010037
Simon Butcherd7f19022016-10-14 09:49:48 +010038# Default commands, can be overriden by the environment
39: ${OPENSSL:="openssl"}
40: ${OPENSSL_LEGACY:="$OPENSSL"}
41: ${GNUTLS_CLI:="gnutls-cli"}
42: ${GNUTLS_SERV:="gnutls-serv"}
43: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
44: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
45: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
46
47usage()
48{
Gilles Peskinea6901f42017-12-10 23:43:39 +010049 cat <<EOF
50Usage: $0 [OPTION]...
51 -h|--help Print this help.
52
53General options:
54 -f|--force Force the tests to overwrite any modified files.
Gilles Peskinea8bf9862017-12-11 00:01:40 +010055 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskinea6901f42017-12-10 23:43:39 +010056 -m|--memory Additional optional memory tests.
57 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
58 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
59 -s|--seed Integer seed value to use for this test run.
60
61Tool path options:
62 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
63 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
64 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
65 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
66 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
67 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
68EOF
Simon Butcherd7f19022016-10-14 09:49:48 +010069}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010070
71# remove built files as well as the cmake cache/config
72cleanup()
73{
Gilles Peskinea8bf9862017-12-11 00:01:40 +010074 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020075
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +020076 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000077 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +020078 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
79 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020080
81 if [ -f "$CONFIG_BAK" ]; then
82 mv "$CONFIG_BAK" "$CONFIG_H"
83 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010084}
85
Gilles Peskinea8bf9862017-12-11 00:01:40 +010086# Executed on exit. May be redefined depending on command line options.
87final_report () {
88 :
89}
90
91fatal_signal () {
92 cleanup
93 final_report $1
94 trap - $1
95 kill -$1 $$
96}
97
98trap 'fatal_signal HUP' HUP
99trap 'fatal_signal INT' INT
100trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200101
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100102msg()
103{
104 echo ""
105 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100106 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000107 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100108 echo "******************************************************************"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100109 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100110}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100111
Simon Butcherd7f19022016-10-14 09:49:48 +0100112err_msg()
113{
114 echo "$1" >&2
115}
116
117check_tools()
118{
119 for TOOL in "$@"; do
120 if ! `hash "$TOOL" >/dev/null 2>&1`; then
121 err_msg "$TOOL not found!"
122 exit 1
123 fi
124 done
125}
126
127while [ $# -gt 0 ]; do
128 case "$1" in
Simon Butcherd7f19022016-10-14 09:49:48 +0100129 --force|-f)
130 FORCE=1
131 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +0100132 --gnutls-cli)
133 shift
134 GNUTLS_CLI="$1"
135 ;;
Simon Butcherd7f19022016-10-14 09:49:48 +0100136 --gnutls-legacy-cli)
137 shift
138 GNUTLS_LEGACY_CLI="$1"
139 ;;
140 --gnutls-legacy-serv)
141 shift
142 GNUTLS_LEGACY_SERV="$1"
143 ;;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100144 --gnutls-serv)
145 shift
146 GNUTLS_SERV="$1"
147 ;;
148 --help|-h)
Simon Butcherd7f19022016-10-14 09:49:48 +0100149 usage
Gilles Peskinea6901f42017-12-10 23:43:39 +0100150 exit
151 ;;
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100152 --keep-going|-k)
153 KEEP_GOING=1
154 ;;
Gilles Peskinea6901f42017-12-10 23:43:39 +0100155 --memory|-m)
156 MEMORY=1
157 ;;
158 --openssl)
159 shift
160 OPENSSL="$1"
161 ;;
162 --openssl-legacy)
163 shift
164 OPENSSL_LEGACY="$1"
165 ;;
166 --out-of-source-dir)
167 shift
168 OUT_OF_SOURCE_DIR="$1"
169 ;;
170 --release-test|-r)
171 RELEASE=1
172 ;;
173 --seed|-s)
174 shift
175 SEED="$1"
176 ;;
177 *)
178 echo >&2 "Unknown option: $1"
179 echo >&2 "Run $0 --help for usage."
180 exit 120
Simon Butcherd7f19022016-10-14 09:49:48 +0100181 ;;
182 esac
183 shift
184done
185
186if [ $FORCE -eq 1 ]; then
187 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
188 git checkout-index -f -q $CONFIG_H
189 cleanup
190else
191
192 if [ -d yotta/module ]; then
193 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
194 echo "You can either delete your work and retry, or force the test to overwrite the"
195 echo "test by rerunning the script as: $0 --force"
196 exit 1
197 fi
198
199 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
200 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
201 echo "You can either delete this directory manually, or force the test by rerunning"
202 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
203 exit 1
204 fi
205
206 if ! git diff-files --quiet include/mbedtls/config.h; then
Simon Butcherd7f19022016-10-14 09:49:48 +0100207 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
208 echo "You can either delete or preserve your work, or force the test by rerunning the"
209 echo "script as: $0 --force"
210 exit 1
211 fi
212fi
213
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100214build_status=0
215if [ $KEEP_GOING -eq 1 ]; then
216 failure_summary=
217 failure_count=0
218 start_red=
219 end_color=
220 if [ -t 1 ]; then
221 case "$TERM" in
222 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
223 start_red=$(printf '\033[31m')
224 end_color=$(printf '\033[0m')
225 ;;
226 esac
227 fi
228 record_status () {
229 if "$@"; then
230 last_status=0
231 else
232 last_status=$?
233 text="$current_section: $* -> $last_status"
234 failure_summary="$failure_summary
235$text"
236 failure_count=$((failure_count + 1))
237 echo "${start_red}^^^^$text^^^^${end_color}"
238 fi
239 }
240 make () {
241 case "$*" in
242 *test|*check)
243 if [ $build_status -eq 0 ]; then
244 record_status command make "$@"
245 else
246 echo "(skipped because the build failed)"
247 fi
248 ;;
249 *)
250 record_status command make "$@"
251 build_status=$last_status
252 ;;
253 esac
254 }
255 final_report () {
256 if [ $failure_count -gt 0 ]; then
257 echo
258 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
259 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
260 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
261 elif [ -z "${1-}" ]; then
262 echo "SUCCESS :)"
263 fi
264 if [ -n "${1-}" ]; then
265 echo "Killed by SIG$1."
266 fi
267 }
268else
269 record_status () {
270 "$@"
271 }
272fi
273if_build_succeeded () {
274 if [ $build_status -eq 0 ]; then
275 record_status "$@"
276 fi
277}
278
Simon Butcherd7f19022016-10-14 09:49:48 +0100279if [ $RELEASE -eq 1 ]; then
280 # Fix the seed value to 1 to ensure that the tests are deterministic.
281 SEED=1
282fi
283
284msg "info: $0 configuration"
285echo "MEMORY: $MEMORY"
286echo "FORCE: $FORCE"
287echo "SEED: ${SEED-"UNSET"}"
288echo "OPENSSL: $OPENSSL"
289echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
290echo "GNUTLS_CLI: $GNUTLS_CLI"
291echo "GNUTLS_SERV: $GNUTLS_SERV"
292echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
293echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
294
295# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
296# we just export the variables they require
297export OPENSSL_CMD="$OPENSSL"
298export GNUTLS_CLI="$GNUTLS_CLI"
299export GNUTLS_SERV="$GNUTLS_SERV"
300
301# Avoid passing --seed flag in every call to ssl-opt.sh
302[ ! -z ${SEED+set} ] && export SEED
303
304# Make sure the tools we need are available.
305check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100306 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
307 "arm-none-eabi-gcc" "armcc"
Simon Butcherd7f19022016-10-14 09:49:48 +0100308
309#
310# Test Suites to be executed
311#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200312# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100313# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200314# and/or are more likely to fail than others (eg I use Clang most of the
315# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200316# 2. Minimize total running time, by avoiding useless rebuilds
317#
318# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100319
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100320msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200321tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100322
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000323msg "test: freshness of generated source files" # < 1s
324tests/scripts/check-generated-files.sh
325
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200326msg "test: doxygen markup outside doxygen blocks" # < 1s
327tests/scripts/check-doxy-blocks.pl
328
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200329msg "test/build: declared and exported names" # < 3s
330cleanup
331tests/scripts/check-names.sh
332
Simon Butcher73156352015-11-04 00:36:30 +0000333# Yotta not supported in 2.1 branch
334#msg "build: create and build yotta module" # ~ 30s
335#cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100336#record_status tests/scripts/yotta-build.sh
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200337
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100338msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100339cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100340CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100341make
342
Simon Butcherd7f19022016-10-14 09:49:48 +0100343msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100344make test
345programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200346
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100347msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100348if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200349
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100350msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100351if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200352
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200353msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
354make
355
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100356msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100357if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200358
Hanno Becker797c0842017-10-19 15:49:21 +0100359msg "build: default config except MFL extension (ASan build)" # ~ 30s
360cleanup
361cp "$CONFIG_H" "$CONFIG_BAK"
362scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
363CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
364make
365
366msg "test: ssl-opt.sh, MFL-related tests"
367tests/ssl-opt.sh -f "Max fragment length"
368
Simon Butcher02b8d482016-03-15 20:39:52 +0000369msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
370cleanup
371cp "$CONFIG_H" "$CONFIG_BAK"
372scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
373CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
374make
375
Simon Butcherd7f19022016-10-14 09:49:48 +0100376msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher02b8d482016-03-15 20:39:52 +0000377make test
378programs/test/selftest
379
380msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100381if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
382if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher02b8d482016-03-15 20:39:52 +0000383
384msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100385if_build_succeeded tests/ssl-opt.sh
Simon Butcher02b8d482016-03-15 20:39:52 +0000386
Hanno Becker4f9973e2017-10-24 11:56:28 +0100387msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
388cleanup
389cp "$CONFIG_H" "$CONFIG_BAK"
390scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
391CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
392make
393
394msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
395make test
396
397msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100398if_build_succeeded tests/ssl-opt.sh
Hanno Becker4f9973e2017-10-24 11:56:28 +0100399
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100400msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100401cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200402cp "$CONFIG_H" "$CONFIG_BAK"
403scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200404scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100405CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100406make
407
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100408msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200409make test
410
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100411msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100412if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200413
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100414msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100415if_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 +0200416
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200417msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100418cleanup
419cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100420if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100421
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200422msg "test/build: key-exchanges (gcc)" # ~ 1 min
423cleanup
424cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100425if_build_succeeded tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard134ca182015-10-23 09:04:45 +0200426
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000427msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100428cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100429make CC=gcc CFLAGS='-Werror -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100430
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200431# this is meant to cath missing #define mbedtls_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000432# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100433msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000434cleanup
435cp "$CONFIG_H" "$CONFIG_BAK"
436scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200437scripts/config.pl unset MBEDTLS_PLATFORM_C
438scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100439scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
440scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
441scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
442scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200443scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
444scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100445make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000446
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100447# catch compile bugs in _uninit functions
448msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
449cleanup
450cp "$CONFIG_H" "$CONFIG_BAK"
451scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100452scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100453make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100454
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200455msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
456cleanup
457cp "$CONFIG_H" "$CONFIG_BAK"
458scripts/config.pl full
459scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100460make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200461
462msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
463cleanup
464cp "$CONFIG_H" "$CONFIG_BAK"
465scripts/config.pl full
466scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100467make CC=gcc CFLAGS='-Werror -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200468
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200469msg "build: full config except net.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200470cleanup
471cp "$CONFIG_H" "$CONFIG_BAK"
472scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200473scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
474scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100475make CC=gcc CFLAGS='-Werror -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200476
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200477if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100478 msg "build/test: make shared" # ~ 40s
479 cleanup
480 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200481fi
482
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000483if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100484 msg "build: i386, make, gcc" # ~ 30s
485 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100486 make CC=gcc CFLAGS='-Werror -m32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000487fi # x86_64
488
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000489msg "build: arm-none-eabi-gcc, make" # ~ 10s
490cleanup
491cp "$CONFIG_H" "$CONFIG_BAK"
492scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200493scripts/config.pl unset MBEDTLS_NET_C
494scripts/config.pl unset MBEDTLS_TIMING_C
495scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcherd7f19022016-10-14 09:49:48 +0100496scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000497# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200498scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
499scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
500scripts/config.pl unset MBEDTLS_THREADING_C
501scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
502scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100503make 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 +0000504
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100505msg "build: armcc, make"
506cleanup
507cp "$CONFIG_H" "$CONFIG_BAK"
508scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200509scripts/config.pl unset MBEDTLS_NET_C
510scripts/config.pl unset MBEDTLS_TIMING_C
511scripts/config.pl unset MBEDTLS_FS_IO
512scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200513scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherd7f19022016-10-14 09:49:48 +0100514scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100515# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200516scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
517scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
518scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
519scripts/config.pl unset MBEDTLS_THREADING_C
520scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
521scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100522make CC=armcc AR=armar WARNING_CFLAGS= lib
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100523
Gilles Peskineb49351d2017-05-12 15:26:58 +0200524msg "build: allow SHA1 in certificates by default"
525cleanup
526cp "$CONFIG_H" "$CONFIG_BAK"
527scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100528make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskineb49351d2017-05-12 15:26:58 +0200529msg "test: allow SHA1 in certificates by default"
530make test
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100531if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskineb49351d2017-05-12 15:26:58 +0200532
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100533if which i686-w64-mingw32-gcc >/dev/null; then
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100534 msg "build: cross-mingw64, make" # ~ 30s
535 cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100536 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1
537 make WINDOWS_BUILD=1 clean
538 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1
539 make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100540fi
541
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000542# MemSan currently only available on Linux 64 bits
543if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000544
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100545 msg "build: MSan (clang)" # ~ 1 min 20s
546 cleanup
547 cp "$CONFIG_H" "$CONFIG_BAK"
548 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
549 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
550 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200551
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100552 msg "test: main suites (MSan)" # ~ 10s
553 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100554
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100555 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100556 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100557
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100558 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100559
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100560 if [ "$MEMORY" -gt 0 ]; then
561 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100562 if_build_succeeded tests/compat.sh
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100563 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100564
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000565else # no MemSan
566
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100567 msg "build: Release (clang)"
568 cleanup
569 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
570 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000571
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100572 msg "test: main suites valgrind (Release)"
573 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000574
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100575 # Optional part(s)
576 # Currently broken, programs don't seem to receive signals
577 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000578
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100579 if [ "$MEMORY" -gt 0 ]; then
580 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100581 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100582 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000583
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100584 if [ "$MEMORY" -gt 1 ]; then
585 msg "test: compat.sh --memcheck (Release)"
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100586 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine30dfbaf2017-12-10 23:22:20 +0100587 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000588
589fi # MemSan
590
Simon Butcherd7f19022016-10-14 09:49:48 +0100591msg "build: cmake 'out-of-source' build"
592cleanup
593MBEDTLS_ROOT_DIR="$PWD"
594mkdir "$OUT_OF_SOURCE_DIR"
595cd "$OUT_OF_SOURCE_DIR"
596cmake "$MBEDTLS_ROOT_DIR"
597make
598
599msg "test: cmake 'out-of-source' build"
600make test
601cd "$MBEDTLS_ROOT_DIR"
602rm -rf "$OUT_OF_SOURCE_DIR"
603
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100604msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100605cleanup
Gilles Peskinea8bf9862017-12-11 00:01:40 +0100606
607final_report