blob: f56b23bcfb12e7af9fc7f42c06a88b03fd87b487 [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * 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#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
62# * component_check_XXX: quick tests that aren't worth parallelizing
63# * component_build_XXX: build things but don't run them
64# * component_test_XXX: build and test
65# * post_XXX: things to do after running the tests.
66# * other: miscellaneous support functions.
67#
Gilles Peskine192c72f2017-12-21 15:59:21 +010068# The tests are roughly in order from fastest to slowest. This doesn't
69# have to be exact, but in general you should add slower tests towards
70# the end and fast checks near the beginning.
71#
72# Sanity checks have the following form:
73# 1. msg "short description of what is about to be done"
74# 2. run sanity check (failure stops the script)
75#
76# Build or build-and-test steps have the following form:
77# 1. msg "short description of what is about to be done"
78# 2. cleanup
79# 3. preparation (config.pl, cmake, ...) (failure stops the script)
80# 4. make
81# 5. Run tests if relevant. All tests must be prefixed with
82# if_build_successful for the sake of --keep-going.
83
84
85
86################################################################
87#### Initialization and command line parsing
88################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010089
SimonB2e23c822016-04-16 21:54:39 +010090# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091set -eu
92
Gilles Peskine8f073122018-11-27 15:58:47 +010093pre_check_environment () {
94 if [ "$( uname )" != "Linux" ]; then
95 echo "This script only works in Linux" >&2
96 exit 1
97 elif [ -d library -a -d include -a -d tests ]; then :; else
98 echo "Must be run from mbed TLS root" >&2
99 exit 1
100 fi
101}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100102
Gilles Peskine8f073122018-11-27 15:58:47 +0100103pre_initialize_variables () {
104 CONFIG_H='include/mbedtls/config.h'
105 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200106
Gilles Peskine92525112018-11-27 18:15:35 +0100107 COMPONENTS=
Gilles Peskine8f073122018-11-27 15:58:47 +0100108 MEMORY=0
109 FORCE=0
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100110 INTROSPECTION_MODE=
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 KEEP_GOING=0
112 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100113
Gilles Peskine8f073122018-11-27 15:58:47 +0100114 # Default commands, can be overriden by the environment
115 : ${OPENSSL:="openssl"}
116 : ${OPENSSL_LEGACY:="$OPENSSL"}
117 : ${OPENSSL_NEXT:="$OPENSSL"}
118 : ${GNUTLS_CLI:="gnutls-cli"}
119 : ${GNUTLS_SERV:="gnutls-serv"}
120 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
121 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
122 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
123 : ${ARMC5_BIN_DIR:=/usr/bin}
124 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100125
Gilles Peskine8f073122018-11-27 15:58:47 +0100126 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
127 if [ -n "${MAKEFLAGS+set}" ]; then
128 export MAKEFLAGS="-j"
129 fi
130}
Andres AG38495a32016-07-12 16:54:33 +0100131
Simon Butcher41eeccf2016-09-07 00:07:09 +0100132usage()
SimonB2e23c822016-04-16 21:54:39 +0100133{
Gilles Peskine709346a2017-12-10 23:43:39 +0100134 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100135Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100136Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100137By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100138
139Special options:
140 -h|--help Print this help and exit.
141 --list-components List available test components and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100142
143General options:
144 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100145 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100146 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100147 --armcc Run ARM Compiler builds (on by default).
148 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100149 --no-force Refuse to overwrite modified files (default).
150 --no-keep-going Stop at the first error (default).
151 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100152 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100153 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100154 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
155 -s|--seed Integer seed value to use for this test run.
156
157Tool path options:
158 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
159 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
160 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
161 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
162 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
163 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
164 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
165 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100166 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100167EOF
SimonB2e23c822016-04-16 21:54:39 +0100168}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100169
170# remove built files as well as the cmake cache/config
171cleanup()
172{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100173 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
174 cd "$MBEDTLS_ROOT_DIR"
175 fi
176
Gilles Peskine7c652162017-12-11 00:01:40 +0100177 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200178
Gilles Peskine31b07e22018-03-21 12:15:06 +0100179 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100180 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100181 -iname CMakeFiles -exec rm -rf {} \+ -o \
182 \( -iname cmake_install.cmake -o \
183 -iname CTestTestfile.cmake -o \
184 -iname CMakeCache.txt \) -exec rm {} \+
185 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000186 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200187 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
188 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200189
190 if [ -f "$CONFIG_BAK" ]; then
191 mv "$CONFIG_BAK" "$CONFIG_H"
192 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100193}
194
Gilles Peskine7c652162017-12-11 00:01:40 +0100195# Executed on exit. May be redefined depending on command line options.
196final_report () {
197 :
198}
199
200fatal_signal () {
201 cleanup
202 final_report $1
203 trap - $1
204 kill -$1 $$
205}
206
207trap 'fatal_signal HUP' HUP
208trap 'fatal_signal INT' INT
209trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200210
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100211msg()
212{
213 echo ""
214 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100215 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000216 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100217 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100218 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100219}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100220
Gilles Peskine8f073122018-11-27 15:58:47 +0100221armc6_build_test()
222{
223 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100224
Gilles Peskine8f073122018-11-27 15:58:47 +0100225 msg "build: ARM Compiler 6 ($FLAGS), make"
226 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
227 WARNING_CFLAGS='-xc -std=c99' make lib
228 make clean
229}
Andres AGa5cd9732016-10-17 15:23:10 +0100230
Andres AGd9eba4b2016-08-26 14:42:14 +0100231err_msg()
232{
233 echo "$1" >&2
234}
235
236check_tools()
237{
238 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000239 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100240 err_msg "$TOOL not found!"
241 exit 1
242 fi
243 done
244}
245
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400246check_headers_in_cpp () {
247 ls include/mbedtls >headers.txt
248 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
249 sort |
250 diff headers.txt -
251 rm headers.txt
252}
253
Gilles Peskine8f073122018-11-27 15:58:47 +0100254pre_parse_command_line () {
255 while [ $# -gt 0 ]; do
256 case "$1" in
257 --armcc) RUN_ARMCC=1;;
258 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
259 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
260 --force|-f) FORCE=1;;
261 --gnutls-cli) shift; GNUTLS_CLI="$1";;
262 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
263 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
264 --gnutls-serv) shift; GNUTLS_SERV="$1";;
265 --help|-h) usage; exit;;
266 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100267 --list-components) INTROSPECTION_MODE=list_components;;
Gilles Peskine8f073122018-11-27 15:58:47 +0100268 --memory|-m) MEMORY=1;;
269 --no-armcc) RUN_ARMCC=0;;
270 --no-force) FORCE=0;;
271 --no-keep-going) KEEP_GOING=0;;
272 --no-memory) MEMORY=0;;
273 --openssl) shift; OPENSSL="$1";;
274 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
275 --openssl-next) shift; OPENSSL_NEXT="$1";;
276 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
277 --random-seed) unset SEED;;
278 --release-test|-r) SEED=1;;
279 --seed|-s) shift; SEED="$1";;
Gilles Peskine92525112018-11-27 18:15:35 +0100280 -*)
Gilles Peskine8f073122018-11-27 15:58:47 +0100281 echo >&2 "Unknown option: $1"
282 echo >&2 "Run $0 --help for usage."
283 exit 120
284 ;;
Gilles Peskine92525112018-11-27 18:15:35 +0100285 *)
286 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine8f073122018-11-27 15:58:47 +0100287 esac
288 shift
289 done
290}
SimonB2e23c822016-04-16 21:54:39 +0100291
Gilles Peskine8f073122018-11-27 15:58:47 +0100292pre_check_git () {
293 if [ $FORCE -eq 1 ]; then
294 git checkout-index -f -q $CONFIG_H
295 cleanup
296 else
SimonB2e23c822016-04-16 21:54:39 +0100297
Gilles Peskine8f073122018-11-27 15:58:47 +0100298 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
299 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
300 echo "You can either delete this directory manually, or force the test by rerunning"
301 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
302 exit 1
303 fi
304
305 if ! git diff-files --quiet include/mbedtls/config.h; then
306 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
307 echo "You can either delete or preserve your work, or force the test by rerunning the"
308 echo "script as: $0 --force"
309 exit 1
310 fi
Andres AGdc192212016-08-31 17:33:13 +0100311 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100312}
Andres AGdc192212016-08-31 17:33:13 +0100313
Gilles Peskine8f073122018-11-27 15:58:47 +0100314pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100315 failure_summary=
316 failure_count=0
317 start_red=
318 end_color=
319 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100320 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100321 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
322 start_red=$(printf '\033[31m')
323 end_color=$(printf '\033[0m')
324 ;;
325 esac
326 fi
327 record_status () {
328 if "$@"; then
329 last_status=0
330 else
331 last_status=$?
332 text="$current_section: $* -> $last_status"
333 failure_summary="$failure_summary
334$text"
335 failure_count=$((failure_count + 1))
336 echo "${start_red}^^^^$text^^^^${end_color}"
337 fi
338 }
339 make () {
340 case "$*" in
341 *test|*check)
342 if [ $build_status -eq 0 ]; then
343 record_status command make "$@"
344 else
345 echo "(skipped because the build failed)"
346 fi
347 ;;
348 *)
349 record_status command make "$@"
350 build_status=$last_status
351 ;;
352 esac
353 }
354 final_report () {
355 if [ $failure_count -gt 0 ]; then
356 echo
357 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
358 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
359 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100360 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100361 elif [ -z "${1-}" ]; then
362 echo "SUCCESS :)"
363 fi
364 if [ -n "${1-}" ]; then
365 echo "Killed by SIG$1."
366 fi
367 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100368}
369
Gilles Peskine7c652162017-12-11 00:01:40 +0100370if_build_succeeded () {
371 if [ $build_status -eq 0 ]; then
372 record_status "$@"
373 fi
374}
375
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200376# to be used instead of ! for commands run with
377# record_status or if_build_succeeded
378not() {
379 ! "$@"
380}
381
Gilles Peskine8f073122018-11-27 15:58:47 +0100382pre_print_configuration () {
383 msg "info: $0 configuration"
384 echo "MEMORY: $MEMORY"
385 echo "FORCE: $FORCE"
386 echo "SEED: ${SEED-"UNSET"}"
387 echo "OPENSSL: $OPENSSL"
388 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
389 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
390 echo "GNUTLS_CLI: $GNUTLS_CLI"
391 echo "GNUTLS_SERV: $GNUTLS_SERV"
392 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
393 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
394 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
395 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
396}
Andres AG87bb5772016-09-27 15:05:15 +0100397
Gilles Peskine8f073122018-11-27 15:58:47 +0100398pre_check_tools () {
399 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
400 ARMC5_AR="$ARMC5_BIN_DIR/armar"
401 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
402 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100403
Gilles Peskine8f073122018-11-27 15:58:47 +0100404 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
405 # we just export the variables they require
406 export OPENSSL_CMD="$OPENSSL"
407 export GNUTLS_CLI="$GNUTLS_CLI"
408 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100409
Gilles Peskine8f073122018-11-27 15:58:47 +0100410 # Avoid passing --seed flag in every call to ssl-opt.sh
411 if [ -n "${SEED-}" ]; then
412 export SEED
413 fi
Andres AG7770ea82016-10-10 15:46:20 +0100414
Gilles Peskine8f073122018-11-27 15:58:47 +0100415 # Make sure the tools we need are available.
416 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
417 "$GNUTLS_CLI" "$GNUTLS_SERV" \
418 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
419 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
420 if [ $RUN_ARMCC -ne 0 ]; then
421 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
422 fi
423}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100424
425
426################################################################
427#### Basic checks
428################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100429
SimonB2e23c822016-04-16 21:54:39 +0100430#
431# Test Suites to be executed
432#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200433# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100434# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200435# and/or are more likely to fail than others (eg I use Clang most of the
436# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200437# 2. Minimize total running time, by avoiding useless rebuilds
438#
439# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100440
Gilles Peskine8f073122018-11-27 15:58:47 +0100441pre_print_tools () {
442 msg "info: output_env.sh"
443 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
444 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
445 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
446 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
447}
Janos Follathb72c6782016-07-19 14:54:17 +0100448
Gilles Peskine8f073122018-11-27 15:58:47 +0100449component_check_recursion () {
450 msg "test: recursion.pl" # < 1s
451 record_status tests/scripts/recursion.pl library/*.c
452}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100453
Gilles Peskine8f073122018-11-27 15:58:47 +0100454component_check_generated_files () {
455 msg "test: freshness of generated source files" # < 1s
456 record_status tests/scripts/check-generated-files.sh
457}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000458
Gilles Peskine8f073122018-11-27 15:58:47 +0100459component_check_doxy_blocks () {
460 msg "test: doxygen markup outside doxygen blocks" # < 1s
461 record_status tests/scripts/check-doxy-blocks.pl
462}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200463
Gilles Peskine8f073122018-11-27 15:58:47 +0100464component_check_files () {
465 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100466 record_status tests/scripts/check-files.py
467}
Darryl Greena07039c2018-03-13 16:48:16 +0000468
Gilles Peskine8f073122018-11-27 15:58:47 +0100469component_check_names () {
470 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100471 record_status tests/scripts/check-names.sh
472}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200473
Gilles Peskine8f073122018-11-27 15:58:47 +0100474component_check_doxygen_warnings () {
475 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100476 record_status tests/scripts/doxygen.sh
477}
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 Peskine8f073122018-11-27 15:58:47 +0100485component_test_default_cmake_gcc_asan () {
486 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100487 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
488 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100489
Gilles Peskine8f073122018-11-27 15:58:47 +0100490 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
491 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200492
Gilles Peskine8f073122018-11-27 15:58:47 +0100493 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
494 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200495
Gilles Peskine8f073122018-11-27 15:58:47 +0100496 msg "test: compat.sh (ASan build)" # ~ 6 min
497 if_build_succeeded tests/compat.sh
498}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200499
Gilles Peskine782f4112018-11-27 16:11:09 +0100500component_test_ref_configs () {
501 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
502 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
503 record_status tests/scripts/test-ref-configs.pl
504}
505
Gilles Peskine8f073122018-11-27 15:58:47 +0100506component_test_sslv3 () {
507 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100508 cp "$CONFIG_H" "$CONFIG_BAK"
509 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
510 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
511 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000512
Gilles Peskine8f073122018-11-27 15:58:47 +0100513 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
514 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000515
Gilles Peskine8f073122018-11-27 15:58:47 +0100516 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
517 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
518 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000519
Gilles Peskine8f073122018-11-27 15:58:47 +0100520 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
521 if_build_succeeded tests/ssl-opt.sh
522}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000523
Gilles Peskine8f073122018-11-27 15:58:47 +0100524component_test_no_renegotiation () {
525 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100526 cp "$CONFIG_H" "$CONFIG_BAK"
527 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
528 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
529 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100530
Gilles Peskine8f073122018-11-27 15:58:47 +0100531 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
532 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100533
Gilles Peskine8f073122018-11-27 15:58:47 +0100534 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
535 if_build_succeeded tests/ssl-opt.sh
536}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100537
Gilles Peskine8f073122018-11-27 15:58:47 +0100538component_test_rsa_no_crt () {
539 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100540 cp "$CONFIG_H" "$CONFIG_BAK"
541 scripts/config.pl set MBEDTLS_RSA_NO_CRT
542 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
543 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100544
Gilles Peskine8f073122018-11-27 15:58:47 +0100545 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
546 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100547
Gilles Peskine8f073122018-11-27 15:58:47 +0100548 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
549 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100550
Gilles Peskine8f073122018-11-27 15:58:47 +0100551 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
552 if_build_succeeded tests/compat.sh -t RSA
553}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100554
Gilles Peskine8f073122018-11-27 15:58:47 +0100555component_test_small_ssl_out_content_len () {
556 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100557 cp "$CONFIG_H" "$CONFIG_BAK"
558 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
559 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
560 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
561 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000562
Gilles Peskine8f073122018-11-27 15:58:47 +0100563 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
564 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
565}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000566
Gilles Peskine8f073122018-11-27 15:58:47 +0100567component_test_small_ssl_in_content_len () {
568 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100569 cp "$CONFIG_H" "$CONFIG_BAK"
570 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
571 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
572 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
573 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000574
Gilles Peskine8f073122018-11-27 15:58:47 +0100575 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
576 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
577}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000578
Gilles Peskine8f073122018-11-27 15:58:47 +0100579component_test_small_ssl_dtls_max_buffering () {
580 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100581 cp "$CONFIG_H" "$CONFIG_BAK"
582 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
583 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
584 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100585
Gilles Peskine8f073122018-11-27 15:58:47 +0100586 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
587 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
588}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100589
Gilles Peskine8f073122018-11-27 15:58:47 +0100590component_test_small_mbedtls_ssl_dtls_max_buffering () {
591 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100592 cp "$CONFIG_H" "$CONFIG_BAK"
593 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
594 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
595 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100596
Gilles Peskine8f073122018-11-27 15:58:47 +0100597 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
598 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
599}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100600
Gilles Peskine8f073122018-11-27 15:58:47 +0100601component_test_full_cmake_clang () {
602 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100603 cp "$CONFIG_H" "$CONFIG_BAK"
604 scripts/config.pl full
605 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
606 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
607 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609 msg "test: main suites (full config)" # ~ 5s
610 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200611
Gilles Peskine8f073122018-11-27 15:58:47 +0100612 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
613 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200614
Gilles Peskine8f073122018-11-27 15:58:47 +0100615 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
616 if_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 +0200617
Gilles Peskine8f073122018-11-27 15:58:47 +0100618 msg "test: compat.sh ARIA + ChachaPoly"
619 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
620}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100621
Gilles Peskine8f073122018-11-27 15:58:47 +0100622component_build_deprecated () {
623 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100624 cp "$CONFIG_H" "$CONFIG_BAK"
625 scripts/config.pl full
626 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
627 # Build with -O -Wextra to catch a maximum of issues.
628 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
629 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
632 # No cleanup, just tweak the configuration and rebuild
633 make clean
634 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
635 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
636 # Build with -O -Wextra to catch a maximum of issues.
637 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
638 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
639}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100640
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642component_test_depends_curves () {
643 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100644 record_status tests/scripts/curves.pl
645}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200646
Gilles Peskine8f073122018-11-27 15:58:47 +0100647component_test_depends_hashes () {
648 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100649 record_status tests/scripts/depends-hashes.pl
650}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200651
Gilles Peskine8f073122018-11-27 15:58:47 +0100652component_test_depends_pkalgs () {
653 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100654 record_status tests/scripts/depends-pkalgs.pl
655}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200656
Gilles Peskine8f073122018-11-27 15:58:47 +0100657component_build_key_exchanges () {
658 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 record_status tests/scripts/key-exchanges.pl
660}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662component_build_default_make_gcc_and_cxx () {
663 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100664 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400665
Gilles Peskine8f073122018-11-27 15:58:47 +0100666 msg "test: verify header list in cpp_dummy_build.cpp"
667 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669 msg "build: Unix make, incremental g++"
670 make TEST_CPP=1
671}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000672
Gilles Peskine8f073122018-11-27 15:58:47 +0100673component_test_no_platform () {
674 # Full configuration build, without platform support, file IO and net sockets.
675 # This should catch missing mbedtls_printf definitions, and by disabling file
676 # IO, it should catch missing '#include <stdio.h>'
677 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100678 cp "$CONFIG_H" "$CONFIG_BAK"
679 scripts/config.pl full
680 scripts/config.pl unset MBEDTLS_PLATFORM_C
681 scripts/config.pl unset MBEDTLS_NET_C
682 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
683 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
684 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
685 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
686 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
687 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
688 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
689 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
690 scripts/config.pl unset MBEDTLS_FS_IO
691 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
692 # to re-enable platform integration features otherwise disabled in C99 builds
693 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
694 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
695}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697component_build_no_std_function () {
698 # catch compile bugs in _uninit functions
699 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100700 cp "$CONFIG_H" "$CONFIG_BAK"
701 scripts/config.pl full
702 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
703 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
704 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
705}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200706
Gilles Peskine8f073122018-11-27 15:58:47 +0100707component_build_no_ssl_srv () {
708 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100709 cp "$CONFIG_H" "$CONFIG_BAK"
710 scripts/config.pl full
711 scripts/config.pl unset MBEDTLS_SSL_SRV_C
712 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
713}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200714
Gilles Peskine8f073122018-11-27 15:58:47 +0100715component_build_no_ssl_cli () {
716 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100717 cp "$CONFIG_H" "$CONFIG_BAK"
718 scripts/config.pl full
719 scripts/config.pl unset MBEDTLS_SSL_CLI_C
720 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
721}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200722
Gilles Peskine8f073122018-11-27 15:58:47 +0100723component_build_no_sockets () {
724 # Note, C99 compliance can also be tested with the sockets support disabled,
725 # as that requires a POSIX platform (which isn't the same as C99).
726 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100727 cp "$CONFIG_H" "$CONFIG_BAK"
728 scripts/config.pl full
729 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
730 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
731 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
732}
Hanno Becker5175ac62017-09-18 15:36:25 +0100733
Gilles Peskine8f073122018-11-27 15:58:47 +0100734component_test_no_max_fragment_length () {
735 # Run max fragment length tests with MFL disabled
736 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100737 cp "$CONFIG_H" "$CONFIG_BAK"
738 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
739 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
740 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742 msg "test: ssl-opt.sh, MFL-related tests"
743 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
744}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000745
Gilles Peskine8f073122018-11-27 15:58:47 +0100746component_test_no_max_fragment_length_small_ssl_out_content_len () {
747 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100748 cp "$CONFIG_H" "$CONFIG_BAK"
749 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
750 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
751 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
752 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
753 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
756 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
757}
Janos Follath06c54002016-06-09 13:57:40 +0100758
Gilles Peskine8f073122018-11-27 15:58:47 +0100759component_test_null_entropy () {
760 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 cp "$CONFIG_H" "$CONFIG_BAK"
762 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
763 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
764 scripts/config.pl set MBEDTLS_ENTROPY_C
765 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
766 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
767 scripts/config.pl unset MBEDTLS_HAVEGE_C
768 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
769 make
Janos Follath06c54002016-06-09 13:57:40 +0100770
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
772 make test
773}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100774
Gilles Peskine8f073122018-11-27 15:58:47 +0100775component_test_platform_calloc_macro () {
776 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100777 cp "$CONFIG_H" "$CONFIG_BAK"
778 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
779 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
780 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
782 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
785 make test
786}
Hanno Becker83ebf782017-07-07 12:29:15 +0100787
Gilles Peskine8f073122018-11-27 15:58:47 +0100788component_test_aes_fewer_tables () {
789 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100790 cp "$CONFIG_H" "$CONFIG_BAK"
791 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
792 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100793
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 msg "test: AES_FEWER_TABLES"
795 make test
796}
Hanno Becker83ebf782017-07-07 12:29:15 +0100797
Gilles Peskine8f073122018-11-27 15:58:47 +0100798component_test_aes_rom_tables () {
799 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100800 cp "$CONFIG_H" "$CONFIG_BAK"
801 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
802 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100803
Gilles Peskine8f073122018-11-27 15:58:47 +0100804 msg "test: AES_ROM_TABLES"
805 make test
806}
Hanno Becker83ebf782017-07-07 12:29:15 +0100807
Gilles Peskine8f073122018-11-27 15:58:47 +0100808component_test_aes_fewer_tables_and_rom_tables () {
809 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 cp "$CONFIG_H" "$CONFIG_BAK"
811 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
812 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
813 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100814
Gilles Peskine8f073122018-11-27 15:58:47 +0100815 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
816 make test
817}
818
819component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100820 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100821 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100822}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100825 # Build once with -O0, to compile out the i386 specific inline assembly
826 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100827 cp "$CONFIG_H" "$CONFIG_BAK"
828 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100829 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100830
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100831 msg "test: i386, make, gcc -O0 (ASan build)"
832 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100833}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100836 # Build again with -O1, to compile in the i386 specific inline assembly
837 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100838 cp "$CONFIG_H" "$CONFIG_BAK"
839 scripts/config.pl full
840 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
841
842 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100843 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100844}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100845
Gilles Peskine8f073122018-11-27 15:58:47 +0100846component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100847 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100848 cp "$CONFIG_H" "$CONFIG_BAK"
849 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100850 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
851
852 msg "test: 64-bit ILP32, make, gcc"
853 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100854}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000855
Gilles Peskine8f073122018-11-27 15:58:47 +0100856component_test_have_int32 () {
857 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100858 cp "$CONFIG_H" "$CONFIG_BAK"
859 scripts/config.pl unset MBEDTLS_HAVE_ASM
860 scripts/config.pl unset MBEDTLS_AESNI_C
861 scripts/config.pl unset MBEDTLS_PADLOCK_C
862 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100863
Gilles Peskine8f073122018-11-27 15:58:47 +0100864 msg "test: gcc, force 32-bit bignum limbs"
865 make test
866}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100867
Gilles Peskine8f073122018-11-27 15:58:47 +0100868component_test_have_int64 () {
869 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100870 cp "$CONFIG_H" "$CONFIG_BAK"
871 scripts/config.pl unset MBEDTLS_HAVE_ASM
872 scripts/config.pl unset MBEDTLS_AESNI_C
873 scripts/config.pl unset MBEDTLS_PADLOCK_C
874 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100875
Gilles Peskine8f073122018-11-27 15:58:47 +0100876 msg "test: gcc, force 64-bit bignum limbs"
877 make test
878}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000879
Gilles Peskine8f073122018-11-27 15:58:47 +0100880component_test_no_udbl_division () {
881 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100882 cp "$CONFIG_H" "$CONFIG_BAK"
883 scripts/config.pl full
884 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
885 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
886 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200887
Gilles Peskine8f073122018-11-27 15:58:47 +0100888 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
889 make test
890}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892component_test_no_64bit_multiplication () {
893 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100894 cp "$CONFIG_H" "$CONFIG_BAK"
895 scripts/config.pl full
896 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
897 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
898 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200899
Gilles Peskine8f073122018-11-27 15:58:47 +0100900 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
901 make test
902}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200903
Gilles Peskine8f073122018-11-27 15:58:47 +0100904component_build_arm_none_eabi_gcc () {
905 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100906 cp "$CONFIG_H" "$CONFIG_BAK"
907 scripts/config.pl full
908 scripts/config.pl unset MBEDTLS_NET_C
909 scripts/config.pl unset MBEDTLS_TIMING_C
910 scripts/config.pl unset MBEDTLS_FS_IO
911 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
912 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
913 # following things are not in the default config
914 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
915 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
916 scripts/config.pl unset MBEDTLS_THREADING_C
917 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
918 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
919 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
920}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200921
Gilles Peskine8f073122018-11-27 15:58:47 +0100922component_build_arm_none_eabi_gcc_no_udbl_division () {
923 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100924 cp "$CONFIG_H" "$CONFIG_BAK"
925 scripts/config.pl full
926 scripts/config.pl unset MBEDTLS_NET_C
927 scripts/config.pl unset MBEDTLS_TIMING_C
928 scripts/config.pl unset MBEDTLS_FS_IO
929 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
930 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
931 # following things are not in the default config
932 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
933 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
934 scripts/config.pl unset MBEDTLS_THREADING_C
935 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
936 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
937 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
938 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
939 echo "Checking that software 64-bit division is not required"
940 if_build_succeeded not grep __aeabi_uldiv library/*.o
941}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200942
Gilles Peskine8f073122018-11-27 15:58:47 +0100943component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
944 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100945 cp "$CONFIG_H" "$CONFIG_BAK"
946 scripts/config.pl full
947 scripts/config.pl unset MBEDTLS_NET_C
948 scripts/config.pl unset MBEDTLS_TIMING_C
949 scripts/config.pl unset MBEDTLS_FS_IO
950 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
951 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
952 # following things are not in the default config
953 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
954 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
955 scripts/config.pl unset MBEDTLS_THREADING_C
956 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
957 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
958 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
959 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
960 echo "Checking that software 64-bit multiplication is not required"
961 if_build_succeeded not grep __aeabi_lmul library/*.o
962}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200963
Gilles Peskine8f073122018-11-27 15:58:47 +0100964component_build_armcc () {
965 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100966 cp "$CONFIG_H" "$CONFIG_BAK"
967 scripts/config.pl full
968 scripts/config.pl unset MBEDTLS_NET_C
969 scripts/config.pl unset MBEDTLS_TIMING_C
970 scripts/config.pl unset MBEDTLS_FS_IO
971 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
972 scripts/config.pl unset MBEDTLS_HAVE_TIME
973 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
974 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
975 # following things are not in the default config
976 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
977 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
978 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
979 scripts/config.pl unset MBEDTLS_THREADING_C
980 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
981 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
982 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984 if [ $RUN_ARMCC -ne 0 ]; then
985 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
986 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200987
Gilles Peskine8f073122018-11-27 15:58:47 +0100988 # ARM Compiler 6 - Target ARMv7-A
989 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +0200990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 # ARM Compiler 6 - Target ARMv7-M
992 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +0100993
Gilles Peskine8f073122018-11-27 15:58:47 +0100994 # ARM Compiler 6 - Target ARMv8-A - AArch32
995 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +0100996
Gilles Peskine8f073122018-11-27 15:58:47 +0100997 # ARM Compiler 6 - Target ARMv8-M
998 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +0200999
Gilles Peskine8f073122018-11-27 15:58:47 +01001000 # ARM Compiler 6 - Target ARMv8-A - AArch64
1001 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1002 fi
1003}
Simon Butcher940737f2017-07-23 13:42:36 +02001004
Gilles Peskine8f073122018-11-27 15:58:47 +01001005component_test_allow_sha1 () {
1006 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001007 cp "$CONFIG_H" "$CONFIG_BAK"
1008 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1009 make CFLAGS='-Werror -Wall -Wextra'
1010 msg "test: allow SHA1 in certificates by default"
1011 make test
1012 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1013}
Simon Butcher940737f2017-07-23 13:42:36 +02001014
Gilles Peskine8f073122018-11-27 15:58:47 +01001015component_build_mingw () {
1016 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001017 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Gilles Peskine2a458da2017-05-12 15:26:58 +02001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 # note Make tests only builds the tests, but doesn't run them
1020 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1021 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1024 make 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
1025 make 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
1026 make WINDOWS_BUILD=1 clean
1027}
Simon Butcher002bc622016-11-17 09:27:45 +00001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001030 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001031 cp "$CONFIG_H" "$CONFIG_BAK"
1032 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1033 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1034 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001035
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001036 msg "test: main suites (MSan)" # ~ 10s
1037 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001038
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001039 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001040 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001041
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001042 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001043
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001044 if [ "$MEMORY" -gt 0 ]; then
1045 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001046 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001047 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001048}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001049
Gilles Peskine8f073122018-11-27 15:58:47 +01001050component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001051 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001052 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1053 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001054
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001055 msg "test: main suites valgrind (Release)"
1056 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001057
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001058 # Optional part(s)
1059 # Currently broken, programs don't seem to receive signals
1060 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001061
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001062 if [ "$MEMORY" -gt 0 ]; then
1063 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001064 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001065 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001066
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001067 if [ "$MEMORY" -gt 1 ]; then
1068 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001069 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001070 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001071}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001072
Gilles Peskine8f073122018-11-27 15:58:47 +01001073component_test_cmake_out_of_source () {
1074 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001075 MBEDTLS_ROOT_DIR="$PWD"
1076 mkdir "$OUT_OF_SOURCE_DIR"
1077 cd "$OUT_OF_SOURCE_DIR"
1078 cmake "$MBEDTLS_ROOT_DIR"
1079 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001080
Gilles Peskine8f073122018-11-27 15:58:47 +01001081 msg "test: cmake 'out-of-source' build"
1082 make test
1083 # Test an SSL option that requires an auxiliary script in test/scripts/.
1084 # Also ensure that there are no error messages such as
1085 # "No such file or directory", which would indicate that some required
1086 # file is missing (ssl-opt.sh tolerates the absence of some files so
1087 # may exit with status 0 but emit errors).
1088 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1089 if [ -s ssl-opt.err ]; then
1090 cat ssl-opt.err >&2
1091 record_status [ ! -s ssl-opt.err ]
1092 rm ssl-opt.err
1093 fi
1094 cd "$MBEDTLS_ROOT_DIR"
1095 rm -rf "$OUT_OF_SOURCE_DIR"
1096 unset MBEDTLS_ROOT_DIR
1097}
Andres AGdc192212016-08-31 17:33:13 +01001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099component_test_zeroize () {
1100 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1101 # different combinations of compilers and optimization flags by using an
1102 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1103 # system in all cases that the script fails, so we must manually search the
1104 # output to check whether the pass string is present and no failure strings
1105 # were printed.
1106 for optimization_flag in -O2 -O3 -Ofast -Os; do
1107 for compiler in clang gcc; do
1108 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Gilles Peskine8f073122018-11-27 15:58:47 +01001109 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
1110 if_build_succeeded gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
1111 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1112 if_build_succeeded not grep -i "error" test_zeroize.log
1113 rm -f test_zeroize.log
Gilles Peskinee48351a2018-11-27 16:06:30 +01001114 make clean
Gilles Peskine8f073122018-11-27 15:58:47 +01001115 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001116 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001117}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001118
Gilles Peskine8f073122018-11-27 15:58:47 +01001119component_check_python_files () {
1120 msg "Lint: Python scripts"
1121 record_status tests/scripts/check-python-files.sh
1122}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001123
Gilles Peskine8f073122018-11-27 15:58:47 +01001124component_check_generate_test_code () {
1125 msg "uint test: generate_test_code.py"
1126 record_status ./tests/scripts/test_generate_test_code.py
1127}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001128
1129################################################################
1130#### Termination
1131################################################################
1132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133post_report () {
1134 msg "Done, cleaning up"
1135 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001136
Gilles Peskine8f073122018-11-27 15:58:47 +01001137 final_report
1138}
1139
1140
1141
1142################################################################
1143#### Run all the things
1144################################################################
1145
Gilles Peskine92525112018-11-27 18:15:35 +01001146run_all_components () {
1147 # Small things
1148 run_component component_check_recursion
1149 run_component component_check_generated_files
1150 run_component component_check_doxy_blocks
1151 run_component component_check_files
1152 run_component component_check_names
1153 run_component component_check_doxygen_warnings
1154
1155 # Test many different configurations
1156 run_component component_test_default_cmake_gcc_asan
1157 run_component component_test_ref_configs
1158 run_component component_test_sslv3
1159 run_component component_test_no_renegotiation
1160 run_component component_test_rsa_no_crt
1161 run_component component_test_small_ssl_out_content_len
1162 run_component component_test_small_ssl_in_content_len
1163 run_component component_test_small_ssl_dtls_max_buffering
1164 run_component component_test_small_mbedtls_ssl_dtls_max_buffering
1165 run_component component_test_full_cmake_clang
1166 run_component component_build_deprecated
1167 run_component component_test_depends_curves
1168 run_component component_test_depends_hashes
1169 run_component component_test_depends_pkalgs
1170 run_component component_build_key_exchanges
1171 run_component component_build_default_make_gcc_and_cxx
1172 run_component component_test_no_platform
1173 run_component component_build_no_std_function
1174 run_component component_build_no_ssl_srv
1175 run_component component_build_no_ssl_cli
1176 run_component component_build_no_sockets
1177 run_component component_test_no_max_fragment_length
1178 run_component component_test_no_max_fragment_length_small_ssl_out_content_len
1179 run_component component_test_null_entropy
1180 run_component component_test_platform_calloc_macro
1181 run_component component_test_aes_fewer_tables
1182 run_component component_test_aes_rom_tables
1183 run_component component_test_aes_fewer_tables_and_rom_tables
1184 if uname -a | grep -F Linux >/dev/null; then
1185 run_component component_test_make_shared
1186 fi
1187 if uname -a | grep -F x86_64 >/dev/null; then
1188 run_component component_test_m32_o0
1189 run_component component_test_m32_o1
1190 run_component component_test_mx32
1191 fi
1192 run_component component_test_have_int32
1193 run_component component_test_have_int64
1194 run_component component_test_no_udbl_division
1195 run_component component_test_no_64bit_multiplication
1196 run_component component_build_arm_none_eabi_gcc
1197 run_component component_build_arm_none_eabi_gcc_no_udbl_division
1198 run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
1199 run_component component_build_armcc
1200 run_component component_test_allow_sha1
1201 run_component component_build_mingw
1202 # MemSan currently only available on Linux 64 bits
1203 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
1204 run_component component_test_memsan
1205 else # no MemSan
1206 run_component component_test_memcheck
1207 fi
1208 run_component component_test_cmake_out_of_source
1209
1210 # More small things
1211 run_component component_test_zeroize
1212 run_component component_check_python_files
1213 run_component component_check_generate_test_code
1214}
1215
Gilles Peskinee48351a2018-11-27 16:06:30 +01001216# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001217run_component () {
1218 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001219 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001220}
1221
1222# Preliminary setup
1223pre_check_environment
1224pre_initialize_variables
1225pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001226
1227case "$INTROSPECTION_MODE" in
1228 list_components)
1229 components=
1230 newline='
1231'
1232 run_component () {
Gilles Peskine92525112018-11-27 18:15:35 +01001233 components="${components}${newline}${1#component_}"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001234 }
1235 ;;
1236
1237 *)
1238 pre_check_git
1239 build_status=0
1240 if [ $KEEP_GOING -eq 1 ]; then
1241 pre_setup_keep_going
1242 else
1243 record_status () {
1244 "$@"
1245 }
1246 fi
1247 pre_print_configuration
1248 pre_check_tools
1249 pre_print_tools
1250 cleanup
1251 ;;
1252esac
Gilles Peskine8f073122018-11-27 15:58:47 +01001253
Gilles Peskine92525112018-11-27 18:15:35 +01001254if [ -n "$COMPONENTS" ]; then
1255 for component in $COMPONENTS; do
1256 run_component "component_$component"
1257 done
1258else
1259 run_all_components
Gilles Peskine8f073122018-11-27 15:58:47 +01001260fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001261
1262# We're done.
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001263case "$INTROSPECTION_MODE" in
1264 list_components)
1265 echo "$components" | sort
1266 ;;
1267 *)
1268 post_report
1269 ;;
1270esac