blob: 41a6f8816058137f630745e32b7a1a3e0a7af05a [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
Gilles Peskine878cf602019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskine192c72f2017-12-21 15:59:21 +010070# The tests are roughly in order from fastest to slowest. This doesn't
71# have to be exact, but in general you should add slower tests towards
72# the end and fast checks near the beginning.
73#
74# Sanity checks have the following form:
75# 1. msg "short description of what is about to be done"
76# 2. run sanity check (failure stops the script)
77#
78# Build or build-and-test steps have the following form:
79# 1. msg "short description of what is about to be done"
80# 2. cleanup
81# 3. preparation (config.pl, cmake, ...) (failure stops the script)
82# 4. make
83# 5. Run tests if relevant. All tests must be prefixed with
84# if_build_successful for the sake of --keep-going.
85
86
87
88################################################################
89#### Initialization and command line parsing
90################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091
SimonB2e23c822016-04-16 21:54:39 +010092# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010093set -eu
94
Gilles Peskine8f073122018-11-27 15:58:47 +010095pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +000096 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +010097 echo "Must be run from mbed TLS root" >&2
98 exit 1
99 fi
100}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100101
Gilles Peskine8f073122018-11-27 15:58:47 +0100102pre_initialize_variables () {
103 CONFIG_H='include/mbedtls/config.h'
104 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200105
Gilles Peskine92525112018-11-27 18:15:35 +0100106 COMPONENTS=
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100107 ALL_EXCEPT=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100108 MEMORY=0
109 FORCE=0
110 KEEP_GOING=0
111 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100112
Gilles Peskine8f073122018-11-27 15:58:47 +0100113 # Default commands, can be overriden by the environment
114 : ${OPENSSL:="openssl"}
115 : ${OPENSSL_LEGACY:="$OPENSSL"}
116 : ${OPENSSL_NEXT:="$OPENSSL"}
117 : ${GNUTLS_CLI:="gnutls-cli"}
118 : ${GNUTLS_SERV:="gnutls-serv"}
119 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
120 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
121 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
122 : ${ARMC5_BIN_DIR:=/usr/bin}
123 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100124
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000126 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100127 export MAKEFLAGS="-j"
128 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000129
130 # Gather the list of available components. These are the functions
131 # defined in this script whose name starts with "component_".
132 # Parse the script with sed, because in sh there is no way to list
133 # defined functions.
134 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
135
136 # Exclude components that are not supported on this platform.
137 SUPPORTED_COMPONENTS=
138 for component in $ALL_COMPONENTS; do
139 case $(type "support_$component" 2>&1) in
140 *' function'*)
141 if ! support_$component; then continue; fi;;
142 esac
143 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
144 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100145}
Andres AG38495a32016-07-12 16:54:33 +0100146
Gilles Peskine878cf602019-01-06 20:50:38 +0000147# Test whether $1 is excluded via the command line.
148is_component_excluded()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100149{
Gilles Peskine878cf602019-01-06 20:50:38 +0000150 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
151 # patterns)?
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100152 set -f
153 for pattern in $COMPONENTS; do
154 set +f
155 case ${1#component_} in $pattern) return 0;; esac
156 done
157 set +f
158 return 1
159}
160
Simon Butcher41eeccf2016-09-07 00:07:09 +0100161usage()
SimonB2e23c822016-04-16 21:54:39 +0100162{
Gilles Peskine709346a2017-12-10 23:43:39 +0100163 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100164Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100165Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100166By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100167
168Special options:
169 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000170 --list-all-components List all available test components and exit.
171 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100172
173General options:
174 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100175 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100176 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100177 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100178 --except If some components are passed on the command line,
179 run all the tests except for these components. In
180 this mode, you can pass shell wildcard patterns as
181 component names, e.g. "$0 --except 'test_*'" to
182 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100183 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100184 --no-force Refuse to overwrite modified files (default).
185 --no-keep-going Stop at the first error (default).
186 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100187 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100188 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100189 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
190 -s|--seed Integer seed value to use for this test run.
191
192Tool path options:
193 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
194 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
195 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
196 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
197 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
198 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
199 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
200 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100201 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100202EOF
SimonB2e23c822016-04-16 21:54:39 +0100203}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100204
205# remove built files as well as the cmake cache/config
206cleanup()
207{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100208 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
209 cd "$MBEDTLS_ROOT_DIR"
210 fi
211
Gilles Peskine7c652162017-12-11 00:01:40 +0100212 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200213
Gilles Peskine31b07e22018-03-21 12:15:06 +0100214 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100215 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100216 -iname CMakeFiles -exec rm -rf {} \+ -o \
217 \( -iname cmake_install.cmake -o \
218 -iname CTestTestfile.cmake -o \
219 -iname CMakeCache.txt \) -exec rm {} \+
220 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000221 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200222 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
223 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200224
225 if [ -f "$CONFIG_BAK" ]; then
226 mv "$CONFIG_BAK" "$CONFIG_H"
227 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100228}
229
Gilles Peskine7c652162017-12-11 00:01:40 +0100230# Executed on exit. May be redefined depending on command line options.
231final_report () {
232 :
233}
234
235fatal_signal () {
236 cleanup
237 final_report $1
238 trap - $1
239 kill -$1 $$
240}
241
242trap 'fatal_signal HUP' HUP
243trap 'fatal_signal INT' INT
244trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200245
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100246msg()
247{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100248 if [ -n "${current_component:-}" ]; then
249 current_section="${current_component#component_}: $1"
250 else
251 current_section="$1"
252 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100253 echo ""
254 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100255 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000256 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100257 echo "******************************************************************"
258}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100259
Gilles Peskine8f073122018-11-27 15:58:47 +0100260armc6_build_test()
261{
262 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100263
Gilles Peskine8f073122018-11-27 15:58:47 +0100264 msg "build: ARM Compiler 6 ($FLAGS), make"
265 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
266 WARNING_CFLAGS='-xc -std=c99' make lib
267 make clean
268}
Andres AGa5cd9732016-10-17 15:23:10 +0100269
Andres AGd9eba4b2016-08-26 14:42:14 +0100270err_msg()
271{
272 echo "$1" >&2
273}
274
275check_tools()
276{
277 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000278 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100279 err_msg "$TOOL not found!"
280 exit 1
281 fi
282 done
283}
284
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400285check_headers_in_cpp () {
286 ls include/mbedtls >headers.txt
287 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
288 sort |
289 diff headers.txt -
290 rm headers.txt
291}
292
Gilles Peskine8f073122018-11-27 15:58:47 +0100293pre_parse_command_line () {
294 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100295 case "$1" in
296 --armcc) RUN_ARMCC=1;;
297 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
298 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
299 --except) ALL_EXCEPT=1;;
300 --force|-f) FORCE=1;;
301 --gnutls-cli) shift; GNUTLS_CLI="$1";;
302 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
303 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
304 --gnutls-serv) shift; GNUTLS_SERV="$1";;
305 --help|-h) usage; exit;;
306 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000307 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
308 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100309 --memory|-m) MEMORY=1;;
310 --no-armcc) RUN_ARMCC=0;;
311 --no-force) FORCE=0;;
312 --no-keep-going) KEEP_GOING=0;;
313 --no-memory) MEMORY=0;;
314 --openssl) shift; OPENSSL="$1";;
315 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
316 --openssl-next) shift; OPENSSL_NEXT="$1";;
317 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
318 --random-seed) unset SEED;;
319 --release-test|-r) SEED=1;;
320 --seed|-s) shift; SEED="$1";;
321 -*)
322 echo >&2 "Unknown option: $1"
323 echo >&2 "Run $0 --help for usage."
324 exit 120
325 ;;
326 *)
327 COMPONENTS="$COMPONENTS $1";;
328 esac
329 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100330 done
331}
SimonB2e23c822016-04-16 21:54:39 +0100332
Gilles Peskine8f073122018-11-27 15:58:47 +0100333pre_check_git () {
334 if [ $FORCE -eq 1 ]; then
335 git checkout-index -f -q $CONFIG_H
336 cleanup
337 else
SimonB2e23c822016-04-16 21:54:39 +0100338
Gilles Peskine8f073122018-11-27 15:58:47 +0100339 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
340 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
341 echo "You can either delete this directory manually, or force the test by rerunning"
342 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
343 exit 1
344 fi
345
346 if ! git diff-files --quiet include/mbedtls/config.h; then
347 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
348 echo "You can either delete or preserve your work, or force the test by rerunning the"
349 echo "script as: $0 --force"
350 exit 1
351 fi
Andres AGdc192212016-08-31 17:33:13 +0100352 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100353}
Andres AGdc192212016-08-31 17:33:13 +0100354
Gilles Peskine8f073122018-11-27 15:58:47 +0100355pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100356 failure_summary=
357 failure_count=0
358 start_red=
359 end_color=
360 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100361 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100362 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
363 start_red=$(printf '\033[31m')
364 end_color=$(printf '\033[0m')
365 ;;
366 esac
367 fi
368 record_status () {
369 if "$@"; then
370 last_status=0
371 else
372 last_status=$?
373 text="$current_section: $* -> $last_status"
374 failure_summary="$failure_summary
375$text"
376 failure_count=$((failure_count + 1))
377 echo "${start_red}^^^^$text^^^^${end_color}"
378 fi
379 }
380 make () {
381 case "$*" in
382 *test|*check)
383 if [ $build_status -eq 0 ]; then
384 record_status command make "$@"
385 else
386 echo "(skipped because the build failed)"
387 fi
388 ;;
389 *)
390 record_status command make "$@"
391 build_status=$last_status
392 ;;
393 esac
394 }
395 final_report () {
396 if [ $failure_count -gt 0 ]; then
397 echo
398 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
399 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
400 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100401 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100402 elif [ -z "${1-}" ]; then
403 echo "SUCCESS :)"
404 fi
405 if [ -n "${1-}" ]; then
406 echo "Killed by SIG$1."
407 fi
408 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100409}
410
Gilles Peskine7c652162017-12-11 00:01:40 +0100411if_build_succeeded () {
412 if [ $build_status -eq 0 ]; then
413 record_status "$@"
414 fi
415}
416
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200417# to be used instead of ! for commands run with
418# record_status or if_build_succeeded
419not() {
420 ! "$@"
421}
422
Gilles Peskine8f073122018-11-27 15:58:47 +0100423pre_print_configuration () {
424 msg "info: $0 configuration"
425 echo "MEMORY: $MEMORY"
426 echo "FORCE: $FORCE"
427 echo "SEED: ${SEED-"UNSET"}"
428 echo "OPENSSL: $OPENSSL"
429 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
430 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
431 echo "GNUTLS_CLI: $GNUTLS_CLI"
432 echo "GNUTLS_SERV: $GNUTLS_SERV"
433 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
434 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
435 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
436 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
437}
Andres AG87bb5772016-09-27 15:05:15 +0100438
Gilles Peskine8f073122018-11-27 15:58:47 +0100439pre_check_tools () {
440 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
441 ARMC5_AR="$ARMC5_BIN_DIR/armar"
442 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
443 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100444
Gilles Peskine8f073122018-11-27 15:58:47 +0100445 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
446 # we just export the variables they require
447 export OPENSSL_CMD="$OPENSSL"
448 export GNUTLS_CLI="$GNUTLS_CLI"
449 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100450
Gilles Peskine8f073122018-11-27 15:58:47 +0100451 # Avoid passing --seed flag in every call to ssl-opt.sh
452 if [ -n "${SEED-}" ]; then
453 export SEED
454 fi
Andres AG7770ea82016-10-10 15:46:20 +0100455
Gilles Peskine8f073122018-11-27 15:58:47 +0100456 # Make sure the tools we need are available.
457 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
458 "$GNUTLS_CLI" "$GNUTLS_SERV" \
459 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
460 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
461 if [ $RUN_ARMCC -ne 0 ]; then
462 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
463 fi
464}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100465
466
467################################################################
468#### Basic checks
469################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100470
SimonB2e23c822016-04-16 21:54:39 +0100471#
472# Test Suites to be executed
473#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200474# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100475# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200476# and/or are more likely to fail than others (eg I use Clang most of the
477# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200478# 2. Minimize total running time, by avoiding useless rebuilds
479#
480# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100481
Gilles Peskine8f073122018-11-27 15:58:47 +0100482pre_print_tools () {
483 msg "info: output_env.sh"
484 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
485 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
486 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
487 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
488}
Janos Follathb72c6782016-07-19 14:54:17 +0100489
Gilles Peskine8f073122018-11-27 15:58:47 +0100490component_check_recursion () {
491 msg "test: recursion.pl" # < 1s
492 record_status tests/scripts/recursion.pl library/*.c
493}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100494
Gilles Peskine8f073122018-11-27 15:58:47 +0100495component_check_generated_files () {
496 msg "test: freshness of generated source files" # < 1s
497 record_status tests/scripts/check-generated-files.sh
498}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000499
Gilles Peskine8f073122018-11-27 15:58:47 +0100500component_check_doxy_blocks () {
501 msg "test: doxygen markup outside doxygen blocks" # < 1s
502 record_status tests/scripts/check-doxy-blocks.pl
503}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200504
Gilles Peskine8f073122018-11-27 15:58:47 +0100505component_check_files () {
506 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100507 record_status tests/scripts/check-files.py
508}
Darryl Greena07039c2018-03-13 16:48:16 +0000509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510component_check_names () {
511 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100512 record_status tests/scripts/check-names.sh
513}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200514
Gilles Peskine8f073122018-11-27 15:58:47 +0100515component_check_doxygen_warnings () {
516 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 record_status tests/scripts/doxygen.sh
518}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100519
Gilles Peskine192c72f2017-12-21 15:59:21 +0100520
521
522################################################################
523#### Build and test many configurations and targets
524################################################################
525
Gilles Peskine8f073122018-11-27 15:58:47 +0100526component_test_default_cmake_gcc_asan () {
527 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100528 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
529 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100530
Gilles Peskine8f073122018-11-27 15:58:47 +0100531 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
532 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200533
Gilles Peskine8f073122018-11-27 15:58:47 +0100534 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
535 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200536
Gilles Peskine8f073122018-11-27 15:58:47 +0100537 msg "test: compat.sh (ASan build)" # ~ 6 min
538 if_build_succeeded tests/compat.sh
539}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200540
Gilles Peskine782f4112018-11-27 16:11:09 +0100541component_test_ref_configs () {
542 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
543 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
544 record_status tests/scripts/test-ref-configs.pl
545}
546
Gilles Peskine8f073122018-11-27 15:58:47 +0100547component_test_sslv3 () {
548 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100549 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
550 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
551 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000552
Gilles Peskine8f073122018-11-27 15:58:47 +0100553 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
554 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000555
Gilles Peskine8f073122018-11-27 15:58:47 +0100556 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
557 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
558 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000559
Gilles Peskine8f073122018-11-27 15:58:47 +0100560 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
561 if_build_succeeded tests/ssl-opt.sh
562}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000563
Gilles Peskine8f073122018-11-27 15:58:47 +0100564component_test_no_renegotiation () {
565 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100566 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
567 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
568 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100569
Gilles Peskine8f073122018-11-27 15:58:47 +0100570 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
571 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100572
Gilles Peskine8f073122018-11-27 15:58:47 +0100573 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
574 if_build_succeeded tests/ssl-opt.sh
575}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577component_test_rsa_no_crt () {
578 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100579 scripts/config.pl set MBEDTLS_RSA_NO_CRT
580 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
581 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100582
Gilles Peskine8f073122018-11-27 15:58:47 +0100583 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
584 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100585
Gilles Peskine8f073122018-11-27 15:58:47 +0100586 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
587 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100588
Gilles Peskine8f073122018-11-27 15:58:47 +0100589 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
590 if_build_succeeded tests/compat.sh -t RSA
591}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100592
Gilles Peskine8f073122018-11-27 15:58:47 +0100593component_test_small_ssl_out_content_len () {
594 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100595 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
596 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
597 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
598 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000599
Gilles Peskine8f073122018-11-27 15:58:47 +0100600 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
601 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
602}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_test_small_ssl_in_content_len () {
605 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
607 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
608 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
609 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
612 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
613}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000614
Gilles Peskine8f073122018-11-27 15:58:47 +0100615component_test_small_ssl_dtls_max_buffering () {
616 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
618 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
619 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
622 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
623}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100624
Gilles Peskine8f073122018-11-27 15:58:47 +0100625component_test_small_mbedtls_ssl_dtls_max_buffering () {
626 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100627 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
628 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
629 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
632 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
633}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100634
Gilles Peskine8f073122018-11-27 15:58:47 +0100635component_test_full_cmake_clang () {
636 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100637 scripts/config.pl full
638 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
639 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
640 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642 msg "test: main suites (full config)" # ~ 5s
643 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200644
Gilles Peskine8f073122018-11-27 15:58:47 +0100645 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
646 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200647
Gilles Peskine8f073122018-11-27 15:58:47 +0100648 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
649 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 +0200650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651 msg "test: compat.sh ARIA + ChachaPoly"
652 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
653}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100654
Gilles Peskine8f073122018-11-27 15:58:47 +0100655component_build_deprecated () {
656 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100657 scripts/config.pl full
658 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
659 # Build with -O -Wextra to catch a maximum of issues.
660 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
661 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100662
Gilles Peskine8f073122018-11-27 15:58:47 +0100663 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
664 # No cleanup, just tweak the configuration and rebuild
665 make clean
666 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
667 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
668 # Build with -O -Wextra to catch a maximum of issues.
669 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
670 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
671}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100672
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674component_test_depends_curves () {
675 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100676 record_status tests/scripts/curves.pl
677}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200678
Gilles Peskine8f073122018-11-27 15:58:47 +0100679component_test_depends_hashes () {
680 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100681 record_status tests/scripts/depends-hashes.pl
682}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200683
Gilles Peskine8f073122018-11-27 15:58:47 +0100684component_test_depends_pkalgs () {
685 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100686 record_status tests/scripts/depends-pkalgs.pl
687}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200688
Gilles Peskine8f073122018-11-27 15:58:47 +0100689component_build_key_exchanges () {
690 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 record_status tests/scripts/key-exchanges.pl
692}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694component_build_default_make_gcc_and_cxx () {
695 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100696 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400697
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 msg "test: verify header list in cpp_dummy_build.cpp"
699 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400700
Gilles Peskine8f073122018-11-27 15:58:47 +0100701 msg "build: Unix make, incremental g++"
702 make TEST_CPP=1
703}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000704
Gilles Peskineb28636b2019-01-02 19:06:24 +0100705component_test_check_params_without_platform () {
706 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
707 scripts/config.pl full # includes CHECK_PARAMS
708 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
709 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
710 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
711 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
712 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
713 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
714 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
715 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
716 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
717 scripts/config.pl unset MBEDTLS_PLATFORM_C
718 make CC=gcc CFLAGS='-Werror -O1' all test
719}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200720
Gilles Peskineb28636b2019-01-02 19:06:24 +0100721component_test_check_params_silent () {
722 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
723 scripts/config.pl full # includes CHECK_PARAMS
724 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
725 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
726 make CC=gcc CFLAGS='-Werror -O1' all test
727}
Hanno Becker5175ac62017-09-18 15:36:25 +0100728
Gilles Peskine8f073122018-11-27 15:58:47 +0100729component_test_no_platform () {
730 # Full configuration build, without platform support, file IO and net sockets.
731 # This should catch missing mbedtls_printf definitions, and by disabling file
732 # IO, it should catch missing '#include <stdio.h>'
733 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 scripts/config.pl full
735 scripts/config.pl unset MBEDTLS_PLATFORM_C
736 scripts/config.pl unset MBEDTLS_NET_C
737 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
738 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
739 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
740 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
741 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
742 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
743 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
744 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
745 scripts/config.pl unset MBEDTLS_FS_IO
746 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
747 # to re-enable platform integration features otherwise disabled in C99 builds
748 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
749 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
750}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200751
Gilles Peskine8f073122018-11-27 15:58:47 +0100752component_build_no_std_function () {
753 # catch compile bugs in _uninit functions
754 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100755 scripts/config.pl full
756 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
757 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
758 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
759}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200760
Gilles Peskine8f073122018-11-27 15:58:47 +0100761component_build_no_ssl_srv () {
762 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100763 scripts/config.pl full
764 scripts/config.pl unset MBEDTLS_SSL_SRV_C
765 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
766}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768component_build_no_ssl_cli () {
769 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 scripts/config.pl full
771 scripts/config.pl unset MBEDTLS_SSL_CLI_C
772 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
773}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000774
Gilles Peskine8f073122018-11-27 15:58:47 +0100775component_build_no_sockets () {
776 # Note, C99 compliance can also be tested with the sockets support disabled,
777 # as that requires a POSIX platform (which isn't the same as C99).
778 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100779 scripts/config.pl full
780 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
781 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
782 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
783}
Hanno Becker5175ac62017-09-18 15:36:25 +0100784
Gilles Peskine8f073122018-11-27 15:58:47 +0100785component_test_no_max_fragment_length () {
786 # Run max fragment length tests with MFL disabled
787 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100788 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
789 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
790 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792 msg "test: ssl-opt.sh, MFL-related tests"
793 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
794}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000795
Gilles Peskine8f073122018-11-27 15:58:47 +0100796component_test_no_max_fragment_length_small_ssl_out_content_len () {
797 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100798 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
799 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
800 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
801 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
802 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000803
Gilles Peskine8f073122018-11-27 15:58:47 +0100804 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
805 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
806}
Janos Follath06c54002016-06-09 13:57:40 +0100807
Gilles Peskine8f073122018-11-27 15:58:47 +0100808component_test_null_entropy () {
809 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
811 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
812 scripts/config.pl set MBEDTLS_ENTROPY_C
813 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
814 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
815 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000816 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100817 make
Janos Follath06c54002016-06-09 13:57:40 +0100818
Gilles Peskine8f073122018-11-27 15:58:47 +0100819 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
820 make test
821}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100822
Gilles Peskine8f073122018-11-27 15:58:47 +0100823component_test_platform_calloc_macro () {
824 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100825 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
826 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
827 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
828 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
829 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100830
Gilles Peskine8f073122018-11-27 15:58:47 +0100831 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
832 make test
833}
Hanno Becker83ebf782017-07-07 12:29:15 +0100834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835component_test_aes_fewer_tables () {
836 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100837 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
838 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100839
Gilles Peskine8f073122018-11-27 15:58:47 +0100840 msg "test: AES_FEWER_TABLES"
841 make test
842}
Hanno Becker83ebf782017-07-07 12:29:15 +0100843
Gilles Peskine8f073122018-11-27 15:58:47 +0100844component_test_aes_rom_tables () {
845 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100846 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
847 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100848
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 msg "test: AES_ROM_TABLES"
850 make test
851}
Hanno Becker83ebf782017-07-07 12:29:15 +0100852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853component_test_aes_fewer_tables_and_rom_tables () {
854 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100855 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
856 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
857 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100858
Gilles Peskine8f073122018-11-27 15:58:47 +0100859 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
860 make test
861}
862
863component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100864 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100865 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100866}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200867
Gilles Peskine8f073122018-11-27 15:58:47 +0100868component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100869 # Build once with -O0, to compile out the i386 specific inline assembly
870 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100871 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100872 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100873
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100874 msg "test: i386, make, gcc -O0 (ASan build)"
875 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100876}
Gilles Peskine878cf602019-01-06 20:50:38 +0000877support_test_m32_o0 () {
878 case $(uname -m) in
879 *64*) true;;
880 *) false;;
881 esac
882}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100885 # Build again with -O1, to compile in the i386 specific inline assembly
886 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100887 scripts/config.pl full
888 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
889
890 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100891 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100892}
Gilles Peskine878cf602019-01-06 20:50:38 +0000893support_test_m32_o1 () {
894 support_test_m32_o0 "$@"
895}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100896
Gilles Peskine8f073122018-11-27 15:58:47 +0100897component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100898 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100899 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100900 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
901
902 msg "test: 64-bit ILP32, make, gcc"
903 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100904}
Gilles Peskine878cf602019-01-06 20:50:38 +0000905support_test_mx32 () {
906 case $(uname -m) in
907 amd64|x86_64) true;;
908 *) false;;
909 esac
910}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912component_test_have_int32 () {
913 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 scripts/config.pl unset MBEDTLS_HAVE_ASM
915 scripts/config.pl unset MBEDTLS_AESNI_C
916 scripts/config.pl unset MBEDTLS_PADLOCK_C
917 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100918
Gilles Peskine8f073122018-11-27 15:58:47 +0100919 msg "test: gcc, force 32-bit bignum limbs"
920 make test
921}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100922
Gilles Peskine8f073122018-11-27 15:58:47 +0100923component_test_have_int64 () {
924 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100925 scripts/config.pl unset MBEDTLS_HAVE_ASM
926 scripts/config.pl unset MBEDTLS_AESNI_C
927 scripts/config.pl unset MBEDTLS_PADLOCK_C
928 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100929
Gilles Peskine8f073122018-11-27 15:58:47 +0100930 msg "test: gcc, force 64-bit bignum limbs"
931 make test
932}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000933
Gilles Peskine8f073122018-11-27 15:58:47 +0100934component_test_no_udbl_division () {
935 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100936 scripts/config.pl full
937 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
938 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
939 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200940
Gilles Peskine8f073122018-11-27 15:58:47 +0100941 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
942 make test
943}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200944
Gilles Peskine8f073122018-11-27 15:58:47 +0100945component_test_no_64bit_multiplication () {
946 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100947 scripts/config.pl full
948 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
949 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
950 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200951
Gilles Peskine8f073122018-11-27 15:58:47 +0100952 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
953 make test
954}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200955
Gilles Peskine8f073122018-11-27 15:58:47 +0100956component_build_arm_none_eabi_gcc () {
957 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100958 scripts/config.pl full
959 scripts/config.pl unset MBEDTLS_NET_C
960 scripts/config.pl unset MBEDTLS_TIMING_C
961 scripts/config.pl unset MBEDTLS_FS_IO
962 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
963 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
964 # following things are not in the default config
965 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
966 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
967 scripts/config.pl unset MBEDTLS_THREADING_C
968 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
969 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
970 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
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_udbl_division () {
974 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100975 scripts/config.pl full
976 scripts/config.pl unset MBEDTLS_NET_C
977 scripts/config.pl unset MBEDTLS_TIMING_C
978 scripts/config.pl unset MBEDTLS_FS_IO
979 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
980 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
981 # following things are not in the default config
982 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
983 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
984 scripts/config.pl unset MBEDTLS_THREADING_C
985 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
986 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
987 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
988 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
989 echo "Checking that software 64-bit division is not required"
990 if_build_succeeded not grep __aeabi_uldiv library/*.o
991}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200992
Gilles Peskine8f073122018-11-27 15:58:47 +0100993component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
994 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100995 scripts/config.pl full
996 scripts/config.pl unset MBEDTLS_NET_C
997 scripts/config.pl unset MBEDTLS_TIMING_C
998 scripts/config.pl unset MBEDTLS_FS_IO
999 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1000 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1001 # following things are not in the default config
1002 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1003 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1004 scripts/config.pl unset MBEDTLS_THREADING_C
1005 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1006 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1007 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1008 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1009 echo "Checking that software 64-bit multiplication is not required"
1010 if_build_succeeded not grep __aeabi_lmul library/*.o
1011}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013component_build_armcc () {
1014 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001015 scripts/config.pl full
1016 scripts/config.pl unset MBEDTLS_NET_C
1017 scripts/config.pl unset MBEDTLS_TIMING_C
1018 scripts/config.pl unset MBEDTLS_FS_IO
1019 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1020 scripts/config.pl unset MBEDTLS_HAVE_TIME
1021 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1022 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1023 # following things are not in the default config
1024 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1025 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1026 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1027 scripts/config.pl unset MBEDTLS_THREADING_C
1028 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1029 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1030 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001031
Gilles Peskine8f073122018-11-27 15:58:47 +01001032 if [ $RUN_ARMCC -ne 0 ]; then
1033 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1034 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001035
Gilles Peskine8f073122018-11-27 15:58:47 +01001036 # ARM Compiler 6 - Target ARMv7-A
1037 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 # ARM Compiler 6 - Target ARMv7-M
1040 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001041
Gilles Peskine8f073122018-11-27 15:58:47 +01001042 # ARM Compiler 6 - Target ARMv8-A - AArch32
1043 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001044
Gilles Peskine8f073122018-11-27 15:58:47 +01001045 # ARM Compiler 6 - Target ARMv8-M
1046 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001047
Gilles Peskine8f073122018-11-27 15:58:47 +01001048 # ARM Compiler 6 - Target ARMv8-A - AArch64
1049 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1050 fi
1051}
Simon Butcher940737f2017-07-23 13:42:36 +02001052
Gilles Peskine8f073122018-11-27 15:58:47 +01001053component_test_allow_sha1 () {
1054 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001055 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1056 make CFLAGS='-Werror -Wall -Wextra'
1057 msg "test: allow SHA1 in certificates by default"
1058 make test
1059 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1060}
Simon Butcher940737f2017-07-23 13:42:36 +02001061
Gilles Peskine8f073122018-11-27 15:58:47 +01001062component_build_mingw () {
1063 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001064 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 +02001065
Gilles Peskine8f073122018-11-27 15:58:47 +01001066 # note Make tests only builds the tests, but doesn't run them
1067 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1068 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001069
Gilles Peskine8f073122018-11-27 15:58:47 +01001070 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1071 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
1072 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
1073 make WINDOWS_BUILD=1 clean
1074}
Simon Butcher002bc622016-11-17 09:27:45 +00001075
Gilles Peskine8f073122018-11-27 15:58:47 +01001076component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001077 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001078 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1079 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1080 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001081
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001082 msg "test: main suites (MSan)" # ~ 10s
1083 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001084
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001085 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001086 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001087
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001088 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001089
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001090 if [ "$MEMORY" -gt 0 ]; then
1091 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001092 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001093 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001094}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001095
Gilles Peskine8f073122018-11-27 15:58:47 +01001096component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001097 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001098 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1099 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001100
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001101 msg "test: main suites valgrind (Release)"
1102 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001103
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001104 # Optional part(s)
1105 # Currently broken, programs don't seem to receive signals
1106 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001107
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001108 if [ "$MEMORY" -gt 0 ]; then
1109 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001110 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001111 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001112
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001113 if [ "$MEMORY" -gt 1 ]; then
1114 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001115 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001116 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001117}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001118
Gilles Peskine8f073122018-11-27 15:58:47 +01001119component_test_cmake_out_of_source () {
1120 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 MBEDTLS_ROOT_DIR="$PWD"
1122 mkdir "$OUT_OF_SOURCE_DIR"
1123 cd "$OUT_OF_SOURCE_DIR"
1124 cmake "$MBEDTLS_ROOT_DIR"
1125 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001126
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 msg "test: cmake 'out-of-source' build"
1128 make test
1129 # Test an SSL option that requires an auxiliary script in test/scripts/.
1130 # Also ensure that there are no error messages such as
1131 # "No such file or directory", which would indicate that some required
1132 # file is missing (ssl-opt.sh tolerates the absence of some files so
1133 # may exit with status 0 but emit errors).
1134 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1135 if [ -s ssl-opt.err ]; then
1136 cat ssl-opt.err >&2
1137 record_status [ ! -s ssl-opt.err ]
1138 rm ssl-opt.err
1139 fi
1140 cd "$MBEDTLS_ROOT_DIR"
1141 rm -rf "$OUT_OF_SOURCE_DIR"
1142 unset MBEDTLS_ROOT_DIR
1143}
Andres AGdc192212016-08-31 17:33:13 +01001144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145component_test_zeroize () {
1146 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1147 # different combinations of compilers and optimization flags by using an
1148 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1149 # system in all cases that the script fails, so we must manually search the
1150 # output to check whether the pass string is present and no failure strings
1151 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001152
1153 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1154 # about a spurious message if Gdb tries and fails, so suppress that.
1155 gdb_disable_aslr=
1156 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1157 gdb_disable_aslr='set disable-randomization off'
1158 fi
1159
Gilles Peskine8f073122018-11-27 15:58:47 +01001160 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001161 for compiler in clang gcc; do
1162 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1163 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001164 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01001165 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1166 if_build_succeeded not grep -i "error" test_zeroize.log
1167 rm -f test_zeroize.log
1168 make clean
1169 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001170 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001171
1172 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001173}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001174
Gilles Peskine8f073122018-11-27 15:58:47 +01001175component_check_python_files () {
1176 msg "Lint: Python scripts"
1177 record_status tests/scripts/check-python-files.sh
1178}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001179
Gilles Peskine8f073122018-11-27 15:58:47 +01001180component_check_generate_test_code () {
1181 msg "uint test: generate_test_code.py"
1182 record_status ./tests/scripts/test_generate_test_code.py
1183}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001184
1185################################################################
1186#### Termination
1187################################################################
1188
Gilles Peskine8f073122018-11-27 15:58:47 +01001189post_report () {
1190 msg "Done, cleaning up"
1191 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001192
Gilles Peskine8f073122018-11-27 15:58:47 +01001193 final_report
1194}
1195
1196
1197
1198################################################################
1199#### Run all the things
1200################################################################
1201
Gilles Peskinee48351a2018-11-27 16:06:30 +01001202# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001203run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001204 # Back up the configuration in case the component modifies it.
1205 # The cleanup function will restore it.
1206 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001207 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001208 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001209 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001210}
1211
1212# Preliminary setup
1213pre_check_environment
1214pre_initialize_variables
1215pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001216
Gilles Peskine878cf602019-01-06 20:50:38 +00001217pre_check_git
1218build_status=0
1219if [ $KEEP_GOING -eq 1 ]; then
1220 pre_setup_keep_going
1221else
1222 record_status () {
1223 "$@"
1224 }
1225fi
1226pre_print_configuration
1227pre_check_tools
1228pre_print_tools
1229cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001230
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001231if [ -n "$COMPONENTS" ] && [ $ALL_EXCEPT -eq 0 ]; then
Gilles Peskine878cf602019-01-06 20:50:38 +00001232 # Run the components passed on the command line.
Gilles Peskine92525112018-11-27 18:15:35 +01001233 for component in $COMPONENTS; do
Gilles Peskine878cf602019-01-06 20:50:38 +00001234 run_component "component_$component"
Gilles Peskine92525112018-11-27 18:15:35 +01001235 done
1236else
Gilles Peskine878cf602019-01-06 20:50:38 +00001237 # Run all components except those excluded on the command line.
1238 for component in $SUPPORTED_COMPONENTS; do
1239 if ! is_component_excluded "$component"; then
1240 run_component "component_$component"
1241 fi
1242 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001243fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001244
1245# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001246post_report