blob: 2799b6689392ed76b129c22792cb8e898a9bbddd [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
62# * component_check_XXX: quick tests that aren't worth parallelizing
63# * component_build_XXX: build things but don't run them
64# * component_test_XXX: build and test
65# * post_XXX: things to do after running the tests.
66# * other: miscellaneous support functions.
67#
Gilles Peskine192c72f2017-12-21 15:59:21 +010068# The tests are roughly in order from fastest to slowest. This doesn't
69# have to be exact, but in general you should add slower tests towards
70# the end and fast checks near the beginning.
71#
72# Sanity checks have the following form:
73# 1. msg "short description of what is about to be done"
74# 2. run sanity check (failure stops the script)
75#
76# Build or build-and-test steps have the following form:
77# 1. msg "short description of what is about to be done"
78# 2. cleanup
79# 3. preparation (config.pl, cmake, ...) (failure stops the script)
80# 4. make
81# 5. Run tests if relevant. All tests must be prefixed with
82# if_build_successful for the sake of --keep-going.
83
84
85
86################################################################
87#### Initialization and command line parsing
88################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010089
SimonB2e23c822016-04-16 21:54:39 +010090# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091set -eu
92
Gilles Peskine8f073122018-11-27 15:58:47 +010093pre_check_environment () {
94 if [ "$( uname )" != "Linux" ]; then
95 echo "This script only works in Linux" >&2
96 exit 1
97 elif [ -d library -a -d include -a -d tests ]; then :; else
98 echo "Must be run from mbed TLS root" >&2
99 exit 1
100 fi
101}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100102
Gilles Peskine8f073122018-11-27 15:58:47 +0100103pre_initialize_variables () {
104 CONFIG_H='include/mbedtls/config.h'
105 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200106
Gilles Peskine92525112018-11-27 18:15:35 +0100107 COMPONENTS=
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100108 ALL_EXCEPT=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100109 MEMORY=0
110 FORCE=0
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100111 INTROSPECTION_MODE=
Gilles Peskine8f073122018-11-27 15:58:47 +0100112 KEEP_GOING=0
113 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine8f073122018-11-27 15:58:47 +0100115 # Default commands, can be overriden by the environment
116 : ${OPENSSL:="openssl"}
117 : ${OPENSSL_LEGACY:="$OPENSSL"}
118 : ${OPENSSL_NEXT:="$OPENSSL"}
119 : ${GNUTLS_CLI:="gnutls-cli"}
120 : ${GNUTLS_SERV:="gnutls-serv"}
121 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
122 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
123 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
124 : ${ARMC5_BIN_DIR:=/usr/bin}
125 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100126
Gilles Peskine8f073122018-11-27 15:58:47 +0100127 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
128 if [ -n "${MAKEFLAGS+set}" ]; then
129 export MAKEFLAGS="-j"
130 fi
131}
Andres AG38495a32016-07-12 16:54:33 +0100132
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100133# Test whether $1 is excluded via $COMPONENTS (a space-separated list of
134# wildcard patterns).
135component_is_excluded()
136{
137 set -f
138 for pattern in $COMPONENTS; do
139 set +f
140 case ${1#component_} in $pattern) return 0;; esac
141 done
142 set +f
143 return 1
144}
145
Simon Butcher41eeccf2016-09-07 00:07:09 +0100146usage()
SimonB2e23c822016-04-16 21:54:39 +0100147{
Gilles Peskine709346a2017-12-10 23:43:39 +0100148 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100149Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100150Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100151By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100152
153Special options:
154 -h|--help Print this help and exit.
155 --list-components List available test components and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100156
157General options:
158 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100159 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100160 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100161 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162 --except If some components are passed on the command line,
163 run all the tests except for these components. In
164 this mode, you can pass shell wildcard patterns as
165 component names, e.g. "$0 --except 'test_*'" to
166 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100167 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100168 --no-force Refuse to overwrite modified files (default).
169 --no-keep-going Stop at the first error (default).
170 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100171 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100172 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100173 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
174 -s|--seed Integer seed value to use for this test run.
175
176Tool path options:
177 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
178 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
179 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
180 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
181 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
182 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
183 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
184 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100185 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100186EOF
SimonB2e23c822016-04-16 21:54:39 +0100187}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100188
189# remove built files as well as the cmake cache/config
190cleanup()
191{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100192 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
193 cd "$MBEDTLS_ROOT_DIR"
194 fi
195
Gilles Peskine7c652162017-12-11 00:01:40 +0100196 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200197
Gilles Peskine31b07e22018-03-21 12:15:06 +0100198 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100199 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100200 -iname CMakeFiles -exec rm -rf {} \+ -o \
201 \( -iname cmake_install.cmake -o \
202 -iname CTestTestfile.cmake -o \
203 -iname CMakeCache.txt \) -exec rm {} \+
204 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000205 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200206 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
207 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200208
209 if [ -f "$CONFIG_BAK" ]; then
210 mv "$CONFIG_BAK" "$CONFIG_H"
211 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100212}
213
Gilles Peskine7c652162017-12-11 00:01:40 +0100214# Executed on exit. May be redefined depending on command line options.
215final_report () {
216 :
217}
218
219fatal_signal () {
220 cleanup
221 final_report $1
222 trap - $1
223 kill -$1 $$
224}
225
226trap 'fatal_signal HUP' HUP
227trap 'fatal_signal INT' INT
228trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200229
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100230msg()
231{
232 echo ""
233 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100234 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000235 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100236 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100237 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100238}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100239
Gilles Peskine8f073122018-11-27 15:58:47 +0100240armc6_build_test()
241{
242 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100243
Gilles Peskine8f073122018-11-27 15:58:47 +0100244 msg "build: ARM Compiler 6 ($FLAGS), make"
245 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
246 WARNING_CFLAGS='-xc -std=c99' make lib
247 make clean
248}
Andres AGa5cd9732016-10-17 15:23:10 +0100249
Andres AGd9eba4b2016-08-26 14:42:14 +0100250err_msg()
251{
252 echo "$1" >&2
253}
254
255check_tools()
256{
257 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000258 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100259 err_msg "$TOOL not found!"
260 exit 1
261 fi
262 done
263}
264
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400265check_headers_in_cpp () {
266 ls include/mbedtls >headers.txt
267 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
268 sort |
269 diff headers.txt -
270 rm headers.txt
271}
272
Gilles Peskine8f073122018-11-27 15:58:47 +0100273pre_parse_command_line () {
274 while [ $# -gt 0 ]; do
275 case "$1" in
276 --armcc) RUN_ARMCC=1;;
277 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
278 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100279 --except) ALL_EXCEPT=1;;
Gilles Peskine8f073122018-11-27 15:58:47 +0100280 --force|-f) FORCE=1;;
281 --gnutls-cli) shift; GNUTLS_CLI="$1";;
282 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
283 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
284 --gnutls-serv) shift; GNUTLS_SERV="$1";;
285 --help|-h) usage; exit;;
286 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100287 --list-components) INTROSPECTION_MODE=list_components;;
Gilles Peskine8f073122018-11-27 15:58:47 +0100288 --memory|-m) MEMORY=1;;
289 --no-armcc) RUN_ARMCC=0;;
290 --no-force) FORCE=0;;
291 --no-keep-going) KEEP_GOING=0;;
292 --no-memory) MEMORY=0;;
293 --openssl) shift; OPENSSL="$1";;
294 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
295 --openssl-next) shift; OPENSSL_NEXT="$1";;
296 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
297 --random-seed) unset SEED;;
298 --release-test|-r) SEED=1;;
299 --seed|-s) shift; SEED="$1";;
Gilles Peskine92525112018-11-27 18:15:35 +0100300 -*)
Gilles Peskine8f073122018-11-27 15:58:47 +0100301 echo >&2 "Unknown option: $1"
302 echo >&2 "Run $0 --help for usage."
303 exit 120
304 ;;
Gilles Peskine92525112018-11-27 18:15:35 +0100305 *)
306 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine8f073122018-11-27 15:58:47 +0100307 esac
308 shift
309 done
310}
SimonB2e23c822016-04-16 21:54:39 +0100311
Gilles Peskine8f073122018-11-27 15:58:47 +0100312pre_check_git () {
313 if [ $FORCE -eq 1 ]; then
314 git checkout-index -f -q $CONFIG_H
315 cleanup
316 else
SimonB2e23c822016-04-16 21:54:39 +0100317
Gilles Peskine8f073122018-11-27 15:58:47 +0100318 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
319 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
320 echo "You can either delete this directory manually, or force the test by rerunning"
321 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
322 exit 1
323 fi
324
325 if ! git diff-files --quiet include/mbedtls/config.h; then
326 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
327 echo "You can either delete or preserve your work, or force the test by rerunning the"
328 echo "script as: $0 --force"
329 exit 1
330 fi
Andres AGdc192212016-08-31 17:33:13 +0100331 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100332}
Andres AGdc192212016-08-31 17:33:13 +0100333
Gilles Peskine8f073122018-11-27 15:58:47 +0100334pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100335 failure_summary=
336 failure_count=0
337 start_red=
338 end_color=
339 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100340 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100341 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
342 start_red=$(printf '\033[31m')
343 end_color=$(printf '\033[0m')
344 ;;
345 esac
346 fi
347 record_status () {
348 if "$@"; then
349 last_status=0
350 else
351 last_status=$?
352 text="$current_section: $* -> $last_status"
353 failure_summary="$failure_summary
354$text"
355 failure_count=$((failure_count + 1))
356 echo "${start_red}^^^^$text^^^^${end_color}"
357 fi
358 }
359 make () {
360 case "$*" in
361 *test|*check)
362 if [ $build_status -eq 0 ]; then
363 record_status command make "$@"
364 else
365 echo "(skipped because the build failed)"
366 fi
367 ;;
368 *)
369 record_status command make "$@"
370 build_status=$last_status
371 ;;
372 esac
373 }
374 final_report () {
375 if [ $failure_count -gt 0 ]; then
376 echo
377 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
378 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
379 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100380 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100381 elif [ -z "${1-}" ]; then
382 echo "SUCCESS :)"
383 fi
384 if [ -n "${1-}" ]; then
385 echo "Killed by SIG$1."
386 fi
387 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100388}
389
Gilles Peskine7c652162017-12-11 00:01:40 +0100390if_build_succeeded () {
391 if [ $build_status -eq 0 ]; then
392 record_status "$@"
393 fi
394}
395
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200396# to be used instead of ! for commands run with
397# record_status or if_build_succeeded
398not() {
399 ! "$@"
400}
401
Gilles Peskine8f073122018-11-27 15:58:47 +0100402pre_print_configuration () {
403 msg "info: $0 configuration"
404 echo "MEMORY: $MEMORY"
405 echo "FORCE: $FORCE"
406 echo "SEED: ${SEED-"UNSET"}"
407 echo "OPENSSL: $OPENSSL"
408 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
409 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
410 echo "GNUTLS_CLI: $GNUTLS_CLI"
411 echo "GNUTLS_SERV: $GNUTLS_SERV"
412 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
413 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
414 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
415 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
416}
Andres AG87bb5772016-09-27 15:05:15 +0100417
Gilles Peskine8f073122018-11-27 15:58:47 +0100418pre_check_tools () {
419 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
420 ARMC5_AR="$ARMC5_BIN_DIR/armar"
421 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
422 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100423
Gilles Peskine8f073122018-11-27 15:58:47 +0100424 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
425 # we just export the variables they require
426 export OPENSSL_CMD="$OPENSSL"
427 export GNUTLS_CLI="$GNUTLS_CLI"
428 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100429
Gilles Peskine8f073122018-11-27 15:58:47 +0100430 # Avoid passing --seed flag in every call to ssl-opt.sh
431 if [ -n "${SEED-}" ]; then
432 export SEED
433 fi
Andres AG7770ea82016-10-10 15:46:20 +0100434
Gilles Peskine8f073122018-11-27 15:58:47 +0100435 # Make sure the tools we need are available.
436 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
437 "$GNUTLS_CLI" "$GNUTLS_SERV" \
438 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
439 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
440 if [ $RUN_ARMCC -ne 0 ]; then
441 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
442 fi
443}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100444
445
446################################################################
447#### Basic checks
448################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100449
SimonB2e23c822016-04-16 21:54:39 +0100450#
451# Test Suites to be executed
452#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200453# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100454# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200455# and/or are more likely to fail than others (eg I use Clang most of the
456# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200457# 2. Minimize total running time, by avoiding useless rebuilds
458#
459# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100460
Gilles Peskine8f073122018-11-27 15:58:47 +0100461pre_print_tools () {
462 msg "info: output_env.sh"
463 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
464 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
465 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
466 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
467}
Janos Follathb72c6782016-07-19 14:54:17 +0100468
Gilles Peskine8f073122018-11-27 15:58:47 +0100469component_check_recursion () {
470 msg "test: recursion.pl" # < 1s
471 record_status tests/scripts/recursion.pl library/*.c
472}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100473
Gilles Peskine8f073122018-11-27 15:58:47 +0100474component_check_generated_files () {
475 msg "test: freshness of generated source files" # < 1s
476 record_status tests/scripts/check-generated-files.sh
477}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000478
Gilles Peskine8f073122018-11-27 15:58:47 +0100479component_check_doxy_blocks () {
480 msg "test: doxygen markup outside doxygen blocks" # < 1s
481 record_status tests/scripts/check-doxy-blocks.pl
482}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200483
Gilles Peskine8f073122018-11-27 15:58:47 +0100484component_check_files () {
485 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100486 record_status tests/scripts/check-files.py
487}
Darryl Greena07039c2018-03-13 16:48:16 +0000488
Gilles Peskine8f073122018-11-27 15:58:47 +0100489component_check_names () {
490 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100491 record_status tests/scripts/check-names.sh
492}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200493
Gilles Peskine8f073122018-11-27 15:58:47 +0100494component_check_doxygen_warnings () {
495 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100496 record_status tests/scripts/doxygen.sh
497}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100498
Gilles Peskine192c72f2017-12-21 15:59:21 +0100499
500
501################################################################
502#### Build and test many configurations and targets
503################################################################
504
Gilles Peskine8f073122018-11-27 15:58:47 +0100505component_test_default_cmake_gcc_asan () {
506 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100507 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
508 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
511 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200512
Gilles Peskine8f073122018-11-27 15:58:47 +0100513 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
514 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200515
Gilles Peskine8f073122018-11-27 15:58:47 +0100516 msg "test: compat.sh (ASan build)" # ~ 6 min
517 if_build_succeeded tests/compat.sh
518}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200519
Gilles Peskine782f4112018-11-27 16:11:09 +0100520component_test_ref_configs () {
521 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
522 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
523 record_status tests/scripts/test-ref-configs.pl
524}
525
Gilles Peskine8f073122018-11-27 15:58:47 +0100526component_test_sslv3 () {
527 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100528 cp "$CONFIG_H" "$CONFIG_BAK"
529 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
530 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
531 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000532
Gilles Peskine8f073122018-11-27 15:58:47 +0100533 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
534 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000535
Gilles Peskine8f073122018-11-27 15:58:47 +0100536 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
537 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
538 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000539
Gilles Peskine8f073122018-11-27 15:58:47 +0100540 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
541 if_build_succeeded tests/ssl-opt.sh
542}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000543
Gilles Peskine8f073122018-11-27 15:58:47 +0100544component_test_no_renegotiation () {
545 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100546 cp "$CONFIG_H" "$CONFIG_BAK"
547 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
548 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
549 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100550
Gilles Peskine8f073122018-11-27 15:58:47 +0100551 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
552 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100553
Gilles Peskine8f073122018-11-27 15:58:47 +0100554 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
555 if_build_succeeded tests/ssl-opt.sh
556}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100557
Gilles Peskine8f073122018-11-27 15:58:47 +0100558component_test_rsa_no_crt () {
559 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100560 cp "$CONFIG_H" "$CONFIG_BAK"
561 scripts/config.pl set MBEDTLS_RSA_NO_CRT
562 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
563 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100564
Gilles Peskine8f073122018-11-27 15:58:47 +0100565 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
566 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100567
Gilles Peskine8f073122018-11-27 15:58:47 +0100568 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
569 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100570
Gilles Peskine8f073122018-11-27 15:58:47 +0100571 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
572 if_build_succeeded tests/compat.sh -t RSA
573}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100574
Gilles Peskine8f073122018-11-27 15:58:47 +0100575component_test_small_ssl_out_content_len () {
576 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100577 cp "$CONFIG_H" "$CONFIG_BAK"
578 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
579 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
580 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
581 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000582
Gilles Peskine8f073122018-11-27 15:58:47 +0100583 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
584 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
585}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587component_test_small_ssl_in_content_len () {
588 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100589 cp "$CONFIG_H" "$CONFIG_BAK"
590 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
591 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
592 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
593 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000594
Gilles Peskine8f073122018-11-27 15:58:47 +0100595 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
596 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
597}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599component_test_small_ssl_dtls_max_buffering () {
600 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100601 cp "$CONFIG_H" "$CONFIG_BAK"
602 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
603 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
604 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100605
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
607 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
608}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100609
Gilles Peskine8f073122018-11-27 15:58:47 +0100610component_test_small_mbedtls_ssl_dtls_max_buffering () {
611 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100612 cp "$CONFIG_H" "$CONFIG_BAK"
613 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
614 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
615 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100616
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
618 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
619}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621component_test_full_cmake_clang () {
622 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100623 cp "$CONFIG_H" "$CONFIG_BAK"
624 scripts/config.pl full
625 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
626 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
627 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100628
Gilles Peskine8f073122018-11-27 15:58:47 +0100629 msg "test: main suites (full config)" # ~ 5s
630 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200631
Gilles Peskine8f073122018-11-27 15:58:47 +0100632 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
633 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200634
Gilles Peskine8f073122018-11-27 15:58:47 +0100635 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
636 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 +0200637
Gilles Peskine8f073122018-11-27 15:58:47 +0100638 msg "test: compat.sh ARIA + ChachaPoly"
639 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
640}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642component_build_deprecated () {
643 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100644 cp "$CONFIG_H" "$CONFIG_BAK"
645 scripts/config.pl full
646 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
647 # Build with -O -Wextra to catch a maximum of issues.
648 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
649 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
652 # No cleanup, just tweak the configuration and rebuild
653 make clean
654 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
655 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
656 # Build with -O -Wextra to catch a maximum of issues.
657 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
658 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
659}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100660
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662component_test_depends_curves () {
663 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100664 record_status tests/scripts/curves.pl
665}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200666
Gilles Peskine8f073122018-11-27 15:58:47 +0100667component_test_depends_hashes () {
668 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100669 record_status tests/scripts/depends-hashes.pl
670}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672component_test_depends_pkalgs () {
673 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 record_status tests/scripts/depends-pkalgs.pl
675}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200676
Gilles Peskine8f073122018-11-27 15:58:47 +0100677component_build_key_exchanges () {
678 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100679 record_status tests/scripts/key-exchanges.pl
680}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100681
Gilles Peskine8f073122018-11-27 15:58:47 +0100682component_build_default_make_gcc_and_cxx () {
683 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100684 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400685
Gilles Peskine8f073122018-11-27 15:58:47 +0100686 msg "test: verify header list in cpp_dummy_build.cpp"
687 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400688
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 msg "build: Unix make, incremental g++"
690 make TEST_CPP=1
691}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000692
Gilles Peskine8f073122018-11-27 15:58:47 +0100693component_test_no_platform () {
694 # Full configuration build, without platform support, file IO and net sockets.
695 # This should catch missing mbedtls_printf definitions, and by disabling file
696 # IO, it should catch missing '#include <stdio.h>'
697 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 cp "$CONFIG_H" "$CONFIG_BAK"
699 scripts/config.pl full
700 scripts/config.pl unset MBEDTLS_PLATFORM_C
701 scripts/config.pl unset MBEDTLS_NET_C
702 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
703 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
704 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
705 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
706 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
707 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
708 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
709 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
710 scripts/config.pl unset MBEDTLS_FS_IO
711 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
712 # to re-enable platform integration features otherwise disabled in C99 builds
713 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
714 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
715}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100716
Gilles Peskine8f073122018-11-27 15:58:47 +0100717component_build_no_std_function () {
718 # catch compile bugs in _uninit functions
719 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100720 cp "$CONFIG_H" "$CONFIG_BAK"
721 scripts/config.pl full
722 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
723 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
724 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
725}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200726
Gilles Peskine8f073122018-11-27 15:58:47 +0100727component_build_no_ssl_srv () {
728 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 cp "$CONFIG_H" "$CONFIG_BAK"
730 scripts/config.pl full
731 scripts/config.pl unset MBEDTLS_SSL_SRV_C
732 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
733}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735component_build_no_ssl_cli () {
736 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100737 cp "$CONFIG_H" "$CONFIG_BAK"
738 scripts/config.pl full
739 scripts/config.pl unset MBEDTLS_SSL_CLI_C
740 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
741}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200742
Gilles Peskine8f073122018-11-27 15:58:47 +0100743component_build_no_sockets () {
744 # Note, C99 compliance can also be tested with the sockets support disabled,
745 # as that requires a POSIX platform (which isn't the same as C99).
746 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100747 cp "$CONFIG_H" "$CONFIG_BAK"
748 scripts/config.pl full
749 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
750 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
751 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
752}
Hanno Becker5175ac62017-09-18 15:36:25 +0100753
Gilles Peskine8f073122018-11-27 15:58:47 +0100754component_test_no_max_fragment_length () {
755 # Run max fragment length tests with MFL disabled
756 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100757 cp "$CONFIG_H" "$CONFIG_BAK"
758 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
759 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
760 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762 msg "test: ssl-opt.sh, MFL-related tests"
763 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
764}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766component_test_no_max_fragment_length_small_ssl_out_content_len () {
767 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 cp "$CONFIG_H" "$CONFIG_BAK"
769 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
770 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
771 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
772 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
773 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000774
Gilles Peskine8f073122018-11-27 15:58:47 +0100775 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
776 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
777}
Janos Follath06c54002016-06-09 13:57:40 +0100778
Gilles Peskine8f073122018-11-27 15:58:47 +0100779component_test_null_entropy () {
780 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 cp "$CONFIG_H" "$CONFIG_BAK"
782 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
783 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
784 scripts/config.pl set MBEDTLS_ENTROPY_C
785 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
786 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
787 scripts/config.pl unset MBEDTLS_HAVEGE_C
788 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
789 make
Janos Follath06c54002016-06-09 13:57:40 +0100790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
792 make test
793}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795component_test_platform_calloc_macro () {
796 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100797 cp "$CONFIG_H" "$CONFIG_BAK"
798 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
799 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
800 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
801 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
802 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100803
Gilles Peskine8f073122018-11-27 15:58:47 +0100804 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
805 make test
806}
Hanno Becker83ebf782017-07-07 12:29:15 +0100807
Gilles Peskine8f073122018-11-27 15:58:47 +0100808component_test_aes_fewer_tables () {
809 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 cp "$CONFIG_H" "$CONFIG_BAK"
811 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
812 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 msg "test: AES_FEWER_TABLES"
815 make test
816}
Hanno Becker83ebf782017-07-07 12:29:15 +0100817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818component_test_aes_rom_tables () {
819 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100820 cp "$CONFIG_H" "$CONFIG_BAK"
821 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
822 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824 msg "test: AES_ROM_TABLES"
825 make test
826}
Hanno Becker83ebf782017-07-07 12:29:15 +0100827
Gilles Peskine8f073122018-11-27 15:58:47 +0100828component_test_aes_fewer_tables_and_rom_tables () {
829 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100830 cp "$CONFIG_H" "$CONFIG_BAK"
831 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
832 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
833 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
836 make test
837}
838
839component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100840 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100841 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100842}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200843
Gilles Peskine8f073122018-11-27 15:58:47 +0100844component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100845 # Build once with -O0, to compile out the i386 specific inline assembly
846 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100847 cp "$CONFIG_H" "$CONFIG_BAK"
848 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100849 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100850
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100851 msg "test: i386, make, gcc -O0 (ASan build)"
852 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100853}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100854
Gilles Peskine8f073122018-11-27 15:58:47 +0100855component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100856 # Build again with -O1, to compile in the i386 specific inline assembly
857 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100858 cp "$CONFIG_H" "$CONFIG_BAK"
859 scripts/config.pl full
860 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
861
862 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100863 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100864}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100865
Gilles Peskine8f073122018-11-27 15:58:47 +0100866component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100867 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100868 cp "$CONFIG_H" "$CONFIG_BAK"
869 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100870 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
871
872 msg "test: 64-bit ILP32, make, gcc"
873 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100874}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000875
Gilles Peskine8f073122018-11-27 15:58:47 +0100876component_test_have_int32 () {
877 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 cp "$CONFIG_H" "$CONFIG_BAK"
879 scripts/config.pl unset MBEDTLS_HAVE_ASM
880 scripts/config.pl unset MBEDTLS_AESNI_C
881 scripts/config.pl unset MBEDTLS_PADLOCK_C
882 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884 msg "test: gcc, force 32-bit bignum limbs"
885 make test
886}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100887
Gilles Peskine8f073122018-11-27 15:58:47 +0100888component_test_have_int64 () {
889 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 cp "$CONFIG_H" "$CONFIG_BAK"
891 scripts/config.pl unset MBEDTLS_HAVE_ASM
892 scripts/config.pl unset MBEDTLS_AESNI_C
893 scripts/config.pl unset MBEDTLS_PADLOCK_C
894 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100895
Gilles Peskine8f073122018-11-27 15:58:47 +0100896 msg "test: gcc, force 64-bit bignum limbs"
897 make test
898}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000899
Gilles Peskine8f073122018-11-27 15:58:47 +0100900component_test_no_udbl_division () {
901 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 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_MEMORY_BACKTRACE # too slow for tests
905 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
906 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200907
Gilles Peskine8f073122018-11-27 15:58:47 +0100908 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
909 make test
910}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912component_test_no_64bit_multiplication () {
913 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 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_MEMORY_BACKTRACE # too slow for tests
917 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
918 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200919
Gilles Peskine8f073122018-11-27 15:58:47 +0100920 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
921 make test
922}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200923
Gilles Peskine8f073122018-11-27 15:58:47 +0100924component_build_arm_none_eabi_gcc () {
925 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100926 cp "$CONFIG_H" "$CONFIG_BAK"
927 scripts/config.pl full
928 scripts/config.pl unset MBEDTLS_NET_C
929 scripts/config.pl unset MBEDTLS_TIMING_C
930 scripts/config.pl unset MBEDTLS_FS_IO
931 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
932 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
933 # following things are not in the default config
934 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
935 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
936 scripts/config.pl unset MBEDTLS_THREADING_C
937 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
938 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
939 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
940}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200941
Gilles Peskine8f073122018-11-27 15:58:47 +0100942component_build_arm_none_eabi_gcc_no_udbl_division () {
943 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100944 cp "$CONFIG_H" "$CONFIG_BAK"
945 scripts/config.pl full
946 scripts/config.pl unset MBEDTLS_NET_C
947 scripts/config.pl unset MBEDTLS_TIMING_C
948 scripts/config.pl unset MBEDTLS_FS_IO
949 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
950 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
951 # following things are not in the default config
952 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
953 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
954 scripts/config.pl unset MBEDTLS_THREADING_C
955 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
956 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
957 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
958 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
959 echo "Checking that software 64-bit division is not required"
960 if_build_succeeded not grep __aeabi_uldiv library/*.o
961}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200962
Gilles Peskine8f073122018-11-27 15:58:47 +0100963component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
964 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100965 cp "$CONFIG_H" "$CONFIG_BAK"
966 scripts/config.pl full
967 scripts/config.pl unset MBEDTLS_NET_C
968 scripts/config.pl unset MBEDTLS_TIMING_C
969 scripts/config.pl unset MBEDTLS_FS_IO
970 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
971 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
972 # following things are not in the default config
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 set MBEDTLS_NO_64BIT_MULTIPLICATION
979 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
980 echo "Checking that software 64-bit multiplication is not required"
981 if_build_succeeded not grep __aeabi_lmul library/*.o
982}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984component_build_armcc () {
985 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100986 cp "$CONFIG_H" "$CONFIG_BAK"
987 scripts/config.pl full
988 scripts/config.pl unset MBEDTLS_NET_C
989 scripts/config.pl unset MBEDTLS_TIMING_C
990 scripts/config.pl unset MBEDTLS_FS_IO
991 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
992 scripts/config.pl unset MBEDTLS_HAVE_TIME
993 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
994 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
995 # following things are not in the default config
996 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
997 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
998 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
999 scripts/config.pl unset MBEDTLS_THREADING_C
1000 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1001 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1002 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001003
Gilles Peskine8f073122018-11-27 15:58:47 +01001004 if [ $RUN_ARMCC -ne 0 ]; then
1005 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1006 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001007
Gilles Peskine8f073122018-11-27 15:58:47 +01001008 # ARM Compiler 6 - Target ARMv7-A
1009 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001010
Gilles Peskine8f073122018-11-27 15:58:47 +01001011 # ARM Compiler 6 - Target ARMv7-M
1012 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001013
Gilles Peskine8f073122018-11-27 15:58:47 +01001014 # ARM Compiler 6 - Target ARMv8-A - AArch32
1015 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017 # ARM Compiler 6 - Target ARMv8-M
1018 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001019
Gilles Peskine8f073122018-11-27 15:58:47 +01001020 # ARM Compiler 6 - Target ARMv8-A - AArch64
1021 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1022 fi
1023}
Simon Butcher940737f2017-07-23 13:42:36 +02001024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025component_test_allow_sha1 () {
1026 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001027 cp "$CONFIG_H" "$CONFIG_BAK"
1028 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1029 make CFLAGS='-Werror -Wall -Wextra'
1030 msg "test: allow SHA1 in certificates by default"
1031 make test
1032 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1033}
Simon Butcher940737f2017-07-23 13:42:36 +02001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035component_build_mingw () {
1036 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001037 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 +02001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 # note Make tests only builds the tests, but doesn't run them
1040 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1041 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001042
Gilles Peskine8f073122018-11-27 15:58:47 +01001043 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1044 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
1045 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
1046 make WINDOWS_BUILD=1 clean
1047}
Simon Butcher002bc622016-11-17 09:27:45 +00001048
Gilles Peskine8f073122018-11-27 15:58:47 +01001049component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001050 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001051 cp "$CONFIG_H" "$CONFIG_BAK"
1052 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1053 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1054 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001055
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001056 msg "test: main suites (MSan)" # ~ 10s
1057 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001058
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001059 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001060 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001061
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001062 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001063
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001064 if [ "$MEMORY" -gt 0 ]; then
1065 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001066 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001067 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001068}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001069
Gilles Peskine8f073122018-11-27 15:58:47 +01001070component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001071 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001072 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1073 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001074
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001075 msg "test: main suites valgrind (Release)"
1076 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001077
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001078 # Optional part(s)
1079 # Currently broken, programs don't seem to receive signals
1080 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001081
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001082 if [ "$MEMORY" -gt 0 ]; then
1083 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001084 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001085 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001086
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001087 if [ "$MEMORY" -gt 1 ]; then
1088 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001089 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001090 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001091}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001092
Gilles Peskine8f073122018-11-27 15:58:47 +01001093component_test_cmake_out_of_source () {
1094 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 MBEDTLS_ROOT_DIR="$PWD"
1096 mkdir "$OUT_OF_SOURCE_DIR"
1097 cd "$OUT_OF_SOURCE_DIR"
1098 cmake "$MBEDTLS_ROOT_DIR"
1099 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001100
Gilles Peskine8f073122018-11-27 15:58:47 +01001101 msg "test: cmake 'out-of-source' build"
1102 make test
1103 # Test an SSL option that requires an auxiliary script in test/scripts/.
1104 # Also ensure that there are no error messages such as
1105 # "No such file or directory", which would indicate that some required
1106 # file is missing (ssl-opt.sh tolerates the absence of some files so
1107 # may exit with status 0 but emit errors).
1108 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1109 if [ -s ssl-opt.err ]; then
1110 cat ssl-opt.err >&2
1111 record_status [ ! -s ssl-opt.err ]
1112 rm ssl-opt.err
1113 fi
1114 cd "$MBEDTLS_ROOT_DIR"
1115 rm -rf "$OUT_OF_SOURCE_DIR"
1116 unset MBEDTLS_ROOT_DIR
1117}
Andres AGdc192212016-08-31 17:33:13 +01001118
Gilles Peskine8f073122018-11-27 15:58:47 +01001119component_test_zeroize () {
1120 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1121 # different combinations of compilers and optimization flags by using an
1122 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1123 # system in all cases that the script fails, so we must manually search the
1124 # output to check whether the pass string is present and no failure strings
1125 # were printed.
1126 for optimization_flag in -O2 -O3 -Ofast -Os; do
1127 for compiler in clang gcc; do
1128 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Gilles Peskine8f073122018-11-27 15:58:47 +01001129 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
1130 if_build_succeeded gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
1131 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1132 if_build_succeeded not grep -i "error" test_zeroize.log
1133 rm -f test_zeroize.log
Gilles Peskinee48351a2018-11-27 16:06:30 +01001134 make clean
Gilles Peskine8f073122018-11-27 15:58:47 +01001135 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001136 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001137}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001138
Gilles Peskine8f073122018-11-27 15:58:47 +01001139component_check_python_files () {
1140 msg "Lint: Python scripts"
1141 record_status tests/scripts/check-python-files.sh
1142}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001143
Gilles Peskine8f073122018-11-27 15:58:47 +01001144component_check_generate_test_code () {
1145 msg "uint test: generate_test_code.py"
1146 record_status ./tests/scripts/test_generate_test_code.py
1147}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001148
1149################################################################
1150#### Termination
1151################################################################
1152
Gilles Peskine8f073122018-11-27 15:58:47 +01001153post_report () {
1154 msg "Done, cleaning up"
1155 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001156
Gilles Peskine8f073122018-11-27 15:58:47 +01001157 final_report
1158}
1159
1160
1161
1162################################################################
1163#### Run all the things
1164################################################################
1165
Gilles Peskine92525112018-11-27 18:15:35 +01001166run_all_components () {
1167 # Small things
1168 run_component component_check_recursion
1169 run_component component_check_generated_files
1170 run_component component_check_doxy_blocks
1171 run_component component_check_files
1172 run_component component_check_names
1173 run_component component_check_doxygen_warnings
1174
1175 # Test many different configurations
1176 run_component component_test_default_cmake_gcc_asan
1177 run_component component_test_ref_configs
1178 run_component component_test_sslv3
1179 run_component component_test_no_renegotiation
1180 run_component component_test_rsa_no_crt
1181 run_component component_test_small_ssl_out_content_len
1182 run_component component_test_small_ssl_in_content_len
1183 run_component component_test_small_ssl_dtls_max_buffering
1184 run_component component_test_small_mbedtls_ssl_dtls_max_buffering
1185 run_component component_test_full_cmake_clang
1186 run_component component_build_deprecated
1187 run_component component_test_depends_curves
1188 run_component component_test_depends_hashes
1189 run_component component_test_depends_pkalgs
1190 run_component component_build_key_exchanges
1191 run_component component_build_default_make_gcc_and_cxx
1192 run_component component_test_no_platform
1193 run_component component_build_no_std_function
1194 run_component component_build_no_ssl_srv
1195 run_component component_build_no_ssl_cli
1196 run_component component_build_no_sockets
1197 run_component component_test_no_max_fragment_length
1198 run_component component_test_no_max_fragment_length_small_ssl_out_content_len
1199 run_component component_test_null_entropy
1200 run_component component_test_platform_calloc_macro
1201 run_component component_test_aes_fewer_tables
1202 run_component component_test_aes_rom_tables
1203 run_component component_test_aes_fewer_tables_and_rom_tables
1204 if uname -a | grep -F Linux >/dev/null; then
1205 run_component component_test_make_shared
1206 fi
1207 if uname -a | grep -F x86_64 >/dev/null; then
1208 run_component component_test_m32_o0
1209 run_component component_test_m32_o1
1210 run_component component_test_mx32
1211 fi
1212 run_component component_test_have_int32
1213 run_component component_test_have_int64
1214 run_component component_test_no_udbl_division
1215 run_component component_test_no_64bit_multiplication
1216 run_component component_build_arm_none_eabi_gcc
1217 run_component component_build_arm_none_eabi_gcc_no_udbl_division
1218 run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
1219 run_component component_build_armcc
1220 run_component component_test_allow_sha1
1221 run_component component_build_mingw
1222 # MemSan currently only available on Linux 64 bits
1223 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
1224 run_component component_test_memsan
1225 else # no MemSan
1226 run_component component_test_memcheck
1227 fi
1228 run_component component_test_cmake_out_of_source
1229
1230 # More small things
1231 run_component component_test_zeroize
1232 run_component component_check_python_files
1233 run_component component_check_generate_test_code
1234}
1235
Gilles Peskinee48351a2018-11-27 16:06:30 +01001236# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001237run_component () {
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001238 if [ $ALL_EXCEPT -ne 0 ] && component_is_excluded "$1"; then
1239 return
1240 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001241 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001242 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001243}
1244
1245# Preliminary setup
1246pre_check_environment
1247pre_initialize_variables
1248pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001249
1250case "$INTROSPECTION_MODE" in
1251 list_components)
1252 components=
1253 newline='
1254'
1255 run_component () {
Gilles Peskine92525112018-11-27 18:15:35 +01001256 components="${components}${newline}${1#component_}"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001257 }
1258 ;;
1259
1260 *)
1261 pre_check_git
1262 build_status=0
1263 if [ $KEEP_GOING -eq 1 ]; then
1264 pre_setup_keep_going
1265 else
1266 record_status () {
1267 "$@"
1268 }
1269 fi
1270 pre_print_configuration
1271 pre_check_tools
1272 pre_print_tools
1273 cleanup
1274 ;;
1275esac
Gilles Peskine8f073122018-11-27 15:58:47 +01001276
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001277if [ -n "$COMPONENTS" ] && [ $ALL_EXCEPT -eq 0 ]; then
Gilles Peskine92525112018-11-27 18:15:35 +01001278 for component in $COMPONENTS; do
1279 run_component "component_$component"
1280 done
1281else
1282 run_all_components
Gilles Peskine8f073122018-11-27 15:58:47 +01001283fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001284
1285# We're done.
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001286case "$INTROSPECTION_MODE" in
1287 list_components)
1288 echo "$components" | sort
1289 ;;
1290 *)
1291 post_report
1292 ;;
1293esac