blob: 7caebd5dc1e3a118c9d82c9aa56e9b6260b22045 [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 Peskine7c652162017-12-11 00:01:40 +0100150 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200151
Gilles Peskine31b07e22018-03-21 12:15:06 +0100152 # Remove CMake artefacts
153 find . -name .git -prune -o -name yotta -prune -o \
154 -iname CMakeFiles -exec rm -rf {} \+ -o \
155 \( -iname cmake_install.cmake -o \
156 -iname CTestTestfile.cmake -o \
157 -iname CMakeCache.txt \) -exec rm {} \+
158 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000159 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200160 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
161 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200162
163 if [ -f "$CONFIG_BAK" ]; then
164 mv "$CONFIG_BAK" "$CONFIG_H"
165 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100166}
167
Gilles Peskine7c652162017-12-11 00:01:40 +0100168# Executed on exit. May be redefined depending on command line options.
169final_report () {
170 :
171}
172
173fatal_signal () {
174 cleanup
175 final_report $1
176 trap - $1
177 kill -$1 $$
178}
179
180trap 'fatal_signal HUP' HUP
181trap 'fatal_signal INT' INT
182trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200183
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100184msg()
185{
186 echo ""
187 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100188 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000189 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100190 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100191 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100192}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100193
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100194if [ $RUN_ARMCC -ne 0 ]; then
195 armc6_build_test()
196 {
197 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100198
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100199 msg "build: ARM Compiler 6 ($FLAGS), make"
200 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
201 WARNING_CFLAGS='-xc -std=c99' make lib
202 make clean
203 }
204fi
Andres AGa5cd9732016-10-17 15:23:10 +0100205
Andres AGd9eba4b2016-08-26 14:42:14 +0100206err_msg()
207{
208 echo "$1" >&2
209}
210
211check_tools()
212{
213 for TOOL in "$@"; do
214 if ! `hash "$TOOL" >/dev/null 2>&1`; then
215 err_msg "$TOOL not found!"
216 exit 1
217 fi
218 done
219}
220
SimonB2e23c822016-04-16 21:54:39 +0100221while [ $# -gt 0 ]; do
222 case "$1" in
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100223 --armcc)
224 RUN_ARMCC=1
Andres AGd9eba4b2016-08-26 14:42:14 +0100225 ;;
Andres AG87bb5772016-09-27 15:05:15 +0100226 --armc5-bin-dir)
227 shift
228 ARMC5_BIN_DIR="$1"
229 ;;
230 --armc6-bin-dir)
231 shift
232 ARMC6_BIN_DIR="$1"
233 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100234 --force|-f)
235 FORCE=1
236 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100237 --gnutls-cli)
238 shift
239 GNUTLS_CLI="$1"
240 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100241 --gnutls-legacy-cli)
SimonB2e23c822016-04-16 21:54:39 +0100242 shift
243 GNUTLS_LEGACY_CLI="$1"
244 ;;
245 --gnutls-legacy-serv)
246 shift
247 GNUTLS_LEGACY_SERV="$1"
248 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100249 --gnutls-serv)
SimonB2e23c822016-04-16 21:54:39 +0100250 shift
Gilles Peskine709346a2017-12-10 23:43:39 +0100251 GNUTLS_SERV="$1"
SimonB2e23c822016-04-16 21:54:39 +0100252 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100253 --help|-h)
Andres AGd9eba4b2016-08-26 14:42:14 +0100254 usage
Gilles Peskine709346a2017-12-10 23:43:39 +0100255 exit
256 ;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100257 --keep-going|-k)
258 KEEP_GOING=1
259 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100260 --memory|-m)
261 MEMORY=1
262 ;;
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100263 --no-armcc)
264 RUN_ARMCC=0
265 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100266 --no-yotta)
267 YOTTA=0
268 ;;
269 --openssl)
270 shift
271 OPENSSL="$1"
272 ;;
273 --openssl-legacy)
274 shift
275 OPENSSL_LEGACY="$1"
276 ;;
277 --out-of-source-dir)
278 shift
279 OUT_OF_SOURCE_DIR="$1"
280 ;;
281 --release-test|-r)
282 RELEASE=1
283 ;;
284 --seed|-s)
285 shift
286 SEED="$1"
287 ;;
Gilles Peskine2a22a802017-12-21 15:19:00 +0100288 --yotta)
289 YOTTA=1
290 ;;
Gilles Peskine709346a2017-12-10 23:43:39 +0100291 *)
292 echo >&2 "Unknown option: $1"
293 echo >&2 "Run $0 --help for usage."
294 exit 120
SimonB2e23c822016-04-16 21:54:39 +0100295 ;;
296 esac
297 shift
298done
299
300if [ $FORCE -eq 1 ]; then
Gilles Peskineda519252017-11-30 13:22:04 +0100301 if [ $YOTTA -eq 1 ]; then
302 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
303 fi
SimonB2e23c822016-04-16 21:54:39 +0100304 git checkout-index -f -q $CONFIG_H
305 cleanup
306else
307
Gilles Peskine2a22a802017-12-21 15:19:00 +0100308 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100309 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
SimonB2e23c822016-04-16 21:54:39 +0100310 echo "You can either delete your work and retry, or force the test to overwrite the"
311 echo "test by rerunning the script as: $0 --force"
312 exit 1
313 fi
314
Andres AGdc192212016-08-31 17:33:13 +0100315 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
316 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
317 echo "You can either delete this directory manually, or force the test by rerunning"
318 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
319 exit 1
320 fi
321
SimonB2e23c822016-04-16 21:54:39 +0100322 if ! git diff-files --quiet include/mbedtls/config.h; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100323 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
SimonB2e23c822016-04-16 21:54:39 +0100324 echo "You can either delete or preserve your work, or force the test by rerunning the"
325 echo "script as: $0 --force"
326 exit 1
327 fi
328fi
329
Gilles Peskine7c652162017-12-11 00:01:40 +0100330build_status=0
331if [ $KEEP_GOING -eq 1 ]; then
332 failure_summary=
333 failure_count=0
334 start_red=
335 end_color=
336 if [ -t 1 ]; then
337 case "$TERM" in
338 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
339 start_red=$(printf '\033[31m')
340 end_color=$(printf '\033[0m')
341 ;;
342 esac
343 fi
344 record_status () {
345 if "$@"; then
346 last_status=0
347 else
348 last_status=$?
349 text="$current_section: $* -> $last_status"
350 failure_summary="$failure_summary
351$text"
352 failure_count=$((failure_count + 1))
353 echo "${start_red}^^^^$text^^^^${end_color}"
354 fi
355 }
356 make () {
357 case "$*" in
358 *test|*check)
359 if [ $build_status -eq 0 ]; then
360 record_status command make "$@"
361 else
362 echo "(skipped because the build failed)"
363 fi
364 ;;
365 *)
366 record_status command make "$@"
367 build_status=$last_status
368 ;;
369 esac
370 }
371 final_report () {
372 if [ $failure_count -gt 0 ]; then
373 echo
374 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
375 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
376 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
377 elif [ -z "${1-}" ]; then
378 echo "SUCCESS :)"
379 fi
380 if [ -n "${1-}" ]; then
381 echo "Killed by SIG$1."
382 fi
383 }
384else
385 record_status () {
386 "$@"
387 }
388fi
389if_build_succeeded () {
390 if [ $build_status -eq 0 ]; then
391 record_status "$@"
392 fi
393}
394
Andres AG7770ea82016-10-10 15:46:20 +0100395if [ $RELEASE -eq 1 ]; then
396 # Fix the seed value to 1 to ensure that the tests are deterministic.
397 SEED=1
398fi
399
Andres AGd9eba4b2016-08-26 14:42:14 +0100400msg "info: $0 configuration"
401echo "MEMORY: $MEMORY"
402echo "FORCE: $FORCE"
Andres AG7770ea82016-10-10 15:46:20 +0100403echo "SEED: ${SEED-"UNSET"}"
Andres AGd9eba4b2016-08-26 14:42:14 +0100404echo "OPENSSL: $OPENSSL"
405echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
406echo "GNUTLS_CLI: $GNUTLS_CLI"
407echo "GNUTLS_SERV: $GNUTLS_SERV"
408echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
409echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
Andres AG87bb5772016-09-27 15:05:15 +0100410echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
411echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
412
413ARMC5_CC="$ARMC5_BIN_DIR/armcc"
414ARMC5_AR="$ARMC5_BIN_DIR/armar"
415ARMC6_CC="$ARMC6_BIN_DIR/armclang"
416ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100417
Andres AGb2fdd042016-09-22 14:17:46 +0100418# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
419# we just export the variables they require
420export OPENSSL_CMD="$OPENSSL"
421export GNUTLS_CLI="$GNUTLS_CLI"
422export GNUTLS_SERV="$GNUTLS_SERV"
423
Andres AG7770ea82016-10-10 15:46:20 +0100424# Avoid passing --seed flag in every call to ssl-opt.sh
425[ ! -z ${SEED+set} ] && export SEED
426
Andres AGd9eba4b2016-08-26 14:42:14 +0100427# Make sure the tools we need are available.
428check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100429 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100430 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
431if [ $RUN_ARMCC -ne 0 ]; then
432 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
433fi
Andres AGd9eba4b2016-08-26 14:42:14 +0100434
Gilles Peskine192c72f2017-12-21 15:59:21 +0100435
436
437################################################################
438#### Basic checks
439################################################################
SimonB2e23c822016-04-16 21:54:39 +0100440
441#
442# Test Suites to be executed
443#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200444# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100445# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200446# and/or are more likely to fail than others (eg I use Clang most of the
447# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200448# 2. Minimize total running time, by avoiding useless rebuilds
449#
450# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100451
Janos Follathb72c6782016-07-19 14:54:17 +0100452msg "info: output_env.sh"
Andres AGd9eba4b2016-08-26 14:42:14 +0100453OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
454 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
Andres AG87bb5772016-09-27 15:05:15 +0100455 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
456 ARMC6_CC="$ARMC6_CC" scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100457
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100458msg "test: recursion.pl" # < 1s
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200459tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100460
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000461msg "test: freshness of generated source files" # < 1s
462tests/scripts/check-generated-files.sh
463
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200464msg "test: doxygen markup outside doxygen blocks" # < 1s
465tests/scripts/check-doxy-blocks.pl
466
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200467msg "test/build: declared and exported names" # < 3s
468cleanup
469tests/scripts/check-names.sh
470
Andres AGd9eba4b2016-08-26 14:42:14 +0100471msg "test: doxygen warnings" # ~ 3s
472cleanup
473tests/scripts/doxygen.sh
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100474
Gilles Peskine192c72f2017-12-21 15:59:21 +0100475
476
477################################################################
478#### Build and test many configurations and targets
479################################################################
480
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100481if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
482 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
483 # path, and uses whatever version of armcc it finds there.
Gilles Peskineda519252017-11-30 13:22:04 +0100484 msg "build: create and build yotta module" # ~ 30s
485 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100486 record_status tests/scripts/yotta-build.sh
Gilles Peskineda519252017-11-30 13:22:04 +0100487fi
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200488
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100489msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100490cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100491CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100492make
493
Simon Butcher8e3afc72016-09-15 17:13:08 +0100494msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100495make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200496
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100497msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100498if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200499
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100500msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +0100501if_build_succeeded tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200502
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200503msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
504make
505
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100506msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100507if_build_succeeded tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200508
Simon Butcher3ea7f522016-03-07 23:22:10 +0000509msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
510cleanup
Simon Butcherf413b6f2016-03-14 22:32:42 +0000511cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcher3ea7f522016-03-07 23:22:10 +0000512scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
513CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
514make
515
Simon Butcher8e3afc72016-09-15 17:13:08 +0100516msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
Simon Butcher3ea7f522016-03-07 23:22:10 +0000517make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000518
519msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100520if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
521if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000522
523msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100524if_build_succeeded tests/ssl-opt.sh
Simon Butcher3ea7f522016-03-07 23:22:10 +0000525
Hanno Becker134c2ab2017-10-12 15:29:50 +0100526msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
527cleanup
528cp "$CONFIG_H" "$CONFIG_BAK"
529scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
530CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
531make
532
533msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
534make test
535
536msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100537if_build_succeeded tests/ssl-opt.sh
Hanno Becker134c2ab2017-10-12 15:29:50 +0100538
Simon Butcherf95c1762016-11-10 17:25:58 +0000539msg "build: cmake, full config, clang, C99" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100540cleanup
Janos Follath35d48cb2016-04-22 14:45:00 +0100541cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200542scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200543scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Simon Butcherf95c1762016-11-10 17:25:58 +0000544CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
Gilles Peskine7c652162017-12-11 00:01:40 +0100545make CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic'
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100546
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100547msg "test: main suites (full config)" # ~ 5s
Gilles Peskine7c652162017-12-11 00:01:40 +0100548make CFLAGS='-Werror -Wall -Wextra' test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200549
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100550msg "test: ssl-opt.sh default (full config)" # ~ 1s
Gilles Peskine7c652162017-12-11 00:01:40 +0100551if_build_succeeded tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200552
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100553msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100554if_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 +0200555
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200556msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100557cleanup
558cmake -D CMAKE_BUILD_TYPE:String=Debug .
Gilles Peskine7c652162017-12-11 00:01:40 +0100559if_build_succeeded tests/scripts/curves.pl
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100560
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200561msg "test/build: key-exchanges (gcc)" # ~ 1 min
562cleanup
563cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine7c652162017-12-11 00:01:40 +0100564if_build_succeeded tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200565
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000566msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100567cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100568make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100569
Simon Butcherf95c1762016-11-10 17:25:58 +0000570# Full configuration build, without platform support, file IO and net sockets.
571# This should catch missing mbedtls_printf definitions, and by disabling file
572# IO, it should catch missing '#include <stdio.h>'
573msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000574cleanup
575cp "$CONFIG_H" "$CONFIG_BAK"
576scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200577scripts/config.pl unset MBEDTLS_PLATFORM_C
Simon Butcherf95c1762016-11-10 17:25:58 +0000578scripts/config.pl unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200579scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100580scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
581scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
582scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Simon Butcherb9283432016-07-13 11:02:41 +0100583scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100584scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Simon Butcher284b4c92016-06-26 13:10:00 +0100585scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
587scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchercb587002017-01-06 16:14:44 +0000588# Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
589# to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine7c652162017-12-11 00:01:40 +0100590make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
591make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000592
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100593# catch compile bugs in _uninit functions
594msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
595cleanup
596cp "$CONFIG_H" "$CONFIG_BAK"
597scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100598scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Simon Butchereebf1b92016-06-27 01:42:39 +0100599scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine7c652162017-12-11 00:01:40 +0100600make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100601
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200602msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
603cleanup
604cp "$CONFIG_H" "$CONFIG_BAK"
605scripts/config.pl full
606scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100607make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200608
609msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
610cleanup
611cp "$CONFIG_H" "$CONFIG_BAK"
612scripts/config.pl full
613scripts/config.pl unset MBEDTLS_SSL_CLI_C
Hanno Beckerd485c312018-01-05 13:03:53 +0000614make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200615
Simon Butcherf95c1762016-11-10 17:25:58 +0000616# Note, C99 compliance can also be tested with the sockets support disabled,
617# as that requires a POSIX platform (which isn't the same as C99).
Andres AG788aa4a2016-09-14 14:32:09 +0100618msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200619cleanup
620cp "$CONFIG_H" "$CONFIG_BAK"
621scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200622scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
623scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine7c652162017-12-11 00:01:40 +0100624make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200625
Hanno Becker5175ac62017-09-18 15:36:25 +0100626msg "build: default config except MFL extension (ASan build)" # ~ 30s
627cleanup
628cp "$CONFIG_H" "$CONFIG_BAK"
629scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
630CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
631make
632
633msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine7c652162017-12-11 00:01:40 +0100634if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Hanno Becker5175ac62017-09-18 15:36:25 +0100635
Simon Butcherab5df402016-06-11 02:31:21 +0100636msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100637cleanup
638cp "$CONFIG_H" "$CONFIG_BAK"
Simon Butcherab5df402016-06-11 02:31:21 +0100639scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
Janos Follath06c54002016-06-09 13:57:40 +0100640scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
641scripts/config.pl set MBEDTLS_ENTROPY_C
642scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
643scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
644scripts/config.pl unset MBEDTLS_HAVEGE_C
Simon Butchereebf1b92016-06-27 01:42:39 +0100645CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
Janos Follath06c54002016-06-09 13:57:40 +0100646make
647
Simon Butcher8e3afc72016-09-15 17:13:08 +0100648msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
Janos Follath06c54002016-06-09 13:57:40 +0100649make test
Janos Follath06c54002016-06-09 13:57:40 +0100650
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200651if uname -a | grep -F Linux >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100652 msg "build/test: make shared" # ~ 40s
653 cleanup
654 make SHARED=1 all check
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200655fi
656
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000657if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100658 msg "build: i386, make, gcc" # ~ 30s
659 cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100660 make CC=gcc CFLAGS='-Werror -Wall -Wextra -m32'
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100661
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100662 msg "build: gcc, force 32-bit compilation"
663 cleanup
664 cp "$CONFIG_H" "$CONFIG_BAK"
665 scripts/config.pl unset MBEDTLS_HAVE_ASM
666 scripts/config.pl unset MBEDTLS_AESNI_C
667 scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100668 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100669
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100670 msg "build: gcc, force 64-bit compilation"
671 cleanup
672 cp "$CONFIG_H" "$CONFIG_BAK"
673 scripts/config.pl unset MBEDTLS_HAVE_ASM
674 scripts/config.pl unset MBEDTLS_AESNI_C
675 scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100676 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Andres Amaya Garcia33264d72017-07-20 13:21:34 +0100677
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100678 msg "test: gcc, force 64-bit compilation"
679 make test
Andres Amaya Garcia33264d72017-07-20 13:21:34 +0100680
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100681 msg "build: gcc, force 64-bit compilation"
682 cleanup
683 cp "$CONFIG_H" "$CONFIG_BAK"
684 scripts/config.pl unset MBEDTLS_HAVE_ASM
685 scripts/config.pl unset MBEDTLS_AESNI_C
686 scripts/config.pl unset MBEDTLS_PADLOCK_C
Gilles Peskine7c652162017-12-11 00:01:40 +0100687 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000688fi # x86_64
689
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000690msg "build: arm-none-eabi-gcc, make" # ~ 10s
691cleanup
692cp "$CONFIG_H" "$CONFIG_BAK"
693scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200694scripts/config.pl unset MBEDTLS_NET_C
695scripts/config.pl unset MBEDTLS_TIMING_C
696scripts/config.pl unset MBEDTLS_FS_IO
Simon Butchereebf1b92016-06-27 01:42:39 +0100697scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcherbc6a4862016-03-07 17:35:59 +0000698scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000699# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
701scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
702scripts/config.pl unset MBEDTLS_THREADING_C
703scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
704scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine7c652162017-12-11 00:01:40 +0100705make 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 +0000706
Gilles Peskine9a9adcd2017-06-08 15:19:20 +0200707msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
708cleanup
Simon Butcher51aaa992017-07-23 13:42:36 +0200709cp "$CONFIG_H" "$CONFIG_BAK"
Andres Amaya Garcia6fb65862017-07-20 13:27:35 +0100710scripts/config.pl full
711scripts/config.pl unset MBEDTLS_NET_C
712scripts/config.pl unset MBEDTLS_TIMING_C
713scripts/config.pl unset MBEDTLS_FS_IO
714scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
715scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
716# following things are not in the default config
717scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
718scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
719scripts/config.pl unset MBEDTLS_THREADING_C
720scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
721scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Gilles Peskine9a9adcd2017-06-08 15:19:20 +0200722scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine7c652162017-12-11 00:01:40 +0100723make 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 +0200724echo "Checking that software 64-bit division is not required"
725! grep __aeabi_uldiv library/*.o
726
Andres AG87bb5772016-09-27 15:05:15 +0100727msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100728cleanup
729cp "$CONFIG_H" "$CONFIG_BAK"
730scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200731scripts/config.pl unset MBEDTLS_NET_C
732scripts/config.pl unset MBEDTLS_TIMING_C
733scripts/config.pl unset MBEDTLS_FS_IO
Simon Butcher1c719652016-06-27 19:02:12 +0100734scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200735scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200736scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Simon Butcherbc6a4862016-03-07 17:35:59 +0000737scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100738# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200739scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
740scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
741scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
742scripts/config.pl unset MBEDTLS_THREADING_C
743scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
744scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Simon Butcher4df5eaf2016-08-24 22:58:31 +0300745scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Andres AG87bb5772016-09-27 15:05:15 +0100746
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100747if [ $RUN_ARMCC -ne 0 ]; then
748 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
749 make clean
Andres AG87bb5772016-09-27 15:05:15 +0100750
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100751 # ARM Compiler 6 - Target ARMv7-A
752 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher51aaa992017-07-23 13:42:36 +0200753
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100754 # ARM Compiler 6 - Target ARMv7-M
755 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher51aaa992017-07-23 13:42:36 +0200756
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100757 # ARM Compiler 6 - Target ARMv8-A - AArch32
758 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher51aaa992017-07-23 13:42:36 +0200759
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100760 # ARM Compiler 6 - Target ARMv8-M
761 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher51aaa992017-07-23 13:42:36 +0200762
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100763 # ARM Compiler 6 - Target ARMv8-A - AArch64
764 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
765fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100766
Gilles Peskine2a458da2017-05-12 15:26:58 +0200767msg "build: allow SHA1 in certificates by default"
768cleanup
769cp "$CONFIG_H" "$CONFIG_BAK"
770scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine7c652162017-12-11 00:01:40 +0100771make CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine2a458da2017-05-12 15:26:58 +0200772msg "test: allow SHA1 in certificates by default"
773make test
Gilles Peskine7c652162017-12-11 00:01:40 +0100774if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine2a458da2017-05-12 15:26:58 +0200775
Hanno Beckerd485c312018-01-05 13:03:53 +0000776msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min
Hanno Beckere963efa2018-01-03 10:03:43 +0000777cleanup
778cp "$CONFIG_H" "$CONFIG_BAK"
779scripts/config.pl set MBEDTLS_RSA_NO_CRT
Hanno Beckerd485c312018-01-05 13:03:53 +0000780CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
781make
Hanno Beckere963efa2018-01-03 10:03:43 +0000782
783msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)"
784make test
785
Simon Butcher002bc622016-11-17 09:27:45 +0000786msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100787cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100788make 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 +0000789
Simon Butcher002bc622016-11-17 09:27:45 +0000790# note Make tests only builds the tests, but doesn't run them
Gilles Peskine7c652162017-12-11 00:01:40 +0100791make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
792make WINDOWS_BUILD=1 clean
Simon Butcherf95c1762016-11-10 17:25:58 +0000793
Simon Butcher002bc622016-11-17 09:27:45 +0000794msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
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 -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
796make 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
797make WINDOWS_BUILD=1 clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100798
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000799# MemSan currently only available on Linux 64 bits
800if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000801
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100802 msg "build: MSan (clang)" # ~ 1 min 20s
803 cleanup
804 cp "$CONFIG_H" "$CONFIG_BAK"
805 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
806 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
807 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200808
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100809 msg "test: main suites (MSan)" # ~ 10s
810 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100811
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100812 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100813 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100814
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100815 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100816
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100817 if [ "$MEMORY" -gt 0 ]; then
818 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +0100819 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100820 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100821
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000822else # no MemSan
823
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100824 msg "build: Release (clang)"
825 cleanup
826 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
827 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000828
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100829 msg "test: main suites valgrind (Release)"
830 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000831
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100832 # Optional part(s)
833 # Currently broken, programs don't seem to receive signals
834 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000835
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100836 if [ "$MEMORY" -gt 0 ]; then
837 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100838 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100839 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000840
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100841 if [ "$MEMORY" -gt 1 ]; then
842 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +0100843 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100844 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000845
846fi # MemSan
847
Andres AGdc192212016-08-31 17:33:13 +0100848msg "build: cmake 'out-of-source' build"
849cleanup
850MBEDTLS_ROOT_DIR="$PWD"
851mkdir "$OUT_OF_SOURCE_DIR"
852cd "$OUT_OF_SOURCE_DIR"
853cmake "$MBEDTLS_ROOT_DIR"
854make
855
856msg "test: cmake 'out-of-source' build"
857make test
858cd "$MBEDTLS_ROOT_DIR"
859rm -rf "$OUT_OF_SOURCE_DIR"
860
Gilles Peskine192c72f2017-12-21 15:59:21 +0100861
862
863################################################################
864#### Termination
865################################################################
866
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100867msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100868cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100869
870final_report