blob: 645cdd9a232a84f1d1d3f644dd3df7dfebb3d7d3 [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 Peskine8f073122018-11-27 15:58:47 +0100107 MEMORY=0
108 FORCE=0
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100109 INTROSPECTION_MODE=
Gilles Peskine8f073122018-11-27 15:58:47 +0100110 KEEP_GOING=0
111 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100112
Gilles Peskine8f073122018-11-27 15:58:47 +0100113 # Default commands, can be overriden by the environment
114 : ${OPENSSL:="openssl"}
115 : ${OPENSSL_LEGACY:="$OPENSSL"}
116 : ${OPENSSL_NEXT:="$OPENSSL"}
117 : ${GNUTLS_CLI:="gnutls-cli"}
118 : ${GNUTLS_SERV:="gnutls-serv"}
119 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
120 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
121 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
122 : ${ARMC5_BIN_DIR:=/usr/bin}
123 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100124
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
126 if [ -n "${MAKEFLAGS+set}" ]; then
127 export MAKEFLAGS="-j"
128 fi
129}
Andres AG38495a32016-07-12 16:54:33 +0100130
Simon Butcher41eeccf2016-09-07 00:07:09 +0100131usage()
SimonB2e23c822016-04-16 21:54:39 +0100132{
Gilles Peskine709346a2017-12-10 23:43:39 +0100133 cat <<EOF
134Usage: $0 [OPTION]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100135Run mbedtls release validation tests.
136
137Special options:
138 -h|--help Print this help and exit.
139 --list-components List available test components and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100140
141General options:
142 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100143 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100144 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100145 --armcc Run ARM Compiler builds (on by default).
146 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100147 --no-force Refuse to overwrite modified files (default).
148 --no-keep-going Stop at the first error (default).
149 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100150 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100151 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100152 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
153 -s|--seed Integer seed value to use for this test run.
154
155Tool path options:
156 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
157 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
158 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
159 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
160 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
161 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
162 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
163 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100164 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100165EOF
SimonB2e23c822016-04-16 21:54:39 +0100166}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100167
168# remove built files as well as the cmake cache/config
169cleanup()
170{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100171 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
172 cd "$MBEDTLS_ROOT_DIR"
173 fi
174
Gilles Peskine7c652162017-12-11 00:01:40 +0100175 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200176
Gilles Peskine31b07e22018-03-21 12:15:06 +0100177 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100178 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100179 -iname CMakeFiles -exec rm -rf {} \+ -o \
180 \( -iname cmake_install.cmake -o \
181 -iname CTestTestfile.cmake -o \
182 -iname CMakeCache.txt \) -exec rm {} \+
183 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000184 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200185 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
186 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200187
188 if [ -f "$CONFIG_BAK" ]; then
189 mv "$CONFIG_BAK" "$CONFIG_H"
190 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100191}
192
Gilles Peskine7c652162017-12-11 00:01:40 +0100193# Executed on exit. May be redefined depending on command line options.
194final_report () {
195 :
196}
197
198fatal_signal () {
199 cleanup
200 final_report $1
201 trap - $1
202 kill -$1 $$
203}
204
205trap 'fatal_signal HUP' HUP
206trap 'fatal_signal INT' INT
207trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200208
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100209msg()
210{
211 echo ""
212 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100213 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000214 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100215 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100216 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100217}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100218
Gilles Peskine8f073122018-11-27 15:58:47 +0100219armc6_build_test()
220{
221 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100222
Gilles Peskine8f073122018-11-27 15:58:47 +0100223 msg "build: ARM Compiler 6 ($FLAGS), make"
224 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
225 WARNING_CFLAGS='-xc -std=c99' make lib
226 make clean
227}
Andres AGa5cd9732016-10-17 15:23:10 +0100228
Andres AGd9eba4b2016-08-26 14:42:14 +0100229err_msg()
230{
231 echo "$1" >&2
232}
233
234check_tools()
235{
236 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000237 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100238 err_msg "$TOOL not found!"
239 exit 1
240 fi
241 done
242}
243
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400244check_headers_in_cpp () {
245 ls include/mbedtls >headers.txt
246 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
247 sort |
248 diff headers.txt -
249 rm headers.txt
250}
251
Gilles Peskine8f073122018-11-27 15:58:47 +0100252pre_parse_command_line () {
253 while [ $# -gt 0 ]; do
254 case "$1" in
255 --armcc) RUN_ARMCC=1;;
256 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
257 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
258 --force|-f) FORCE=1;;
259 --gnutls-cli) shift; GNUTLS_CLI="$1";;
260 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
261 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
262 --gnutls-serv) shift; GNUTLS_SERV="$1";;
263 --help|-h) usage; exit;;
264 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100265 --list-components) INTROSPECTION_MODE=list_components;;
Gilles Peskine8f073122018-11-27 15:58:47 +0100266 --memory|-m) MEMORY=1;;
267 --no-armcc) RUN_ARMCC=0;;
268 --no-force) FORCE=0;;
269 --no-keep-going) KEEP_GOING=0;;
270 --no-memory) MEMORY=0;;
271 --openssl) shift; OPENSSL="$1";;
272 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
273 --openssl-next) shift; OPENSSL_NEXT="$1";;
274 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
275 --random-seed) unset SEED;;
276 --release-test|-r) SEED=1;;
277 --seed|-s) shift; SEED="$1";;
278 *)
279 echo >&2 "Unknown option: $1"
280 echo >&2 "Run $0 --help for usage."
281 exit 120
282 ;;
283 esac
284 shift
285 done
286}
SimonB2e23c822016-04-16 21:54:39 +0100287
Gilles Peskine8f073122018-11-27 15:58:47 +0100288pre_check_git () {
289 if [ $FORCE -eq 1 ]; then
290 git checkout-index -f -q $CONFIG_H
291 cleanup
292 else
SimonB2e23c822016-04-16 21:54:39 +0100293
Gilles Peskine8f073122018-11-27 15:58:47 +0100294 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
295 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
296 echo "You can either delete this directory manually, or force the test by rerunning"
297 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
298 exit 1
299 fi
300
301 if ! git diff-files --quiet include/mbedtls/config.h; then
302 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
303 echo "You can either delete or preserve your work, or force the test by rerunning the"
304 echo "script as: $0 --force"
305 exit 1
306 fi
Andres AGdc192212016-08-31 17:33:13 +0100307 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100308}
Andres AGdc192212016-08-31 17:33:13 +0100309
Gilles Peskine8f073122018-11-27 15:58:47 +0100310pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100311 failure_summary=
312 failure_count=0
313 start_red=
314 end_color=
315 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100316 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100317 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
318 start_red=$(printf '\033[31m')
319 end_color=$(printf '\033[0m')
320 ;;
321 esac
322 fi
323 record_status () {
324 if "$@"; then
325 last_status=0
326 else
327 last_status=$?
328 text="$current_section: $* -> $last_status"
329 failure_summary="$failure_summary
330$text"
331 failure_count=$((failure_count + 1))
332 echo "${start_red}^^^^$text^^^^${end_color}"
333 fi
334 }
335 make () {
336 case "$*" in
337 *test|*check)
338 if [ $build_status -eq 0 ]; then
339 record_status command make "$@"
340 else
341 echo "(skipped because the build failed)"
342 fi
343 ;;
344 *)
345 record_status command make "$@"
346 build_status=$last_status
347 ;;
348 esac
349 }
350 final_report () {
351 if [ $failure_count -gt 0 ]; then
352 echo
353 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
354 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
355 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100356 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100357 elif [ -z "${1-}" ]; then
358 echo "SUCCESS :)"
359 fi
360 if [ -n "${1-}" ]; then
361 echo "Killed by SIG$1."
362 fi
363 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100364}
365
Gilles Peskine7c652162017-12-11 00:01:40 +0100366if_build_succeeded () {
367 if [ $build_status -eq 0 ]; then
368 record_status "$@"
369 fi
370}
371
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200372# to be used instead of ! for commands run with
373# record_status or if_build_succeeded
374not() {
375 ! "$@"
376}
377
Gilles Peskine8f073122018-11-27 15:58:47 +0100378pre_print_configuration () {
379 msg "info: $0 configuration"
380 echo "MEMORY: $MEMORY"
381 echo "FORCE: $FORCE"
382 echo "SEED: ${SEED-"UNSET"}"
383 echo "OPENSSL: $OPENSSL"
384 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
385 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
386 echo "GNUTLS_CLI: $GNUTLS_CLI"
387 echo "GNUTLS_SERV: $GNUTLS_SERV"
388 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
389 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
390 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
391 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
392}
Andres AG87bb5772016-09-27 15:05:15 +0100393
Gilles Peskine8f073122018-11-27 15:58:47 +0100394pre_check_tools () {
395 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
396 ARMC5_AR="$ARMC5_BIN_DIR/armar"
397 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
398 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100399
Gilles Peskine8f073122018-11-27 15:58:47 +0100400 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
401 # we just export the variables they require
402 export OPENSSL_CMD="$OPENSSL"
403 export GNUTLS_CLI="$GNUTLS_CLI"
404 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100405
Gilles Peskine8f073122018-11-27 15:58:47 +0100406 # Avoid passing --seed flag in every call to ssl-opt.sh
407 if [ -n "${SEED-}" ]; then
408 export SEED
409 fi
Andres AG7770ea82016-10-10 15:46:20 +0100410
Gilles Peskine8f073122018-11-27 15:58:47 +0100411 # Make sure the tools we need are available.
412 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
413 "$GNUTLS_CLI" "$GNUTLS_SERV" \
414 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
415 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
416 if [ $RUN_ARMCC -ne 0 ]; then
417 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
418 fi
419}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100420
421
422################################################################
423#### Basic checks
424################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100425
SimonB2e23c822016-04-16 21:54:39 +0100426#
427# Test Suites to be executed
428#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200429# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100430# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200431# and/or are more likely to fail than others (eg I use Clang most of the
432# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200433# 2. Minimize total running time, by avoiding useless rebuilds
434#
435# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100436
Gilles Peskine8f073122018-11-27 15:58:47 +0100437pre_print_tools () {
438 msg "info: output_env.sh"
439 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
440 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
441 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
442 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
443}
Janos Follathb72c6782016-07-19 14:54:17 +0100444
Gilles Peskine8f073122018-11-27 15:58:47 +0100445component_check_recursion () {
446 msg "test: recursion.pl" # < 1s
447 record_status tests/scripts/recursion.pl library/*.c
448}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100449
Gilles Peskine8f073122018-11-27 15:58:47 +0100450component_check_generated_files () {
451 msg "test: freshness of generated source files" # < 1s
452 record_status tests/scripts/check-generated-files.sh
453}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000454
Gilles Peskine8f073122018-11-27 15:58:47 +0100455component_check_doxy_blocks () {
456 msg "test: doxygen markup outside doxygen blocks" # < 1s
457 record_status tests/scripts/check-doxy-blocks.pl
458}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200459
Gilles Peskine8f073122018-11-27 15:58:47 +0100460component_check_files () {
461 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100462 record_status tests/scripts/check-files.py
463}
Darryl Greena07039c2018-03-13 16:48:16 +0000464
Gilles Peskine8f073122018-11-27 15:58:47 +0100465component_check_names () {
466 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100467 record_status tests/scripts/check-names.sh
468}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200469
Gilles Peskine8f073122018-11-27 15:58:47 +0100470component_check_doxygen_warnings () {
471 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100472 record_status tests/scripts/doxygen.sh
473}
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 Peskine8f073122018-11-27 15:58:47 +0100481component_test_default_cmake_gcc_asan () {
482 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100483 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
484 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100485
Gilles Peskine8f073122018-11-27 15:58:47 +0100486 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
487 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200488
Gilles Peskine8f073122018-11-27 15:58:47 +0100489 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
490 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200491
Gilles Peskine8f073122018-11-27 15:58:47 +0100492 msg "test: compat.sh (ASan build)" # ~ 6 min
493 if_build_succeeded tests/compat.sh
494}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200495
Gilles Peskine782f4112018-11-27 16:11:09 +0100496component_test_ref_configs () {
497 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
498 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
499 record_status tests/scripts/test-ref-configs.pl
500}
501
Gilles Peskine8f073122018-11-27 15:58:47 +0100502component_test_sslv3 () {
503 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100504 cp "$CONFIG_H" "$CONFIG_BAK"
505 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
506 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
507 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000508
Gilles Peskine8f073122018-11-27 15:58:47 +0100509 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
510 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000511
Gilles Peskine8f073122018-11-27 15:58:47 +0100512 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
513 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
514 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000515
Gilles Peskine8f073122018-11-27 15:58:47 +0100516 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
517 if_build_succeeded tests/ssl-opt.sh
518}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000519
Gilles Peskine8f073122018-11-27 15:58:47 +0100520component_test_no_renegotiation () {
521 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100522 cp "$CONFIG_H" "$CONFIG_BAK"
523 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
524 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
525 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100526
Gilles Peskine8f073122018-11-27 15:58:47 +0100527 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
528 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100529
Gilles Peskine8f073122018-11-27 15:58:47 +0100530 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
531 if_build_succeeded tests/ssl-opt.sh
532}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100533
Gilles Peskine8f073122018-11-27 15:58:47 +0100534component_test_rsa_no_crt () {
535 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100536 cp "$CONFIG_H" "$CONFIG_BAK"
537 scripts/config.pl set MBEDTLS_RSA_NO_CRT
538 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
539 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100540
Gilles Peskine8f073122018-11-27 15:58:47 +0100541 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
542 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100543
Gilles Peskine8f073122018-11-27 15:58:47 +0100544 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
545 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100546
Gilles Peskine8f073122018-11-27 15:58:47 +0100547 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
548 if_build_succeeded tests/compat.sh -t RSA
549}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100550
Gilles Peskine8f073122018-11-27 15:58:47 +0100551component_test_small_ssl_out_content_len () {
552 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100553 cp "$CONFIG_H" "$CONFIG_BAK"
554 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
555 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
556 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
557 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000558
Gilles Peskine8f073122018-11-27 15:58:47 +0100559 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
560 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
561}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000562
Gilles Peskine8f073122018-11-27 15:58:47 +0100563component_test_small_ssl_in_content_len () {
564 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100565 cp "$CONFIG_H" "$CONFIG_BAK"
566 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
567 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
568 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
569 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000570
Gilles Peskine8f073122018-11-27 15:58:47 +0100571 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
572 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
573}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000574
Gilles Peskine8f073122018-11-27 15:58:47 +0100575component_test_small_ssl_dtls_max_buffering () {
576 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100577 cp "$CONFIG_H" "$CONFIG_BAK"
578 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
579 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
580 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100581
Gilles Peskine8f073122018-11-27 15:58:47 +0100582 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
583 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
584}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100585
Gilles Peskine8f073122018-11-27 15:58:47 +0100586component_test_small_mbedtls_ssl_dtls_max_buffering () {
587 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100588 cp "$CONFIG_H" "$CONFIG_BAK"
589 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
590 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
591 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100592
Gilles Peskine8f073122018-11-27 15:58:47 +0100593 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
594 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
595}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100596
Gilles Peskine8f073122018-11-27 15:58:47 +0100597component_test_full_cmake_clang () {
598 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100599 cp "$CONFIG_H" "$CONFIG_BAK"
600 scripts/config.pl full
601 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
602 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
603 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100604
Gilles Peskine8f073122018-11-27 15:58:47 +0100605 msg "test: main suites (full config)" # ~ 5s
606 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200607
Gilles Peskine8f073122018-11-27 15:58:47 +0100608 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
609 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
612 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 +0200613
Gilles Peskine8f073122018-11-27 15:58:47 +0100614 msg "test: compat.sh ARIA + ChachaPoly"
615 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
616}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100617
Gilles Peskine8f073122018-11-27 15:58:47 +0100618component_build_deprecated () {
619 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 cp "$CONFIG_H" "$CONFIG_BAK"
621 scripts/config.pl full
622 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
623 # Build with -O -Wextra to catch a maximum of issues.
624 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
625 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100626
Gilles Peskine8f073122018-11-27 15:58:47 +0100627 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
628 # No cleanup, just tweak the configuration and rebuild
629 make clean
630 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
631 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
632 # Build with -O -Wextra to catch a maximum of issues.
633 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
634 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
635}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100636
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200637
Gilles Peskine8f073122018-11-27 15:58:47 +0100638component_test_depends_curves () {
639 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100640 record_status tests/scripts/curves.pl
641}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200642
Gilles Peskine8f073122018-11-27 15:58:47 +0100643component_test_depends_hashes () {
644 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100645 record_status tests/scripts/depends-hashes.pl
646}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200647
Gilles Peskine8f073122018-11-27 15:58:47 +0100648component_test_depends_pkalgs () {
649 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100650 record_status tests/scripts/depends-pkalgs.pl
651}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200652
Gilles Peskine8f073122018-11-27 15:58:47 +0100653component_build_key_exchanges () {
654 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100655 record_status tests/scripts/key-exchanges.pl
656}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100657
Gilles Peskine8f073122018-11-27 15:58:47 +0100658component_build_default_make_gcc_and_cxx () {
659 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100660 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662 msg "test: verify header list in cpp_dummy_build.cpp"
663 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400664
Gilles Peskine8f073122018-11-27 15:58:47 +0100665 msg "build: Unix make, incremental g++"
666 make TEST_CPP=1
667}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669component_test_no_platform () {
670 # Full configuration build, without platform support, file IO and net sockets.
671 # This should catch missing mbedtls_printf definitions, and by disabling file
672 # IO, it should catch missing '#include <stdio.h>'
673 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 cp "$CONFIG_H" "$CONFIG_BAK"
675 scripts/config.pl full
676 scripts/config.pl unset MBEDTLS_PLATFORM_C
677 scripts/config.pl unset MBEDTLS_NET_C
678 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
679 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
680 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
681 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
682 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
683 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
684 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
685 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
686 scripts/config.pl unset MBEDTLS_FS_IO
687 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
688 # to re-enable platform integration features otherwise disabled in C99 builds
689 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
690 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
691}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100692
Gilles Peskine8f073122018-11-27 15:58:47 +0100693component_build_no_std_function () {
694 # catch compile bugs in _uninit functions
695 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100696 cp "$CONFIG_H" "$CONFIG_BAK"
697 scripts/config.pl full
698 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
699 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
700 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
701}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200702
Gilles Peskine8f073122018-11-27 15:58:47 +0100703component_build_no_ssl_srv () {
704 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100705 cp "$CONFIG_H" "$CONFIG_BAK"
706 scripts/config.pl full
707 scripts/config.pl unset MBEDTLS_SSL_SRV_C
708 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
709}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711component_build_no_ssl_cli () {
712 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 cp "$CONFIG_H" "$CONFIG_BAK"
714 scripts/config.pl full
715 scripts/config.pl unset MBEDTLS_SSL_CLI_C
716 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
717}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200718
Gilles Peskine8f073122018-11-27 15:58:47 +0100719component_build_no_sockets () {
720 # Note, C99 compliance can also be tested with the sockets support disabled,
721 # as that requires a POSIX platform (which isn't the same as C99).
722 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100723 cp "$CONFIG_H" "$CONFIG_BAK"
724 scripts/config.pl full
725 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
726 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
727 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
728}
Hanno Becker5175ac62017-09-18 15:36:25 +0100729
Gilles Peskine8f073122018-11-27 15:58:47 +0100730component_test_no_max_fragment_length () {
731 # Run max fragment length tests with MFL disabled
732 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 cp "$CONFIG_H" "$CONFIG_BAK"
734 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
735 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
736 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 msg "test: ssl-opt.sh, MFL-related tests"
739 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
740}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742component_test_no_max_fragment_length_small_ssl_out_content_len () {
743 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 cp "$CONFIG_H" "$CONFIG_BAK"
745 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
746 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
747 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
748 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
749 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000750
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
752 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
753}
Janos Follath06c54002016-06-09 13:57:40 +0100754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755component_test_null_entropy () {
756 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100757 cp "$CONFIG_H" "$CONFIG_BAK"
758 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
759 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
760 scripts/config.pl set MBEDTLS_ENTROPY_C
761 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
762 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
763 scripts/config.pl unset MBEDTLS_HAVEGE_C
764 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
765 make
Janos Follath06c54002016-06-09 13:57:40 +0100766
Gilles Peskine8f073122018-11-27 15:58:47 +0100767 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
768 make test
769}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100770
Gilles Peskine8f073122018-11-27 15:58:47 +0100771component_test_platform_calloc_macro () {
772 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100773 cp "$CONFIG_H" "$CONFIG_BAK"
774 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
775 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
776 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
777 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
778 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100779
Gilles Peskine8f073122018-11-27 15:58:47 +0100780 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
781 make test
782}
Hanno Becker83ebf782017-07-07 12:29:15 +0100783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784component_test_aes_fewer_tables () {
785 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100786 cp "$CONFIG_H" "$CONFIG_BAK"
787 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
788 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100789
Gilles Peskine8f073122018-11-27 15:58:47 +0100790 msg "test: AES_FEWER_TABLES"
791 make test
792}
Hanno Becker83ebf782017-07-07 12:29:15 +0100793
Gilles Peskine8f073122018-11-27 15:58:47 +0100794component_test_aes_rom_tables () {
795 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100796 cp "$CONFIG_H" "$CONFIG_BAK"
797 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
798 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800 msg "test: AES_ROM_TABLES"
801 make test
802}
Hanno Becker83ebf782017-07-07 12:29:15 +0100803
Gilles Peskine8f073122018-11-27 15:58:47 +0100804component_test_aes_fewer_tables_and_rom_tables () {
805 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100806 cp "$CONFIG_H" "$CONFIG_BAK"
807 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
808 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
809 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100810
Gilles Peskine8f073122018-11-27 15:58:47 +0100811 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
812 make test
813}
814
815component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100816 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100817 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100818}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100821 # Build once with -O0, to compile out the i386 specific inline assembly
822 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100823 cp "$CONFIG_H" "$CONFIG_BAK"
824 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100825 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100826
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100827 msg "test: i386, make, gcc -O0 (ASan build)"
828 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100829}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100830
Gilles Peskine8f073122018-11-27 15:58:47 +0100831component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100832 # Build again with -O1, to compile in the i386 specific inline assembly
833 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100834 cp "$CONFIG_H" "$CONFIG_BAK"
835 scripts/config.pl full
836 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
837
838 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100839 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100840}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100841
Gilles Peskine8f073122018-11-27 15:58:47 +0100842component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100843 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100844 cp "$CONFIG_H" "$CONFIG_BAK"
845 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100846 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
847
848 msg "test: 64-bit ILP32, make, gcc"
849 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100850}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000851
Gilles Peskine8f073122018-11-27 15:58:47 +0100852component_test_have_int32 () {
853 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100854 cp "$CONFIG_H" "$CONFIG_BAK"
855 scripts/config.pl unset MBEDTLS_HAVE_ASM
856 scripts/config.pl unset MBEDTLS_AESNI_C
857 scripts/config.pl unset MBEDTLS_PADLOCK_C
858 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100859
Gilles Peskine8f073122018-11-27 15:58:47 +0100860 msg "test: gcc, force 32-bit bignum limbs"
861 make test
862}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100863
Gilles Peskine8f073122018-11-27 15:58:47 +0100864component_test_have_int64 () {
865 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 cp "$CONFIG_H" "$CONFIG_BAK"
867 scripts/config.pl unset MBEDTLS_HAVE_ASM
868 scripts/config.pl unset MBEDTLS_AESNI_C
869 scripts/config.pl unset MBEDTLS_PADLOCK_C
870 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100871
Gilles Peskine8f073122018-11-27 15:58:47 +0100872 msg "test: gcc, force 64-bit bignum limbs"
873 make test
874}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000875
Gilles Peskine8f073122018-11-27 15:58:47 +0100876component_test_no_udbl_division () {
877 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 cp "$CONFIG_H" "$CONFIG_BAK"
879 scripts/config.pl full
880 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
881 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
882 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
885 make test
886}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200887
Gilles Peskine8f073122018-11-27 15:58:47 +0100888component_test_no_64bit_multiplication () {
889 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 cp "$CONFIG_H" "$CONFIG_BAK"
891 scripts/config.pl full
892 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
893 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
894 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200895
Gilles Peskine8f073122018-11-27 15:58:47 +0100896 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
897 make test
898}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200899
Gilles Peskine8f073122018-11-27 15:58:47 +0100900component_build_arm_none_eabi_gcc () {
901 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100902 cp "$CONFIG_H" "$CONFIG_BAK"
903 scripts/config.pl full
904 scripts/config.pl unset MBEDTLS_NET_C
905 scripts/config.pl unset MBEDTLS_TIMING_C
906 scripts/config.pl unset MBEDTLS_FS_IO
907 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
908 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
909 # following things are not in the default config
910 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
911 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
912 scripts/config.pl unset MBEDTLS_THREADING_C
913 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
914 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
915 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
916}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200917
Gilles Peskine8f073122018-11-27 15:58:47 +0100918component_build_arm_none_eabi_gcc_no_udbl_division () {
919 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100920 cp "$CONFIG_H" "$CONFIG_BAK"
921 scripts/config.pl full
922 scripts/config.pl unset MBEDTLS_NET_C
923 scripts/config.pl unset MBEDTLS_TIMING_C
924 scripts/config.pl unset MBEDTLS_FS_IO
925 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
926 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
927 # following things are not in the default config
928 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
929 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
930 scripts/config.pl unset MBEDTLS_THREADING_C
931 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
932 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
933 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
934 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
935 echo "Checking that software 64-bit division is not required"
936 if_build_succeeded not grep __aeabi_uldiv library/*.o
937}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200938
Gilles Peskine8f073122018-11-27 15:58:47 +0100939component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
940 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100941 cp "$CONFIG_H" "$CONFIG_BAK"
942 scripts/config.pl full
943 scripts/config.pl unset MBEDTLS_NET_C
944 scripts/config.pl unset MBEDTLS_TIMING_C
945 scripts/config.pl unset MBEDTLS_FS_IO
946 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
947 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
948 # following things are not in the default config
949 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
950 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
951 scripts/config.pl unset MBEDTLS_THREADING_C
952 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
953 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
954 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
955 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
956 echo "Checking that software 64-bit multiplication is not required"
957 if_build_succeeded not grep __aeabi_lmul library/*.o
958}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200959
Gilles Peskine8f073122018-11-27 15:58:47 +0100960component_build_armcc () {
961 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100962 cp "$CONFIG_H" "$CONFIG_BAK"
963 scripts/config.pl full
964 scripts/config.pl unset MBEDTLS_NET_C
965 scripts/config.pl unset MBEDTLS_TIMING_C
966 scripts/config.pl unset MBEDTLS_FS_IO
967 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
968 scripts/config.pl unset MBEDTLS_HAVE_TIME
969 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
970 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
971 # following things are not in the default config
972 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
973 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
974 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
975 scripts/config.pl unset MBEDTLS_THREADING_C
976 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
977 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
978 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000979
Gilles Peskine8f073122018-11-27 15:58:47 +0100980 if [ $RUN_ARMCC -ne 0 ]; then
981 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
982 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984 # ARM Compiler 6 - Target ARMv7-A
985 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +0200986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987 # ARM Compiler 6 - Target ARMv7-M
988 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +0100989
Gilles Peskine8f073122018-11-27 15:58:47 +0100990 # ARM Compiler 6 - Target ARMv8-A - AArch32
991 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +0100992
Gilles Peskine8f073122018-11-27 15:58:47 +0100993 # ARM Compiler 6 - Target ARMv8-M
994 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +0200995
Gilles Peskine8f073122018-11-27 15:58:47 +0100996 # ARM Compiler 6 - Target ARMv8-A - AArch64
997 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
998 fi
999}
Simon Butcher940737f2017-07-23 13:42:36 +02001000
Gilles Peskine8f073122018-11-27 15:58:47 +01001001component_test_allow_sha1 () {
1002 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001003 cp "$CONFIG_H" "$CONFIG_BAK"
1004 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1005 make CFLAGS='-Werror -Wall -Wextra'
1006 msg "test: allow SHA1 in certificates by default"
1007 make test
1008 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1009}
Simon Butcher940737f2017-07-23 13:42:36 +02001010
Gilles Peskine8f073122018-11-27 15:58:47 +01001011component_build_mingw () {
1012 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 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 +02001014
Gilles Peskine8f073122018-11-27 15:58:47 +01001015 # note Make tests only builds the tests, but doesn't run them
1016 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1017 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1020 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
1021 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
1022 make WINDOWS_BUILD=1 clean
1023}
Simon Butcher002bc622016-11-17 09:27:45 +00001024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001026 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001027 cp "$CONFIG_H" "$CONFIG_BAK"
1028 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1029 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1030 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001031
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001032 msg "test: main suites (MSan)" # ~ 10s
1033 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001034
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001035 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001036 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001037
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001038 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001039
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001040 if [ "$MEMORY" -gt 0 ]; then
1041 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001042 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001043 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001044}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001045
Gilles Peskine8f073122018-11-27 15:58:47 +01001046component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001047 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001048 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1049 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001050
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001051 msg "test: main suites valgrind (Release)"
1052 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001053
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001054 # Optional part(s)
1055 # Currently broken, programs don't seem to receive signals
1056 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001057
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001058 if [ "$MEMORY" -gt 0 ]; then
1059 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001060 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001061 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001062
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001063 if [ "$MEMORY" -gt 1 ]; then
1064 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001065 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001066 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001067}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001068
Gilles Peskine8f073122018-11-27 15:58:47 +01001069component_test_cmake_out_of_source () {
1070 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001071 MBEDTLS_ROOT_DIR="$PWD"
1072 mkdir "$OUT_OF_SOURCE_DIR"
1073 cd "$OUT_OF_SOURCE_DIR"
1074 cmake "$MBEDTLS_ROOT_DIR"
1075 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001076
Gilles Peskine8f073122018-11-27 15:58:47 +01001077 msg "test: cmake 'out-of-source' build"
1078 make test
1079 # Test an SSL option that requires an auxiliary script in test/scripts/.
1080 # Also ensure that there are no error messages such as
1081 # "No such file or directory", which would indicate that some required
1082 # file is missing (ssl-opt.sh tolerates the absence of some files so
1083 # may exit with status 0 but emit errors).
1084 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1085 if [ -s ssl-opt.err ]; then
1086 cat ssl-opt.err >&2
1087 record_status [ ! -s ssl-opt.err ]
1088 rm ssl-opt.err
1089 fi
1090 cd "$MBEDTLS_ROOT_DIR"
1091 rm -rf "$OUT_OF_SOURCE_DIR"
1092 unset MBEDTLS_ROOT_DIR
1093}
Andres AGdc192212016-08-31 17:33:13 +01001094
Gilles Peskine8f073122018-11-27 15:58:47 +01001095component_test_zeroize () {
1096 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1097 # different combinations of compilers and optimization flags by using an
1098 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1099 # system in all cases that the script fails, so we must manually search the
1100 # output to check whether the pass string is present and no failure strings
1101 # were printed.
1102 for optimization_flag in -O2 -O3 -Ofast -Os; do
1103 for compiler in clang gcc; do
1104 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Gilles Peskine8f073122018-11-27 15:58:47 +01001105 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
1106 if_build_succeeded gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
1107 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1108 if_build_succeeded not grep -i "error" test_zeroize.log
1109 rm -f test_zeroize.log
Gilles Peskinee48351a2018-11-27 16:06:30 +01001110 make clean
Gilles Peskine8f073122018-11-27 15:58:47 +01001111 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001112 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001113}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001114
Gilles Peskine8f073122018-11-27 15:58:47 +01001115component_check_python_files () {
1116 msg "Lint: Python scripts"
1117 record_status tests/scripts/check-python-files.sh
1118}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001119
Gilles Peskine8f073122018-11-27 15:58:47 +01001120component_check_generate_test_code () {
1121 msg "uint test: generate_test_code.py"
1122 record_status ./tests/scripts/test_generate_test_code.py
1123}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001124
1125################################################################
1126#### Termination
1127################################################################
1128
Gilles Peskine8f073122018-11-27 15:58:47 +01001129post_report () {
1130 msg "Done, cleaning up"
1131 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133 final_report
1134}
1135
1136
1137
1138################################################################
1139#### Run all the things
1140################################################################
1141
Gilles Peskinee48351a2018-11-27 16:06:30 +01001142# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001143run_component () {
1144 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001145 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001146}
1147
1148# Preliminary setup
1149pre_check_environment
1150pre_initialize_variables
1151pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001152
1153case "$INTROSPECTION_MODE" in
1154 list_components)
1155 components=
1156 newline='
1157'
1158 run_component () {
1159 components="${components}${newline}${1}"
1160 }
1161 ;;
1162
1163 *)
1164 pre_check_git
1165 build_status=0
1166 if [ $KEEP_GOING -eq 1 ]; then
1167 pre_setup_keep_going
1168 else
1169 record_status () {
1170 "$@"
1171 }
1172 fi
1173 pre_print_configuration
1174 pre_check_tools
1175 pre_print_tools
1176 cleanup
1177 ;;
1178esac
Gilles Peskine8f073122018-11-27 15:58:47 +01001179
1180# Small things
1181run_component component_check_recursion
1182run_component component_check_generated_files
1183run_component component_check_doxy_blocks
1184run_component component_check_files
1185run_component component_check_names
1186run_component component_check_doxygen_warnings
1187
1188# Test many different configurations
1189run_component component_test_default_cmake_gcc_asan
Gilles Peskine782f4112018-11-27 16:11:09 +01001190run_component component_test_ref_configs
Gilles Peskine8f073122018-11-27 15:58:47 +01001191run_component component_test_sslv3
1192run_component component_test_no_renegotiation
1193run_component component_test_rsa_no_crt
1194run_component component_test_small_ssl_out_content_len
1195run_component component_test_small_ssl_in_content_len
1196run_component component_test_small_ssl_dtls_max_buffering
1197run_component component_test_small_mbedtls_ssl_dtls_max_buffering
1198run_component component_test_full_cmake_clang
1199run_component component_build_deprecated
1200run_component component_test_depends_curves
1201run_component component_test_depends_hashes
1202run_component component_test_depends_pkalgs
1203run_component component_build_key_exchanges
1204run_component component_build_default_make_gcc_and_cxx
1205run_component component_test_no_platform
1206run_component component_build_no_std_function
1207run_component component_build_no_ssl_srv
1208run_component component_build_no_ssl_cli
1209run_component component_build_no_sockets
1210run_component component_test_no_max_fragment_length
1211run_component component_test_no_max_fragment_length_small_ssl_out_content_len
1212run_component component_test_null_entropy
1213run_component component_test_platform_calloc_macro
1214run_component component_test_aes_fewer_tables
1215run_component component_test_aes_rom_tables
1216run_component component_test_aes_fewer_tables_and_rom_tables
1217if uname -a | grep -F Linux >/dev/null; then
1218 run_component component_test_make_shared
1219fi
1220if uname -a | grep -F x86_64 >/dev/null; then
1221 run_component component_test_m32_o0
1222 run_component component_test_m32_o1
1223 run_component component_test_mx32
1224fi
1225run_component component_test_have_int32
1226run_component component_test_have_int64
1227run_component component_test_no_udbl_division
1228run_component component_test_no_64bit_multiplication
1229run_component component_build_arm_none_eabi_gcc
1230run_component component_build_arm_none_eabi_gcc_no_udbl_division
1231run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
1232run_component component_build_armcc
1233run_component component_test_allow_sha1
Gilles Peskine8f073122018-11-27 15:58:47 +01001234run_component component_build_mingw
1235# MemSan currently only available on Linux 64 bits
1236if uname -a | grep 'Linux.*x86_64' >/dev/null; then
1237 run_component component_test_memsan
1238else # no MemSan
1239 run_component component_test_memcheck
1240fi
1241run_component component_test_cmake_out_of_source
1242
1243# More small things
1244run_component component_test_zeroize
1245run_component component_check_python_files
1246run_component component_check_generate_test_code
1247
1248# We're done.
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001249case "$INTROSPECTION_MODE" in
1250 list_components)
1251 echo "$components" | sort
1252 ;;
1253 *)
1254 post_report
1255 ;;
1256esac