blob: a521c74b1b139fe8771df83f0efb3b0de5e239f7 [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
456 cleanup
457 record_status tests/scripts/check-files.py
458}
Darryl Greena07039c2018-03-13 16:48:16 +0000459
Gilles Peskine8f073122018-11-27 15:58:47 +0100460component_check_names () {
461 msg "test/build: declared and exported names" # < 3s
462 cleanup
463 record_status tests/scripts/check-names.sh
464}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200465
Gilles Peskine8f073122018-11-27 15:58:47 +0100466component_check_doxygen_warnings () {
467 msg "test: doxygen warnings" # ~ 3s
468 cleanup
469 record_status tests/scripts/doxygen.sh
470}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100471
Gilles Peskine192c72f2017-12-21 15:59:21 +0100472
473
474################################################################
475#### Build and test many configurations and targets
476################################################################
477
Gilles Peskine8f073122018-11-27 15:58:47 +0100478component_test_default_cmake_gcc_asan () {
479 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
480 cleanup
481 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
482 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100483
Gilles Peskine8f073122018-11-27 15:58:47 +0100484 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
485 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200486
Gilles Peskine8f073122018-11-27 15:58:47 +0100487 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
488 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200489
Gilles Peskine8f073122018-11-27 15:58:47 +0100490 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
491 record_status tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200492
Gilles Peskine8f073122018-11-27 15:58:47 +0100493 msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
494 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200495
Gilles Peskine8f073122018-11-27 15:58:47 +0100496 msg "test: compat.sh (ASan build)" # ~ 6 min
497 if_build_succeeded tests/compat.sh
498}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200499
Gilles Peskine8f073122018-11-27 15:58:47 +0100500component_test_sslv3 () {
501 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
502 cleanup
503 cp "$CONFIG_H" "$CONFIG_BAK"
504 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
505 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
506 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000507
Gilles Peskine8f073122018-11-27 15:58:47 +0100508 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
509 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000510
Gilles Peskine8f073122018-11-27 15:58:47 +0100511 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
512 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
513 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000514
Gilles Peskine8f073122018-11-27 15:58:47 +0100515 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
516 if_build_succeeded tests/ssl-opt.sh
517}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000518
Gilles Peskine8f073122018-11-27 15:58:47 +0100519component_test_no_renegotiation () {
520 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
521 cleanup
522 cp "$CONFIG_H" "$CONFIG_BAK"
523 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
524 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
525 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100526
Gilles Peskine8f073122018-11-27 15:58:47 +0100527 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
528 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100529
Gilles Peskine8f073122018-11-27 15:58:47 +0100530 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
531 if_build_succeeded tests/ssl-opt.sh
532}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100533
Gilles Peskine8f073122018-11-27 15:58:47 +0100534component_test_rsa_no_crt () {
535 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
536 cleanup
537 cp "$CONFIG_H" "$CONFIG_BAK"
538 scripts/config.pl set MBEDTLS_RSA_NO_CRT
539 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
540 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100541
Gilles Peskine8f073122018-11-27 15:58:47 +0100542 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
543 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100544
Gilles Peskine8f073122018-11-27 15:58:47 +0100545 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
546 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100547
Gilles Peskine8f073122018-11-27 15:58:47 +0100548 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
549 if_build_succeeded tests/compat.sh -t RSA
550}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100551
Gilles Peskine8f073122018-11-27 15:58:47 +0100552component_test_small_ssl_out_content_len () {
553 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
554 cleanup
555 cp "$CONFIG_H" "$CONFIG_BAK"
556 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
557 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
558 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
559 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000560
Gilles Peskine8f073122018-11-27 15:58:47 +0100561 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
562 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
563}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000564
Gilles Peskine8f073122018-11-27 15:58:47 +0100565component_test_small_ssl_in_content_len () {
566 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
567 cleanup
568 cp "$CONFIG_H" "$CONFIG_BAK"
569 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
570 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
571 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
572 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000573
Gilles Peskine8f073122018-11-27 15:58:47 +0100574 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
575 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
576}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000577
Gilles Peskine8f073122018-11-27 15:58:47 +0100578component_test_small_ssl_dtls_max_buffering () {
579 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
580 cleanup
581 cp "$CONFIG_H" "$CONFIG_BAK"
582 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
583 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
584 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100585
Gilles Peskine8f073122018-11-27 15:58:47 +0100586 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
587 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
588}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100589
Gilles Peskine8f073122018-11-27 15:58:47 +0100590component_test_small_mbedtls_ssl_dtls_max_buffering () {
591 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
592 cleanup
593 cp "$CONFIG_H" "$CONFIG_BAK"
594 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
595 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
596 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100597
Gilles Peskine8f073122018-11-27 15:58:47 +0100598 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
599 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
600}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100601
Gilles Peskine8f073122018-11-27 15:58:47 +0100602component_test_full_cmake_clang () {
603 msg "build: cmake, full config, clang" # ~ 50s
604 cleanup
605 cp "$CONFIG_H" "$CONFIG_BAK"
606 scripts/config.pl full
607 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
608 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
609 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 msg "test: main suites (full config)" # ~ 5s
612 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200613
Gilles Peskine8f073122018-11-27 15:58:47 +0100614 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
615 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200616
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
618 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 +0200619
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 msg "test: compat.sh ARIA + ChachaPoly"
621 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
622}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100623
Gilles Peskine8f073122018-11-27 15:58:47 +0100624component_build_deprecated () {
625 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
626 cleanup
627 cp "$CONFIG_H" "$CONFIG_BAK"
628 scripts/config.pl full
629 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
630 # Build with -O -Wextra to catch a maximum of issues.
631 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
632 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100633
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
635 # No cleanup, just tweak the configuration and rebuild
636 make clean
637 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
638 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
639 # Build with -O -Wextra to catch a maximum of issues.
640 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
641 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
642}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100643
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200644
Gilles Peskine8f073122018-11-27 15:58:47 +0100645component_test_depends_curves () {
646 msg "test/build: curves.pl (gcc)" # ~ 4 min
647 cleanup
648 record_status tests/scripts/curves.pl
649}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651component_test_depends_hashes () {
652 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
653 cleanup
654 record_status tests/scripts/depends-hashes.pl
655}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200656
Gilles Peskine8f073122018-11-27 15:58:47 +0100657component_test_depends_pkalgs () {
658 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
659 cleanup
660 record_status tests/scripts/depends-pkalgs.pl
661}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200662
Gilles Peskine8f073122018-11-27 15:58:47 +0100663component_build_key_exchanges () {
664 msg "test/build: key-exchanges (gcc)" # ~ 1 min
665 cleanup
666 record_status tests/scripts/key-exchanges.pl
667}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669component_build_default_make_gcc_and_cxx () {
670 msg "build: Unix make, -Os (gcc)" # ~ 30s
671 cleanup
672 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 msg "test: verify header list in cpp_dummy_build.cpp"
675 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400676
Gilles Peskine8f073122018-11-27 15:58:47 +0100677 msg "build: Unix make, incremental g++"
678 make TEST_CPP=1
679}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000680
Gilles Peskine8f073122018-11-27 15:58:47 +0100681component_test_no_platform () {
682 # Full configuration build, without platform support, file IO and net sockets.
683 # This should catch missing mbedtls_printf definitions, and by disabling file
684 # IO, it should catch missing '#include <stdio.h>'
685 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
686 cleanup
687 cp "$CONFIG_H" "$CONFIG_BAK"
688 scripts/config.pl full
689 scripts/config.pl unset MBEDTLS_PLATFORM_C
690 scripts/config.pl unset MBEDTLS_NET_C
691 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
692 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
693 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
694 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
695 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
696 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
697 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
698 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
699 scripts/config.pl unset MBEDTLS_FS_IO
700 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
701 # to re-enable platform integration features otherwise disabled in C99 builds
702 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
703 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
704}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100705
Gilles Peskine8f073122018-11-27 15:58:47 +0100706component_build_no_std_function () {
707 # catch compile bugs in _uninit functions
708 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
709 cleanup
710 cp "$CONFIG_H" "$CONFIG_BAK"
711 scripts/config.pl full
712 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
713 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
714 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
715}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200716
Gilles Peskine8f073122018-11-27 15:58:47 +0100717component_build_no_ssl_srv () {
718 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
719 cleanup
720 cp "$CONFIG_H" "$CONFIG_BAK"
721 scripts/config.pl full
722 scripts/config.pl unset MBEDTLS_SSL_SRV_C
723 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
724}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200725
Gilles Peskine8f073122018-11-27 15:58:47 +0100726component_build_no_ssl_cli () {
727 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
728 cleanup
729 cp "$CONFIG_H" "$CONFIG_BAK"
730 scripts/config.pl full
731 scripts/config.pl unset MBEDTLS_SSL_CLI_C
732 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
733}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735component_build_no_sockets () {
736 # Note, C99 compliance can also be tested with the sockets support disabled,
737 # as that requires a POSIX platform (which isn't the same as C99).
738 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
739 cleanup
740 cp "$CONFIG_H" "$CONFIG_BAK"
741 scripts/config.pl full
742 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
743 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
744 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
745}
Hanno Becker5175ac62017-09-18 15:36:25 +0100746
Gilles Peskine8f073122018-11-27 15:58:47 +0100747component_test_no_max_fragment_length () {
748 # Run max fragment length tests with MFL disabled
749 msg "build: default config except MFL extension (ASan build)" # ~ 30s
750 cleanup
751 cp "$CONFIG_H" "$CONFIG_BAK"
752 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
753 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
754 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000755
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 msg "test: ssl-opt.sh, MFL-related tests"
757 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
758}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000759
Gilles Peskine8f073122018-11-27 15:58:47 +0100760component_test_no_max_fragment_length_small_ssl_out_content_len () {
761 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
762 cleanup
763 cp "$CONFIG_H" "$CONFIG_BAK"
764 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
765 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
766 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
767 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
768 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
771 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
772}
Janos Follath06c54002016-06-09 13:57:40 +0100773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774component_test_null_entropy () {
775 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
776 cleanup
777 cp "$CONFIG_H" "$CONFIG_BAK"
778 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
779 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
780 scripts/config.pl set MBEDTLS_ENTROPY_C
781 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
782 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
783 scripts/config.pl unset MBEDTLS_HAVEGE_C
784 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
785 make
Janos Follath06c54002016-06-09 13:57:40 +0100786
Gilles Peskine8f073122018-11-27 15:58:47 +0100787 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
788 make test
789}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791component_test_platform_calloc_macro () {
792 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
793 cleanup
794 cp "$CONFIG_H" "$CONFIG_BAK"
795 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
796 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
797 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
798 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
799 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
802 make test
803}
Hanno Becker83ebf782017-07-07 12:29:15 +0100804
Gilles Peskine8f073122018-11-27 15:58:47 +0100805component_test_aes_fewer_tables () {
806 msg "build: default config with AES_FEWER_TABLES enabled"
807 cleanup
808 cp "$CONFIG_H" "$CONFIG_BAK"
809 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
810 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100811
Gilles Peskine8f073122018-11-27 15:58:47 +0100812 msg "test: AES_FEWER_TABLES"
813 make test
814}
Hanno Becker83ebf782017-07-07 12:29:15 +0100815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816component_test_aes_rom_tables () {
817 msg "build: default config with AES_ROM_TABLES enabled"
818 cleanup
819 cp "$CONFIG_H" "$CONFIG_BAK"
820 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
821 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100822
Gilles Peskine8f073122018-11-27 15:58:47 +0100823 msg "test: AES_ROM_TABLES"
824 make test
825}
Hanno Becker83ebf782017-07-07 12:29:15 +0100826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827component_test_aes_fewer_tables_and_rom_tables () {
828 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
829 cleanup
830 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
841 cleanup
842 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100843}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200844
Gilles Peskine8f073122018-11-27 15:58:47 +0100845component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100846 # Build once with -O0, to compile out the i386 specific inline assembly
847 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100848 cleanup
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100849 cp "$CONFIG_H" "$CONFIG_BAK"
850 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100851 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100852
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100853 msg "test: i386, make, gcc -O0 (ASan build)"
854 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100855}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100856
Gilles Peskine8f073122018-11-27 15:58:47 +0100857component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100858 # Build again with -O1, to compile in the i386 specific inline assembly
859 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
860 cleanup
861 cp "$CONFIG_H" "$CONFIG_BAK"
862 scripts/config.pl full
863 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
864
865 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100866 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100867}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100868
Gilles Peskine8f073122018-11-27 15:58:47 +0100869component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100870 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
871 cleanup
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100872 cp "$CONFIG_H" "$CONFIG_BAK"
873 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100874 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
875
876 msg "test: 64-bit ILP32, make, gcc"
877 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100878}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000879
Gilles Peskine8f073122018-11-27 15:58:47 +0100880component_test_have_int32 () {
881 msg "build: gcc, force 32-bit bignum limbs"
882 cleanup
883 cp "$CONFIG_H" "$CONFIG_BAK"
884 scripts/config.pl unset MBEDTLS_HAVE_ASM
885 scripts/config.pl unset MBEDTLS_AESNI_C
886 scripts/config.pl unset MBEDTLS_PADLOCK_C
887 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100888
Gilles Peskine8f073122018-11-27 15:58:47 +0100889 msg "test: gcc, force 32-bit bignum limbs"
890 make test
891}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100892
Gilles Peskine8f073122018-11-27 15:58:47 +0100893component_test_have_int64 () {
894 msg "build: gcc, force 64-bit bignum limbs"
895 cleanup
896 cp "$CONFIG_H" "$CONFIG_BAK"
897 scripts/config.pl unset MBEDTLS_HAVE_ASM
898 scripts/config.pl unset MBEDTLS_AESNI_C
899 scripts/config.pl unset MBEDTLS_PADLOCK_C
900 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100901
Gilles Peskine8f073122018-11-27 15:58:47 +0100902 msg "test: gcc, force 64-bit bignum limbs"
903 make test
904}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000905
Gilles Peskine8f073122018-11-27 15:58:47 +0100906component_test_no_udbl_division () {
907 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
908 cleanup
909 cp "$CONFIG_H" "$CONFIG_BAK"
910 scripts/config.pl full
911 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
912 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
913 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200914
Gilles Peskine8f073122018-11-27 15:58:47 +0100915 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
916 make test
917}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200918
Gilles Peskine8f073122018-11-27 15:58:47 +0100919component_test_no_64bit_multiplication () {
920 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
921 cleanup
922 cp "$CONFIG_H" "$CONFIG_BAK"
923 scripts/config.pl full
924 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
925 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
926 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200927
Gilles Peskine8f073122018-11-27 15:58:47 +0100928 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
929 make test
930}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200931
Gilles Peskine8f073122018-11-27 15:58:47 +0100932component_build_arm_none_eabi_gcc () {
933 msg "build: arm-none-eabi-gcc, make" # ~ 10s
934 cleanup
935 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 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
949}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200950
Gilles Peskine8f073122018-11-27 15:58:47 +0100951component_build_arm_none_eabi_gcc_no_udbl_division () {
952 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
953 cleanup
954 cp "$CONFIG_H" "$CONFIG_BAK"
955 scripts/config.pl full
956 scripts/config.pl unset MBEDTLS_NET_C
957 scripts/config.pl unset MBEDTLS_TIMING_C
958 scripts/config.pl unset MBEDTLS_FS_IO
959 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
960 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
961 # following things are not in the default config
962 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
963 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
964 scripts/config.pl unset MBEDTLS_THREADING_C
965 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
966 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
967 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
968 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
969 echo "Checking that software 64-bit division is not required"
970 if_build_succeeded not grep __aeabi_uldiv library/*.o
971}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200972
Gilles Peskine8f073122018-11-27 15:58:47 +0100973component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
974 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
975 cleanup
976 cp "$CONFIG_H" "$CONFIG_BAK"
977 scripts/config.pl full
978 scripts/config.pl unset MBEDTLS_NET_C
979 scripts/config.pl unset MBEDTLS_TIMING_C
980 scripts/config.pl unset MBEDTLS_FS_IO
981 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
982 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
983 # following things are not in the default config
984 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
985 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
986 scripts/config.pl unset MBEDTLS_THREADING_C
987 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
988 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
989 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
990 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
991 echo "Checking that software 64-bit multiplication is not required"
992 if_build_succeeded not grep __aeabi_lmul library/*.o
993}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200994
Gilles Peskine8f073122018-11-27 15:58:47 +0100995component_build_armcc () {
996 msg "build: ARM Compiler 5, make"
997 cleanup
998 cp "$CONFIG_H" "$CONFIG_BAK"
999 scripts/config.pl full
1000 scripts/config.pl unset MBEDTLS_NET_C
1001 scripts/config.pl unset MBEDTLS_TIMING_C
1002 scripts/config.pl unset MBEDTLS_FS_IO
1003 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1004 scripts/config.pl unset MBEDTLS_HAVE_TIME
1005 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1006 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1007 # following things are not in the default config
1008 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1009 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1010 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1011 scripts/config.pl unset MBEDTLS_THREADING_C
1012 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1013 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1014 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 if [ $RUN_ARMCC -ne 0 ]; then
1017 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1018 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001019
Gilles Peskine8f073122018-11-27 15:58:47 +01001020 # ARM Compiler 6 - Target ARMv7-A
1021 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023 # ARM Compiler 6 - Target ARMv7-M
1024 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001025
Gilles Peskine8f073122018-11-27 15:58:47 +01001026 # ARM Compiler 6 - Target ARMv8-A - AArch32
1027 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 # ARM Compiler 6 - Target ARMv8-M
1030 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001031
Gilles Peskine8f073122018-11-27 15:58:47 +01001032 # ARM Compiler 6 - Target ARMv8-A - AArch64
1033 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1034 fi
1035}
Simon Butcher940737f2017-07-23 13:42:36 +02001036
Gilles Peskine8f073122018-11-27 15:58:47 +01001037component_test_allow_sha1 () {
1038 msg "build: allow SHA1 in certificates by default"
1039 cleanup
1040 cp "$CONFIG_H" "$CONFIG_BAK"
1041 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1042 make CFLAGS='-Werror -Wall -Wextra'
1043 msg "test: allow SHA1 in certificates by default"
1044 make test
1045 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1046}
Simon Butcher940737f2017-07-23 13:42:36 +02001047
Gilles Peskine8f073122018-11-27 15:58:47 +01001048component_build_mingw () {
1049 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
1050 cleanup
1051 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 +02001052
Gilles Peskine8f073122018-11-27 15:58:47 +01001053 # note Make tests only builds the tests, but doesn't run them
1054 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1055 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001056
Gilles Peskine8f073122018-11-27 15:58:47 +01001057 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1058 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
1059 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
1060 make WINDOWS_BUILD=1 clean
1061}
Simon Butcher002bc622016-11-17 09:27:45 +00001062
Gilles Peskine8f073122018-11-27 15:58:47 +01001063component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001064 msg "build: MSan (clang)" # ~ 1 min 20s
1065 cleanup
1066 cp "$CONFIG_H" "$CONFIG_BAK"
1067 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1068 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1069 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001070
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001071 msg "test: main suites (MSan)" # ~ 10s
1072 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001073
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001074 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001075 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001076
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001077 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001078
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001079 if [ "$MEMORY" -gt 0 ]; then
1080 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001081 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001082 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001083}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001084
Gilles Peskine8f073122018-11-27 15:58:47 +01001085component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001086 msg "build: Release (clang)"
1087 cleanup
1088 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1089 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001090
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001091 msg "test: main suites valgrind (Release)"
1092 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001093
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001094 # Optional part(s)
1095 # Currently broken, programs don't seem to receive signals
1096 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001097
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001098 if [ "$MEMORY" -gt 0 ]; then
1099 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001100 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001101 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001102
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001103 if [ "$MEMORY" -gt 1 ]; then
1104 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001105 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001106 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001107}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001108
Gilles Peskine8f073122018-11-27 15:58:47 +01001109component_test_cmake_out_of_source () {
1110 msg "build: cmake 'out-of-source' build"
1111 cleanup
1112 MBEDTLS_ROOT_DIR="$PWD"
1113 mkdir "$OUT_OF_SOURCE_DIR"
1114 cd "$OUT_OF_SOURCE_DIR"
1115 cmake "$MBEDTLS_ROOT_DIR"
1116 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001117
Gilles Peskine8f073122018-11-27 15:58:47 +01001118 msg "test: cmake 'out-of-source' build"
1119 make test
1120 # Test an SSL option that requires an auxiliary script in test/scripts/.
1121 # Also ensure that there are no error messages such as
1122 # "No such file or directory", which would indicate that some required
1123 # file is missing (ssl-opt.sh tolerates the absence of some files so
1124 # may exit with status 0 but emit errors).
1125 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1126 if [ -s ssl-opt.err ]; then
1127 cat ssl-opt.err >&2
1128 record_status [ ! -s ssl-opt.err ]
1129 rm ssl-opt.err
1130 fi
1131 cd "$MBEDTLS_ROOT_DIR"
1132 rm -rf "$OUT_OF_SOURCE_DIR"
1133 unset MBEDTLS_ROOT_DIR
1134}
Andres AGdc192212016-08-31 17:33:13 +01001135
Gilles Peskine8f073122018-11-27 15:58:47 +01001136component_test_zeroize () {
1137 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1138 # different combinations of compilers and optimization flags by using an
1139 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1140 # system in all cases that the script fails, so we must manually search the
1141 # output to check whether the pass string is present and no failure strings
1142 # were printed.
1143 for optimization_flag in -O2 -O3 -Ofast -Os; do
1144 for compiler in clang gcc; do
1145 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1146 cleanup
1147 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
1148 if_build_succeeded gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
1149 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1150 if_build_succeeded not grep -i "error" test_zeroize.log
1151 rm -f test_zeroize.log
1152 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001153 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001154}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001155
Gilles Peskine8f073122018-11-27 15:58:47 +01001156component_check_python_files () {
1157 msg "Lint: Python scripts"
1158 record_status tests/scripts/check-python-files.sh
1159}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001160
Gilles Peskine8f073122018-11-27 15:58:47 +01001161component_check_generate_test_code () {
1162 msg "uint test: generate_test_code.py"
1163 record_status ./tests/scripts/test_generate_test_code.py
1164}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001165
1166################################################################
1167#### Termination
1168################################################################
1169
Gilles Peskine8f073122018-11-27 15:58:47 +01001170post_report () {
1171 msg "Done, cleaning up"
1172 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001173
Gilles Peskine8f073122018-11-27 15:58:47 +01001174 final_report
1175}
1176
1177
1178
1179################################################################
1180#### Run all the things
1181################################################################
1182
1183# Run one component. Currently trivial.
1184run_component () {
1185 "$@"
1186}
1187
1188# Preliminary setup
1189pre_check_environment
1190pre_initialize_variables
1191pre_parse_command_line "$@"
1192pre_check_git
1193build_status=0
1194if [ $KEEP_GOING -eq 1 ]; then
1195 pre_setup_keep_going
1196else
1197 record_status () {
1198 "$@"
1199 }
1200fi
1201pre_print_configuration
1202pre_check_tools
1203pre_print_tools
1204
1205# Small things
1206run_component component_check_recursion
1207run_component component_check_generated_files
1208run_component component_check_doxy_blocks
1209run_component component_check_files
1210run_component component_check_names
1211run_component component_check_doxygen_warnings
1212
1213# Test many different configurations
1214run_component component_test_default_cmake_gcc_asan
1215run_component component_test_sslv3
1216run_component component_test_no_renegotiation
1217run_component component_test_rsa_no_crt
1218run_component component_test_small_ssl_out_content_len
1219run_component component_test_small_ssl_in_content_len
1220run_component component_test_small_ssl_dtls_max_buffering
1221run_component component_test_small_mbedtls_ssl_dtls_max_buffering
1222run_component component_test_full_cmake_clang
1223run_component component_build_deprecated
1224run_component component_test_depends_curves
1225run_component component_test_depends_hashes
1226run_component component_test_depends_pkalgs
1227run_component component_build_key_exchanges
1228run_component component_build_default_make_gcc_and_cxx
1229run_component component_test_no_platform
1230run_component component_build_no_std_function
1231run_component component_build_no_ssl_srv
1232run_component component_build_no_ssl_cli
1233run_component component_build_no_sockets
1234run_component component_test_no_max_fragment_length
1235run_component component_test_no_max_fragment_length_small_ssl_out_content_len
1236run_component component_test_null_entropy
1237run_component component_test_platform_calloc_macro
1238run_component component_test_aes_fewer_tables
1239run_component component_test_aes_rom_tables
1240run_component component_test_aes_fewer_tables_and_rom_tables
1241if uname -a | grep -F Linux >/dev/null; then
1242 run_component component_test_make_shared
1243fi
1244if uname -a | grep -F x86_64 >/dev/null; then
1245 run_component component_test_m32_o0
1246 run_component component_test_m32_o1
1247 run_component component_test_mx32
1248fi
1249run_component component_test_have_int32
1250run_component component_test_have_int64
1251run_component component_test_no_udbl_division
1252run_component component_test_no_64bit_multiplication
1253run_component component_build_arm_none_eabi_gcc
1254run_component component_build_arm_none_eabi_gcc_no_udbl_division
1255run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
1256run_component component_build_armcc
1257run_component component_test_allow_sha1
Gilles Peskine8f073122018-11-27 15:58:47 +01001258run_component component_build_mingw
1259# MemSan currently only available on Linux 64 bits
1260if uname -a | grep 'Linux.*x86_64' >/dev/null; then
1261 run_component component_test_memsan
1262else # no MemSan
1263 run_component component_test_memcheck
1264fi
1265run_component component_test_cmake_out_of_source
1266
1267# More small things
1268run_component component_test_zeroize
1269run_component component_check_python_files
1270run_component component_check_generate_test_code
1271
1272# We're done.
1273post_report