blob: 17f90027024cdf4841e72aa4dc805c717c87990e [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
109 KEEP_GOING=0
110 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100111
Gilles Peskine8f073122018-11-27 15:58:47 +0100112 # Default commands, can be overriden by the environment
113 : ${OPENSSL:="openssl"}
114 : ${OPENSSL_LEGACY:="$OPENSSL"}
115 : ${OPENSSL_NEXT:="$OPENSSL"}
116 : ${GNUTLS_CLI:="gnutls-cli"}
117 : ${GNUTLS_SERV:="gnutls-serv"}
118 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
119 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
120 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
121 : ${ARMC5_BIN_DIR:=/usr/bin}
122 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100123
Gilles Peskine8f073122018-11-27 15:58:47 +0100124 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
125 if [ -n "${MAKEFLAGS+set}" ]; then
126 export MAKEFLAGS="-j"
127 fi
128}
Andres AG38495a32016-07-12 16:54:33 +0100129
Simon Butcher41eeccf2016-09-07 00:07:09 +0100130usage()
SimonB2e23c822016-04-16 21:54:39 +0100131{
Gilles Peskine709346a2017-12-10 23:43:39 +0100132 cat <<EOF
133Usage: $0 [OPTION]...
134 -h|--help Print this help.
135
136General options:
137 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100138 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100139 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100140 --armcc Run ARM Compiler builds (on by default).
141 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100142 --no-force Refuse to overwrite modified files (default).
143 --no-keep-going Stop at the first error (default).
144 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100145 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100146 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100147 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
148 -s|--seed Integer seed value to use for this test run.
149
150Tool path options:
151 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
152 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
153 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
154 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
155 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
156 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
157 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
158 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100159 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100160EOF
SimonB2e23c822016-04-16 21:54:39 +0100161}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100162
163# remove built files as well as the cmake cache/config
164cleanup()
165{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100166 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
167 cd "$MBEDTLS_ROOT_DIR"
168 fi
169
Gilles Peskine7c652162017-12-11 00:01:40 +0100170 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200171
Gilles Peskine31b07e22018-03-21 12:15:06 +0100172 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100173 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100174 -iname CMakeFiles -exec rm -rf {} \+ -o \
175 \( -iname cmake_install.cmake -o \
176 -iname CTestTestfile.cmake -o \
177 -iname CMakeCache.txt \) -exec rm {} \+
178 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000179 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200180 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
181 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200182
183 if [ -f "$CONFIG_BAK" ]; then
184 mv "$CONFIG_BAK" "$CONFIG_H"
185 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100186}
187
Gilles Peskine7c652162017-12-11 00:01:40 +0100188# Executed on exit. May be redefined depending on command line options.
189final_report () {
190 :
191}
192
193fatal_signal () {
194 cleanup
195 final_report $1
196 trap - $1
197 kill -$1 $$
198}
199
200trap 'fatal_signal HUP' HUP
201trap 'fatal_signal INT' INT
202trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200203
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100204msg()
205{
206 echo ""
207 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100208 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000209 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100210 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100211 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100212}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100213
Gilles Peskine8f073122018-11-27 15:58:47 +0100214armc6_build_test()
215{
216 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100217
Gilles Peskine8f073122018-11-27 15:58:47 +0100218 msg "build: ARM Compiler 6 ($FLAGS), make"
219 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
220 WARNING_CFLAGS='-xc -std=c99' make lib
221 make clean
222}
Andres AGa5cd9732016-10-17 15:23:10 +0100223
Andres AGd9eba4b2016-08-26 14:42:14 +0100224err_msg()
225{
226 echo "$1" >&2
227}
228
229check_tools()
230{
231 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000232 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100233 err_msg "$TOOL not found!"
234 exit 1
235 fi
236 done
237}
238
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400239check_headers_in_cpp () {
240 ls include/mbedtls >headers.txt
241 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
242 sort |
243 diff headers.txt -
244 rm headers.txt
245}
246
Gilles Peskine8f073122018-11-27 15:58:47 +0100247pre_parse_command_line () {
248 while [ $# -gt 0 ]; do
249 case "$1" in
250 --armcc) RUN_ARMCC=1;;
251 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
252 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
253 --force|-f) FORCE=1;;
254 --gnutls-cli) shift; GNUTLS_CLI="$1";;
255 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
256 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
257 --gnutls-serv) shift; GNUTLS_SERV="$1";;
258 --help|-h) usage; exit;;
259 --keep-going|-k) KEEP_GOING=1;;
260 --memory|-m) MEMORY=1;;
261 --no-armcc) RUN_ARMCC=0;;
262 --no-force) FORCE=0;;
263 --no-keep-going) KEEP_GOING=0;;
264 --no-memory) MEMORY=0;;
265 --openssl) shift; OPENSSL="$1";;
266 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
267 --openssl-next) shift; OPENSSL_NEXT="$1";;
268 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
269 --random-seed) unset SEED;;
270 --release-test|-r) SEED=1;;
271 --seed|-s) shift; SEED="$1";;
272 *)
273 echo >&2 "Unknown option: $1"
274 echo >&2 "Run $0 --help for usage."
275 exit 120
276 ;;
277 esac
278 shift
279 done
280}
SimonB2e23c822016-04-16 21:54:39 +0100281
Gilles Peskine8f073122018-11-27 15:58:47 +0100282pre_check_git () {
283 if [ $FORCE -eq 1 ]; then
284 git checkout-index -f -q $CONFIG_H
285 cleanup
286 else
SimonB2e23c822016-04-16 21:54:39 +0100287
Gilles Peskine8f073122018-11-27 15:58:47 +0100288 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
289 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
290 echo "You can either delete this directory manually, or force the test by rerunning"
291 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
292 exit 1
293 fi
294
295 if ! git diff-files --quiet include/mbedtls/config.h; then
296 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
297 echo "You can either delete or preserve your work, or force the test by rerunning the"
298 echo "script as: $0 --force"
299 exit 1
300 fi
Andres AGdc192212016-08-31 17:33:13 +0100301 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100302}
Andres AGdc192212016-08-31 17:33:13 +0100303
Gilles Peskine8f073122018-11-27 15:58:47 +0100304pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100305 failure_summary=
306 failure_count=0
307 start_red=
308 end_color=
309 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100310 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100311 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
312 start_red=$(printf '\033[31m')
313 end_color=$(printf '\033[0m')
314 ;;
315 esac
316 fi
317 record_status () {
318 if "$@"; then
319 last_status=0
320 else
321 last_status=$?
322 text="$current_section: $* -> $last_status"
323 failure_summary="$failure_summary
324$text"
325 failure_count=$((failure_count + 1))
326 echo "${start_red}^^^^$text^^^^${end_color}"
327 fi
328 }
329 make () {
330 case "$*" in
331 *test|*check)
332 if [ $build_status -eq 0 ]; then
333 record_status command make "$@"
334 else
335 echo "(skipped because the build failed)"
336 fi
337 ;;
338 *)
339 record_status command make "$@"
340 build_status=$last_status
341 ;;
342 esac
343 }
344 final_report () {
345 if [ $failure_count -gt 0 ]; then
346 echo
347 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
348 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
349 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100350 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100351 elif [ -z "${1-}" ]; then
352 echo "SUCCESS :)"
353 fi
354 if [ -n "${1-}" ]; then
355 echo "Killed by SIG$1."
356 fi
357 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100358}
359
Gilles Peskine7c652162017-12-11 00:01:40 +0100360if_build_succeeded () {
361 if [ $build_status -eq 0 ]; then
362 record_status "$@"
363 fi
364}
365
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200366# to be used instead of ! for commands run with
367# record_status or if_build_succeeded
368not() {
369 ! "$@"
370}
371
Gilles Peskine8f073122018-11-27 15:58:47 +0100372pre_print_configuration () {
373 msg "info: $0 configuration"
374 echo "MEMORY: $MEMORY"
375 echo "FORCE: $FORCE"
376 echo "SEED: ${SEED-"UNSET"}"
377 echo "OPENSSL: $OPENSSL"
378 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
379 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
380 echo "GNUTLS_CLI: $GNUTLS_CLI"
381 echo "GNUTLS_SERV: $GNUTLS_SERV"
382 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
383 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
384 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
385 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
386}
Andres AG87bb5772016-09-27 15:05:15 +0100387
Gilles Peskine8f073122018-11-27 15:58:47 +0100388pre_check_tools () {
389 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
390 ARMC5_AR="$ARMC5_BIN_DIR/armar"
391 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
392 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100393
Gilles Peskine8f073122018-11-27 15:58:47 +0100394 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
395 # we just export the variables they require
396 export OPENSSL_CMD="$OPENSSL"
397 export GNUTLS_CLI="$GNUTLS_CLI"
398 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100399
Gilles Peskine8f073122018-11-27 15:58:47 +0100400 # Avoid passing --seed flag in every call to ssl-opt.sh
401 if [ -n "${SEED-}" ]; then
402 export SEED
403 fi
Andres AG7770ea82016-10-10 15:46:20 +0100404
Gilles Peskine8f073122018-11-27 15:58:47 +0100405 # Make sure the tools we need are available.
406 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
407 "$GNUTLS_CLI" "$GNUTLS_SERV" \
408 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
409 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
410 if [ $RUN_ARMCC -ne 0 ]; then
411 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
412 fi
413}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100414
415
416################################################################
417#### Basic checks
418################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100419
SimonB2e23c822016-04-16 21:54:39 +0100420#
421# Test Suites to be executed
422#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200423# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100424# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200425# and/or are more likely to fail than others (eg I use Clang most of the
426# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200427# 2. Minimize total running time, by avoiding useless rebuilds
428#
429# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100430
Gilles Peskine8f073122018-11-27 15:58:47 +0100431pre_print_tools () {
432 msg "info: output_env.sh"
433 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
434 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
435 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
436 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
437}
Janos Follathb72c6782016-07-19 14:54:17 +0100438
Gilles Peskine8f073122018-11-27 15:58:47 +0100439component_check_recursion () {
440 msg "test: recursion.pl" # < 1s
441 record_status tests/scripts/recursion.pl library/*.c
442}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100443
Gilles Peskine8f073122018-11-27 15:58:47 +0100444component_check_generated_files () {
445 msg "test: freshness of generated source files" # < 1s
446 record_status tests/scripts/check-generated-files.sh
447}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000448
Gilles Peskine8f073122018-11-27 15:58:47 +0100449component_check_doxy_blocks () {
450 msg "test: doxygen markup outside doxygen blocks" # < 1s
451 record_status tests/scripts/check-doxy-blocks.pl
452}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200453
Gilles Peskine8f073122018-11-27 15:58:47 +0100454component_check_files () {
455 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100456 record_status tests/scripts/check-files.py
457}
Darryl Greena07039c2018-03-13 16:48:16 +0000458
Gilles Peskine8f073122018-11-27 15:58:47 +0100459component_check_names () {
460 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100461 record_status tests/scripts/check-names.sh
462}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200463
Gilles Peskine8f073122018-11-27 15:58:47 +0100464component_check_doxygen_warnings () {
465 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100466 record_status tests/scripts/doxygen.sh
467}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100468
Gilles Peskine192c72f2017-12-21 15:59:21 +0100469
470
471################################################################
472#### Build and test many configurations and targets
473################################################################
474
Gilles Peskine8f073122018-11-27 15:58:47 +0100475component_test_default_cmake_gcc_asan () {
476 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100477 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
478 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100479
Gilles Peskine8f073122018-11-27 15:58:47 +0100480 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
481 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200482
Gilles Peskine8f073122018-11-27 15:58:47 +0100483 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
484 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200485
Gilles Peskine8f073122018-11-27 15:58:47 +0100486 msg "test: compat.sh (ASan build)" # ~ 6 min
487 if_build_succeeded tests/compat.sh
488}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200489
Gilles Peskine782f4112018-11-27 16:11:09 +0100490component_test_ref_configs () {
491 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
492 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
493 record_status tests/scripts/test-ref-configs.pl
494}
495
Gilles Peskine8f073122018-11-27 15:58:47 +0100496component_test_sslv3 () {
497 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100498 cp "$CONFIG_H" "$CONFIG_BAK"
499 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
500 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
501 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000502
Gilles Peskine8f073122018-11-27 15:58:47 +0100503 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
504 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000505
Gilles Peskine8f073122018-11-27 15:58:47 +0100506 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
507 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
508 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
511 if_build_succeeded tests/ssl-opt.sh
512}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000513
Gilles Peskine8f073122018-11-27 15:58:47 +0100514component_test_no_renegotiation () {
515 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100516 cp "$CONFIG_H" "$CONFIG_BAK"
517 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
518 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
519 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100520
Gilles Peskine8f073122018-11-27 15:58:47 +0100521 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
522 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100523
Gilles Peskine8f073122018-11-27 15:58:47 +0100524 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
525 if_build_succeeded tests/ssl-opt.sh
526}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100527
Gilles Peskine8f073122018-11-27 15:58:47 +0100528component_test_rsa_no_crt () {
529 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100530 cp "$CONFIG_H" "$CONFIG_BAK"
531 scripts/config.pl set MBEDTLS_RSA_NO_CRT
532 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
533 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100534
Gilles Peskine8f073122018-11-27 15:58:47 +0100535 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
536 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100537
Gilles Peskine8f073122018-11-27 15:58:47 +0100538 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
539 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100540
Gilles Peskine8f073122018-11-27 15:58:47 +0100541 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
542 if_build_succeeded tests/compat.sh -t RSA
543}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100544
Gilles Peskine8f073122018-11-27 15:58:47 +0100545component_test_small_ssl_out_content_len () {
546 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100547 cp "$CONFIG_H" "$CONFIG_BAK"
548 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
549 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
550 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
551 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000552
Gilles Peskine8f073122018-11-27 15:58:47 +0100553 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
554 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
555}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000556
Gilles Peskine8f073122018-11-27 15:58:47 +0100557component_test_small_ssl_in_content_len () {
558 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100559 cp "$CONFIG_H" "$CONFIG_BAK"
560 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
561 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
562 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
563 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000564
Gilles Peskine8f073122018-11-27 15:58:47 +0100565 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
566 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
567}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569component_test_small_ssl_dtls_max_buffering () {
570 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100571 cp "$CONFIG_H" "$CONFIG_BAK"
572 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
573 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
574 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100575
Gilles Peskine8f073122018-11-27 15:58:47 +0100576 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
577 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
578}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100579
Gilles Peskine8f073122018-11-27 15:58:47 +0100580component_test_small_mbedtls_ssl_dtls_max_buffering () {
581 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100582 cp "$CONFIG_H" "$CONFIG_BAK"
583 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
584 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
585 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
588 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
589}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100590
Gilles Peskine8f073122018-11-27 15:58:47 +0100591component_test_full_cmake_clang () {
592 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100593 cp "$CONFIG_H" "$CONFIG_BAK"
594 scripts/config.pl full
595 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
596 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
597 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599 msg "test: main suites (full config)" # ~ 5s
600 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200601
Gilles Peskine8f073122018-11-27 15:58:47 +0100602 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
603 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200604
Gilles Peskine8f073122018-11-27 15:58:47 +0100605 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
606 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 +0200607
Gilles Peskine8f073122018-11-27 15:58:47 +0100608 msg "test: compat.sh ARIA + ChachaPoly"
609 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
610}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100611
Gilles Peskine8f073122018-11-27 15:58:47 +0100612component_build_deprecated () {
613 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100614 cp "$CONFIG_H" "$CONFIG_BAK"
615 scripts/config.pl full
616 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
617 # Build with -O -Wextra to catch a maximum of issues.
618 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
619 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
622 # No cleanup, just tweak the configuration and rebuild
623 make clean
624 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
625 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
626 # Build with -O -Wextra to catch a maximum of issues.
627 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
628 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
629}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100630
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200631
Gilles Peskine8f073122018-11-27 15:58:47 +0100632component_test_depends_curves () {
633 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 record_status tests/scripts/curves.pl
635}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200636
Gilles Peskine8f073122018-11-27 15:58:47 +0100637component_test_depends_hashes () {
638 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 record_status tests/scripts/depends-hashes.pl
640}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642component_test_depends_pkalgs () {
643 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100644 record_status tests/scripts/depends-pkalgs.pl
645}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200646
Gilles Peskine8f073122018-11-27 15:58:47 +0100647component_build_key_exchanges () {
648 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100649 record_status tests/scripts/key-exchanges.pl
650}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100651
Gilles Peskine8f073122018-11-27 15:58:47 +0100652component_build_default_make_gcc_and_cxx () {
653 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100654 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 msg "test: verify header list in cpp_dummy_build.cpp"
657 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400658
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 msg "build: Unix make, incremental g++"
660 make TEST_CPP=1
661}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000662
Gilles Peskine8f073122018-11-27 15:58:47 +0100663component_test_no_platform () {
664 # Full configuration build, without platform support, file IO and net sockets.
665 # This should catch missing mbedtls_printf definitions, and by disabling file
666 # IO, it should catch missing '#include <stdio.h>'
667 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100668 cp "$CONFIG_H" "$CONFIG_BAK"
669 scripts/config.pl full
670 scripts/config.pl unset MBEDTLS_PLATFORM_C
671 scripts/config.pl unset MBEDTLS_NET_C
672 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
673 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
674 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
675 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
676 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
677 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
678 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
679 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
680 scripts/config.pl unset MBEDTLS_FS_IO
681 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
682 # to re-enable platform integration features otherwise disabled in C99 builds
683 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
684 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
685}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100686
Gilles Peskine8f073122018-11-27 15:58:47 +0100687component_build_no_std_function () {
688 # catch compile bugs in _uninit functions
689 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 cp "$CONFIG_H" "$CONFIG_BAK"
691 scripts/config.pl full
692 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
693 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
694 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
695}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697component_build_no_ssl_srv () {
698 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100699 cp "$CONFIG_H" "$CONFIG_BAK"
700 scripts/config.pl full
701 scripts/config.pl unset MBEDTLS_SSL_SRV_C
702 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
703}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200704
Gilles Peskine8f073122018-11-27 15:58:47 +0100705component_build_no_ssl_cli () {
706 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100707 cp "$CONFIG_H" "$CONFIG_BAK"
708 scripts/config.pl full
709 scripts/config.pl unset MBEDTLS_SSL_CLI_C
710 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
711}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200712
Gilles Peskine8f073122018-11-27 15:58:47 +0100713component_build_no_sockets () {
714 # Note, C99 compliance can also be tested with the sockets support disabled,
715 # as that requires a POSIX platform (which isn't the same as C99).
716 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 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_NET_C # getaddrinfo() undeclared, etc.
720 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
721 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
722}
Hanno Becker5175ac62017-09-18 15:36:25 +0100723
Gilles Peskine8f073122018-11-27 15:58:47 +0100724component_test_no_max_fragment_length () {
725 # Run max fragment length tests with MFL disabled
726 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100727 cp "$CONFIG_H" "$CONFIG_BAK"
728 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
729 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
730 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732 msg "test: ssl-opt.sh, MFL-related tests"
733 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
734}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736component_test_no_max_fragment_length_small_ssl_out_content_len () {
737 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 cp "$CONFIG_H" "$CONFIG_BAK"
739 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
740 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
741 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
742 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
743 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000744
Gilles Peskine8f073122018-11-27 15:58:47 +0100745 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
746 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
747}
Janos Follath06c54002016-06-09 13:57:40 +0100748
Gilles Peskine8f073122018-11-27 15:58:47 +0100749component_test_null_entropy () {
750 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 cp "$CONFIG_H" "$CONFIG_BAK"
752 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
753 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
754 scripts/config.pl set MBEDTLS_ENTROPY_C
755 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
756 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
757 scripts/config.pl unset MBEDTLS_HAVEGE_C
758 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
759 make
Janos Follath06c54002016-06-09 13:57:40 +0100760
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
762 make test
763}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100764
Gilles Peskine8f073122018-11-27 15:58:47 +0100765component_test_platform_calloc_macro () {
766 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100767 cp "$CONFIG_H" "$CONFIG_BAK"
768 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
769 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
770 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
771 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
772 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
775 make test
776}
Hanno Becker83ebf782017-07-07 12:29:15 +0100777
Gilles Peskine8f073122018-11-27 15:58:47 +0100778component_test_aes_fewer_tables () {
779 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100780 cp "$CONFIG_H" "$CONFIG_BAK"
781 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
782 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784 msg "test: AES_FEWER_TABLES"
785 make test
786}
Hanno Becker83ebf782017-07-07 12:29:15 +0100787
Gilles Peskine8f073122018-11-27 15:58:47 +0100788component_test_aes_rom_tables () {
789 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100790 cp "$CONFIG_H" "$CONFIG_BAK"
791 scripts/config.pl set MBEDTLS_AES_ROM_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_ROM_TABLES"
795 make test
796}
Hanno Becker83ebf782017-07-07 12:29:15 +0100797
Gilles Peskine8f073122018-11-27 15:58:47 +0100798component_test_aes_fewer_tables_and_rom_tables () {
799 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100800 cp "$CONFIG_H" "$CONFIG_BAK"
801 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
802 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
803 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100804
Gilles Peskine8f073122018-11-27 15:58:47 +0100805 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
806 make test
807}
808
809component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100810 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100811 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100812}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100815 # Build once with -O0, to compile out the i386 specific inline assembly
816 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100817 cp "$CONFIG_H" "$CONFIG_BAK"
818 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100819 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100820
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100821 msg "test: i386, make, gcc -O0 (ASan build)"
822 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100823}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100824
Gilles Peskine8f073122018-11-27 15:58:47 +0100825component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100826 # Build again with -O1, to compile in the i386 specific inline assembly
827 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100828 cp "$CONFIG_H" "$CONFIG_BAK"
829 scripts/config.pl full
830 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
831
832 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100833 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100834}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100835
Gilles Peskine8f073122018-11-27 15:58:47 +0100836component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100837 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100838 cp "$CONFIG_H" "$CONFIG_BAK"
839 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100840 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
841
842 msg "test: 64-bit ILP32, make, gcc"
843 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100844}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000845
Gilles Peskine8f073122018-11-27 15:58:47 +0100846component_test_have_int32 () {
847 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100848 cp "$CONFIG_H" "$CONFIG_BAK"
849 scripts/config.pl unset MBEDTLS_HAVE_ASM
850 scripts/config.pl unset MBEDTLS_AESNI_C
851 scripts/config.pl unset MBEDTLS_PADLOCK_C
852 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100853
Gilles Peskine8f073122018-11-27 15:58:47 +0100854 msg "test: gcc, force 32-bit bignum limbs"
855 make test
856}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100857
Gilles Peskine8f073122018-11-27 15:58:47 +0100858component_test_have_int64 () {
859 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100860 cp "$CONFIG_H" "$CONFIG_BAK"
861 scripts/config.pl unset MBEDTLS_HAVE_ASM
862 scripts/config.pl unset MBEDTLS_AESNI_C
863 scripts/config.pl unset MBEDTLS_PADLOCK_C
864 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100865
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 msg "test: gcc, force 64-bit bignum limbs"
867 make test
868}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000869
Gilles Peskine8f073122018-11-27 15:58:47 +0100870component_test_no_udbl_division () {
871 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100872 cp "$CONFIG_H" "$CONFIG_BAK"
873 scripts/config.pl full
874 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
875 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
876 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200877
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
879 make test
880}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200881
Gilles Peskine8f073122018-11-27 15:58:47 +0100882component_test_no_64bit_multiplication () {
883 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100884 cp "$CONFIG_H" "$CONFIG_BAK"
885 scripts/config.pl full
886 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
887 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
888 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200889
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
891 make test
892}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200893
Gilles Peskine8f073122018-11-27 15:58:47 +0100894component_build_arm_none_eabi_gcc () {
895 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100896 cp "$CONFIG_H" "$CONFIG_BAK"
897 scripts/config.pl full
898 scripts/config.pl unset MBEDTLS_NET_C
899 scripts/config.pl unset MBEDTLS_TIMING_C
900 scripts/config.pl unset MBEDTLS_FS_IO
901 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
902 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
903 # following things are not in the default config
904 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
905 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
906 scripts/config.pl unset MBEDTLS_THREADING_C
907 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
908 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
909 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
910}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912component_build_arm_none_eabi_gcc_no_udbl_division () {
913 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 cp "$CONFIG_H" "$CONFIG_BAK"
915 scripts/config.pl full
916 scripts/config.pl unset MBEDTLS_NET_C
917 scripts/config.pl unset MBEDTLS_TIMING_C
918 scripts/config.pl unset MBEDTLS_FS_IO
919 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
920 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
921 # following things are not in the default config
922 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
923 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
924 scripts/config.pl unset MBEDTLS_THREADING_C
925 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
926 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
927 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
928 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
929 echo "Checking that software 64-bit division is not required"
930 if_build_succeeded not grep __aeabi_uldiv library/*.o
931}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200932
Gilles Peskine8f073122018-11-27 15:58:47 +0100933component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
934 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100935 cp "$CONFIG_H" "$CONFIG_BAK"
936 scripts/config.pl full
937 scripts/config.pl unset MBEDTLS_NET_C
938 scripts/config.pl unset MBEDTLS_TIMING_C
939 scripts/config.pl unset MBEDTLS_FS_IO
940 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
941 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
942 # following things are not in the default config
943 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
944 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
945 scripts/config.pl unset MBEDTLS_THREADING_C
946 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
947 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
948 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
949 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
950 echo "Checking that software 64-bit multiplication is not required"
951 if_build_succeeded not grep __aeabi_lmul library/*.o
952}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200953
Gilles Peskine8f073122018-11-27 15:58:47 +0100954component_build_armcc () {
955 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100956 cp "$CONFIG_H" "$CONFIG_BAK"
957 scripts/config.pl full
958 scripts/config.pl unset MBEDTLS_NET_C
959 scripts/config.pl unset MBEDTLS_TIMING_C
960 scripts/config.pl unset MBEDTLS_FS_IO
961 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
962 scripts/config.pl unset MBEDTLS_HAVE_TIME
963 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
964 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
965 # following things are not in the default config
966 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
967 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
968 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
969 scripts/config.pl unset MBEDTLS_THREADING_C
970 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
971 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
972 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000973
Gilles Peskine8f073122018-11-27 15:58:47 +0100974 if [ $RUN_ARMCC -ne 0 ]; then
975 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
976 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200977
Gilles Peskine8f073122018-11-27 15:58:47 +0100978 # ARM Compiler 6 - Target ARMv7-A
979 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +0200980
Gilles Peskine8f073122018-11-27 15:58:47 +0100981 # ARM Compiler 6 - Target ARMv7-M
982 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +0100983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984 # ARM Compiler 6 - Target ARMv8-A - AArch32
985 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +0100986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987 # ARM Compiler 6 - Target ARMv8-M
988 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +0200989
Gilles Peskine8f073122018-11-27 15:58:47 +0100990 # ARM Compiler 6 - Target ARMv8-A - AArch64
991 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
992 fi
993}
Simon Butcher940737f2017-07-23 13:42:36 +0200994
Gilles Peskine8f073122018-11-27 15:58:47 +0100995component_test_allow_sha1 () {
996 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +0100997 cp "$CONFIG_H" "$CONFIG_BAK"
998 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
999 make CFLAGS='-Werror -Wall -Wextra'
1000 msg "test: allow SHA1 in certificates by default"
1001 make test
1002 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1003}
Simon Butcher940737f2017-07-23 13:42:36 +02001004
Gilles Peskine8f073122018-11-27 15:58:47 +01001005component_build_mingw () {
1006 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001007 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 +02001008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 # note Make tests only builds the tests, but doesn't run them
1010 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1011 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1014 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
1015 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
1016 make WINDOWS_BUILD=1 clean
1017}
Simon Butcher002bc622016-11-17 09:27:45 +00001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001020 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001021 cp "$CONFIG_H" "$CONFIG_BAK"
1022 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1023 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1024 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001025
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001026 msg "test: main suites (MSan)" # ~ 10s
1027 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001028
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001029 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001030 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001031
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001032 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001033
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001034 if [ "$MEMORY" -gt 0 ]; then
1035 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001036 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001037 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001038}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001039
Gilles Peskine8f073122018-11-27 15:58:47 +01001040component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001041 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001042 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1043 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001044
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001045 msg "test: main suites valgrind (Release)"
1046 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001047
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001048 # Optional part(s)
1049 # Currently broken, programs don't seem to receive signals
1050 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001051
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001052 if [ "$MEMORY" -gt 0 ]; then
1053 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001054 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001055 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001056
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001057 if [ "$MEMORY" -gt 1 ]; then
1058 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001059 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001060 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001061}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001062
Gilles Peskine8f073122018-11-27 15:58:47 +01001063component_test_cmake_out_of_source () {
1064 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001065 MBEDTLS_ROOT_DIR="$PWD"
1066 mkdir "$OUT_OF_SOURCE_DIR"
1067 cd "$OUT_OF_SOURCE_DIR"
1068 cmake "$MBEDTLS_ROOT_DIR"
1069 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071 msg "test: cmake 'out-of-source' build"
1072 make test
1073 # Test an SSL option that requires an auxiliary script in test/scripts/.
1074 # Also ensure that there are no error messages such as
1075 # "No such file or directory", which would indicate that some required
1076 # file is missing (ssl-opt.sh tolerates the absence of some files so
1077 # may exit with status 0 but emit errors).
1078 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1079 if [ -s ssl-opt.err ]; then
1080 cat ssl-opt.err >&2
1081 record_status [ ! -s ssl-opt.err ]
1082 rm ssl-opt.err
1083 fi
1084 cd "$MBEDTLS_ROOT_DIR"
1085 rm -rf "$OUT_OF_SOURCE_DIR"
1086 unset MBEDTLS_ROOT_DIR
1087}
Andres AGdc192212016-08-31 17:33:13 +01001088
Gilles Peskine8f073122018-11-27 15:58:47 +01001089component_test_zeroize () {
1090 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1091 # different combinations of compilers and optimization flags by using an
1092 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1093 # system in all cases that the script fails, so we must manually search the
1094 # output to check whether the pass string is present and no failure strings
1095 # were printed.
1096 for optimization_flag in -O2 -O3 -Ofast -Os; do
1097 for compiler in clang gcc; do
1098 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Gilles Peskine8f073122018-11-27 15:58:47 +01001099 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
1100 if_build_succeeded gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
1101 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1102 if_build_succeeded not grep -i "error" test_zeroize.log
1103 rm -f test_zeroize.log
Gilles Peskinee48351a2018-11-27 16:06:30 +01001104 make clean
Gilles Peskine8f073122018-11-27 15:58:47 +01001105 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001106 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001107}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001108
Gilles Peskine8f073122018-11-27 15:58:47 +01001109component_check_python_files () {
1110 msg "Lint: Python scripts"
1111 record_status tests/scripts/check-python-files.sh
1112}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001113
Gilles Peskine8f073122018-11-27 15:58:47 +01001114component_check_generate_test_code () {
1115 msg "uint test: generate_test_code.py"
1116 record_status ./tests/scripts/test_generate_test_code.py
1117}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001118
1119################################################################
1120#### Termination
1121################################################################
1122
Gilles Peskine8f073122018-11-27 15:58:47 +01001123post_report () {
1124 msg "Done, cleaning up"
1125 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001126
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 final_report
1128}
1129
1130
1131
1132################################################################
1133#### Run all the things
1134################################################################
1135
Gilles Peskinee48351a2018-11-27 16:06:30 +01001136# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001137run_component () {
1138 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001139 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001140}
1141
1142# Preliminary setup
1143pre_check_environment
1144pre_initialize_variables
1145pre_parse_command_line "$@"
1146pre_check_git
1147build_status=0
1148if [ $KEEP_GOING -eq 1 ]; then
1149 pre_setup_keep_going
1150else
1151 record_status () {
1152 "$@"
1153 }
1154fi
1155pre_print_configuration
1156pre_check_tools
1157pre_print_tools
Gilles Peskinee48351a2018-11-27 16:06:30 +01001158cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001159
1160# Small things
1161run_component component_check_recursion
1162run_component component_check_generated_files
1163run_component component_check_doxy_blocks
1164run_component component_check_files
1165run_component component_check_names
1166run_component component_check_doxygen_warnings
1167
1168# Test many different configurations
1169run_component component_test_default_cmake_gcc_asan
Gilles Peskine782f4112018-11-27 16:11:09 +01001170run_component component_test_ref_configs
Gilles Peskine8f073122018-11-27 15:58:47 +01001171run_component component_test_sslv3
1172run_component component_test_no_renegotiation
1173run_component component_test_rsa_no_crt
1174run_component component_test_small_ssl_out_content_len
1175run_component component_test_small_ssl_in_content_len
1176run_component component_test_small_ssl_dtls_max_buffering
1177run_component component_test_small_mbedtls_ssl_dtls_max_buffering
1178run_component component_test_full_cmake_clang
1179run_component component_build_deprecated
1180run_component component_test_depends_curves
1181run_component component_test_depends_hashes
1182run_component component_test_depends_pkalgs
1183run_component component_build_key_exchanges
1184run_component component_build_default_make_gcc_and_cxx
1185run_component component_test_no_platform
1186run_component component_build_no_std_function
1187run_component component_build_no_ssl_srv
1188run_component component_build_no_ssl_cli
1189run_component component_build_no_sockets
1190run_component component_test_no_max_fragment_length
1191run_component component_test_no_max_fragment_length_small_ssl_out_content_len
1192run_component component_test_null_entropy
1193run_component component_test_platform_calloc_macro
1194run_component component_test_aes_fewer_tables
1195run_component component_test_aes_rom_tables
1196run_component component_test_aes_fewer_tables_and_rom_tables
1197if uname -a | grep -F Linux >/dev/null; then
1198 run_component component_test_make_shared
1199fi
1200if uname -a | grep -F x86_64 >/dev/null; then
1201 run_component component_test_m32_o0
1202 run_component component_test_m32_o1
1203 run_component component_test_mx32
1204fi
1205run_component component_test_have_int32
1206run_component component_test_have_int64
1207run_component component_test_no_udbl_division
1208run_component component_test_no_64bit_multiplication
1209run_component component_build_arm_none_eabi_gcc
1210run_component component_build_arm_none_eabi_gcc_no_udbl_division
1211run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
1212run_component component_build_armcc
1213run_component component_test_allow_sha1
Gilles Peskine8f073122018-11-27 15:58:47 +01001214run_component component_build_mingw
1215# MemSan currently only available on Linux 64 bits
1216if uname -a | grep 'Linux.*x86_64' >/dev/null; then
1217 run_component component_test_memsan
1218else # no MemSan
1219 run_component component_test_memcheck
1220fi
1221run_component component_test_cmake_out_of_source
1222
1223# More small things
1224run_component component_test_zeroize
1225run_component component_check_python_files
1226run_component component_check_generate_test_code
1227
1228# We're done.
1229post_report