blob: 2414f452a2f3462beecaaa6d0eeda57e1857a462 [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# See the invocation of check_tools below for details.
42#
43# This script must be invoked from the toplevel directory of a git
44# working copy of Mbed TLS.
45#
46# Note that the output is not saved. You may want to run
47# script -c tests/scripts/all.sh
48# or
49# tests/scripts/all.sh >all.log 2>&1
50#
51# Notes for maintainers
52# ---------------------
53#
Gilles Peskine8f073122018-11-27 15:58:47 +010054# The bulk of the code is organized into functions that follow one of the
55# following naming conventions:
56# * pre_XXX: things to do before running the tests, in order.
57# * component_XXX: independent components. They can be run in any order.
Gilles Peskine92bff7f2019-01-09 22:29:17 +010058# * component_check_XXX: quick tests that aren't worth parallelizing.
59# * component_build_XXX: build things but don't run them.
60# * component_test_XXX: build and test.
Gilles Peskine10726102019-01-06 20:50:38 +000061# * support_XXX: if support_XXX exists and returns false then
62# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010063# * post_XXX: things to do after running the tests.
64# * other: miscellaneous support functions.
65#
Gilles Peskine92bff7f2019-01-09 22:29:17 +010066# Each component must start by invoking `msg` with a short informative message.
67#
68# The framework performs some cleanup tasks after each component. This
69# means that components can assume that the working directory is in a
70# cleaned-up state, and don't need to perform the cleanup themselves.
71# * Run `make clean`.
72# * Restore `include/mbedtks/config.h` from a backup made before running
73# the component.
74# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
75# `tests/Makefile` from git. This cleans up after an in-tree use of
76# CMake.
77#
78# Any command that is expected to fail must be protected so that the
79# script keeps running in --keep-going mode despite `set -e`. In keep-going
80# mode, if a protected command fails, this is logged as a failure and the
81# script will exit with a failure status once it has run all components.
82# Commands can be protected in any of the following ways:
83# * `make` is a function which runs the `make` command with protection.
84# Note that you must write `make VAR=value`, not `VAR=value make`,
85# because the `VAR=value make` syntax doesn't work with functions.
86# * Put `report_status` before the command to protect it.
87# * Put `if_build_successful` before a command. This protects it, and
88# additionally skips it if a prior invocation of `make` in the same
89# component failed.
90#
Gilles Peskine192c72f2017-12-21 15:59:21 +010091# The tests are roughly in order from fastest to slowest. This doesn't
92# have to be exact, but in general you should add slower tests towards
93# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010094
95
96
97################################################################
98#### Initialization and command line parsing
99################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100100
SimonB2e23c822016-04-16 21:54:39 +0100101# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100102set -eu
103
Gilles Peskine8f073122018-11-27 15:58:47 +0100104pre_check_environment () {
Gilles Peskinebdf3f522019-01-06 19:58:02 +0000105 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100106 echo "Must be run from mbed TLS root" >&2
107 exit 1
108 fi
109}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100110
Gilles Peskine8f073122018-11-27 15:58:47 +0100111pre_initialize_variables () {
112 CONFIG_H='include/mbedtls/config.h'
113 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200114
Gilles Peskine8f073122018-11-27 15:58:47 +0100115 FORCE=0
116 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100117
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000118 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100119 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
120 : ${ARMC5_BIN_DIR:=/usr/bin}
121 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100122
Gilles Peskine8f073122018-11-27 15:58:47 +0100123 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine55ae1622019-01-06 20:15:26 +0000124 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 export MAKEFLAGS="-j"
126 fi
Gilles Peskine10726102019-01-06 20:50:38 +0000127
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000128 # Include more verbose output for failing tests run by CMake
129 export CTEST_OUTPUT_ON_FAILURE=1
130
Gilles Peskine004206c2019-10-21 17:11:33 +0200131 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskinebfeed662019-10-21 19:06:33 +0200132 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine004206c2019-10-21 17:11:33 +0200133
Gilles Peskine10726102019-01-06 20:50:38 +0000134 # Gather the list of available components. These are the functions
135 # defined in this script whose name starts with "component_".
136 # Parse the script with sed, because in sh there is no way to list
137 # defined functions.
138 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
139
140 # Exclude components that are not supported on this platform.
141 SUPPORTED_COMPONENTS=
142 for component in $ALL_COMPONENTS; do
143 case $(type "support_$component" 2>&1) in
144 *' function'*)
145 if ! support_$component; then continue; fi;;
146 esac
147 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
148 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100149}
Andres AG38495a32016-07-12 16:54:33 +0100150
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100151# Test whether the component $1 is included in the command line patterns.
152is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100153{
154 set -f
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000155 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100156 set +f
157 case ${1#component_} in $pattern) return 0;; esac
158 done
159 set +f
160 return 1
161}
162
Simon Butcher41eeccf2016-09-07 00:07:09 +0100163usage()
SimonB2e23c822016-04-16 21:54:39 +0100164{
Gilles Peskine709346a2017-12-10 23:43:39 +0100165 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100166Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100167Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100168By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100169COMPONENT can be the name of a component or a shell wildcard pattern.
170
171Examples:
172 $0 "check_*"
173 Run all sanity checks.
174 $0 --no-armcc --except test_memsan
175 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100176
177Special options:
178 -h|--help Print this help and exit.
Gilles Peskine10726102019-01-06 20:50:38 +0000179 --list-all-components List all available test components and exit.
180 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100181
182General options:
183 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100184 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100185 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100186 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100187 --except Exclude the COMPONENTs listed on the command line,
188 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100189 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100190 --no-force Refuse to overwrite modified files (default).
191 --no-keep-going Stop at the first error (default).
192 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100193 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100194 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100195 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
196 -s|--seed Integer seed value to use for this test run.
197
198Tool path options:
199 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
200 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gilles Peskine709346a2017-12-10 23:43:39 +0100201EOF
SimonB2e23c822016-04-16 21:54:39 +0100202}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100203
204# remove built files as well as the cmake cache/config
205cleanup()
206{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100207 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
208 cd "$MBEDTLS_ROOT_DIR"
209 fi
210
Gilles Peskine7c652162017-12-11 00:01:40 +0100211 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200212
Gilles Peskine31b07e22018-03-21 12:15:06 +0100213 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000214 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100215 -iname CMakeFiles -exec rm -rf {} \+ -o \
216 \( -iname cmake_install.cmake -o \
217 -iname CTestTestfile.cmake -o \
218 -iname CMakeCache.txt \) -exec rm {} \+
219 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000220 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200221 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
222 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200223
Jaeden Ameroe8451f22019-06-20 17:38:22 +0100224 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
225 rm -rf programs/test/cmake_subproject/build
226 rm -f programs/test/cmake_subproject/Makefile
227 rm -f programs/test/cmake_subproject/cmake_subproject
228
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100229 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
230 rm -rf programs/test/cmake_subproject/build
231 rm -f programs/test/cmake_subproject/Makefile
232 rm -f programs/test/cmake_subproject/cmake_subproject
233
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200234 if [ -f "$CONFIG_BAK" ]; then
235 mv "$CONFIG_BAK" "$CONFIG_H"
236 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100237}
238
Gilles Peskine7c652162017-12-11 00:01:40 +0100239# Executed on exit. May be redefined depending on command line options.
240final_report () {
241 :
242}
243
244fatal_signal () {
245 cleanup
246 final_report $1
247 trap - $1
248 kill -$1 $$
249}
250
251trap 'fatal_signal HUP' HUP
252trap 'fatal_signal INT' INT
253trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200254
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100255msg()
256{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100257 if [ -n "${current_component:-}" ]; then
258 current_section="${current_component#component_}: $1"
259 else
260 current_section="$1"
261 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100262 echo ""
263 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100264 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000265 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100266 echo "******************************************************************"
267}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100268
Gilles Peskine8f073122018-11-27 15:58:47 +0100269armc6_build_test()
270{
271 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100272
Gilles Peskine8f073122018-11-27 15:58:47 +0100273 msg "build: ARM Compiler 6 ($FLAGS), make"
274 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
275 WARNING_CFLAGS='-xc -std=c99' make lib
276 make clean
277}
Andres AGa5cd9732016-10-17 15:23:10 +0100278
Andres AGd9eba4b2016-08-26 14:42:14 +0100279err_msg()
280{
281 echo "$1" >&2
282}
283
284check_tools()
285{
286 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000287 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100288 err_msg "$TOOL not found!"
289 exit 1
290 fi
291 done
292}
293
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400294check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600295 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400296 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
297 sort |
298 diff headers.txt -
299 rm headers.txt
300}
301
Gilles Peskine8f073122018-11-27 15:58:47 +0100302pre_parse_command_line () {
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000303 COMMAND_LINE_COMPONENTS=
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100304 all_except=0
Gilles Peskinee26ab182019-01-06 22:23:42 +0000305 no_armcc=
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000306
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000307 # Note that legacy options are ignored instead of being omitted from this
308 # list of options, so invocations that worked with previous version of
309 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100310 while [ $# -gt 0 ]; do
Gilles Peskine06b385f2019-01-09 22:28:21 +0100311 case "$1" in
Gilles Peskinee26ab182019-01-06 22:23:42 +0000312 --armcc) no_armcc=;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100313 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
314 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000315 --except) all_except=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100316 --force|-f) FORCE=1;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000317 --gnutls-cli) shift;;
318 --gnutls-legacy-cli) shift;;
319 --gnutls-legacy-serv) shift;;
320 --gnutls-serv) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100321 --help|-h) usage; exit;;
322 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine10726102019-01-06 20:50:38 +0000323 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
324 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000325 --memory|-m) ;;
Gilles Peskinee26ab182019-01-06 22:23:42 +0000326 --no-armcc) no_armcc=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100327 --no-force) FORCE=0;;
328 --no-keep-going) KEEP_GOING=0;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000329 --no-memory) ;;
330 --openssl) shift;;
331 --openssl-legacy) shift;;
332 --openssl-next) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100333 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000334 --random-seed) ;;
335 --release-test|-r) ;;
336 --seed|-s) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100337 -*)
338 echo >&2 "Unknown option: $1"
339 echo >&2 "Run $0 --help for usage."
340 exit 120
341 ;;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000342 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100343 esac
344 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100345 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000346
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100347 # With no list of components, run everything.
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000348 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
349 all_except=1
350 fi
351
Gilles Peskinee26ab182019-01-06 22:23:42 +0000352 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
353 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100354 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskinee26ab182019-01-06 22:23:42 +0000355 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
356 fi
357
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000358 # Build the list of components to run.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100359 RUN_COMPONENTS=
360 for component in $SUPPORTED_COMPONENTS; do
361 if is_component_included "$component"; [ $? -eq $all_except ]; then
362 RUN_COMPONENTS="$RUN_COMPONENTS $component"
363 fi
364 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000365
366 unset all_except
Gilles Peskinee26ab182019-01-06 22:23:42 +0000367 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100368}
SimonB2e23c822016-04-16 21:54:39 +0100369
Gilles Peskine8f073122018-11-27 15:58:47 +0100370pre_check_git () {
371 if [ $FORCE -eq 1 ]; then
Gilles Peskined692e112019-01-09 23:17:35 +0100372 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100373 git checkout-index -f -q $CONFIG_H
374 cleanup
375 else
SimonB2e23c822016-04-16 21:54:39 +0100376
Gilles Peskine8f073122018-11-27 15:58:47 +0100377 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
378 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
379 echo "You can either delete this directory manually, or force the test by rerunning"
380 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
381 exit 1
382 fi
383
Gilles Peskineadd1d232019-01-09 22:30:01 +0100384 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100385 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
386 echo "You can either delete or preserve your work, or force the test by rerunning the"
387 echo "script as: $0 --force"
388 exit 1
389 fi
Andres AGdc192212016-08-31 17:33:13 +0100390 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100391}
Andres AGdc192212016-08-31 17:33:13 +0100392
Andrzej Kurekeb508712019-02-14 07:18:59 -0500393pre_check_seedfile () {
394 if [ ! -f "./tests/seedfile" ]; then
395 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
396 fi
397}
398
Gilles Peskine8f073122018-11-27 15:58:47 +0100399pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100400 failure_summary=
401 failure_count=0
402 start_red=
403 end_color=
404 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100405 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100406 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
407 start_red=$(printf '\033[31m')
408 end_color=$(printf '\033[0m')
409 ;;
410 esac
411 fi
412 record_status () {
413 if "$@"; then
414 last_status=0
415 else
416 last_status=$?
417 text="$current_section: $* -> $last_status"
418 failure_summary="$failure_summary
419$text"
420 failure_count=$((failure_count + 1))
421 echo "${start_red}^^^^$text^^^^${end_color}"
422 fi
423 }
424 make () {
425 case "$*" in
426 *test|*check)
427 if [ $build_status -eq 0 ]; then
428 record_status command make "$@"
429 else
430 echo "(skipped because the build failed)"
431 fi
432 ;;
433 *)
434 record_status command make "$@"
435 build_status=$last_status
436 ;;
437 esac
438 }
439 final_report () {
440 if [ $failure_count -gt 0 ]; then
441 echo
442 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
443 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
444 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100445 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100446 elif [ -z "${1-}" ]; then
447 echo "SUCCESS :)"
448 fi
449 if [ -n "${1-}" ]; then
450 echo "Killed by SIG$1."
451 fi
452 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100453}
454
Gilles Peskine7c652162017-12-11 00:01:40 +0100455if_build_succeeded () {
456 if [ $build_status -eq 0 ]; then
457 record_status "$@"
458 fi
459}
460
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200461# to be used instead of ! for commands run with
462# record_status or if_build_succeeded
463not() {
464 ! "$@"
465}
466
Gilles Peskine8f073122018-11-27 15:58:47 +0100467pre_print_configuration () {
468 msg "info: $0 configuration"
Gilles Peskine8f073122018-11-27 15:58:47 +0100469 echo "FORCE: $FORCE"
Gilles Peskine8f073122018-11-27 15:58:47 +0100470 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
471 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
472}
Andres AG87bb5772016-09-27 15:05:15 +0100473
Gilles Peskine657f59a2019-01-06 22:40:00 +0000474# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100475pre_check_tools () {
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000476 # Build the list of variables to pass to output_env.sh.
477 set env
478
Gilles Peskine657f59a2019-01-06 22:40:00 +0000479 case " $RUN_COMPONENTS " in
Gilles Peskine657f59a2019-01-06 22:40:00 +0000480 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
481 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100482
Gilles Peskine657f59a2019-01-06 22:40:00 +0000483 case " $RUN_COMPONENTS " in
484 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
485 esac
Andres AG7770ea82016-10-10 15:46:20 +0100486
Gilles Peskine657f59a2019-01-06 22:40:00 +0000487 case " $RUN_COMPONENTS " in
488 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
489 esac
490
491 case " $RUN_COMPONENTS " in
492 *" test_zeroize "*) check_tools "gdb";;
493 esac
494
495 case " $RUN_COMPONENTS " in
Gilles Peskinee26ab182019-01-06 22:23:42 +0000496 *_armcc*)
Gilles Peskine657f59a2019-01-06 22:40:00 +0000497 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
498 ARMC5_AR="$ARMC5_BIN_DIR/armar"
499 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
500 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee26ab182019-01-06 22:23:42 +0000501 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
502 esac
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000503
504 msg "info: output_env.sh"
505 case $RUN_COMPONENTS in
506 *_armcc*)
507 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
508 *) set "$@" RUN_ARMCC=0;;
509 esac
510 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100511}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100512
513
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000514
Gilles Peskine192c72f2017-12-21 15:59:21 +0100515################################################################
516#### Basic checks
517################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100518
SimonB2e23c822016-04-16 21:54:39 +0100519#
520# Test Suites to be executed
521#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200522# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100523# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200524# and/or are more likely to fail than others (eg I use Clang most of the
525# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200526# 2. Minimize total running time, by avoiding useless rebuilds
527#
528# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100529
Gilles Peskine8f073122018-11-27 15:58:47 +0100530component_check_recursion () {
531 msg "test: recursion.pl" # < 1s
532 record_status tests/scripts/recursion.pl library/*.c
533}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100534
Gilles Peskine8f073122018-11-27 15:58:47 +0100535component_check_generated_files () {
536 msg "test: freshness of generated source files" # < 1s
537 record_status tests/scripts/check-generated-files.sh
538}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000539
Gilles Peskine8f073122018-11-27 15:58:47 +0100540component_check_doxy_blocks () {
541 msg "test: doxygen markup outside doxygen blocks" # < 1s
542 record_status tests/scripts/check-doxy-blocks.pl
543}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200544
Gilles Peskine8f073122018-11-27 15:58:47 +0100545component_check_files () {
546 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100547 record_status tests/scripts/check-files.py
548}
Darryl Greena07039c2018-03-13 16:48:16 +0000549
Gilles Peskine8f073122018-11-27 15:58:47 +0100550component_check_names () {
551 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200552 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100553}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200554
Gilles Peskine8f073122018-11-27 15:58:47 +0100555component_check_doxygen_warnings () {
556 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100557 record_status tests/scripts/doxygen.sh
558}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100559
Gilles Peskine192c72f2017-12-21 15:59:21 +0100560
Gilles Peskine192c72f2017-12-21 15:59:21 +0100561################################################################
562#### Build and test many configurations and targets
563################################################################
564
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200565component_test_default_out_of_box () {
566 msg "build: make, default config (out-of-box)" # ~1min
567 make
568
569 msg "test: main suites make, default config (out-of-box)" # ~10s
570 make test
571
572 msg "selftest: make, default config (out-of-box)" # ~10s
573 programs/test/selftest
574}
575
Gilles Peskine8f073122018-11-27 15:58:47 +0100576component_test_default_cmake_gcc_asan () {
577 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100578 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
579 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100580
Gilles Peskine8f073122018-11-27 15:58:47 +0100581 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
582 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100583}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200584
Gilles Peskine782f4112018-11-27 16:11:09 +0100585component_test_ref_configs () {
586 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
587 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
588 record_status tests/scripts/test-ref-configs.pl
589}
590
Hanno Beckera545be22019-05-10 14:45:37 +0100591component_test_no_pem_no_fs () {
592 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
593 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
594 scripts/config.pl unset MBEDTLS_FS_IO
Jaeden Amero8dd16902019-07-22 16:39:49 +0100595 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
596 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
Hanno Beckera545be22019-05-10 14:45:37 +0100597 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
598 make
599
600 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
601 make test
Hanno Beckera545be22019-05-10 14:45:37 +0100602}
603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_test_rsa_no_crt () {
605 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 scripts/config.pl set MBEDTLS_RSA_NO_CRT
607 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
608 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100609
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
611 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100612}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100613
Gilles Peskinee023c802019-02-22 12:31:02 +0100614component_test_new_ecdh_context () {
615 msg "build: new ECDH context (ASan build)" # ~ 6 min
616 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
617 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
618 make
619
620 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
621 make test
Manuel Pégourié-Gonnard9fece7e2018-06-18 11:38:22 +0200622}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200623
Gilles Peskine09a24b32019-04-12 20:29:48 +0200624component_test_everest () {
625 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
626 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
627 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
628 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
629 make
630
631 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
632 make test
633}
634
Gilles Peskine75cc7712019-09-06 19:47:17 +0200635component_test_psa_collect_statuses () {
636 msg "build+test: psa_collect_statuses" # ~30s
637 scripts/config.pl full
638 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # slow and irrelevant
639 record_status tests/scripts/psa_collect_statuses.py
640 # Check that psa_crypto_init() succeeded at least once
641 record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
642 rm -f tests/statuses.log
643}
644
Gilles Peskine8f073122018-11-27 15:58:47 +0100645component_test_full_cmake_clang () {
646 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100647 scripts/config.pl full
648 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
649 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
650 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200651
k-stachowiak0291cb72019-06-26 15:52:12 +0200652 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +0100653 make test
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100654
k-stachowiak0291cb72019-06-26 15:52:12 +0200655 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Darryl Green45010a32019-02-06 13:43:58 +0000656 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100657}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100658
k-stachowiak5559b312019-06-27 11:28:11 +0200659component_test_full_make_gcc_o0 () {
660 msg "build: make, full config, gcc -O0" # ~ 50s
k-stachowiak0291cb72019-06-26 15:52:12 +0200661 scripts/config.pl full
662 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
k-stachowiak5559b312019-06-27 11:28:11 +0200663 make CC=gcc CFLAGS='-O0'
k-stachowiak0291cb72019-06-26 15:52:12 +0200664
k-stachowiak5559b312019-06-27 11:28:11 +0200665 msg "test: main suites (full config, gcc -O0)" # ~ 5s
k-stachowiak0291cb72019-06-26 15:52:12 +0200666 make test
667}
668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669component_build_deprecated () {
670 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100671 scripts/config.pl full
672 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
673 # Build with -O -Wextra to catch a maximum of issues.
674 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
675 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100676
Gilles Peskine8f073122018-11-27 15:58:47 +0100677 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
678 # No cleanup, just tweak the configuration and rebuild
679 make clean
680 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
681 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
682 # Build with -O -Wextra to catch a maximum of issues.
683 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
684 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
685}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100686
Gilles Peskine8f073122018-11-27 15:58:47 +0100687component_test_depends_curves () {
688 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 record_status tests/scripts/curves.pl
690}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200691
Gilles Peskine8f073122018-11-27 15:58:47 +0100692component_test_depends_hashes () {
693 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 record_status tests/scripts/depends-hashes.pl
695}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697component_test_depends_pkalgs () {
698 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100699 record_status tests/scripts/depends-pkalgs.pl
700}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702component_build_default_make_gcc_and_cxx () {
703 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100704 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400705
Gilles Peskine8f073122018-11-27 15:58:47 +0100706 msg "test: verify header list in cpp_dummy_build.cpp"
707 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400708
Gilles Peskine8f073122018-11-27 15:58:47 +0100709 msg "build: Unix make, incremental g++"
710 make TEST_CPP=1
711}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000712
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100713component_test_no_use_psa_crypto_full_cmake_asan() {
714 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500715 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
716 scripts/config.pl full
Unknownf094b532019-09-03 07:52:21 -0400717 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Jaeden Amero0f220ec2019-07-05 15:03:40 +0100718 scripts/config.pl set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500719 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100720 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
721 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400722 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Jaeden Amero67ea2c52019-02-11 12:05:54 +0000723 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500724 make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100725
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100726 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500727 make test
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500728}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500729
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200730component_test_check_params_functionality () {
731 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
732 scripts/config.pl full # includes CHECK_PARAMS
733 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
734 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
735 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
736 # Only build and run tests. Do not build sample programs, because
737 # they don't have a mbedtls_param_failed() function.
738 make CC=gcc CFLAGS='-Werror -O1' lib test
739}
740
Gilles Peskineb28636b2019-01-02 19:06:24 +0100741component_test_check_params_without_platform () {
742 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
743 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200744 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100745 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
746 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
747 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
748 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
749 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
750 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
751 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
752 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
753 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
754 scripts/config.pl unset MBEDTLS_PLATFORM_C
755 make CC=gcc CFLAGS='-Werror -O1' all test
756}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500757
Gilles Peskineb28636b2019-01-02 19:06:24 +0100758component_test_check_params_silent () {
759 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
760 scripts/config.pl full # includes CHECK_PARAMS
761 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200762 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100763 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
764 make CC=gcc CFLAGS='-Werror -O1' all test
765}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500766
Gilles Peskine8f073122018-11-27 15:58:47 +0100767component_test_no_platform () {
768 # Full configuration build, without platform support, file IO and net sockets.
769 # This should catch missing mbedtls_printf definitions, and by disabling file
770 # IO, it should catch missing '#include <stdio.h>'
771 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100772 scripts/config.pl full
773 scripts/config.pl unset MBEDTLS_PLATFORM_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
775 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
776 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
777 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
778 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
779 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
780 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
781 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
782 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinea8ade162019-06-26 11:24:49 +0200783 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine51585382019-01-05 10:27:47 +0100784 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskinee435f232019-02-24 14:03:29 +0100785 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100786 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
787 # to re-enable platform integration features otherwise disabled in C99 builds
788 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
789 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
790}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792component_build_no_std_function () {
793 # catch compile bugs in _uninit functions
794 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100795 scripts/config.pl full
796 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
797 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
798 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
799}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801component_test_null_entropy () {
802 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100803 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
804 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
805 scripts/config.pl set MBEDTLS_ENTROPY_C
806 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
807 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
808 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine19275652019-01-06 19:48:30 +0000809 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 make
Janos Follath06c54002016-06-09 13:57:40 +0100811
Gilles Peskine8f073122018-11-27 15:58:47 +0100812 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
813 make test
814}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816component_test_platform_calloc_macro () {
817 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
819 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
820 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
821 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
822 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
825 make test
826}
Hanno Becker83ebf782017-07-07 12:29:15 +0100827
Gilles Peskine31b0a3c2019-09-17 19:04:38 +0200828component_test_malloc_0_null () {
829 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
830 scripts/config.pl full
831 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Gilles Peskine004206c2019-10-21 17:11:33 +0200832 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine31b0a3c2019-09-17 19:04:38 +0200833
834 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
835 make test
836
837 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
838 # Just the calloc selftest. "make test" ran the others as part of the
839 # test suites.
840 if_build_succeeded programs/test/selftest calloc
841}
842
Gilles Peskine8f073122018-11-27 15:58:47 +0100843component_test_aes_fewer_tables () {
844 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100845 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
846 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100847
Gilles Peskine8f073122018-11-27 15:58:47 +0100848 msg "test: AES_FEWER_TABLES"
849 make test
850}
Hanno Becker83ebf782017-07-07 12:29:15 +0100851
Gilles Peskine8f073122018-11-27 15:58:47 +0100852component_test_aes_rom_tables () {
853 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100854 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
855 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100856
Gilles Peskine8f073122018-11-27 15:58:47 +0100857 msg "test: AES_ROM_TABLES"
858 make test
859}
Hanno Becker83ebf782017-07-07 12:29:15 +0100860
Gilles Peskine8f073122018-11-27 15:58:47 +0100861component_test_aes_fewer_tables_and_rom_tables () {
862 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100863 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
864 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
865 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100866
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
868 make test
869}
870
Gilles Peskinef96aefe2019-07-24 14:58:38 +0200871component_test_se_default () {
872 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
873 scripts/config.pl set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +0200874 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +0200875
876 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
877 make test
878}
879
880component_test_se_full () {
881 msg "build: full config + MBEDTLS_PSA_CRYPTO_SE_C"
882 scripts/config.pl set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +0200883 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +0200884
885 msg "test: full config + MBEDTLS_PSA_CRYPTO_SE_C"
886 make test
887}
888
Gilles Peskine8f073122018-11-27 15:58:47 +0100889component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100890 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -0400891 make SHARED=1 all check -j1
Gilles Peskine56c01612019-07-03 20:43:32 +0200892 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +0100893}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200894
Gilles Peskinecf740502019-07-03 20:43:05 +0200895component_test_cmake_shared () {
896 msg "build/test: cmake shared" # ~ 2min
897 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
898 make
Gilles Peskine56c01612019-07-03 20:43:32 +0200899 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +0200900 make test
901}
902
Gilles Peskineabf9b4d2019-07-03 20:42:16 +0200903component_build_mbedtls_config_file () {
904 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
905 # Use the full config so as to catch a maximum of places where
906 # the check of MBEDTLS_CONFIG_FILE might be missing.
907 scripts/config.pl full
908 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
909 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
910 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
911 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000912}
913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100915 # Build once with -O0, to compile out the i386 specific inline assembly
916 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100917 scripts/config.pl full
Gilles Peskine004206c2019-10-21 17:11:33 +0200918 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100919
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100920 msg "test: i386, make, gcc -O0 (ASan build)"
921 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100922}
Gilles Peskine10726102019-01-06 20:50:38 +0000923support_test_m32_o0 () {
924 case $(uname -m) in
925 *64*) true;;
926 *) false;;
927 esac
928}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100929
Gilles Peskine8f073122018-11-27 15:58:47 +0100930component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100931 # Build again with -O1, to compile in the i386 specific inline assembly
932 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100933 scripts/config.pl full
Gilles Peskine4b317612019-04-08 16:58:02 +0200934 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
935 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
936 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
Gilles Peskine004206c2019-10-21 17:11:33 +0200937 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100938
939 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100940 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100941}
Gilles Peskine10726102019-01-06 20:50:38 +0000942support_test_m32_o1 () {
943 support_test_m32_o0 "$@"
944}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100945
Gilles Peskine09a24b32019-04-12 20:29:48 +0200946component_test_m32_everest () {
947 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
948 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
949 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine004206c2019-10-21 17:11:33 +0200950 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine09a24b32019-04-12 20:29:48 +0200951
952 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
953 make test
954}
955support_test_m32_everest () {
956 support_test_m32_o0 "$@"
957}
958
Gilles Peskine8f073122018-11-27 15:58:47 +0100959component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100960 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100961 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +0200962 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100963
964 msg "test: 64-bit ILP32, make, gcc"
965 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100966}
Gilles Peskine10726102019-01-06 20:50:38 +0000967support_test_mx32 () {
968 case $(uname -m) in
969 amd64|x86_64) true;;
970 *) false;;
971 esac
972}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000973
Peter Kolbus60c6da22018-12-27 06:59:04 -0600974component_test_min_mpi_window_size () {
975 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
976 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
977 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
978 make
979
980 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
981 make test
982}
983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984component_test_have_int32 () {
985 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100986 scripts/config.pl unset MBEDTLS_HAVE_ASM
987 scripts/config.pl unset MBEDTLS_AESNI_C
988 scripts/config.pl unset MBEDTLS_PADLOCK_C
989 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 msg "test: gcc, force 32-bit bignum limbs"
992 make test
993}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100994
Gilles Peskine8f073122018-11-27 15:58:47 +0100995component_test_have_int64 () {
996 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100997 scripts/config.pl unset MBEDTLS_HAVE_ASM
998 scripts/config.pl unset MBEDTLS_AESNI_C
999 scripts/config.pl unset MBEDTLS_PADLOCK_C
1000 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001001
Gilles Peskine8f073122018-11-27 15:58:47 +01001002 msg "test: gcc, force 64-bit bignum limbs"
1003 make test
1004}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001005
Gilles Peskine8f073122018-11-27 15:58:47 +01001006component_test_no_udbl_division () {
1007 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001008 scripts/config.pl full
1009 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1010 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1011 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1014 make test
1015}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017component_test_no_64bit_multiplication () {
1018 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 scripts/config.pl full
1020 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1021 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1022 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001023
Gilles Peskine8f073122018-11-27 15:58:47 +01001024 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1025 make test
1026}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001027
Gilles Peskine8f073122018-11-27 15:58:47 +01001028component_build_arm_none_eabi_gcc () {
1029 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001030 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001031 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1032}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001033
Gilles Peskine2c897d72019-08-09 16:05:05 +02001034component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001035 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine93e4e032019-08-05 11:34:25 +02001036 scripts/config.pl baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001037 # Build for a target platform that's close to what Debian uses
1038 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1039 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1040 # It would be better to build with arm-linux-gnueabi-gcc but
1041 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001042 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine93e4e032019-08-05 11:34:25 +02001043}
1044
Gilles Peskine8f073122018-11-27 15:58:47 +01001045component_build_arm_none_eabi_gcc_no_udbl_division () {
1046 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001047 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001048 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1049 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1050 echo "Checking that software 64-bit division is not required"
1051 if_build_succeeded not grep __aeabi_uldiv library/*.o
1052}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1055 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001056 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001057 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1058 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1059 echo "Checking that software 64-bit multiplication is not required"
1060 if_build_succeeded not grep __aeabi_lmul library/*.o
1061}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001062
Gilles Peskine8f073122018-11-27 15:58:47 +01001063component_build_armcc () {
1064 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001065 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001066
Gilles Peskinee26ab182019-01-06 22:23:42 +00001067 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1068 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001069
Gilles Peskinee26ab182019-01-06 22:23:42 +00001070 # ARM Compiler 6 - Target ARMv7-A
1071 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001072
Gilles Peskinee26ab182019-01-06 22:23:42 +00001073 # ARM Compiler 6 - Target ARMv7-M
1074 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001075
Gilles Peskinee26ab182019-01-06 22:23:42 +00001076 # ARM Compiler 6 - Target ARMv8-A - AArch32
1077 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001078
Gilles Peskinee26ab182019-01-06 22:23:42 +00001079 # ARM Compiler 6 - Target ARMv8-M
1080 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001081
Gilles Peskinee26ab182019-01-06 22:23:42 +00001082 # ARM Compiler 6 - Target ARMv8-A - AArch64
1083 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001084}
Simon Butcher940737f2017-07-23 13:42:36 +02001085
Gilles Peskine8f073122018-11-27 15:58:47 +01001086component_build_mingw () {
1087 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001088 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 -j1
Gilles Peskine2a458da2017-05-12 15:26:58 +02001089
Gilles Peskine8f073122018-11-27 15:58:47 +01001090 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001091 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001093
Gilles Peskine8f073122018-11-27 15:58:47 +01001094 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001095 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 -j1
1096 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 -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001097 make WINDOWS_BUILD=1 clean
1098}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001099support_build_mingw() {
1100 case $(i686-w64-mingw32-gcc -dumpversion) in
1101 [0-5]*) false;;
1102 *) true;;
1103 esac
1104}
Simon Butcher002bc622016-11-17 09:27:45 +00001105
Gilles Peskine8f073122018-11-27 15:58:47 +01001106component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001107 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001108 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1109 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1110 make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001111
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001112 msg "test: main suites (MSan)" # ~ 10s
1113 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001114}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001115
Gilles Peskinee8789872019-01-10 00:11:42 +01001116component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001117 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001118 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1119 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001120
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001121 msg "test: main suites valgrind (Release)"
1122 make memcheck
Gilles Peskine8f073122018-11-27 15:58:47 +01001123}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001124
Gilles Peskine8f073122018-11-27 15:58:47 +01001125component_test_cmake_out_of_source () {
1126 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 MBEDTLS_ROOT_DIR="$PWD"
1128 mkdir "$OUT_OF_SOURCE_DIR"
1129 cd "$OUT_OF_SOURCE_DIR"
1130 cmake "$MBEDTLS_ROOT_DIR"
1131 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133 msg "test: cmake 'out-of-source' build"
1134 make test
Jaeden Amero9b90f2e2018-11-02 18:34:17 +00001135
Gilles Peskine8f073122018-11-27 15:58:47 +01001136 cd "$MBEDTLS_ROOT_DIR"
1137 rm -rf "$OUT_OF_SOURCE_DIR"
1138 unset MBEDTLS_ROOT_DIR
1139}
Andres AGdc192212016-08-31 17:33:13 +01001140
Jaeden Ameroe8451f22019-06-20 17:38:22 +01001141component_test_cmake_as_subdirectory () {
1142 msg "build: cmake 'as-subdirectory' build"
1143 MBEDTLS_ROOT_DIR="$PWD"
1144
1145 cd programs/test/cmake_subproject
1146 cmake .
1147 make
1148 if_build_succeeded ./cmake_subproject
1149
1150 cd "$MBEDTLS_ROOT_DIR"
1151 unset MBEDTLS_ROOT_DIR
1152}
1153
Gilles Peskine8f073122018-11-27 15:58:47 +01001154component_test_zeroize () {
1155 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1156 # different combinations of compilers and optimization flags by using an
1157 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1158 # system in all cases that the script fails, so we must manually search the
1159 # output to check whether the pass string is present and no failure strings
1160 # were printed.
Gilles Peskine74851d82019-01-06 19:52:22 +00001161
1162 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1163 # about a spurious message if Gdb tries and fails, so suppress that.
1164 gdb_disable_aslr=
1165 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1166 gdb_disable_aslr='set disable-randomization off'
1167 fi
1168
Gilles Peskine8f073122018-11-27 15:58:47 +01001169 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine06b385f2019-01-09 22:28:21 +01001170 for compiler in clang gcc; do
1171 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1172 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine74851d82019-01-06 19:52:22 +00001173 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine06b385f2019-01-09 22:28:21 +01001174 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1175 if_build_succeeded not grep -i "error" test_zeroize.log
1176 rm -f test_zeroize.log
1177 make clean
1178 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001179 done
Gilles Peskine74851d82019-01-06 19:52:22 +00001180
1181 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001182}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001183
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001184support_check_python_files () {
1185 type pylint3 >/dev/null 2>/dev/null
1186}
Gilles Peskine8f073122018-11-27 15:58:47 +01001187component_check_python_files () {
1188 msg "Lint: Python scripts"
1189 record_status tests/scripts/check-python-files.sh
1190}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001191
Gilles Peskine8f073122018-11-27 15:58:47 +01001192component_check_generate_test_code () {
1193 msg "uint test: generate_test_code.py"
1194 record_status ./tests/scripts/test_generate_test_code.py
1195}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001196
1197################################################################
1198#### Termination
1199################################################################
1200
Gilles Peskine8f073122018-11-27 15:58:47 +01001201post_report () {
1202 msg "Done, cleaning up"
1203 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001204
Gilles Peskine8f073122018-11-27 15:58:47 +01001205 final_report
1206}
1207
1208
1209
1210################################################################
1211#### Run all the things
1212################################################################
1213
Gilles Peskinee48351a2018-11-27 16:06:30 +01001214# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001215run_component () {
Gilles Peskine8ae15dd2019-01-02 18:57:02 +01001216 # Back up the configuration in case the component modifies it.
1217 # The cleanup function will restore it.
1218 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001219 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001220 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001221 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001222}
1223
1224# Preliminary setup
1225pre_check_environment
1226pre_initialize_variables
1227pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001228
Gilles Peskine10726102019-01-06 20:50:38 +00001229pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001230pre_check_seedfile
1231
Gilles Peskine10726102019-01-06 20:50:38 +00001232build_status=0
1233if [ $KEEP_GOING -eq 1 ]; then
1234 pre_setup_keep_going
1235else
1236 record_status () {
1237 "$@"
1238 }
1239fi
1240pre_print_configuration
1241pre_check_tools
Gilles Peskine10726102019-01-06 20:50:38 +00001242cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001243
Gilles Peskine1bcb1c82019-01-06 22:11:25 +00001244# Run the requested tests.
1245for component in $RUN_COMPONENTS; do
1246 run_component "component_$component"
1247done
Gilles Peskine8f073122018-11-27 15:58:47 +01001248
1249# We're done.
Gilles Peskine10726102019-01-06 20:50:38 +00001250post_report