blob: cbf4837e6d560177bac65b258bef8d399d0e64b7 [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
Andres AG7770ea82016-10-10 15:46:20 +010097RELEASE=0
Gilles Peskinebca6ab92017-12-19 18:24:31 +010098RUN_ARMCC=1
Gilles Peskineda519252017-11-30 13:22:04 +010099YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100100
Andres AGd9eba4b2016-08-26 14:42:14 +0100101# Default commands, can be overriden by the environment
102: ${OPENSSL:="openssl"}
103: ${OPENSSL_LEGACY:="$OPENSSL"}
104: ${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 Peskine2a22a802017-12-21 15:19:00 +0100129 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100130 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
131 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
132 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100133 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100134
135Tool path options:
136 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
137 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
138 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
139 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
140 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
141 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
142 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
143 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
144EOF
SimonB2e23c822016-04-16 21:54:39 +0100145}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100146
147# remove built files as well as the cmake cache/config
148cleanup()
149{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100150 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
151 cd "$MBEDTLS_ROOT_DIR"
152 fi
153
Gilles Peskine7c652162017-12-11 00:01:40 +0100154 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200155
Gilles Peskine31b07e22018-03-21 12:15:06 +0100156 # Remove CMake artefacts
157 find . -name .git -prune -o -name yotta -prune -o \
158 -iname CMakeFiles -exec rm -rf {} \+ -o \
159 \( -iname cmake_install.cmake -o \
160 -iname CTestTestfile.cmake -o \
161 -iname CMakeCache.txt \) -exec rm {} \+
162 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000163 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200164 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
165 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200166
167 if [ -f "$CONFIG_BAK" ]; then
168 mv "$CONFIG_BAK" "$CONFIG_H"
169 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100170}
171
Gilles Peskine7c652162017-12-11 00:01:40 +0100172# Executed on exit. May be redefined depending on command line options.
173final_report () {
174 :
175}
176
177fatal_signal () {
178 cleanup
179 final_report $1
180 trap - $1
181 kill -$1 $$
182}
183
184trap 'fatal_signal HUP' HUP
185trap 'fatal_signal INT' INT
186trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200187
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100188msg()
189{
190 echo ""
191 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100192 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000193 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100194 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100195 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100196}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100197
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100198if [ $RUN_ARMCC -ne 0 ]; then
199 armc6_build_test()
200 {
201 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100202
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100203 msg "build: ARM Compiler 6 ($FLAGS), make"
204 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
205 WARNING_CFLAGS='-xc -std=c99' make lib
206 make clean
207 }
208fi
Andres AGa5cd9732016-10-17 15:23:10 +0100209
Andres AGd9eba4b2016-08-26 14:42:14 +0100210err_msg()
211{
212 echo "$1" >&2
213}
214
215check_tools()
216{
217 for TOOL in "$@"; do
218 if ! `hash "$TOOL" >/dev/null 2>&1`; then
219 err_msg "$TOOL not found!"
220 exit 1
221 fi
222 done
223}
224
SimonB2e23c822016-04-16 21:54:39 +0100225while [ $# -gt 0 ]; do
226 case "$1" in
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100227 --armcc)
228 RUN_ARMCC=1
Andres AGd9eba4b2016-08-26 14:42:14 +0100229 ;;
Andres AG87bb5772016-09-27 15:05:15 +0100230 --armc5-bin-dir)
231 shift
232 ARMC5_BIN_DIR="$1"
233 ;;
234 --armc6-bin-dir)
235 shift
236 ARMC6_BIN_DIR="$1"
237 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100238 --force|-f)
239 FORCE=1
240 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100241 --gnutls-cli)
242 shift
243 GNUTLS_CLI="$1"
244 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100245 --gnutls-legacy-cli)
SimonB2e23c822016-04-16 21:54:39 +0100246 shift
247 GNUTLS_LEGACY_CLI="$1"
248 ;;
249 --gnutls-legacy-serv)
250 shift
251 GNUTLS_LEGACY_SERV="$1"
252 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100253 --gnutls-serv)
SimonB2e23c822016-04-16 21:54:39 +0100254 shift
Gilles Peskine709346a2017-12-10 23:43:39 +0100255 GNUTLS_SERV="$1"
SimonB2e23c822016-04-16 21:54:39 +0100256 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100257 --help|-h)
Andres AGd9eba4b2016-08-26 14:42:14 +0100258 usage
Gilles Peskine709346a2017-12-10 23:43:39 +0100259 exit
260 ;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100261 --keep-going|-k)
262 KEEP_GOING=1
263 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100264 --memory|-m)
265 MEMORY=1
266 ;;
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100267 --no-armcc)
268 RUN_ARMCC=0
269 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100270 --no-yotta)
271 YOTTA=0
272 ;;
273 --openssl)
274 shift
275 OPENSSL="$1"
276 ;;
277 --openssl-legacy)
278 shift
279 OPENSSL_LEGACY="$1"
280 ;;
281 --out-of-source-dir)
282 shift
283 OUT_OF_SOURCE_DIR="$1"
284 ;;
285 --release-test|-r)
286 RELEASE=1
287 ;;
288 --seed|-s)
289 shift
290 SEED="$1"
291 ;;
Gilles Peskine2a22a802017-12-21 15:19:00 +0100292 --yotta)
293 YOTTA=1
294 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100295 *)
296 echo >&2 "Unknown option: $1"
297 echo >&2 "Run $0 --help for usage."
298 exit 120
SimonB2e23c822016-04-16 21:54:39 +0100299 ;;
300 esac
301 shift
302done
303
304if [ $FORCE -eq 1 ]; then
Gilles Peskineda519252017-11-30 13:22:04 +0100305 if [ $YOTTA -eq 1 ]; then
306 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
307 fi
SimonB2e23c822016-04-16 21:54:39 +0100308 git checkout-index -f -q $CONFIG_H
309 cleanup
310else
311
Gilles Peskine2a22a802017-12-21 15:19:00 +0100312 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100313 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
SimonB2e23c822016-04-16 21:54:39 +0100314 echo "You can either delete your work and retry, or force the test to overwrite the"
315 echo "test by rerunning the script as: $0 --force"
316 exit 1
317 fi
318
Andres AGdc192212016-08-31 17:33:13 +0100319 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
320 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
321 echo "You can either delete this directory manually, or force the test by rerunning"
322 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
323 exit 1
324 fi
325
SimonB2e23c822016-04-16 21:54:39 +0100326 if ! git diff-files --quiet include/mbedtls/config.h; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100327 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
SimonB2e23c822016-04-16 21:54:39 +0100328 echo "You can either delete or preserve your work, or force the test by rerunning the"
329 echo "script as: $0 --force"
330 exit 1
331 fi
332fi
333
Gilles Peskine7c652162017-12-11 00:01:40 +0100334build_status=0
335if [ $KEEP_GOING -eq 1 ]; then
336 failure_summary=
337 failure_count=0
338 start_red=
339 end_color=
340 if [ -t 1 ]; then
341 case "$TERM" in
342 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
343 start_red=$(printf '\033[31m')
344 end_color=$(printf '\033[0m')
345 ;;
346 esac
347 fi
348 record_status () {
349 if "$@"; then
350 last_status=0
351 else
352 last_status=$?
353 text="$current_section: $* -> $last_status"
354 failure_summary="$failure_summary
355$text"
356 failure_count=$((failure_count + 1))
357 echo "${start_red}^^^^$text^^^^${end_color}"
358 fi
359 }
360 make () {
361 case "$*" in
362 *test|*check)
363 if [ $build_status -eq 0 ]; then
364 record_status command make "$@"
365 else
366 echo "(skipped because the build failed)"
367 fi
368 ;;
369 *)
370 record_status command make "$@"
371 build_status=$last_status
372 ;;
373 esac
374 }
375 final_report () {
376 if [ $failure_count -gt 0 ]; then
377 echo
378 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
379 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
380 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
381 elif [ -z "${1-}" ]; then
382 echo "SUCCESS :)"
383 fi
384 if [ -n "${1-}" ]; then
385 echo "Killed by SIG$1."
386 fi
387 }
388else
389 record_status () {
390 "$@"
391 }
392fi
393if_build_succeeded () {
394 if [ $build_status -eq 0 ]; then
395 record_status "$@"
396 fi
397}
398
Andres AG7770ea82016-10-10 15:46:20 +0100399if [ $RELEASE -eq 1 ]; then
400 # Fix the seed value to 1 to ensure that the tests are deterministic.
401 SEED=1
402fi
403
Andres AGd9eba4b2016-08-26 14:42:14 +0100404msg "info: $0 configuration"
405echo "MEMORY: $MEMORY"
406echo "FORCE: $FORCE"
Andres AG7770ea82016-10-10 15:46:20 +0100407echo "SEED: ${SEED-"UNSET"}"
Andres AGd9eba4b2016-08-26 14:42:14 +0100408echo "OPENSSL: $OPENSSL"
409echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
410echo "GNUTLS_CLI: $GNUTLS_CLI"
411echo "GNUTLS_SERV: $GNUTLS_SERV"
412echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
413echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
Andres AG87bb5772016-09-27 15:05:15 +0100414echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
415echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
416
417ARMC5_CC="$ARMC5_BIN_DIR/armcc"
418ARMC5_AR="$ARMC5_BIN_DIR/armar"
419ARMC6_CC="$ARMC6_BIN_DIR/armclang"
420ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100421
Andres AGb2fdd042016-09-22 14:17:46 +0100422# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
423# we just export the variables they require
424export OPENSSL_CMD="$OPENSSL"
425export GNUTLS_CLI="$GNUTLS_CLI"
426export GNUTLS_SERV="$GNUTLS_SERV"
427
Andres AG7770ea82016-10-10 15:46:20 +0100428# Avoid passing --seed flag in every call to ssl-opt.sh
429[ ! -z ${SEED+set} ] && export SEED
430
Andres AGd9eba4b2016-08-26 14:42:14 +0100431# Make sure the tools we need are available.
432check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100433 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100434 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
435if [ $RUN_ARMCC -ne 0 ]; then
436 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
437fi
Andres AGd9eba4b2016-08-26 14:42:14 +0100438
Gilles Peskine192c72f2017-12-21 15:59:21 +0100439
440
441################################################################
442#### Basic checks
443################################################################
SimonB2e23c822016-04-16 21:54:39 +0100444
445#
446# Test Suites to be executed
447#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200448# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100449# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200450# and/or are more likely to fail than others (eg I use Clang most of the
451# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200452# 2. Minimize total running time, by avoiding useless rebuilds
453#
454# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100455
Janos Follathb72c6782016-07-19 14:54:17 +0100456msg "info: output_env.sh"
Andres AGd9eba4b2016-08-26 14:42:14 +0100457OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
458 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
Andres AG87bb5772016-09-27 15:05:15 +0100459 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
460 ARMC6_CC="$ARMC6_CC" scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100461
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100462msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200463tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100464
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000465msg "test: freshness of generated source files" # < 1s
466tests/scripts/check-generated-files.sh
467
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200468msg "test: doxygen markup outside doxygen blocks" # < 1s
469tests/scripts/check-doxy-blocks.pl
470
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200471msg "test/build: declared and exported names" # < 3s
472cleanup
473tests/scripts/check-names.sh
474
Andres AGd9eba4b2016-08-26 14:42:14 +0100475msg "test: doxygen warnings" # ~ 3s
476cleanup
477tests/scripts/doxygen.sh
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100478
Gilles Peskine192c72f2017-12-21 15:59:21 +0100479
480
481################################################################
482#### Build and test many configurations and targets
483################################################################
484
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100485if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
486 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
487 # path, and uses whatever version of armcc it finds there.
Gilles Peskineda519252017-11-30 13:22:04 +0100488 msg "build: create and build yotta module" # ~ 30s
489 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100490 record_status tests/scripts/yotta-build.sh
Gilles Peskineda519252017-11-30 13:22:04 +0100491fi
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200492
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100493msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100494cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100495CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100496make
497
Simon Butcher8e3afc72016-09-15 17:13:08 +0100498msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100499make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200500
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100501msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100502if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200503
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100504msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +0100505if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200506
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200507msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
508make
509
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100510msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100511if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200512
Simon Butcher3ea7f522016-03-07 23:22:10 +0000513msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
514cleanup
Simon Butcherf413b6f2016-03-14 22:32:42 +0000515cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcher3ea7f522016-03-07 23:22:10 +0000516scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
517CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
518make
519
Simon Butcher8e3afc72016-09-15 17:13:08 +0100520msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher3ea7f522016-03-07 23:22:10 +0000521make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000522
523msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100524if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
525if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000526
527msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100528if_build_succeeded tests/ssl-opt.sh
Simon Butcher3ea7f522016-03-07 23:22:10 +0000529
Hanno Becker134c2ab2017-10-12 15:29:50 +0100530msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
531cleanup
532cp "$CONFIG_H" "$CONFIG_BAK"
533scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
534CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
535make
536
537msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
538make test
539
540msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100541if_build_succeeded tests/ssl-opt.sh
Hanno Becker134c2ab2017-10-12 15:29:50 +0100542
Simon Butcherf95c1762016-11-10 17:25:58 +0000543msg "build: cmake, full config, clang, C99" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100544cleanup
Janos Follath35d48cb2016-04-22 14:45:00 +0100545cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200546scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Simon Butcherf95c1762016-11-10 17:25:58 +0000548CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
Gilles Peskine7c652162017-12-11 00:01:40 +0100549make CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic'
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100550
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100551msg "test: main suites (full config)" # ~ 5s
Gilles Peskine7c652162017-12-11 00:01:40 +0100552make CFLAGS='-Werror -Wall -Wextra' test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200553
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100554msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskine7c652162017-12-11 00:01:40 +0100555if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200556
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100557msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100558if_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 +0200559
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200560msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100561cleanup
562cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskine7c652162017-12-11 00:01:40 +0100563if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100564
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200565msg "test/build: key-exchanges (gcc)" # ~ 1 min
566cleanup
567cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine7c652162017-12-11 00:01:40 +0100568if_build_succeeded tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200569
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000570msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100571cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100572make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100573
Simon Butcherf95c1762016-11-10 17:25:58 +0000574# Full configuration build, without platform support, file IO and net sockets.
575# This should catch missing mbedtls_printf definitions, and by disabling file
576# IO, it should catch missing '#include <stdio.h>'
577msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000578cleanup
579cp "$CONFIG_H" "$CONFIG_BAK"
580scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200581scripts/config.pl unset MBEDTLS_PLATFORM_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000582scripts/config.pl unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100584scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
585scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
586scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Simon Butcherb9283432016-07-13 11:02:41 +0100587scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100588scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Simon Butcher284b4c92016-06-26 13:10:00 +0100589scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
591scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchercb587002017-01-06 16:14:44 +0000592# Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
593# to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine7c652162017-12-11 00:01:40 +0100594make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
595make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000596
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100597# catch compile bugs in _uninit functions
598msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
599cleanup
600cp "$CONFIG_H" "$CONFIG_BAK"
601scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100602scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Simon Butchereebf1b92016-06-27 01:42:39 +0100603scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine7c652162017-12-11 00:01:40 +0100604make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100605
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200606msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
607cleanup
608cp "$CONFIG_H" "$CONFIG_BAK"
609scripts/config.pl full
610scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100611make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200612
613msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
614cleanup
615cp "$CONFIG_H" "$CONFIG_BAK"
616scripts/config.pl full
617scripts/config.pl unset MBEDTLS_SSL_CLI_C
Hanno Beckerd485c312018-01-05 13:03:53 +0000618make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200619
Simon Butcherf95c1762016-11-10 17:25:58 +0000620# Note, C99 compliance can also be tested with the sockets support disabled,
621# as that requires a POSIX platform (which isn't the same as C99).
Andres AG788aa4a2016-09-14 14:32:09 +0100622msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200623cleanup
624cp "$CONFIG_H" "$CONFIG_BAK"
625scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200626scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
627scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine7c652162017-12-11 00:01:40 +0100628make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200629
Hanno Becker5175ac62017-09-18 15:36:25 +0100630msg "build: default config except MFL extension (ASan build)" # ~ 30s
631cleanup
632cp "$CONFIG_H" "$CONFIG_BAK"
633scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
634CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
635make
636
637msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine7c652162017-12-11 00:01:40 +0100638if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Hanno Becker5175ac62017-09-18 15:36:25 +0100639
Simon Butcherab5df402016-06-11 02:31:21 +0100640msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100641cleanup
642cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcherab5df402016-06-11 02:31:21 +0100643scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
Janos Follath06c54002016-06-09 13:57:40 +0100644scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
645scripts/config.pl set MBEDTLS_ENTROPY_C
646scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
647scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
648scripts/config.pl unset MBEDTLS_HAVEGE_C
Simon Butchereebf1b92016-06-27 01:42:39 +0100649CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
Janos Follath06c54002016-06-09 13:57:40 +0100650make
651
Simon Butcher8e3afc72016-09-15 17:13:08 +0100652msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100653make test
Janos Follath06c54002016-06-09 13:57:40 +0100654
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200655if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100656 msg "build/test: make shared" # ~ 40s
657 cleanup
658 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200659fi
660
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000661if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100662 msg "build: i386, make, gcc" # ~ 30s
663 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100664 make CC=gcc CFLAGS='-Werror -Wall -Wextra -m32'
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100665
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100666 msg "build: gcc, force 32-bit compilation"
667 cleanup
668 cp "$CONFIG_H" "$CONFIG_BAK"
669 scripts/config.pl unset MBEDTLS_HAVE_ASM
670 scripts/config.pl unset MBEDTLS_AESNI_C
671 scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100672 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100673
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100674 msg "build: gcc, force 64-bit compilation"
675 cleanup
676 cp "$CONFIG_H" "$CONFIG_BAK"
677 scripts/config.pl unset MBEDTLS_HAVE_ASM
678 scripts/config.pl unset MBEDTLS_AESNI_C
679 scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100680 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Andres Amaya Garcia33264d72017-07-20 13:21:34 +0100681
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100682 msg "test: gcc, force 64-bit compilation"
683 make test
Andres Amaya Garcia33264d72017-07-20 13:21:34 +0100684
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100685 msg "build: gcc, force 64-bit compilation"
686 cleanup
687 cp "$CONFIG_H" "$CONFIG_BAK"
688 scripts/config.pl unset MBEDTLS_HAVE_ASM
689 scripts/config.pl unset MBEDTLS_AESNI_C
690 scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100691 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000692fi # x86_64
693
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000694msg "build: arm-none-eabi-gcc, make" # ~ 10s
695cleanup
696cp "$CONFIG_H" "$CONFIG_BAK"
697scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200698scripts/config.pl unset MBEDTLS_NET_C
699scripts/config.pl unset MBEDTLS_TIMING_C
700scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchereebf1b92016-06-27 01:42:39 +0100701scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherbc6a4862016-03-07 17:35:59 +0000702scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000703# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200704scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
705scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
706scripts/config.pl unset MBEDTLS_THREADING_C
707scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
708scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine7c652162017-12-11 00:01:40 +0100709make 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 +0000710
Gilles Peskine9a9adcd2017-06-08 15:19:20 +0200711msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
712cleanup
Simon Butcher51aaa992017-07-23 13:42:36 +0200713cp "$CONFIG_H" "$CONFIG_BAK"
Andres Amaya Garcia6fb65862017-07-20 13:27:35 +0100714scripts/config.pl full
715scripts/config.pl unset MBEDTLS_NET_C
716scripts/config.pl unset MBEDTLS_TIMING_C
717scripts/config.pl unset MBEDTLS_FS_IO
718scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
719scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
720# following things are not in the default config
721scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
722scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
723scripts/config.pl unset MBEDTLS_THREADING_C
724scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
725scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine9a9adcd2017-06-08 15:19:20 +0200726scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine7c652162017-12-11 00:01:40 +0100727make 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 +0200728echo "Checking that software 64-bit division is not required"
729! grep __aeabi_uldiv library/*.o
730
Andres AG87bb5772016-09-27 15:05:15 +0100731msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100732cleanup
733cp "$CONFIG_H" "$CONFIG_BAK"
734scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200735scripts/config.pl unset MBEDTLS_NET_C
736scripts/config.pl unset MBEDTLS_TIMING_C
737scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher1c719652016-06-27 19:02:12 +0100738scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200739scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200740scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherbc6a4862016-03-07 17:35:59 +0000741scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100742# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200743scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
744scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
745scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
746scripts/config.pl unset MBEDTLS_THREADING_C
747scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
748scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcher4df5eaf2016-08-24 22:58:31 +0300749scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Andres AG87bb5772016-09-27 15:05:15 +0100750
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100751if [ $RUN_ARMCC -ne 0 ]; then
752 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
753 make clean
Andres AG87bb5772016-09-27 15:05:15 +0100754
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100755 # ARM Compiler 6 - Target ARMv7-A
756 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher51aaa992017-07-23 13:42:36 +0200757
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100758 # ARM Compiler 6 - Target ARMv7-M
759 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher51aaa992017-07-23 13:42:36 +0200760
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100761 # ARM Compiler 6 - Target ARMv8-A - AArch32
762 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher51aaa992017-07-23 13:42:36 +0200763
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100764 # ARM Compiler 6 - Target ARMv8-M
765 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher51aaa992017-07-23 13:42:36 +0200766
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100767 # ARM Compiler 6 - Target ARMv8-A - AArch64
768 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
769fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100770
Gilles Peskine2a458da2017-05-12 15:26:58 +0200771msg "build: allow SHA1 in certificates by default"
772cleanup
773cp "$CONFIG_H" "$CONFIG_BAK"
774scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine7c652162017-12-11 00:01:40 +0100775make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine2a458da2017-05-12 15:26:58 +0200776msg "test: allow SHA1 in certificates by default"
777make test
Gilles Peskine7c652162017-12-11 00:01:40 +0100778if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine2a458da2017-05-12 15:26:58 +0200779
Hanno Beckerd485c312018-01-05 13:03:53 +0000780msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min
Hanno Beckere963efa2018-01-03 10:03:43 +0000781cleanup
782cp "$CONFIG_H" "$CONFIG_BAK"
783scripts/config.pl set MBEDTLS_RSA_NO_CRT
Hanno Beckerd485c312018-01-05 13:03:53 +0000784CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
785make
Hanno Beckere963efa2018-01-03 10:03:43 +0000786
787msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)"
788make test
789
Simon Butcher002bc622016-11-17 09:27:45 +0000790msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100791cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100792make 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 +0000793
Simon Butcher002bc622016-11-17 09:27:45 +0000794# note Make tests only builds the tests, but doesn't run them
Gilles Peskine7c652162017-12-11 00:01:40 +0100795make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
796make WINDOWS_BUILD=1 clean
Simon Butcherf95c1762016-11-10 17:25:58 +0000797
Simon Butcher002bc622016-11-17 09:27:45 +0000798msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Gilles Peskine7c652162017-12-11 00:01:40 +0100799make 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
800make 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
801make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100802
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000803# MemSan currently only available on Linux 64 bits
804if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000805
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100806 msg "build: MSan (clang)" # ~ 1 min 20s
807 cleanup
808 cp "$CONFIG_H" "$CONFIG_BAK"
809 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
810 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
811 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200812
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100813 msg "test: main suites (MSan)" # ~ 10s
814 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100815
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100816 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100817 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100818
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100819 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100820
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100821 if [ "$MEMORY" -gt 0 ]; then
822 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +0100823 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100824 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100825
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000826else # no MemSan
827
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100828 msg "build: Release (clang)"
829 cleanup
830 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
831 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000832
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100833 msg "test: main suites valgrind (Release)"
834 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000835
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100836 # Optional part(s)
837 # Currently broken, programs don't seem to receive signals
838 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000839
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100840 if [ "$MEMORY" -gt 0 ]; then
841 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100842 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100843 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000844
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100845 if [ "$MEMORY" -gt 1 ]; then
846 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100847 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100848 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000849
850fi # MemSan
851
Andres AGdc192212016-08-31 17:33:13 +0100852msg "build: cmake 'out-of-source' build"
853cleanup
854MBEDTLS_ROOT_DIR="$PWD"
855mkdir "$OUT_OF_SOURCE_DIR"
856cd "$OUT_OF_SOURCE_DIR"
857cmake "$MBEDTLS_ROOT_DIR"
858make
859
860msg "test: cmake 'out-of-source' build"
861make test
Gilles Peskine0114ffc2018-03-21 12:17:20 +0100862# Test an SSL option that requires an auxiliary script in test/scripts/.
863# Also ensure that there are no error messages such as
864# "No such file or directory", which would indicate that some required
865# file is missing (ssl-opt.sh tolerates the absence of some files so
866# may exit with status 0 but emit errors).
867if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
868if [ -s ssl-opt.err ]; then
869 cat ssl-opt.err >&2
870 record_status [ ! -s ssl-opt.err ]
871 rm ssl-opt.err
872fi
Andres AGdc192212016-08-31 17:33:13 +0100873cd "$MBEDTLS_ROOT_DIR"
874rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100875unset MBEDTLS_ROOT_DIR
Andres AGdc192212016-08-31 17:33:13 +0100876
Gilles Peskine192c72f2017-12-21 15:59:21 +0100877
878
879################################################################
880#### Termination
881################################################################
882
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100883msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100884cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100885
886final_report