blob: 297611e579f0d62de2a1584de293efa6cf606545 [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"}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100103: ${OPENSSL_NEXT:="$OPENSSL"}
Andres AGd9eba4b2016-08-26 14:42:14 +0100104: ${GNUTLS_CLI:="gnutls-cli"}
105: ${GNUTLS_SERV:="gnutls-serv"}
106: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
107: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
Andres AGdc192212016-08-31 17:33:13 +0100108: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
Andres AG87bb5772016-09-27 15:05:15 +0100109: ${ARMC5_BIN_DIR:=/usr/bin}
110: ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100111
Andres AG38495a32016-07-12 16:54:33 +0100112# if MAKEFLAGS is not set add the -j option to speed up invocations of make
113if [ -n "${MAKEFLAGS+set}" ]; then
114 export MAKEFLAGS="-j"
115fi
116
Simon Butcher41eeccf2016-09-07 00:07:09 +0100117usage()
SimonB2e23c822016-04-16 21:54:39 +0100118{
Gilles Peskine709346a2017-12-10 23:43:39 +0100119 cat <<EOF
120Usage: $0 [OPTION]...
121 -h|--help Print this help.
122
123General options:
124 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100125 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100126 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100127 --armcc Run ARM Compiler builds (on by default).
128 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100129 --no-force Refuse to overwrite modified files (default).
130 --no-keep-going Stop at the first error (default).
131 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100132 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100133 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100134 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100135 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
136 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100137 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100138
139Tool path options:
140 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
141 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
142 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
143 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
144 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
145 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
146 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
147 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100148 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100149EOF
SimonB2e23c822016-04-16 21:54:39 +0100150}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100151
152# remove built files as well as the cmake cache/config
153cleanup()
154{
Gilles Peskine7c652162017-12-11 00:01:40 +0100155 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200156
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200157 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000158 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200159 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
160 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200161
162 if [ -f "$CONFIG_BAK" ]; then
163 mv "$CONFIG_BAK" "$CONFIG_H"
164 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100165}
166
Gilles Peskine7c652162017-12-11 00:01:40 +0100167# Executed on exit. May be redefined depending on command line options.
168final_report () {
169 :
170}
171
172fatal_signal () {
173 cleanup
174 final_report $1
175 trap - $1
176 kill -$1 $$
177}
178
179trap 'fatal_signal HUP' HUP
180trap 'fatal_signal INT' INT
181trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200182
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100183msg()
184{
185 echo ""
186 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100187 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000188 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100189 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100190 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100191}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100192
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100193if [ $RUN_ARMCC -ne 0 ]; then
194 armc6_build_test()
195 {
196 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100197
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100198 msg "build: ARM Compiler 6 ($FLAGS), make"
199 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
200 WARNING_CFLAGS='-xc -std=c99' make lib
201 make clean
202 }
203fi
Andres AGa5cd9732016-10-17 15:23:10 +0100204
Andres AGd9eba4b2016-08-26 14:42:14 +0100205err_msg()
206{
207 echo "$1" >&2
208}
209
210check_tools()
211{
212 for TOOL in "$@"; do
213 if ! `hash "$TOOL" >/dev/null 2>&1`; then
214 err_msg "$TOOL not found!"
215 exit 1
216 fi
217 done
218}
219
SimonB2e23c822016-04-16 21:54:39 +0100220while [ $# -gt 0 ]; do
221 case "$1" in
Gilles Peskine8a244c92018-03-21 08:39:32 +0100222 --armcc) RUN_ARMCC=1;;
223 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
224 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
225 --force|-f) FORCE=1;;
226 --gnutls-cli) shift; GNUTLS_CLI="$1";;
227 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
228 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
229 --gnutls-serv) shift; GNUTLS_SERV="$1";;
230 --help|-h) usage; exit;;
231 --keep-going|-k) KEEP_GOING=1;;
232 --memory|-m) MEMORY=1;;
233 --no-armcc) RUN_ARMCC=0;;
Gilles Peskine38d81652018-03-21 08:40:26 +0100234 --no-force) FORCE=0;;
235 --no-keep-going) KEEP_GOING=0;;
236 --no-memory) MEMORY=0;;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100237 --no-yotta) YOTTA=0;;
238 --openssl) shift; OPENSSL="$1";;
239 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
Manuel Pégourié-Gonnarda3712be2018-05-22 15:58:50 +0200240 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100241 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Gilles Peskine38d81652018-03-21 08:40:26 +0100242 --random-seed) unset SEED;;
243 --release-test|-r) SEED=1;;
Gilles Peskine8a244c92018-03-21 08:39:32 +0100244 --seed|-s) shift; SEED="$1";;
245 --yotta) YOTTA=1;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100246 *)
247 echo >&2 "Unknown option: $1"
248 echo >&2 "Run $0 --help for usage."
249 exit 120
SimonB2e23c822016-04-16 21:54:39 +0100250 ;;
251 esac
252 shift
253done
254
255if [ $FORCE -eq 1 ]; then
Gilles Peskineda519252017-11-30 13:22:04 +0100256 if [ $YOTTA -eq 1 ]; then
257 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
258 fi
SimonB2e23c822016-04-16 21:54:39 +0100259 git checkout-index -f -q $CONFIG_H
260 cleanup
261else
262
Gilles Peskine2a22a802017-12-21 15:19:00 +0100263 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100264 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
SimonB2e23c822016-04-16 21:54:39 +0100265 echo "You can either delete your work and retry, or force the test to overwrite the"
266 echo "test by rerunning the script as: $0 --force"
267 exit 1
268 fi
269
Andres AGdc192212016-08-31 17:33:13 +0100270 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
271 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
272 echo "You can either delete this directory manually, or force the test by rerunning"
273 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
274 exit 1
275 fi
276
SimonB2e23c822016-04-16 21:54:39 +0100277 if ! git diff-files --quiet include/mbedtls/config.h; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100278 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
SimonB2e23c822016-04-16 21:54:39 +0100279 echo "You can either delete or preserve your work, or force the test by rerunning the"
280 echo "script as: $0 --force"
281 exit 1
282 fi
283fi
284
Gilles Peskine7c652162017-12-11 00:01:40 +0100285build_status=0
286if [ $KEEP_GOING -eq 1 ]; then
287 failure_summary=
288 failure_count=0
289 start_red=
290 end_color=
291 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100292 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100293 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
294 start_red=$(printf '\033[31m')
295 end_color=$(printf '\033[0m')
296 ;;
297 esac
298 fi
299 record_status () {
300 if "$@"; then
301 last_status=0
302 else
303 last_status=$?
304 text="$current_section: $* -> $last_status"
305 failure_summary="$failure_summary
306$text"
307 failure_count=$((failure_count + 1))
308 echo "${start_red}^^^^$text^^^^${end_color}"
309 fi
310 }
311 make () {
312 case "$*" in
313 *test|*check)
314 if [ $build_status -eq 0 ]; then
315 record_status command make "$@"
316 else
317 echo "(skipped because the build failed)"
318 fi
319 ;;
320 *)
321 record_status command make "$@"
322 build_status=$last_status
323 ;;
324 esac
325 }
326 final_report () {
327 if [ $failure_count -gt 0 ]; then
328 echo
329 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
330 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
331 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
332 elif [ -z "${1-}" ]; then
333 echo "SUCCESS :)"
334 fi
335 if [ -n "${1-}" ]; then
336 echo "Killed by SIG$1."
337 fi
338 }
339else
340 record_status () {
341 "$@"
342 }
343fi
344if_build_succeeded () {
345 if [ $build_status -eq 0 ]; then
346 record_status "$@"
347 fi
348}
349
Andres AGd9eba4b2016-08-26 14:42:14 +0100350msg "info: $0 configuration"
351echo "MEMORY: $MEMORY"
352echo "FORCE: $FORCE"
Andres AG7770ea82016-10-10 15:46:20 +0100353echo "SEED: ${SEED-"UNSET"}"
Andres AGd9eba4b2016-08-26 14:42:14 +0100354echo "OPENSSL: $OPENSSL"
355echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100356echo "OPENSSL_NEXT: $OPENSSL_NEXT"
Andres AGd9eba4b2016-08-26 14:42:14 +0100357echo "GNUTLS_CLI: $GNUTLS_CLI"
358echo "GNUTLS_SERV: $GNUTLS_SERV"
359echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
360echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
Andres AG87bb5772016-09-27 15:05:15 +0100361echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
362echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
363
364ARMC5_CC="$ARMC5_BIN_DIR/armcc"
365ARMC5_AR="$ARMC5_BIN_DIR/armar"
366ARMC6_CC="$ARMC6_BIN_DIR/armclang"
367ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100368
Andres AGb2fdd042016-09-22 14:17:46 +0100369# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
370# we just export the variables they require
371export OPENSSL_CMD="$OPENSSL"
372export GNUTLS_CLI="$GNUTLS_CLI"
373export GNUTLS_SERV="$GNUTLS_SERV"
374
Andres AG7770ea82016-10-10 15:46:20 +0100375# Avoid passing --seed flag in every call to ssl-opt.sh
Gilles Peskine38d81652018-03-21 08:40:26 +0100376if [ -n "${SEED-}" ]; then
377 export SEED
378fi
Andres AG7770ea82016-10-10 15:46:20 +0100379
Andres AGd9eba4b2016-08-26 14:42:14 +0100380# Make sure the tools we need are available.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100381check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
382 "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100383 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Andres Amaya Garciaddebc492017-10-24 22:16:34 +0100384 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100385if [ $RUN_ARMCC -ne 0 ]; then
386 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
387fi
Andres AGd9eba4b2016-08-26 14:42:14 +0100388
Gilles Peskine192c72f2017-12-21 15:59:21 +0100389
390
391################################################################
392#### Basic checks
393################################################################
SimonB2e23c822016-04-16 21:54:39 +0100394
395#
396# Test Suites to be executed
397#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200398# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100399# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200400# and/or are more likely to fail than others (eg I use Clang most of the
401# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200402# 2. Minimize total running time, by avoiding useless rebuilds
403#
404# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100405
Janos Follathb72c6782016-07-19 14:54:17 +0100406msg "info: output_env.sh"
Andres AGd9eba4b2016-08-26 14:42:14 +0100407OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
408 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
Andres AG87bb5772016-09-27 15:05:15 +0100409 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
Gilles Peskine26232962018-03-21 08:35:07 +0100410 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100411
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100412msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200413tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100414
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000415msg "test: freshness of generated source files" # < 1s
416tests/scripts/check-generated-files.sh
417
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200418msg "test: doxygen markup outside doxygen blocks" # < 1s
419tests/scripts/check-doxy-blocks.pl
420
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200421msg "test/build: declared and exported names" # < 3s
422cleanup
423tests/scripts/check-names.sh
424
Andres AGd9eba4b2016-08-26 14:42:14 +0100425msg "test: doxygen warnings" # ~ 3s
426cleanup
427tests/scripts/doxygen.sh
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100428
Gilles Peskine192c72f2017-12-21 15:59:21 +0100429
430
431################################################################
432#### Build and test many configurations and targets
433################################################################
434
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100435if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
436 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
437 # path, and uses whatever version of armcc it finds there.
Gilles Peskineda519252017-11-30 13:22:04 +0100438 msg "build: create and build yotta module" # ~ 30s
439 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100440 record_status tests/scripts/yotta-build.sh
Gilles Peskineda519252017-11-30 13:22:04 +0100441fi
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200442
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100443msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100444cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100445CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100446make
447
Simon Butcher8e3afc72016-09-15 17:13:08 +0100448msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100449make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200450
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100451msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100452if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200453
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100454msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskine396fac12018-03-22 22:26:03 +0100455record_status tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200456
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200457msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
458make
459
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100460msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100461if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200462
Simon Butcher3ea7f522016-03-07 23:22:10 +0000463msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
464cleanup
Simon Butcherf413b6f2016-03-14 22:32:42 +0000465cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcher3ea7f522016-03-07 23:22:10 +0000466scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
467CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
468make
469
Simon Butcher8e3afc72016-09-15 17:13:08 +0100470msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher3ea7f522016-03-07 23:22:10 +0000471make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000472
473msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100474if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
475if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000476
477msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100478if_build_succeeded tests/ssl-opt.sh
Simon Butcher3ea7f522016-03-07 23:22:10 +0000479
Hanno Becker134c2ab2017-10-12 15:29:50 +0100480msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
481cleanup
482cp "$CONFIG_H" "$CONFIG_BAK"
483scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
484CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
485make
486
487msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
488make test
489
490msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100491if_build_succeeded tests/ssl-opt.sh
Hanno Becker134c2ab2017-10-12 15:29:50 +0100492
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100493msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
494cleanup
495cp "$CONFIG_H" "$CONFIG_BAK"
496scripts/config.pl set MBEDTLS_RSA_NO_CRT
497CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
498make
499
500msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
501make test
502
503msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
504tests/ssl-opt.sh -f RSA
505
506msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
507tests/compat.sh -t RSA
508
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200509msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100510cleanup
Janos Follath35d48cb2016-04-22 14:45:00 +0100511cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200512scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200513scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Simon Butcherf95c1762016-11-10 17:25:58 +0000514CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200515make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100516
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100517msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnard602544e2017-06-20 10:49:24 +0200518make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200519
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100520msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskine7c652162017-12-11 00:01:40 +0100521if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200522
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100523msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100524if_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 +0200525
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100526msg "test: compat.sh ARIA"
527if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA'
528
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200529msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100530cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100531record_status tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100532
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200533msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
534cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100535record_status tests/scripts/depends-hashes.pl
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200536
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200537msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
538cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100539record_status tests/scripts/depends-pkalgs.pl
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100540
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200541msg "test/build: key-exchanges (gcc)" # ~ 1 min
542cleanup
Gilles Peskine396fac12018-03-22 22:26:03 +0100543record_status tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200544
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000545msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100546cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100547make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100548
Simon Butcherf95c1762016-11-10 17:25:58 +0000549# Full configuration build, without platform support, file IO and net sockets.
550# This should catch missing mbedtls_printf definitions, and by disabling file
551# IO, it should catch missing '#include <stdio.h>'
552msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000553cleanup
554cp "$CONFIG_H" "$CONFIG_BAK"
555scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556scripts/config.pl unset MBEDTLS_PLATFORM_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000557scripts/config.pl unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200558scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100559scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
560scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
561scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Simon Butcherb9283432016-07-13 11:02:41 +0100562scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100563scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Simon Butcher284b4c92016-06-26 13:10:00 +0100564scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200565scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
566scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchercb587002017-01-06 16:14:44 +0000567# Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
568# to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine7c652162017-12-11 00:01:40 +0100569make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
570make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000571
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100572# catch compile bugs in _uninit functions
573msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
574cleanup
575cp "$CONFIG_H" "$CONFIG_BAK"
576scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100577scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Simon Butchereebf1b92016-06-27 01:42:39 +0100578scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine7c652162017-12-11 00:01:40 +0100579make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100580
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200581msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
582cleanup
583cp "$CONFIG_H" "$CONFIG_BAK"
584scripts/config.pl full
585scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100586make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200587
588msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
589cleanup
590cp "$CONFIG_H" "$CONFIG_BAK"
591scripts/config.pl full
592scripts/config.pl unset MBEDTLS_SSL_CLI_C
Hanno Beckerd485c312018-01-05 13:03:53 +0000593make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200594
Simon Butcherf95c1762016-11-10 17:25:58 +0000595# Note, C99 compliance can also be tested with the sockets support disabled,
596# as that requires a POSIX platform (which isn't the same as C99).
Andres AG788aa4a2016-09-14 14:32:09 +0100597msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200598cleanup
599cp "$CONFIG_H" "$CONFIG_BAK"
600scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200601scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
602scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine7c652162017-12-11 00:01:40 +0100603make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200604
Hanno Becker5175ac62017-09-18 15:36:25 +0100605msg "build: default config except MFL extension (ASan build)" # ~ 30s
606cleanup
607cp "$CONFIG_H" "$CONFIG_BAK"
608scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
609CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
610make
611
612msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine7c652162017-12-11 00:01:40 +0100613if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Hanno Becker5175ac62017-09-18 15:36:25 +0100614
Simon Butcherab5df402016-06-11 02:31:21 +0100615msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100616cleanup
617cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcherab5df402016-06-11 02:31:21 +0100618scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
Janos Follath06c54002016-06-09 13:57:40 +0100619scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
620scripts/config.pl set MBEDTLS_ENTROPY_C
621scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
622scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
623scripts/config.pl unset MBEDTLS_HAVEGE_C
Simon Butchereebf1b92016-06-27 01:42:39 +0100624CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
Janos Follath06c54002016-06-09 13:57:40 +0100625make
626
Simon Butcher8e3afc72016-09-15 17:13:08 +0100627msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100628make test
Janos Follath06c54002016-06-09 13:57:40 +0100629
Hanno Becker83ebf782017-07-07 12:29:15 +0100630msg "build: default config with AES_FEWER_TABLES enabled"
631cleanup
632cp "$CONFIG_H" "$CONFIG_BAK"
633scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100634make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100635
636msg "test: AES_FEWER_TABLES"
637make test
638
639msg "build: default config with AES_ROM_TABLES enabled"
640cleanup
641cp "$CONFIG_H" "$CONFIG_BAK"
642scripts/config.pl set MBEDTLS_AES_ROM_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100643make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100644
645msg "test: AES_ROM_TABLES"
646make test
647
648msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
649cleanup
650cp "$CONFIG_H" "$CONFIG_BAK"
651scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
652scripts/config.pl set MBEDTLS_AES_ROM_TABLES
Hanno Becker98a67862018-03-27 17:10:09 +0100653make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100654
655msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
656make test
657
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200658if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100659 msg "build/test: make shared" # ~ 40s
660 cleanup
661 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200662fi
663
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000664if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100665 msg "build: i386, make, gcc" # ~ 30s
666 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100667 make CC=gcc CFLAGS='-Werror -Wall -Wextra -m32'
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100668
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100669 msg "test: i386, make, gcc"
670 make test
671
672 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
673 cleanup
674 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
675
676 msg "test: 64-bit ILP32, make, gcc"
677 make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000678fi # x86_64
679
Gilles Peskine14c3c062018-01-29 21:25:12 +0100680msg "build: gcc, force 32-bit bignum limbs"
681cleanup
682cp "$CONFIG_H" "$CONFIG_BAK"
683scripts/config.pl unset MBEDTLS_HAVE_ASM
684scripts/config.pl unset MBEDTLS_AESNI_C
685scripts/config.pl unset MBEDTLS_PADLOCK_C
686make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
687
688msg "test: gcc, force 32-bit bignum limbs"
689make test
690
691msg "build: gcc, force 64-bit bignum limbs"
692cleanup
693cp "$CONFIG_H" "$CONFIG_BAK"
694scripts/config.pl unset MBEDTLS_HAVE_ASM
695scripts/config.pl unset MBEDTLS_AESNI_C
696scripts/config.pl unset MBEDTLS_PADLOCK_C
697make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
698
699msg "test: gcc, force 64-bit bignum limbs"
700make test
701
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000702msg "build: arm-none-eabi-gcc, make" # ~ 10s
703cleanup
704cp "$CONFIG_H" "$CONFIG_BAK"
705scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200706scripts/config.pl unset MBEDTLS_NET_C
707scripts/config.pl unset MBEDTLS_TIMING_C
708scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchereebf1b92016-06-27 01:42:39 +0100709scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherbc6a4862016-03-07 17:35:59 +0000710scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000711# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200712scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
713scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
714scripts/config.pl unset MBEDTLS_THREADING_C
715scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
716scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine7c652162017-12-11 00:01:40 +0100717make 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 +0000718
Gilles Peskine9a9adcd2017-06-08 15:19:20 +0200719msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
720cleanup
Simon Butcher51aaa992017-07-23 13:42:36 +0200721cp "$CONFIG_H" "$CONFIG_BAK"
Andres Amaya Garcia6fb65862017-07-20 13:27:35 +0100722scripts/config.pl full
723scripts/config.pl unset MBEDTLS_NET_C
724scripts/config.pl unset MBEDTLS_TIMING_C
725scripts/config.pl unset MBEDTLS_FS_IO
726scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
727scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
728# following things are not in the default config
729scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
730scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
731scripts/config.pl unset MBEDTLS_THREADING_C
732scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
733scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine9a9adcd2017-06-08 15:19:20 +0200734scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine7c652162017-12-11 00:01:40 +0100735make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine9a9adcd2017-06-08 15:19:20 +0200736echo "Checking that software 64-bit division is not required"
737! grep __aeabi_uldiv library/*.o
738
Andres AG87bb5772016-09-27 15:05:15 +0100739msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100740cleanup
741cp "$CONFIG_H" "$CONFIG_BAK"
742scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200743scripts/config.pl unset MBEDTLS_NET_C
744scripts/config.pl unset MBEDTLS_TIMING_C
745scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher1c719652016-06-27 19:02:12 +0100746scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200747scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200748scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherbc6a4862016-03-07 17:35:59 +0000749scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100750# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200751scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
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
Simon Butcher4df5eaf2016-08-24 22:58:31 +0300757scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Andres AG87bb5772016-09-27 15:05:15 +0100758
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100759if [ $RUN_ARMCC -ne 0 ]; then
760 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
761 make clean
Andres AG87bb5772016-09-27 15:05:15 +0100762
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100763 # ARM Compiler 6 - Target ARMv7-A
764 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher51aaa992017-07-23 13:42:36 +0200765
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100766 # ARM Compiler 6 - Target ARMv7-M
767 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher51aaa992017-07-23 13:42:36 +0200768
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100769 # ARM Compiler 6 - Target ARMv8-A - AArch32
770 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher51aaa992017-07-23 13:42:36 +0200771
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100772 # ARM Compiler 6 - Target ARMv8-M
773 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher51aaa992017-07-23 13:42:36 +0200774
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100775 # ARM Compiler 6 - Target ARMv8-A - AArch64
776 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
777fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100778
Gilles Peskine2a458da2017-05-12 15:26:58 +0200779msg "build: allow SHA1 in certificates by default"
780cleanup
781cp "$CONFIG_H" "$CONFIG_BAK"
782scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine7c652162017-12-11 00:01:40 +0100783make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine2a458da2017-05-12 15:26:58 +0200784msg "test: allow SHA1 in certificates by default"
785make test
Gilles Peskine7c652162017-12-11 00:01:40 +0100786if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine2a458da2017-05-12 15:26:58 +0200787
Hanno Beckerd485c312018-01-05 13:03:53 +0000788msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min
Hanno Beckere963efa2018-01-03 10:03:43 +0000789cleanup
790cp "$CONFIG_H" "$CONFIG_BAK"
791scripts/config.pl set MBEDTLS_RSA_NO_CRT
Hanno Beckerd485c312018-01-05 13:03:53 +0000792CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
793make
Hanno Beckere963efa2018-01-03 10:03:43 +0000794
795msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)"
796make test
797
Simon Butcher002bc622016-11-17 09:27:45 +0000798msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100799cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100800make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Simon Butcher91aef332016-11-17 09:20:50 +0000801
Simon Butcher002bc622016-11-17 09:27:45 +0000802# note Make tests only builds the tests, but doesn't run them
Gilles Peskine7c652162017-12-11 00:01:40 +0100803make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
804make WINDOWS_BUILD=1 clean
Simon Butcherf95c1762016-11-10 17:25:58 +0000805
Simon Butcher002bc622016-11-17 09:27:45 +0000806msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Gilles Peskine7c652162017-12-11 00:01:40 +0100807make 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
808make 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
809make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100810
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000811# MemSan currently only available on Linux 64 bits
812if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000813
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100814 msg "build: MSan (clang)" # ~ 1 min 20s
815 cleanup
816 cp "$CONFIG_H" "$CONFIG_BAK"
817 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
818 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
819 make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100820
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100821 msg "test: main suites (MSan)" # ~ 10s
822 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100823
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100824 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100825 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100826
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100827 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100828
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100829 if [ "$MEMORY" -gt 0 ]; then
830 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +0100831 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100832 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100833
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000834else # no MemSan
835
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100836 msg "build: Release (clang)"
837 cleanup
838 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
839 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000840
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100841 msg "test: main suites valgrind (Release)"
842 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000843
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100844 # Optional part(s)
845 # Currently broken, programs don't seem to receive signals
846 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000847
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100848 if [ "$MEMORY" -gt 0 ]; then
849 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100850 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100851 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000852
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100853 if [ "$MEMORY" -gt 1 ]; then
854 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100855 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100856 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000857
858fi # MemSan
859
Andres AGdc192212016-08-31 17:33:13 +0100860msg "build: cmake 'out-of-source' build"
861cleanup
862MBEDTLS_ROOT_DIR="$PWD"
863mkdir "$OUT_OF_SOURCE_DIR"
864cd "$OUT_OF_SOURCE_DIR"
865cmake "$MBEDTLS_ROOT_DIR"
866make
867
868msg "test: cmake 'out-of-source' build"
869make test
870cd "$MBEDTLS_ROOT_DIR"
871rm -rf "$OUT_OF_SOURCE_DIR"
872
Andres Amaya Garcia29673812017-10-25 10:35:51 +0100873for optimization_flag in -O2 -O3 -Ofast -Os; do
874 for compiler in clang gcc; do
Andres Amaya Garcia708c5cb2018-04-24 08:33:31 -0500875 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Andres Amaya Garcia29673812017-10-25 10:35:51 +0100876 cleanup
877 CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag" make programs
878 gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx
879 done
880done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +0100881
Gilles Peskine192c72f2017-12-21 15:59:21 +0100882
883
884################################################################
885#### Termination
886################################################################
887
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100888msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100889cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100890
891final_report