blob: 1f9d40baf7e35d8105a501c8b3b929ea6326e286 [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-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)
Andrzej Kurek45a67192018-06-26 07:50:19 -040038# * G++, unless invoked with --no-cxx
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
41# * Yotta build dependencies, unless invoked with --no-yotta
42# * OpenSSL and GnuTLS command line tools, recent enough for the
43# interoperability tests. If they don't support SSLv3 then a legacy
44# version of these tools must be present as well (search for LEGACY
45# below).
46# See the invocation of check_tools below for details.
47#
48# This script must be invoked from the toplevel directory of a git
49# working copy of Mbed TLS.
50#
51# Note that the output is not saved. You may want to run
52# script -c tests/scripts/all.sh
53# or
54# tests/scripts/all.sh >all.log 2>&1
55#
56# Notes for maintainers
57# ---------------------
58#
59# The tests are roughly in order from fastest to slowest. This doesn't
60# have to be exact, but in general you should add slower tests towards
61# the end and fast checks near the beginning.
62#
63# Sanity checks have the following form:
64# 1. msg "short description of what is about to be done"
65# 2. run sanity check (failure stops the script)
66#
67# Build or build-and-test steps have the following form:
68# 1. msg "short description of what is about to be done"
69# 2. cleanup
70# 3. preparation (config.pl, cmake, ...) (failure stops the script)
71# 4. make
72# 5. Run tests if relevant. All tests must be prefixed with
73# if_build_successful for the sake of --keep-going.
74
75
76
77################################################################
78#### Initialization and command line parsing
79################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010080
SimonB2e23c822016-04-16 21:54:39 +010081# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010082set -eu
83
Andres AG38495a32016-07-12 16:54:33 +010084if [ "$( uname )" != "Linux" ]; then
85 echo "This script only works in Linux" >&2
86 exit 1
87elif [ -d library -a -d include -a -d tests ]; then :; else
88 echo "Must be run from mbed TLS root" >&2
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010089 exit 1
90fi
91
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000092CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020093CONFIG_BAK="$CONFIG_H.bak"
94
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010095MEMORY=0
SimonB2e23c822016-04-16 21:54:39 +010096FORCE=0
Gilles Peskine7c652162017-12-11 00:01:40 +010097KEEP_GOING=0
Gilles Peskinebca6ab92017-12-19 18:24:31 +010098RUN_ARMCC=1
Gilles Peskineda519252017-11-30 13:22:04 +010099YOTTA=1
Andrzej Kurek45a67192018-06-26 07:50:19 -0400100TEST_CXX=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100101
Andres AGd9eba4b2016-08-26 14:42:14 +0100102# Default commands, can be overriden by the environment
103: ${OPENSSL:="openssl"}
104: ${OPENSSL_LEGACY:="$OPENSSL"}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100105: ${OPENSSL_NEXT:="$OPENSSL"}
Andres AGd9eba4b2016-08-26 14:42:14 +0100106: ${GNUTLS_CLI:="gnutls-cli"}
107: ${GNUTLS_SERV:="gnutls-serv"}
108: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
109: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
Andres AGdc192212016-08-31 17:33:13 +0100110: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
Andres AG87bb5772016-09-27 15:05:15 +0100111: ${ARMC5_BIN_DIR:=/usr/bin}
112: ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100113
Andres AG38495a32016-07-12 16:54:33 +0100114# if MAKEFLAGS is not set add the -j option to speed up invocations of make
115if [ -n "${MAKEFLAGS+set}" ]; then
116 export MAKEFLAGS="-j"
117fi
118
Simon Butcher41eeccf2016-09-07 00:07:09 +0100119usage()
SimonB2e23c822016-04-16 21:54:39 +0100120{
Gilles Peskine709346a2017-12-10 23:43:39 +0100121 cat <<EOF
122Usage: $0 [OPTION]...
123 -h|--help Print this help.
124
125General options:
126 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100127 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100128 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100129 --armcc Run ARM Compiler builds (on by default).
130 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100131 --no-force Refuse to overwrite modified files (default).
132 --no-keep-going Stop at the first error (default).
133 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100134 --no-yotta Skip yotta module build.
Andrzej Kurek45a67192018-06-26 07:50:19 -0400135 --no-cxx Skip CXX Compiler build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100136 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100137 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100138 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
139 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100140 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100141
142Tool path options:
143 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
144 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
145 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
146 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
147 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
148 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
149 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
150 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100151 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100152EOF
SimonB2e23c822016-04-16 21:54:39 +0100153}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100154
155# remove built files as well as the cmake cache/config
156cleanup()
157{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100158 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
159 cd "$MBEDTLS_ROOT_DIR"
160 fi
161
Gilles Peskine7c652162017-12-11 00:01:40 +0100162 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200163
Gilles Peskine31b07e22018-03-21 12:15:06 +0100164 # Remove CMake artefacts
165 find . -name .git -prune -o -name yotta -prune -o \
166 -iname CMakeFiles -exec rm -rf {} \+ -o \
167 \( -iname cmake_install.cmake -o \
168 -iname CTestTestfile.cmake -o \
169 -iname CMakeCache.txt \) -exec rm {} \+
170 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000171 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200172 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
173 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200174
175 if [ -f "$CONFIG_BAK" ]; then
176 mv "$CONFIG_BAK" "$CONFIG_H"
177 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100178}
179
Gilles Peskine7c652162017-12-11 00:01:40 +0100180# Executed on exit. May be redefined depending on command line options.
181final_report () {
182 :
183}
184
185fatal_signal () {
186 cleanup
187 final_report $1
188 trap - $1
189 kill -$1 $$
190}
191
192trap 'fatal_signal HUP' HUP
193trap 'fatal_signal INT' INT
194trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200195
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100196msg()
197{
198 echo ""
199 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100200 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000201 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100202 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100203 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100204}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100205
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100206if [ $RUN_ARMCC -ne 0 ]; then
207 armc6_build_test()
208 {
209 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100210
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100211 msg "build: ARM Compiler 6 ($FLAGS), make"
212 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
213 WARNING_CFLAGS='-xc -std=c99' make lib
214 make clean
215 }
216fi
Andres AGa5cd9732016-10-17 15:23:10 +0100217
Andres AGd9eba4b2016-08-26 14:42:14 +0100218err_msg()
219{
220 echo "$1" >&2
221}
222
223check_tools()
224{
225 for TOOL in "$@"; do
226 if ! `hash "$TOOL" >/dev/null 2>&1`; then
227 err_msg "$TOOL not found!"
228 exit 1
229 fi
230 done
231}
232
SimonB2e23c822016-04-16 21:54:39 +0100233while [ $# -gt 0 ]; do
234 case "$1" in
Gilles Peskine8a244c92018-03-21 08:39:32 +0100235 --armcc) RUN_ARMCC=1;;
236 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
237 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
238 --force|-f) FORCE=1;;
239 --gnutls-cli) shift; GNUTLS_CLI="$1";;
240 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
241 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
242 --gnutls-serv) shift; GNUTLS_SERV="$1";;
243 --help|-h) usage; exit;;
244 --keep-going|-k) KEEP_GOING=1;;
245 --memory|-m) MEMORY=1;;
246 --no-armcc) RUN_ARMCC=0;;
Gilles Peskine38d81652018-03-21 08:40:26 +0100247 --no-force) FORCE=0;;
248 --no-keep-going) KEEP_GOING=0;;
249 --no-memory) MEMORY=0;;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100250 --no-yotta) YOTTA=0;;
251 --openssl) shift; OPENSSL="$1";;
252 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
Manuel Pégourié-Gonnarda3712be2018-05-22 15:58:50 +0200253 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100254 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Gilles Peskine38d81652018-03-21 08:40:26 +0100255 --random-seed) unset SEED;;
256 --release-test|-r) SEED=1;;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100257 --seed|-s) shift; SEED="$1";;
258 --yotta) YOTTA=1;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100259 *)
260 echo >&2 "Unknown option: $1"
261 echo >&2 "Run $0 --help for usage."
262 exit 120
SimonB2e23c822016-04-16 21:54:39 +0100263 ;;
264 esac
265 shift
266done
267
268if [ $FORCE -eq 1 ]; then
Gilles Peskineda519252017-11-30 13:22:04 +0100269 if [ $YOTTA -eq 1 ]; then
270 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
271 fi
SimonB2e23c822016-04-16 21:54:39 +0100272 git checkout-index -f -q $CONFIG_H
273 cleanup
274else
275
Gilles Peskine2a22a802017-12-21 15:19:00 +0100276 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100277 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
SimonB2e23c822016-04-16 21:54:39 +0100278 echo "You can either delete your work and retry, or force the test to overwrite the"
279 echo "test by rerunning the script as: $0 --force"
280 exit 1
281 fi
282
Andres AGdc192212016-08-31 17:33:13 +0100283 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
284 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
285 echo "You can either delete this directory manually, or force the test by rerunning"
286 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
287 exit 1
288 fi
289
SimonB2e23c822016-04-16 21:54:39 +0100290 if ! git diff-files --quiet include/mbedtls/config.h; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100291 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
SimonB2e23c822016-04-16 21:54:39 +0100292 echo "You can either delete or preserve your work, or force the test by rerunning the"
293 echo "script as: $0 --force"
294 exit 1
295 fi
296fi
297
Gilles Peskine7c652162017-12-11 00:01:40 +0100298build_status=0
299if [ $KEEP_GOING -eq 1 ]; then
300 failure_summary=
301 failure_count=0
302 start_red=
303 end_color=
304 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100305 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100306 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
307 start_red=$(printf '\033[31m')
308 end_color=$(printf '\033[0m')
309 ;;
310 esac
311 fi
312 record_status () {
313 if "$@"; then
314 last_status=0
315 else
316 last_status=$?
317 text="$current_section: $* -> $last_status"
318 failure_summary="$failure_summary
319$text"
320 failure_count=$((failure_count + 1))
321 echo "${start_red}^^^^$text^^^^${end_color}"
322 fi
323 }
324 make () {
325 case "$*" in
326 *test|*check)
327 if [ $build_status -eq 0 ]; then
328 record_status command make "$@"
329 else
330 echo "(skipped because the build failed)"
331 fi
332 ;;
333 *)
334 record_status command make "$@"
335 build_status=$last_status
336 ;;
337 esac
338 }
339 final_report () {
340 if [ $failure_count -gt 0 ]; then
341 echo
342 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
343 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
344 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
345 elif [ -z "${1-}" ]; then
346 echo "SUCCESS :)"
347 fi
348 if [ -n "${1-}" ]; then
349 echo "Killed by SIG$1."
350 fi
351 }
352else
353 record_status () {
354 "$@"
355 }
356fi
357if_build_succeeded () {
358 if [ $build_status -eq 0 ]; then
359 record_status "$@"
360 fi
361}
362
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200363# to be used instead of ! for commands run with
364# record_status or if_build_succeeded
365not() {
366 ! "$@"
367}
368
Andres AGd9eba4b2016-08-26 14:42:14 +0100369msg "info: $0 configuration"
370echo "MEMORY: $MEMORY"
371echo "FORCE: $FORCE"
Andres AG7770ea82016-10-10 15:46:20 +0100372echo "SEED: ${SEED-"UNSET"}"
Andres AGd9eba4b2016-08-26 14:42:14 +0100373echo "OPENSSL: $OPENSSL"
374echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100375echo "OPENSSL_NEXT: $OPENSSL_NEXT"
Andres AGd9eba4b2016-08-26 14:42:14 +0100376echo "GNUTLS_CLI: $GNUTLS_CLI"
377echo "GNUTLS_SERV: $GNUTLS_SERV"
378echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
379echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
Andres AG87bb5772016-09-27 15:05:15 +0100380echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
381echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
382
383ARMC5_CC="$ARMC5_BIN_DIR/armcc"
384ARMC5_AR="$ARMC5_BIN_DIR/armar"
385ARMC6_CC="$ARMC6_BIN_DIR/armclang"
386ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100387
Andres AGb2fdd042016-09-22 14:17:46 +0100388# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
389# we just export the variables they require
390export OPENSSL_CMD="$OPENSSL"
391export GNUTLS_CLI="$GNUTLS_CLI"
392export GNUTLS_SERV="$GNUTLS_SERV"
393
Andres AG7770ea82016-10-10 15:46:20 +0100394# Avoid passing --seed flag in every call to ssl-opt.sh
Gilles Peskine38d81652018-03-21 08:40:26 +0100395if [ -n "${SEED-}" ]; then
396 export SEED
397fi
Andres AG7770ea82016-10-10 15:46:20 +0100398
Andres AGd9eba4b2016-08-26 14:42:14 +0100399# Make sure the tools we need are available.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100400check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
401 "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100402 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Andres Amaya Garciaddebc492017-10-24 22:16:34 +0100403 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100404if [ $RUN_ARMCC -ne 0 ]; then
405 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
406fi
Andres AGd9eba4b2016-08-26 14:42:14 +0100407
Gilles Peskine192c72f2017-12-21 15:59:21 +0100408
409
410################################################################
411#### Basic checks
412################################################################
SimonB2e23c822016-04-16 21:54:39 +0100413
414#
415# Test Suites to be executed
416#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200417# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100418# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200419# and/or are more likely to fail than others (eg I use Clang most of the
420# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200421# 2. Minimize total running time, by avoiding useless rebuilds
422#
423# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100424
Janos Follathb72c6782016-07-19 14:54:17 +0100425msg "info: output_env.sh"
Andres AGd9eba4b2016-08-26 14:42:14 +0100426OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
427 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
Andres AG87bb5772016-09-27 15:05:15 +0100428 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
Gilles Peskine26232962018-03-21 08:35:07 +0100429 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100430
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100431msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200432tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100433
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000434msg "test: freshness of generated source files" # < 1s
435tests/scripts/check-generated-files.sh
436
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200437msg "test: doxygen markup outside doxygen blocks" # < 1s
438tests/scripts/check-doxy-blocks.pl
439
Darryl Greena07039c2018-03-13 16:48:16 +0000440msg "test: check-files.py" # < 1s
441cleanup
442tests/scripts/check-files.py
443
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200444msg "test/build: declared and exported names" # < 3s
445cleanup
446tests/scripts/check-names.sh
447
Andres AGd9eba4b2016-08-26 14:42:14 +0100448msg "test: doxygen warnings" # ~ 3s
449cleanup
450tests/scripts/doxygen.sh
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100451
Gilles Peskine192c72f2017-12-21 15:59:21 +0100452
453
454################################################################
455#### Build and test many configurations and targets
456################################################################
457
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100458if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
459 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
460 # path, and uses whatever version of armcc it finds there.
Gilles Peskineda519252017-11-30 13:22:04 +0100461 msg "build: create and build yotta module" # ~ 30s
462 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100463 record_status tests/scripts/yotta-build.sh
Gilles Peskineda519252017-11-30 13:22:04 +0100464fi
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200465
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100466msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100467cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100468CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100469make
470
Simon Butcher8e3afc72016-09-15 17:13:08 +0100471msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100472make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200473
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100474msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100475if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200476
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100477msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskine396fac12018-03-22 22:26:03 +0100478record_status tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200479
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200480msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
481make
482
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100483msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100484if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200485
Simon Butcher3ea7f522016-03-07 23:22:10 +0000486msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
487cleanup
Simon Butcherf413b6f2016-03-14 22:32:42 +0000488cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcher3ea7f522016-03-07 23:22:10 +0000489scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
490CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
491make
492
Simon Butcher8e3afc72016-09-15 17:13:08 +0100493msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher3ea7f522016-03-07 23:22:10 +0000494make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000495
496msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100497if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
498if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000499
500msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100501if_build_succeeded tests/ssl-opt.sh
Simon Butcher3ea7f522016-03-07 23:22:10 +0000502
Hanno Becker134c2ab2017-10-12 15:29:50 +0100503msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
504cleanup
505cp "$CONFIG_H" "$CONFIG_BAK"
506scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
507CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
508make
509
510msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
511make test
512
513msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100514if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100515
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100516msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
517cleanup
518cp "$CONFIG_H" "$CONFIG_BAK"
519scripts/config.pl set MBEDTLS_RSA_NO_CRT
520CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
521make
522
523msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
524make test
525
526msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
527tests/ssl-opt.sh -f RSA
528
529msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
530tests/compat.sh -t RSA
531
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200532msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200533cleanup
Janos Follath35d48cb2016-04-22 14:45:00 +0100534cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200535scripts/config.pl full
536scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Simon Butcherf95c1762016-11-10 17:25:58 +0000537CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200538make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100539
540msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200541make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200542
Jaeden Amerod9c71da2018-06-15 20:31:26 +0100543msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
544if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200545
546msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100547if_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 +0200548
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100549msg "test: compat.sh ARIA"
550if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA'
551
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100552msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
553cleanup
554cp "$CONFIG_H" "$CONFIG_BAK"
555scripts/config.pl full
Gilles Peskine0afe6242018-02-21 19:28:12 +0100556scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100557# Build with -O -Wextra to catch a maximum of issues.
558make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
559make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
560
561msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
562# No cleanup, just tweak the configuration and rebuild
563make clean
564scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
Gilles Peskine0afe6242018-02-21 19:28:12 +0100565scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100566# Build with -O -Wextra to catch a maximum of issues.
567make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
568make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine0afe6242018-02-21 19:28:12 +0100569
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200570msg "test/build: curves.pl (gcc)" # ~ 4 min
571cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100572record_status tests/scripts/curves.pl
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200573
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200574msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
575cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100576record_status tests/scripts/depends-hashes.pl
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200577
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200578msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
579cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100580record_status tests/scripts/depends-pkalgs.pl
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200581
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200582msg "test/build: key-exchanges (gcc)" # ~ 1 min
583cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100584record_status tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200585
Andrzej Kurek45a67192018-06-26 07:50:19 -0400586if [ $TEST_CXX -ne 0 ]; then
587 msg "build: Unix make, gcc and g++ test" # ~ 30s
588 cleanup
589 make TEST_CPP=1
590
591 msg "build: cmake, gcc and g++ test" # ~ 30s
592 cleanup
593 CC=gcc cmake -D TEST_CPP=YES .
594 make
595fi
596
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000597msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100598cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100599make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100600
Simon Butcherf95c1762016-11-10 17:25:58 +0000601# Full configuration build, without platform support, file IO and net sockets.
602# This should catch missing mbedtls_printf definitions, and by disabling file
603# IO, it should catch missing '#include <stdio.h>'
604msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000605cleanup
606cp "$CONFIG_H" "$CONFIG_BAK"
607scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200608scripts/config.pl unset MBEDTLS_PLATFORM_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000609scripts/config.pl unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200610scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100611scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
612scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
613scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Simon Butcherb9283432016-07-13 11:02:41 +0100614scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100615scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Simon Butcher284b4c92016-06-26 13:10:00 +0100616scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200617scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
618scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchercb587002017-01-06 16:14:44 +0000619# Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
620# to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine7c652162017-12-11 00:01:40 +0100621make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
622make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000623
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100624# catch compile bugs in _uninit functions
625msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
626cleanup
627cp "$CONFIG_H" "$CONFIG_BAK"
628scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100629scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Simon Butchereebf1b92016-06-27 01:42:39 +0100630scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine7c652162017-12-11 00:01:40 +0100631make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100632
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200633msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
634cleanup
635cp "$CONFIG_H" "$CONFIG_BAK"
636scripts/config.pl full
637scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100638make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200639
640msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
641cleanup
642cp "$CONFIG_H" "$CONFIG_BAK"
643scripts/config.pl full
644scripts/config.pl unset MBEDTLS_SSL_CLI_C
Hanno Beckerd485c312018-01-05 13:03:53 +0000645make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200646
Simon Butcherf95c1762016-11-10 17:25:58 +0000647# Note, C99 compliance can also be tested with the sockets support disabled,
648# as that requires a POSIX platform (which isn't the same as C99).
Andres AG788aa4a2016-09-14 14:32:09 +0100649msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200650cleanup
651cp "$CONFIG_H" "$CONFIG_BAK"
652scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200653scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
654scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine7c652162017-12-11 00:01:40 +0100655make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200656
Hanno Becker5175ac62017-09-18 15:36:25 +0100657msg "build: default config except MFL extension (ASan build)" # ~ 30s
658cleanup
659cp "$CONFIG_H" "$CONFIG_BAK"
660scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
661CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
662make
663
664msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine7c652162017-12-11 00:01:40 +0100665if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000666
Simon Butcherab5df402016-06-11 02:31:21 +0100667msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100668cleanup
669cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcherab5df402016-06-11 02:31:21 +0100670scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
Janos Follath06c54002016-06-09 13:57:40 +0100671scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
672scripts/config.pl set MBEDTLS_ENTROPY_C
673scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
674scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
675scripts/config.pl unset MBEDTLS_HAVEGE_C
Simon Butchereebf1b92016-06-27 01:42:39 +0100676CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
Janos Follath06c54002016-06-09 13:57:40 +0100677make
678
Simon Butcher8e3afc72016-09-15 17:13:08 +0100679msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100680make test
Janos Follath06c54002016-06-09 13:57:40 +0100681
Hanno Becker83ebf782017-07-07 12:29:15 +0100682msg "build: default config with AES_FEWER_TABLES enabled"
683cleanup
684cp "$CONFIG_H" "$CONFIG_BAK"
685scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100686make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100687
688msg "test: AES_FEWER_TABLES"
689make test
690
691msg "build: default config with AES_ROM_TABLES enabled"
692cleanup
693cp "$CONFIG_H" "$CONFIG_BAK"
694scripts/config.pl set MBEDTLS_AES_ROM_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100695make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100696
697msg "test: AES_ROM_TABLES"
698make test
699
700msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
701cleanup
702cp "$CONFIG_H" "$CONFIG_BAK"
703scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
704scripts/config.pl set MBEDTLS_AES_ROM_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100705make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100706
707msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
708make test
709
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200710if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100711 msg "build/test: make shared" # ~ 40s
712 cleanup
713 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200714fi
715
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000716if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100717 msg "build: i386, make, gcc" # ~ 30s
718 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100719 make CC=gcc CFLAGS='-Werror -Wall -Wextra -m32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100720
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100721 msg "test: i386, make, gcc"
722 make test
723
724 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
725 cleanup
726 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
727
728 msg "test: 64-bit ILP32, make, gcc"
729 make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000730fi # x86_64
731
Gilles Peskine14c3c062018-01-29 21:25:12 +0100732msg "build: gcc, force 32-bit bignum limbs"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100733cleanup
734cp "$CONFIG_H" "$CONFIG_BAK"
735scripts/config.pl unset MBEDTLS_HAVE_ASM
736scripts/config.pl unset MBEDTLS_AESNI_C
737scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine14c3c062018-01-29 21:25:12 +0100738make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100739
Gilles Peskine14c3c062018-01-29 21:25:12 +0100740msg "test: gcc, force 32-bit bignum limbs"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100741make test
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100742
Gilles Peskine14c3c062018-01-29 21:25:12 +0100743msg "build: gcc, force 64-bit bignum limbs"
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100744cleanup
745cp "$CONFIG_H" "$CONFIG_BAK"
746scripts/config.pl unset MBEDTLS_HAVE_ASM
747scripts/config.pl unset MBEDTLS_AESNI_C
748scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine14c3c062018-01-29 21:25:12 +0100749make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
750
751msg "test: gcc, force 64-bit bignum limbs"
752make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000753
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200754
755msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
756cleanup
757cp "$CONFIG_H" "$CONFIG_BAK"
758scripts/config.pl full
759scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
760scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
761make CFLAGS='-Werror -O1'
762
763msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
764make test
765
766
767msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
768cleanup
769cp "$CONFIG_H" "$CONFIG_BAK"
770scripts/config.pl full
771scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
772scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
773make CFLAGS='-Werror -O1'
774
775msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
776make test
777
778
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000779msg "build: arm-none-eabi-gcc, make" # ~ 10s
780cleanup
781cp "$CONFIG_H" "$CONFIG_BAK"
782scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200783scripts/config.pl unset MBEDTLS_NET_C
784scripts/config.pl unset MBEDTLS_TIMING_C
785scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchereebf1b92016-06-27 01:42:39 +0100786scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherbc6a4862016-03-07 17:35:59 +0000787scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000788# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200789scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
790scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
791scripts/config.pl unset MBEDTLS_THREADING_C
792scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
793scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine7c652162017-12-11 00:01:40 +0100794make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000795
Gilles Peskineed942f82017-06-08 15:19:20 +0200796msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
797cleanup
Simon Butcher940737f2017-07-23 13:42:36 +0200798cp "$CONFIG_H" "$CONFIG_BAK"
Andres Amaya Garcia05931972017-07-20 13:27:35 +0100799scripts/config.pl full
800scripts/config.pl unset MBEDTLS_NET_C
801scripts/config.pl unset MBEDTLS_TIMING_C
802scripts/config.pl unset MBEDTLS_FS_IO
803scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
804scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
805# following things are not in the default config
806scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
807scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
808scripts/config.pl unset MBEDTLS_THREADING_C
809scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
810scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskineed942f82017-06-08 15:19:20 +0200811scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine7c652162017-12-11 00:01:40 +0100812make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskineed942f82017-06-08 15:19:20 +0200813echo "Checking that software 64-bit division is not required"
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200814if_build_succeeded not grep __aeabi_uldiv library/*.o
815
816msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
817cleanup
818cp "$CONFIG_H" "$CONFIG_BAK"
819scripts/config.pl full
820scripts/config.pl unset MBEDTLS_NET_C
821scripts/config.pl unset MBEDTLS_TIMING_C
822scripts/config.pl unset MBEDTLS_FS_IO
823scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
824scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
825# following things are not in the default config
826scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
827scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
828scripts/config.pl unset MBEDTLS_THREADING_C
829scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
830scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
831scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
832make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
833echo "Checking that software 64-bit multiplication is not required"
834if_build_succeeded not grep __aeabi_lmul library/*.o
Gilles Peskineed942f82017-06-08 15:19:20 +0200835
Andres AG87bb5772016-09-27 15:05:15 +0100836msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100837cleanup
838cp "$CONFIG_H" "$CONFIG_BAK"
839scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200840scripts/config.pl unset MBEDTLS_NET_C
841scripts/config.pl unset MBEDTLS_TIMING_C
842scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher1c719652016-06-27 19:02:12 +0100843scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200844scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200845scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherbc6a4862016-03-07 17:35:59 +0000846scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100847# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200848scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
849scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
850scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
851scripts/config.pl unset MBEDTLS_THREADING_C
852scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
853scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcher4df5eaf2016-08-24 22:58:31 +0300854scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Andres AG87bb5772016-09-27 15:05:15 +0100855
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100856if [ $RUN_ARMCC -ne 0 ]; then
857 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
858 make clean
Andres AG87bb5772016-09-27 15:05:15 +0100859
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100860 # ARM Compiler 6 - Target ARMv7-A
861 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +0200862
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100863 # ARM Compiler 6 - Target ARMv7-M
864 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +0200865
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100866 # ARM Compiler 6 - Target ARMv8-A - AArch32
867 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +0200868
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100869 # ARM Compiler 6 - Target ARMv8-M
870 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +0200871
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100872 # ARM Compiler 6 - Target ARMv8-A - AArch64
873 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
874fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100875
Gilles Peskine2a458da2017-05-12 15:26:58 +0200876msg "build: allow SHA1 in certificates by default"
877cleanup
878cp "$CONFIG_H" "$CONFIG_BAK"
879scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine7c652162017-12-11 00:01:40 +0100880make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine2a458da2017-05-12 15:26:58 +0200881msg "test: allow SHA1 in certificates by default"
882make test
Gilles Peskine7c652162017-12-11 00:01:40 +0100883if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine2a458da2017-05-12 15:26:58 +0200884
Hanno Beckerd485c312018-01-05 13:03:53 +0000885msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min
Hanno Beckere963efa2018-01-03 10:03:43 +0000886cleanup
887cp "$CONFIG_H" "$CONFIG_BAK"
888scripts/config.pl set MBEDTLS_RSA_NO_CRT
Hanno Beckerd485c312018-01-05 13:03:53 +0000889CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
890make
Hanno Beckere963efa2018-01-03 10:03:43 +0000891
892msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)"
893make test
Simon Butcher002bc622016-11-17 09:27:45 +0000894
895msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
896cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100897make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Manuel Pégourié-Gonnard52fa38a2015-06-23 14:29:58 +0200898
Manuel Pégourié-Gonnarde33316c2015-08-07 13:17:23 +0200899# note Make tests only builds the tests, but doesn't run them
Gilles Peskine7c652162017-12-11 00:01:40 +0100900make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
901make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100902
903msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Gilles Peskine7c652162017-12-11 00:01:40 +0100904make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
905make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
906make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100907
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000908# MemSan currently only available on Linux 64 bits
909if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000910
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100911 msg "build: MSan (clang)" # ~ 1 min 20s
912 cleanup
913 cp "$CONFIG_H" "$CONFIG_BAK"
914 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
915 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
916 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200917
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100918 msg "test: main suites (MSan)" # ~ 10s
919 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100920
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100921 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100922 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100923
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100924 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100925
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100926 if [ "$MEMORY" -gt 0 ]; then
927 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +0100928 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100929 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100930
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000931else # no MemSan
932
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100933 msg "build: Release (clang)"
934 cleanup
935 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
936 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000937
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100938 msg "test: main suites valgrind (Release)"
939 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000940
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100941 # Optional part(s)
942 # Currently broken, programs don't seem to receive signals
943 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000944
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100945 if [ "$MEMORY" -gt 0 ]; then
946 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100947 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100948 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000949
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100950 if [ "$MEMORY" -gt 1 ]; then
951 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100952 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100953 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000954
955fi # MemSan
956
Andres AGdc192212016-08-31 17:33:13 +0100957msg "build: cmake 'out-of-source' build"
958cleanup
959MBEDTLS_ROOT_DIR="$PWD"
960mkdir "$OUT_OF_SOURCE_DIR"
961cd "$OUT_OF_SOURCE_DIR"
962cmake "$MBEDTLS_ROOT_DIR"
963make
964
965msg "test: cmake 'out-of-source' build"
966make test
Gilles Peskine0114ffc2018-03-21 12:17:20 +0100967# Test an SSL option that requires an auxiliary script in test/scripts/.
968# Also ensure that there are no error messages such as
969# "No such file or directory", which would indicate that some required
970# file is missing (ssl-opt.sh tolerates the absence of some files so
971# may exit with status 0 but emit errors).
972if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
973if [ -s ssl-opt.err ]; then
974 cat ssl-opt.err >&2
975 record_status [ ! -s ssl-opt.err ]
976 rm ssl-opt.err
977fi
Andres AGdc192212016-08-31 17:33:13 +0100978cd "$MBEDTLS_ROOT_DIR"
979rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100980unset MBEDTLS_ROOT_DIR
Andres AGdc192212016-08-31 17:33:13 +0100981
Andres Amaya Garcia29673812017-10-25 10:35:51 +0100982for optimization_flag in -O2 -O3 -Ofast -Os; do
983 for compiler in clang gcc; do
Andres Amaya Garcia708c5cb2018-04-24 08:33:31 -0500984 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Andres Amaya Garcia29673812017-10-25 10:35:51 +0100985 cleanup
986 CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag" make programs
987 gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx
988 done
989done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +0100990
Gilles Peskine192c72f2017-12-21 15:59:21 +0100991
992
993################################################################
994#### Termination
995################################################################
996
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100997msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100998cleanup
999
Gilles Peskine7c652162017-12-11 00:01:40 +01001000final_report