blob: 83011f5a0fa248f83d90387d63eb4e854e0f868d [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)
38# * arm-gcc and mingw-gcc
39# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
40# * Yotta build dependencies, unless invoked with --no-yotta
41# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
58# The tests are roughly in order from fastest to slowest. This doesn't
59# have to be exact, but in general you should add slower tests towards
60# the end and fast checks near the beginning.
61#
62# Sanity checks have the following form:
63# 1. msg "short description of what is about to be done"
64# 2. run sanity check (failure stops the script)
65#
66# Build or build-and-test steps have the following form:
67# 1. msg "short description of what is about to be done"
68# 2. cleanup
69# 3. preparation (config.pl, cmake, ...) (failure stops the script)
70# 4. make
71# 5. Run tests if relevant. All tests must be prefixed with
72# if_build_successful for the sake of --keep-going.
73
74
75
76################################################################
77#### Initialization and command line parsing
78################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010079
SimonB2e23c822016-04-16 21:54:39 +010080# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010081set -eu
82
Andres AG38495a32016-07-12 16:54:33 +010083if [ "$( uname )" != "Linux" ]; then
84 echo "This script only works in Linux" >&2
85 exit 1
86elif [ -d library -a -d include -a -d tests ]; then :; else
87 echo "Must be run from mbed TLS root" >&2
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010088 exit 1
89fi
90
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000091CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020092CONFIG_BAK="$CONFIG_H.bak"
93
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010094MEMORY=0
SimonB2e23c822016-04-16 21:54:39 +010095FORCE=0
Gilles Peskine7c652162017-12-11 00:01:40 +010096KEEP_GOING=0
Gilles Peskinebca6ab92017-12-19 18:24:31 +010097RUN_ARMCC=1
Gilles Peskineda519252017-11-30 13:22:04 +010098YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010099
Andres AGd9eba4b2016-08-26 14:42:14 +0100100# Default commands, can be overriden by the environment
101: ${OPENSSL:="openssl"}
102: ${OPENSSL_LEGACY:="$OPENSSL"}
103: ${GNUTLS_CLI:="gnutls-cli"}
104: ${GNUTLS_SERV:="gnutls-serv"}
105: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
106: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
Andres AGdc192212016-08-31 17:33:13 +0100107: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
Andres AG87bb5772016-09-27 15:05:15 +0100108: ${ARMC5_BIN_DIR:=/usr/bin}
109: ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100110
Andres AG38495a32016-07-12 16:54:33 +0100111# if MAKEFLAGS is not set add the -j option to speed up invocations of make
112if [ -n "${MAKEFLAGS+set}" ]; then
113 export MAKEFLAGS="-j"
114fi
115
Simon Butcher41eeccf2016-09-07 00:07:09 +0100116usage()
SimonB2e23c822016-04-16 21:54:39 +0100117{
Gilles Peskine709346a2017-12-10 23:43:39 +0100118 cat <<EOF
119Usage: $0 [OPTION]...
120 -h|--help Print this help.
121
122General options:
123 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100124 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100125 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100126 --armcc Run ARM Compiler builds (on by default).
127 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100128 --no-force Refuse to overwrite modified files (default).
129 --no-keep-going Stop at the first error (default).
130 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100131 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100132 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100133 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100134 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
135 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100136 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100137
138Tool path options:
139 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
140 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
141 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
142 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
143 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
144 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
145 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
146 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
147EOF
SimonB2e23c822016-04-16 21:54:39 +0100148}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100149
150# remove built files as well as the cmake cache/config
151cleanup()
152{
Gilles Peskine7c652162017-12-11 00:01:40 +0100153 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200154
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200155 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000156 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200157 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
158 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200159
160 if [ -f "$CONFIG_BAK" ]; then
161 mv "$CONFIG_BAK" "$CONFIG_H"
162 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100163}
164
Gilles Peskine7c652162017-12-11 00:01:40 +0100165# Executed on exit. May be redefined depending on command line options.
166final_report () {
167 :
168}
169
170fatal_signal () {
171 cleanup
172 final_report $1
173 trap - $1
174 kill -$1 $$
175}
176
177trap 'fatal_signal HUP' HUP
178trap 'fatal_signal INT' INT
179trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200180
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100181msg()
182{
183 echo ""
184 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100185 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000186 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100187 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100188 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100189}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100190
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100191if [ $RUN_ARMCC -ne 0 ]; then
192 armc6_build_test()
193 {
194 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100195
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100196 msg "build: ARM Compiler 6 ($FLAGS), make"
197 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
198 WARNING_CFLAGS='-xc -std=c99' make lib
199 make clean
200 }
201fi
Andres AGa5cd9732016-10-17 15:23:10 +0100202
Andres AGd9eba4b2016-08-26 14:42:14 +0100203err_msg()
204{
205 echo "$1" >&2
206}
207
208check_tools()
209{
210 for TOOL in "$@"; do
211 if ! `hash "$TOOL" >/dev/null 2>&1`; then
212 err_msg "$TOOL not found!"
213 exit 1
214 fi
215 done
216}
217
SimonB2e23c822016-04-16 21:54:39 +0100218while [ $# -gt 0 ]; do
219 case "$1" in
Gilles Peskine8a244c92018-03-21 08:39:32 +0100220 --armcc) RUN_ARMCC=1;;
221 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
222 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
223 --force|-f) FORCE=1;;
224 --gnutls-cli) shift; GNUTLS_CLI="$1";;
225 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
226 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
227 --gnutls-serv) shift; GNUTLS_SERV="$1";;
228 --help|-h) usage; exit;;
229 --keep-going|-k) KEEP_GOING=1;;
230 --memory|-m) MEMORY=1;;
231 --no-armcc) RUN_ARMCC=0;;
Gilles Peskine38d81652018-03-21 08:40:26 +0100232 --no-force) FORCE=0;;
233 --no-keep-going) KEEP_GOING=0;;
234 --no-memory) MEMORY=0;;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100235 --no-yotta) YOTTA=0;;
236 --openssl) shift; OPENSSL="$1";;
237 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
238 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Gilles Peskine38d81652018-03-21 08:40:26 +0100239 --random-seed) unset SEED;;
240 --release-test|-r) SEED=1;;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100241 --seed|-s) shift; SEED="$1";;
242 --yotta) YOTTA=1;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100243 *)
244 echo >&2 "Unknown option: $1"
245 echo >&2 "Run $0 --help for usage."
246 exit 120
SimonB2e23c822016-04-16 21:54:39 +0100247 ;;
248 esac
249 shift
250done
251
252if [ $FORCE -eq 1 ]; then
Gilles Peskineda519252017-11-30 13:22:04 +0100253 if [ $YOTTA -eq 1 ]; then
254 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
255 fi
SimonB2e23c822016-04-16 21:54:39 +0100256 git checkout-index -f -q $CONFIG_H
257 cleanup
258else
259
Gilles Peskine2a22a802017-12-21 15:19:00 +0100260 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100261 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
SimonB2e23c822016-04-16 21:54:39 +0100262 echo "You can either delete your work and retry, or force the test to overwrite the"
263 echo "test by rerunning the script as: $0 --force"
264 exit 1
265 fi
266
Andres AGdc192212016-08-31 17:33:13 +0100267 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
268 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
269 echo "You can either delete this directory manually, or force the test by rerunning"
270 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
271 exit 1
272 fi
273
SimonB2e23c822016-04-16 21:54:39 +0100274 if ! git diff-files --quiet include/mbedtls/config.h; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100275 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
SimonB2e23c822016-04-16 21:54:39 +0100276 echo "You can either delete or preserve your work, or force the test by rerunning the"
277 echo "script as: $0 --force"
278 exit 1
279 fi
280fi
281
Gilles Peskine7c652162017-12-11 00:01:40 +0100282build_status=0
283if [ $KEEP_GOING -eq 1 ]; then
284 failure_summary=
285 failure_count=0
286 start_red=
287 end_color=
288 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100289 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100290 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
291 start_red=$(printf '\033[31m')
292 end_color=$(printf '\033[0m')
293 ;;
294 esac
295 fi
296 record_status () {
297 if "$@"; then
298 last_status=0
299 else
300 last_status=$?
301 text="$current_section: $* -> $last_status"
302 failure_summary="$failure_summary
303$text"
304 failure_count=$((failure_count + 1))
305 echo "${start_red}^^^^$text^^^^${end_color}"
306 fi
307 }
308 make () {
309 case "$*" in
310 *test|*check)
311 if [ $build_status -eq 0 ]; then
312 record_status command make "$@"
313 else
314 echo "(skipped because the build failed)"
315 fi
316 ;;
317 *)
318 record_status command make "$@"
319 build_status=$last_status
320 ;;
321 esac
322 }
323 final_report () {
324 if [ $failure_count -gt 0 ]; then
325 echo
326 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
327 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
328 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
329 elif [ -z "${1-}" ]; then
330 echo "SUCCESS :)"
331 fi
332 if [ -n "${1-}" ]; then
333 echo "Killed by SIG$1."
334 fi
335 }
336else
337 record_status () {
338 "$@"
339 }
340fi
341if_build_succeeded () {
342 if [ $build_status -eq 0 ]; then
343 record_status "$@"
344 fi
345}
346
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200347# to be used instead of ! for commands run with
348# record_status or if_build_succeeded
349not() {
350 ! "$@"
351}
352
Andres AGd9eba4b2016-08-26 14:42:14 +0100353msg "info: $0 configuration"
354echo "MEMORY: $MEMORY"
355echo "FORCE: $FORCE"
Andres AG7770ea82016-10-10 15:46:20 +0100356echo "SEED: ${SEED-"UNSET"}"
Andres AGd9eba4b2016-08-26 14:42:14 +0100357echo "OPENSSL: $OPENSSL"
358echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
359echo "GNUTLS_CLI: $GNUTLS_CLI"
360echo "GNUTLS_SERV: $GNUTLS_SERV"
361echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
362echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
Andres AG87bb5772016-09-27 15:05:15 +0100363echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
364echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
365
366ARMC5_CC="$ARMC5_BIN_DIR/armcc"
367ARMC5_AR="$ARMC5_BIN_DIR/armar"
368ARMC6_CC="$ARMC6_BIN_DIR/armclang"
369ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100370
Andres AGb2fdd042016-09-22 14:17:46 +0100371# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
372# we just export the variables they require
373export OPENSSL_CMD="$OPENSSL"
374export GNUTLS_CLI="$GNUTLS_CLI"
375export GNUTLS_SERV="$GNUTLS_SERV"
376
Andres AG7770ea82016-10-10 15:46:20 +0100377# Avoid passing --seed flag in every call to ssl-opt.sh
Gilles Peskine38d81652018-03-21 08:40:26 +0100378if [ -n "${SEED-}" ]; then
379 export SEED
380fi
Andres AG7770ea82016-10-10 15:46:20 +0100381
Andres AGd9eba4b2016-08-26 14:42:14 +0100382# Make sure the tools we need are available.
383check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100384 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Andres Amaya Garciaddebc492017-10-24 22:16:34 +0100385 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100386if [ $RUN_ARMCC -ne 0 ]; then
387 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
388fi
Andres AGd9eba4b2016-08-26 14:42:14 +0100389
Gilles Peskine192c72f2017-12-21 15:59:21 +0100390
391
392################################################################
393#### Basic checks
394################################################################
SimonB2e23c822016-04-16 21:54:39 +0100395
396#
397# Test Suites to be executed
398#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200399# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100400# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200401# and/or are more likely to fail than others (eg I use Clang most of the
402# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200403# 2. Minimize total running time, by avoiding useless rebuilds
404#
405# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100406
Janos Follathb72c6782016-07-19 14:54:17 +0100407msg "info: output_env.sh"
Andres AGd9eba4b2016-08-26 14:42:14 +0100408OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
409 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
Andres AG87bb5772016-09-27 15:05:15 +0100410 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
Gilles Peskine26232962018-03-21 08:35:07 +0100411 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100412
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100413msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200414tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100415
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000416msg "test: freshness of generated source files" # < 1s
417tests/scripts/check-generated-files.sh
418
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200419msg "test: doxygen markup outside doxygen blocks" # < 1s
420tests/scripts/check-doxy-blocks.pl
421
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200422msg "test/build: declared and exported names" # < 3s
423cleanup
424tests/scripts/check-names.sh
425
Andres AGd9eba4b2016-08-26 14:42:14 +0100426msg "test: doxygen warnings" # ~ 3s
427cleanup
428tests/scripts/doxygen.sh
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100429
Gilles Peskine192c72f2017-12-21 15:59:21 +0100430
431
432################################################################
433#### Build and test many configurations and targets
434################################################################
435
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100436if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
437 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
438 # path, and uses whatever version of armcc it finds there.
Gilles Peskineda519252017-11-30 13:22:04 +0100439 msg "build: create and build yotta module" # ~ 30s
440 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100441 record_status tests/scripts/yotta-build.sh
Gilles Peskineda519252017-11-30 13:22:04 +0100442fi
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200443
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100444msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100445cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100446CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100447make
448
Simon Butcher8e3afc72016-09-15 17:13:08 +0100449msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100450make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200451
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100452msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100453if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200454
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100455msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskine396fac12018-03-22 22:26:03 +0100456record_status tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200457
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200458msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
459make
460
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100461msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100462if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200463
Simon Butcher3ea7f522016-03-07 23:22:10 +0000464msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
465cleanup
Simon Butcherf413b6f2016-03-14 22:32:42 +0000466cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcher3ea7f522016-03-07 23:22:10 +0000467scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
468CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
469make
470
Simon Butcher8e3afc72016-09-15 17:13:08 +0100471msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher3ea7f522016-03-07 23:22:10 +0000472make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000473
474msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100475if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
476if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000477
478msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100479if_build_succeeded tests/ssl-opt.sh
Simon Butcher3ea7f522016-03-07 23:22:10 +0000480
Hanno Becker134c2ab2017-10-12 15:29:50 +0100481msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
482cleanup
483cp "$CONFIG_H" "$CONFIG_BAK"
484scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
485CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
486make
487
488msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
489make test
490
491msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100492if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100493
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100494msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
495cleanup
496cp "$CONFIG_H" "$CONFIG_BAK"
497scripts/config.pl set MBEDTLS_RSA_NO_CRT
498CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
499make
500
501msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
502make test
503
504msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
505tests/ssl-opt.sh -f RSA
506
507msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
508tests/compat.sh -t RSA
509
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200510msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200511cleanup
Janos Follath35d48cb2016-04-22 14:45:00 +0100512cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200513scripts/config.pl full
514scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Simon Butcherf95c1762016-11-10 17:25:58 +0000515CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200516make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100517
518msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200519make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200520
521msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskine7c652162017-12-11 00:01:40 +0100522if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200523
524msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100525if_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 +0200526
527msg "test/build: curves.pl (gcc)" # ~ 4 min
528cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100529record_status tests/scripts/curves.pl
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200530
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200531msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
532cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100533record_status tests/scripts/depends-hashes.pl
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200534
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200535msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
536cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100537record_status tests/scripts/depends-pkalgs.pl
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200538
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200539msg "test/build: key-exchanges (gcc)" # ~ 1 min
540cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100541record_status tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200542
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000543msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100544cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100545make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100546
Simon Butcherf95c1762016-11-10 17:25:58 +0000547# Full configuration build, without platform support, file IO and net sockets.
548# This should catch missing mbedtls_printf definitions, and by disabling file
549# IO, it should catch missing '#include <stdio.h>'
550msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000551cleanup
552cp "$CONFIG_H" "$CONFIG_BAK"
553scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554scripts/config.pl unset MBEDTLS_PLATFORM_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000555scripts/config.pl unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100557scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
558scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
559scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Simon Butcherb9283432016-07-13 11:02:41 +0100560scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100561scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Simon Butcher284b4c92016-06-26 13:10:00 +0100562scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200563scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
564scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchercb587002017-01-06 16:14:44 +0000565# Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
566# to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine7c652162017-12-11 00:01:40 +0100567make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
568make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000569
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100570# catch compile bugs in _uninit functions
571msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
572cleanup
573cp "$CONFIG_H" "$CONFIG_BAK"
574scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100575scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Simon Butchereebf1b92016-06-27 01:42:39 +0100576scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine7c652162017-12-11 00:01:40 +0100577make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100578
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200579msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
580cleanup
581cp "$CONFIG_H" "$CONFIG_BAK"
582scripts/config.pl full
583scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100584make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200585
586msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
587cleanup
588cp "$CONFIG_H" "$CONFIG_BAK"
589scripts/config.pl full
590scripts/config.pl unset MBEDTLS_SSL_CLI_C
Hanno Beckerd485c312018-01-05 13:03:53 +0000591make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200592
Simon Butcherf95c1762016-11-10 17:25:58 +0000593# Note, C99 compliance can also be tested with the sockets support disabled,
594# as that requires a POSIX platform (which isn't the same as C99).
Andres AG788aa4a2016-09-14 14:32:09 +0100595msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200596cleanup
597cp "$CONFIG_H" "$CONFIG_BAK"
598scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200599scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
600scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine7c652162017-12-11 00:01:40 +0100601make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200602
Hanno Becker5175ac62017-09-18 15:36:25 +0100603msg "build: default config except MFL extension (ASan build)" # ~ 30s
604cleanup
605cp "$CONFIG_H" "$CONFIG_BAK"
606scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
607CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
608make
609
610msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine7c652162017-12-11 00:01:40 +0100611if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000612
Simon Butcherab5df402016-06-11 02:31:21 +0100613msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100614cleanup
615cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcherab5df402016-06-11 02:31:21 +0100616scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
Janos Follath06c54002016-06-09 13:57:40 +0100617scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
618scripts/config.pl set MBEDTLS_ENTROPY_C
619scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
620scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
621scripts/config.pl unset MBEDTLS_HAVEGE_C
Simon Butchereebf1b92016-06-27 01:42:39 +0100622CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
Janos Follath06c54002016-06-09 13:57:40 +0100623make
624
Simon Butcher8e3afc72016-09-15 17:13:08 +0100625msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100626make test
Janos Follath06c54002016-06-09 13:57:40 +0100627
Hanno Becker83ebf782017-07-07 12:29:15 +0100628msg "build: default config with AES_FEWER_TABLES enabled"
629cleanup
630cp "$CONFIG_H" "$CONFIG_BAK"
631scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100632make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100633
634msg "test: AES_FEWER_TABLES"
635make test
636
637msg "build: default config with AES_ROM_TABLES enabled"
638cleanup
639cp "$CONFIG_H" "$CONFIG_BAK"
640scripts/config.pl set MBEDTLS_AES_ROM_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100641make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100642
643msg "test: AES_ROM_TABLES"
644make test
645
646msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
647cleanup
648cp "$CONFIG_H" "$CONFIG_BAK"
649scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
650scripts/config.pl set MBEDTLS_AES_ROM_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100651make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100652
653msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
654make test
655
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200656if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100657 msg "build/test: make shared" # ~ 40s
658 cleanup
659 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200660fi
661
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000662if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100663 msg "build: i386, make, gcc" # ~ 30s
664 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100665 make CC=gcc CFLAGS='-Werror -Wall -Wextra -m32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100666
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100667 msg "test: i386, make, gcc"
668 make test
669
670 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
671 cleanup
672 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
673
674 msg "test: 64-bit ILP32, make, gcc"
675 make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000676fi # x86_64
677
Gilles Peskine14c3c062018-01-29 21:25:12 +0100678msg "build: gcc, force 32-bit bignum limbs"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100679cleanup
680cp "$CONFIG_H" "$CONFIG_BAK"
681scripts/config.pl unset MBEDTLS_HAVE_ASM
682scripts/config.pl unset MBEDTLS_AESNI_C
683scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine14c3c062018-01-29 21:25:12 +0100684make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100685
Gilles Peskine14c3c062018-01-29 21:25:12 +0100686msg "test: gcc, force 32-bit bignum limbs"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100687make test
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100688
Gilles Peskine14c3c062018-01-29 21:25:12 +0100689msg "build: gcc, force 64-bit bignum limbs"
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100690cleanup
691cp "$CONFIG_H" "$CONFIG_BAK"
692scripts/config.pl unset MBEDTLS_HAVE_ASM
693scripts/config.pl unset MBEDTLS_AESNI_C
694scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine14c3c062018-01-29 21:25:12 +0100695make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
696
697msg "test: gcc, force 64-bit bignum limbs"
698make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000699
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200700
701msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
702cleanup
703cp "$CONFIG_H" "$CONFIG_BAK"
704scripts/config.pl full
705scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
706scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
707make CFLAGS='-Werror -O1'
708
709msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
710make test
711
712
713msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
714cleanup
715cp "$CONFIG_H" "$CONFIG_BAK"
716scripts/config.pl full
717scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
718scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
719make CFLAGS='-Werror -O1'
720
721msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
722make test
723
724
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000725msg "build: arm-none-eabi-gcc, make" # ~ 10s
726cleanup
727cp "$CONFIG_H" "$CONFIG_BAK"
728scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729scripts/config.pl unset MBEDTLS_NET_C
730scripts/config.pl unset MBEDTLS_TIMING_C
731scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchereebf1b92016-06-27 01:42:39 +0100732scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherbc6a4862016-03-07 17:35:59 +0000733scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000734# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200735scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
736scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
737scripts/config.pl unset MBEDTLS_THREADING_C
738scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
739scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine7c652162017-12-11 00:01:40 +0100740make 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 +0000741
Gilles Peskineed942f82017-06-08 15:19:20 +0200742msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
743cleanup
Simon Butcher940737f2017-07-23 13:42:36 +0200744cp "$CONFIG_H" "$CONFIG_BAK"
Andres Amaya Garcia05931972017-07-20 13:27:35 +0100745scripts/config.pl full
746scripts/config.pl unset MBEDTLS_NET_C
747scripts/config.pl unset MBEDTLS_TIMING_C
748scripts/config.pl unset MBEDTLS_FS_IO
749scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
750scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
751# following things are not in the default config
752scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
753scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
754scripts/config.pl unset MBEDTLS_THREADING_C
755scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
756scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskineed942f82017-06-08 15:19:20 +0200757scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine7c652162017-12-11 00:01:40 +0100758make 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 +0200759echo "Checking that software 64-bit division is not required"
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200760if_build_succeeded not grep __aeabi_uldiv library/*.o
761
762msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
763cleanup
764cp "$CONFIG_H" "$CONFIG_BAK"
765scripts/config.pl full
766scripts/config.pl unset MBEDTLS_NET_C
767scripts/config.pl unset MBEDTLS_TIMING_C
768scripts/config.pl unset MBEDTLS_FS_IO
769scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
770scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
771# following things are not in the default config
772scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
773scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
774scripts/config.pl unset MBEDTLS_THREADING_C
775scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
776scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
777scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
778make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
779echo "Checking that software 64-bit multiplication is not required"
780if_build_succeeded not grep __aeabi_lmul library/*.o
Gilles Peskineed942f82017-06-08 15:19:20 +0200781
Andres AG87bb5772016-09-27 15:05:15 +0100782msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100783cleanup
784cp "$CONFIG_H" "$CONFIG_BAK"
785scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200786scripts/config.pl unset MBEDTLS_NET_C
787scripts/config.pl unset MBEDTLS_TIMING_C
788scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher1c719652016-06-27 19:02:12 +0100789scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200790scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200791scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherbc6a4862016-03-07 17:35:59 +0000792scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100793# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200794scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
795scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
796scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
797scripts/config.pl unset MBEDTLS_THREADING_C
798scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
799scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcher4df5eaf2016-08-24 22:58:31 +0300800scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Andres AG87bb5772016-09-27 15:05:15 +0100801
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100802if [ $RUN_ARMCC -ne 0 ]; then
803 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
804 make clean
Andres AG87bb5772016-09-27 15:05:15 +0100805
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100806 # ARM Compiler 6 - Target ARMv7-A
807 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +0200808
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100809 # ARM Compiler 6 - Target ARMv7-M
810 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +0200811
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100812 # ARM Compiler 6 - Target ARMv8-A - AArch32
813 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +0200814
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100815 # ARM Compiler 6 - Target ARMv8-M
816 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +0200817
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100818 # ARM Compiler 6 - Target ARMv8-A - AArch64
819 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
820fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100821
Gilles Peskine2a458da2017-05-12 15:26:58 +0200822msg "build: allow SHA1 in certificates by default"
823cleanup
824cp "$CONFIG_H" "$CONFIG_BAK"
825scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine7c652162017-12-11 00:01:40 +0100826make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine2a458da2017-05-12 15:26:58 +0200827msg "test: allow SHA1 in certificates by default"
828make test
Gilles Peskine7c652162017-12-11 00:01:40 +0100829if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine2a458da2017-05-12 15:26:58 +0200830
Hanno Beckerd485c312018-01-05 13:03:53 +0000831msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min
Hanno Beckere963efa2018-01-03 10:03:43 +0000832cleanup
833cp "$CONFIG_H" "$CONFIG_BAK"
834scripts/config.pl set MBEDTLS_RSA_NO_CRT
Hanno Beckerd485c312018-01-05 13:03:53 +0000835CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
836make
Hanno Beckere963efa2018-01-03 10:03:43 +0000837
838msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)"
839make test
Simon Butcher002bc622016-11-17 09:27:45 +0000840
841msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
842cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100843make 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 +0200844
Manuel Pégourié-Gonnarde33316c2015-08-07 13:17:23 +0200845# note Make tests only builds the tests, but doesn't run them
Gilles Peskine7c652162017-12-11 00:01:40 +0100846make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
847make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100848
849msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Gilles Peskine7c652162017-12-11 00:01:40 +0100850make 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
851make 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
852make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100853
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000854# MemSan currently only available on Linux 64 bits
855if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000856
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100857 msg "build: MSan (clang)" # ~ 1 min 20s
858 cleanup
859 cp "$CONFIG_H" "$CONFIG_BAK"
860 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
861 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
862 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200863
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100864 msg "test: main suites (MSan)" # ~ 10s
865 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100866
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100867 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100868 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100869
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100870 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100871
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100872 if [ "$MEMORY" -gt 0 ]; then
873 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +0100874 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100875 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100876
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000877else # no MemSan
878
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100879 msg "build: Release (clang)"
880 cleanup
881 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
882 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000883
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100884 msg "test: main suites valgrind (Release)"
885 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000886
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100887 # Optional part(s)
888 # Currently broken, programs don't seem to receive signals
889 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000890
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100891 if [ "$MEMORY" -gt 0 ]; then
892 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100893 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100894 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000895
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100896 if [ "$MEMORY" -gt 1 ]; then
897 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100898 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100899 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000900
901fi # MemSan
902
Andres AGdc192212016-08-31 17:33:13 +0100903msg "build: cmake 'out-of-source' build"
904cleanup
905MBEDTLS_ROOT_DIR="$PWD"
906mkdir "$OUT_OF_SOURCE_DIR"
907cd "$OUT_OF_SOURCE_DIR"
908cmake "$MBEDTLS_ROOT_DIR"
909make
910
911msg "test: cmake 'out-of-source' build"
912make test
913cd "$MBEDTLS_ROOT_DIR"
914rm -rf "$OUT_OF_SOURCE_DIR"
915
Andres Amaya Garcia29673812017-10-25 10:35:51 +0100916for optimization_flag in -O2 -O3 -Ofast -Os; do
917 for compiler in clang gcc; do
Andres Amaya Garcia708c5cb2018-04-24 08:33:31 -0500918 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Andres Amaya Garcia29673812017-10-25 10:35:51 +0100919 cleanup
920 CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag" make programs
921 gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx
922 done
923done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +0100924
Gilles Peskine192c72f2017-12-21 15:59:21 +0100925
926
927################################################################
928#### Termination
929################################################################
930
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100931msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100932cleanup
933
Gilles Peskine7c652162017-12-11 00:01:40 +0100934final_report