blob: 9a4788979a995dd1a71b0d0bccb7c2c5419553be [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 Peskine67ffdaf2019-09-16 15:55:46 +0200115 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100116 FORCE=0
117 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200119 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200120 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200121 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200122 export MBEDTLS_TEST_PLATFORM
123
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000124 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
126 : ${ARMC5_BIN_DIR:=/usr/bin}
127 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100128
Gilles Peskine8f073122018-11-27 15:58:47 +0100129 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine55ae1622019-01-06 20:15:26 +0000130 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100131 export MAKEFLAGS="-j"
132 fi
Gilles Peskine10726102019-01-06 20:50:38 +0000133
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000134 # Include more verbose output for failing tests run by CMake
135 export CTEST_OUTPUT_ON_FAILURE=1
136
Gilles Peskine004206c2019-10-21 17:11:33 +0200137 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskinebfeed662019-10-21 19:06:33 +0200138 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine004206c2019-10-21 17:11:33 +0200139
Gilles Peskine10726102019-01-06 20:50:38 +0000140 # Gather the list of available components. These are the functions
141 # defined in this script whose name starts with "component_".
142 # Parse the script with sed, because in sh there is no way to list
143 # defined functions.
144 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
145
146 # Exclude components that are not supported on this platform.
147 SUPPORTED_COMPONENTS=
148 for component in $ALL_COMPONENTS; do
149 case $(type "support_$component" 2>&1) in
150 *' function'*)
151 if ! support_$component; then continue; fi;;
152 esac
153 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
154 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100155}
Andres AG38495a32016-07-12 16:54:33 +0100156
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100157# Test whether the component $1 is included in the command line patterns.
158is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100159{
160 set -f
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000161 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162 set +f
163 case ${1#component_} in $pattern) return 0;; esac
164 done
165 set +f
166 return 1
167}
168
Simon Butcher41eeccf2016-09-07 00:07:09 +0100169usage()
SimonB2e23c822016-04-16 21:54:39 +0100170{
Gilles Peskine709346a2017-12-10 23:43:39 +0100171 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100172Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100173Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100174By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100175COMPONENT can be the name of a component or a shell wildcard pattern.
176
177Examples:
178 $0 "check_*"
179 Run all sanity checks.
180 $0 --no-armcc --except test_memsan
181 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100182
183Special options:
184 -h|--help Print this help and exit.
Gilles Peskine10726102019-01-06 20:50:38 +0000185 --list-all-components List all available test components and exit.
186 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100187
188General options:
189 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100190 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200192 --append-outcome Append to the outcome file (if used).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100193 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100194 --except Exclude the COMPONENTs listed on the command line,
195 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200196 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100197 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100198 --no-force Refuse to overwrite modified files (default).
199 --no-keep-going Stop at the first error (default).
200 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100201 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200202 --outcome-file=<path> File where test outcomes are written (not done if
203 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100204 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100205 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
206 -s|--seed Integer seed value to use for this test run.
207
208Tool path options:
209 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
210 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gilles Peskine709346a2017-12-10 23:43:39 +0100211EOF
SimonB2e23c822016-04-16 21:54:39 +0100212}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100213
214# remove built files as well as the cmake cache/config
215cleanup()
216{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100217 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
218 cd "$MBEDTLS_ROOT_DIR"
219 fi
220
Gilles Peskine7c652162017-12-11 00:01:40 +0100221 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200222
Gilles Peskine31b07e22018-03-21 12:15:06 +0100223 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000224 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100225 -iname CMakeFiles -exec rm -rf {} \+ -o \
226 \( -iname cmake_install.cmake -o \
227 -iname CTestTestfile.cmake -o \
228 -iname CMakeCache.txt \) -exec rm {} \+
229 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000230 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200231 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
232 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200233
Jaeden Ameroe8451f22019-06-20 17:38:22 +0100234 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
235 rm -rf programs/test/cmake_subproject/build
236 rm -f programs/test/cmake_subproject/Makefile
237 rm -f programs/test/cmake_subproject/cmake_subproject
238
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100239 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
240 rm -rf programs/test/cmake_subproject/build
241 rm -f programs/test/cmake_subproject/Makefile
242 rm -f programs/test/cmake_subproject/cmake_subproject
243
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200244 if [ -f "$CONFIG_BAK" ]; then
245 mv "$CONFIG_BAK" "$CONFIG_H"
246 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100247}
248
Gilles Peskine7c652162017-12-11 00:01:40 +0100249# Executed on exit. May be redefined depending on command line options.
250final_report () {
251 :
252}
253
254fatal_signal () {
255 cleanup
256 final_report $1
257 trap - $1
258 kill -$1 $$
259}
260
261trap 'fatal_signal HUP' HUP
262trap 'fatal_signal INT' INT
263trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200264
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100265msg()
266{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100267 if [ -n "${current_component:-}" ]; then
268 current_section="${current_component#component_}: $1"
269 else
270 current_section="$1"
271 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100272 echo ""
273 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100274 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000275 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100276 echo "******************************************************************"
277}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100278
Gilles Peskine8f073122018-11-27 15:58:47 +0100279armc6_build_test()
280{
281 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100282
Gilles Peskine8f073122018-11-27 15:58:47 +0100283 msg "build: ARM Compiler 6 ($FLAGS), make"
284 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
285 WARNING_CFLAGS='-xc -std=c99' make lib
286 make clean
287}
Andres AGa5cd9732016-10-17 15:23:10 +0100288
Andres AGd9eba4b2016-08-26 14:42:14 +0100289err_msg()
290{
291 echo "$1" >&2
292}
293
294check_tools()
295{
296 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000297 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100298 err_msg "$TOOL not found!"
299 exit 1
300 fi
301 done
302}
303
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400304check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600305 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400306 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
307 sort |
308 diff headers.txt -
309 rm headers.txt
310}
311
Gilles Peskine8f073122018-11-27 15:58:47 +0100312pre_parse_command_line () {
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000313 COMMAND_LINE_COMPONENTS=
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100314 all_except=0
Gilles Peskinee26ab182019-01-06 22:23:42 +0000315 no_armcc=
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000316
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000317 # Note that legacy options are ignored instead of being omitted from this
318 # list of options, so invocations that worked with previous version of
319 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100320 while [ $# -gt 0 ]; do
Gilles Peskine06b385f2019-01-09 22:28:21 +0100321 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200322 --append-outcome) append_outcome=1;;
Gilles Peskinee26ab182019-01-06 22:23:42 +0000323 --armcc) no_armcc=;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100324 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
325 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000326 --except) all_except=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100327 --force|-f) FORCE=1;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000328 --gnutls-cli) shift;;
329 --gnutls-legacy-cli) shift;;
330 --gnutls-legacy-serv) shift;;
331 --gnutls-serv) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100332 --help|-h) usage; exit;;
333 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine10726102019-01-06 20:50:38 +0000334 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
335 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000336 --memory|-m) ;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200337 --no-append-outcome) append_outcome=0;;
Gilles Peskinee26ab182019-01-06 22:23:42 +0000338 --no-armcc) no_armcc=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100339 --no-force) FORCE=0;;
340 --no-keep-going) KEEP_GOING=0;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000341 --no-memory) ;;
342 --openssl) shift;;
343 --openssl-legacy) shift;;
344 --openssl-next) shift;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200345 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100346 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000347 --random-seed) ;;
348 --release-test|-r) ;;
349 --seed|-s) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100350 -*)
351 echo >&2 "Unknown option: $1"
352 echo >&2 "Run $0 --help for usage."
353 exit 120
354 ;;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000355 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100356 esac
357 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100358 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000359
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100360 # With no list of components, run everything.
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000361 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
362 all_except=1
363 fi
364
Gilles Peskinee26ab182019-01-06 22:23:42 +0000365 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
366 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100367 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskinee26ab182019-01-06 22:23:42 +0000368 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
369 fi
370
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000371 # Build the list of components to run.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100372 RUN_COMPONENTS=
373 for component in $SUPPORTED_COMPONENTS; do
374 if is_component_included "$component"; [ $? -eq $all_except ]; then
375 RUN_COMPONENTS="$RUN_COMPONENTS $component"
376 fi
377 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000378
379 unset all_except
Gilles Peskinee26ab182019-01-06 22:23:42 +0000380 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100381}
SimonB2e23c822016-04-16 21:54:39 +0100382
Gilles Peskine8f073122018-11-27 15:58:47 +0100383pre_check_git () {
384 if [ $FORCE -eq 1 ]; then
Gilles Peskined692e112019-01-09 23:17:35 +0100385 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100386 git checkout-index -f -q $CONFIG_H
387 cleanup
388 else
SimonB2e23c822016-04-16 21:54:39 +0100389
Gilles Peskine8f073122018-11-27 15:58:47 +0100390 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
391 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
392 echo "You can either delete this directory manually, or force the test by rerunning"
393 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
394 exit 1
395 fi
396
Gilles Peskineadd1d232019-01-09 22:30:01 +0100397 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100398 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
399 echo "You can either delete or preserve your work, or force the test by rerunning the"
400 echo "script as: $0 --force"
401 exit 1
402 fi
Andres AGdc192212016-08-31 17:33:13 +0100403 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100404}
Andres AGdc192212016-08-31 17:33:13 +0100405
Gilles Peskine8f073122018-11-27 15:58:47 +0100406pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100407 failure_summary=
408 failure_count=0
409 start_red=
410 end_color=
411 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100412 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100413 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
414 start_red=$(printf '\033[31m')
415 end_color=$(printf '\033[0m')
416 ;;
417 esac
418 fi
419 record_status () {
420 if "$@"; then
421 last_status=0
422 else
423 last_status=$?
424 text="$current_section: $* -> $last_status"
425 failure_summary="$failure_summary
426$text"
427 failure_count=$((failure_count + 1))
428 echo "${start_red}^^^^$text^^^^${end_color}"
429 fi
430 }
431 make () {
432 case "$*" in
433 *test|*check)
434 if [ $build_status -eq 0 ]; then
435 record_status command make "$@"
436 else
437 echo "(skipped because the build failed)"
438 fi
439 ;;
440 *)
441 record_status command make "$@"
442 build_status=$last_status
443 ;;
444 esac
445 }
446 final_report () {
447 if [ $failure_count -gt 0 ]; then
448 echo
449 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
450 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
451 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100452 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100453 elif [ -z "${1-}" ]; then
454 echo "SUCCESS :)"
455 fi
456 if [ -n "${1-}" ]; then
457 echo "Killed by SIG$1."
458 fi
459 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100460}
461
Gilles Peskine7c652162017-12-11 00:01:40 +0100462if_build_succeeded () {
463 if [ $build_status -eq 0 ]; then
464 record_status "$@"
465 fi
466}
467
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200468# to be used instead of ! for commands run with
469# record_status or if_build_succeeded
470not() {
471 ! "$@"
472}
473
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200474pre_prepare_outcome_file () {
475 case "$MBEDTLS_TEST_OUTCOME_FILE" in
476 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
477 esac
478 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
479 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
480 fi
481}
482
Gilles Peskine8f073122018-11-27 15:58:47 +0100483pre_print_configuration () {
484 msg "info: $0 configuration"
Gilles Peskine8f073122018-11-27 15:58:47 +0100485 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200486 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100487 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
488 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
489}
Andres AG87bb5772016-09-27 15:05:15 +0100490
Gilles Peskine657f59a2019-01-06 22:40:00 +0000491# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100492pre_check_tools () {
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000493 # Build the list of variables to pass to output_env.sh.
494 set env
495
Gilles Peskine657f59a2019-01-06 22:40:00 +0000496 case " $RUN_COMPONENTS " in
Gilles Peskine657f59a2019-01-06 22:40:00 +0000497 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
498 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100499
Gilles Peskine657f59a2019-01-06 22:40:00 +0000500 case " $RUN_COMPONENTS " in
501 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
502 esac
Andres AG7770ea82016-10-10 15:46:20 +0100503
Gilles Peskine657f59a2019-01-06 22:40:00 +0000504 case " $RUN_COMPONENTS " in
505 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
506 esac
507
508 case " $RUN_COMPONENTS " in
509 *" test_zeroize "*) check_tools "gdb";;
510 esac
511
512 case " $RUN_COMPONENTS " in
Gilles Peskinee26ab182019-01-06 22:23:42 +0000513 *_armcc*)
Gilles Peskine657f59a2019-01-06 22:40:00 +0000514 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
515 ARMC5_AR="$ARMC5_BIN_DIR/armar"
516 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
517 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee26ab182019-01-06 22:23:42 +0000518 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
519 esac
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000520
521 msg "info: output_env.sh"
522 case $RUN_COMPONENTS in
523 *_armcc*)
524 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
525 *) set "$@" RUN_ARMCC=0;;
526 esac
527 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100528}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100529
530
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000531
Gilles Peskine192c72f2017-12-21 15:59:21 +0100532################################################################
533#### Basic checks
534################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100535
SimonB2e23c822016-04-16 21:54:39 +0100536#
537# Test Suites to be executed
538#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200539# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100540# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200541# and/or are more likely to fail than others (eg I use Clang most of the
542# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200543# 2. Minimize total running time, by avoiding useless rebuilds
544#
545# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100546
Gilles Peskine8f073122018-11-27 15:58:47 +0100547component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200548 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100549 record_status tests/scripts/recursion.pl library/*.c
550}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100551
Gilles Peskine8f073122018-11-27 15:58:47 +0100552component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200553 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100554 record_status tests/scripts/check-generated-files.sh
555}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000556
Gilles Peskine8f073122018-11-27 15:58:47 +0100557component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200558 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100559 record_status tests/scripts/check-doxy-blocks.pl
560}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200561
Gilles Peskine8f073122018-11-27 15:58:47 +0100562component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200563 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100564 record_status tests/scripts/check-files.py
565}
Darryl Greena07039c2018-03-13 16:48:16 +0000566
Gilles Peskine8f073122018-11-27 15:58:47 +0100567component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200568 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200569 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100570}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200571
Gilles Peskine895868b2019-09-19 21:30:05 +0200572component_check_test_cases () {
573 msg "Check: test case descriptions" # < 1s
574 record_status tests/scripts/check-test-cases.py
575}
576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200578 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100579 record_status tests/scripts/doxygen.sh
580}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100581
Gilles Peskine192c72f2017-12-21 15:59:21 +0100582
Gilles Peskine192c72f2017-12-21 15:59:21 +0100583################################################################
584#### Build and test many configurations and targets
585################################################################
586
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200587component_test_default_out_of_box () {
588 msg "build: make, default config (out-of-box)" # ~1min
589 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200590 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200591 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200592 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200593
594 msg "test: main suites make, default config (out-of-box)" # ~10s
595 make test
596
597 msg "selftest: make, default config (out-of-box)" # ~10s
598 programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200599
600 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
601 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200602}
603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_test_default_cmake_gcc_asan () {
605 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
607 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
610 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100611}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200612
Hanno Becker01635512019-02-26 14:27:09 +0000613component_test_full_cmake_gcc_asan () {
614 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200615 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000616 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
617 make
618
619 msg "test: main suites (inc. selftests) (full config, ASan build)"
620 make test
Hanno Becker01635512019-02-26 14:27:09 +0000621}
622
Gilles Peskine782f4112018-11-27 16:11:09 +0100623component_test_ref_configs () {
624 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
625 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
626 record_status tests/scripts/test-ref-configs.pl
627}
628
Hanno Beckera545be22019-05-10 14:45:37 +0100629component_test_no_pem_no_fs () {
630 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200631 scripts/config.py unset MBEDTLS_PEM_PARSE_C
632 scripts/config.py unset MBEDTLS_FS_IO
633 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
634 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
Hanno Beckera545be22019-05-10 14:45:37 +0100635 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
636 make
637
638 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
639 make test
Hanno Beckera545be22019-05-10 14:45:37 +0100640}
641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642component_test_rsa_no_crt () {
643 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200644 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100645 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
646 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100647
Gilles Peskine8f073122018-11-27 15:58:47 +0100648 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
649 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100650}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100651
Gilles Peskinee023c802019-02-22 12:31:02 +0100652component_test_new_ecdh_context () {
653 msg "build: new ECDH context (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200654 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
Gilles Peskinee023c802019-02-22 12:31:02 +0100655 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
656 make
657
658 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
659 make test
Manuel Pégourié-Gonnard9fece7e2018-06-18 11:38:22 +0200660}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200661
Gilles Peskine09a24b32019-04-12 20:29:48 +0200662component_test_everest () {
663 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200664 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
665 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine09a24b32019-04-12 20:29:48 +0200666 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
667 make
668
669 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
670 make test
671}
672
Gilles Peskine75cc7712019-09-06 19:47:17 +0200673component_test_psa_collect_statuses () {
674 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200675 scripts/config.py full
Gilles Peskine75cc7712019-09-06 19:47:17 +0200676 record_status tests/scripts/psa_collect_statuses.py
677 # Check that psa_crypto_init() succeeded at least once
678 record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
679 rm -f tests/statuses.log
680}
681
Gilles Peskine8f073122018-11-27 15:58:47 +0100682component_test_full_cmake_clang () {
683 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200684 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +0100685 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
686 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200687
k-stachowiak0291cb72019-06-26 15:52:12 +0200688 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 make test
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100690
k-stachowiak0291cb72019-06-26 15:52:12 +0200691 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Darryl Green45010a32019-02-06 13:43:58 +0000692 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100693}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100694
k-stachowiak5559b312019-06-27 11:28:11 +0200695component_test_full_make_gcc_o0 () {
696 msg "build: make, full config, gcc -O0" # ~ 50s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200697 scripts/config.py full
k-stachowiak5559b312019-06-27 11:28:11 +0200698 make CC=gcc CFLAGS='-O0'
k-stachowiak0291cb72019-06-26 15:52:12 +0200699
k-stachowiak5559b312019-06-27 11:28:11 +0200700 msg "test: main suites (full config, gcc -O0)" # ~ 5s
k-stachowiak0291cb72019-06-26 15:52:12 +0200701 make test
702}
703
Gilles Peskine8f073122018-11-27 15:58:47 +0100704component_build_deprecated () {
705 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200706 scripts/config.py full
707 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 # Build with -O -Wextra to catch a maximum of issues.
709 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
710 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100711
Gilles Peskine841b14b2019-11-26 17:37:37 +0100712 msg "test: make, full config + DEPRECATED_WARNING, expect warnings" # ~ 30s
713 make -C tests clean
714 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -DMBEDTLS_TEST_DEPRECATED' tests
715
Gilles Peskine8f073122018-11-27 15:58:47 +0100716 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
717 # No cleanup, just tweak the configuration and rebuild
718 make clean
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200719 scripts/config.py unset MBEDTLS_DEPRECATED_WARNING
720 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine8f073122018-11-27 15:58:47 +0100721 # Build with -O -Wextra to catch a maximum of issues.
722 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
723 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
724}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100725
Gilles Peskine8f073122018-11-27 15:58:47 +0100726component_test_depends_curves () {
727 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100728 record_status tests/scripts/curves.pl
729}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731component_test_depends_hashes () {
732 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 record_status tests/scripts/depends-hashes.pl
734}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736component_test_depends_pkalgs () {
737 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 record_status tests/scripts/depends-pkalgs.pl
739}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200740
Gilles Peskine8f073122018-11-27 15:58:47 +0100741component_build_default_make_gcc_and_cxx () {
742 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100743 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400744
Gilles Peskine8f073122018-11-27 15:58:47 +0100745 msg "test: verify header list in cpp_dummy_build.cpp"
746 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400747
Gilles Peskine8f073122018-11-27 15:58:47 +0100748 msg "build: Unix make, incremental g++"
749 make TEST_CPP=1
750}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000751
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100752component_test_no_use_psa_crypto_full_cmake_asan() {
753 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200754 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200755 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200756 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
757 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
758 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
759 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
760 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Jaeden Amero67ea2c52019-02-11 12:05:54 +0000761 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500762 make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100763
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100764 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500765 make test
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500766}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500767
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200768component_test_check_params_functionality () {
769 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200770 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200771 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200772 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200773 # Only build and run tests. Do not build sample programs, because
774 # they don't have a mbedtls_param_failed() function.
775 make CC=gcc CFLAGS='-Werror -O1' lib test
776}
777
Gilles Peskineb28636b2019-01-02 19:06:24 +0100778component_test_check_params_without_platform () {
779 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200780 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200781 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200782 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
783 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
784 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
785 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
786 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
787 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
788 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
789 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +0100790 make CC=gcc CFLAGS='-Werror -O1' all test
791}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500792
Gilles Peskineb28636b2019-01-02 19:06:24 +0100793component_test_check_params_silent () {
794 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200795 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200796 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100797 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
798 make CC=gcc CFLAGS='-Werror -O1' all test
799}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801component_test_no_platform () {
802 # Full configuration build, without platform support, file IO and net sockets.
803 # This should catch missing mbedtls_printf definitions, and by disabling file
804 # IO, it should catch missing '#include <stdio.h>'
805 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200806 scripts/config.py full
807 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskine4e117492020-02-26 18:56:08 +0100808 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200809 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
810 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
811 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
812 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
813 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
814 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
815 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200816 scripts/config.py unset MBEDTLS_FS_IO
817 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
818 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
819 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100820 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
821 # to re-enable platform integration features otherwise disabled in C99 builds
822 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
823 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
824}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826component_build_no_std_function () {
827 # catch compile bugs in _uninit functions
828 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200829 scripts/config.py full
830 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
831 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100832 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
833}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200834
Gilles Peskine26e4fdc2020-03-02 21:15:04 +0100835component_test_memory_buffer_allocator_backtrace () {
836 msg "build: default config with memory buffer allocator and backtrace enabled"
837 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
838 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
839 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
840 scripts/config.py set MBEDTLS_MEMORY_DEBUG
841 CC=gcc cmake .
842 make
843
844 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
845 make test
846}
847
848component_test_memory_buffer_allocator () {
849 msg "build: default config with memory buffer allocator"
850 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
851 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
852 CC=gcc cmake .
853 make
854
855 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
856 make test
857}
858
Gilles Peskine8f073122018-11-27 15:58:47 +0100859component_test_null_entropy () {
860 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200861 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
862 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
863 scripts/config.py set MBEDTLS_ENTROPY_C
864 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
865 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
866 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine19275652019-01-06 19:48:30 +0000867 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100868 make
Janos Follath06c54002016-06-09 13:57:40 +0100869
Gilles Peskine8f073122018-11-27 15:58:47 +0100870 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
871 make test
872}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100873
Gilles Peskine8f073122018-11-27 15:58:47 +0100874component_test_platform_calloc_macro () {
875 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200876 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
877 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
878 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +0100879 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
880 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100881
Gilles Peskine8f073122018-11-27 15:58:47 +0100882 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
883 make test
884}
Hanno Becker83ebf782017-07-07 12:29:15 +0100885
Gilles Peskine31b0a3c2019-09-17 19:04:38 +0200886component_test_malloc_0_null () {
887 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200888 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +0200889 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 +0200890
891 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
892 make test
893
894 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
895 # Just the calloc selftest. "make test" ran the others as part of the
896 # test suites.
897 if_build_succeeded programs/test/selftest calloc
898}
899
Gilles Peskine8f073122018-11-27 15:58:47 +0100900component_test_aes_fewer_tables () {
901 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200902 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +0100903 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100904
Gilles Peskine8f073122018-11-27 15:58:47 +0100905 msg "test: AES_FEWER_TABLES"
906 make test
907}
Hanno Becker83ebf782017-07-07 12:29:15 +0100908
Gilles Peskine8f073122018-11-27 15:58:47 +0100909component_test_aes_rom_tables () {
910 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200911 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +0100912 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 msg "test: AES_ROM_TABLES"
915 make test
916}
Hanno Becker83ebf782017-07-07 12:29:15 +0100917
Gilles Peskine8f073122018-11-27 15:58:47 +0100918component_test_aes_fewer_tables_and_rom_tables () {
919 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200920 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
921 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +0100922 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100923
Gilles Peskine8f073122018-11-27 15:58:47 +0100924 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
925 make test
926}
927
Gilles Peskine592f5912019-10-07 18:49:32 +0200928component_test_ctr_drbg_aes_256_sha_256 () {
929 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
930 scripts/config.pl full
931 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
932 scripts/config.pl set MBEDTLS_ENTROPY_FORCE_SHA256
933 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
934 make
935
936 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
937 make test
938}
939
940component_test_ctr_drbg_aes_128_sha_512 () {
941 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
942 scripts/config.pl full
943 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
944 scripts/config.pl set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
945 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
946 make
947
948 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
949 make test
950}
951
952component_test_ctr_drbg_aes_128_sha_256 () {
953 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
954 scripts/config.pl full
955 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
956 scripts/config.pl set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
957 scripts/config.pl set MBEDTLS_ENTROPY_FORCE_SHA256
958 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
959 make
960
961 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
962 make test
963}
964
Gilles Peskinef96aefe2019-07-24 14:58:38 +0200965component_test_se_default () {
966 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200967 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +0200968 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +0200969
970 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
971 make test
972}
973
974component_test_se_full () {
975 msg "build: full config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200976 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200977 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +0200978 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +0200979
980 msg "test: full config + MBEDTLS_PSA_CRYPTO_SE_C"
981 make test
982}
983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100985 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -0400986 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +0200987 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +0100988}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200989
Gilles Peskinecf740502019-07-03 20:43:05 +0200990component_test_cmake_shared () {
991 msg "build/test: cmake shared" # ~ 2min
992 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
993 make
Gilles Peskine56c01612019-07-03 20:43:32 +0200994 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +0200995 make test
996}
997
Gilles Peskineabf9b4d2019-07-03 20:42:16 +0200998component_build_mbedtls_config_file () {
999 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1000 # Use the full config so as to catch a maximum of places where
1001 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001002 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001003 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1004 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1005 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1006 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001007}
1008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001010 # Build once with -O0, to compile out the i386 specific inline assembly
1011 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001012 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001013 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001014
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001015 msg "test: i386, make, gcc -O0 (ASan build)"
1016 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001017}
Gilles Peskine10726102019-01-06 20:50:38 +00001018support_test_m32_o0 () {
1019 case $(uname -m) in
1020 *64*) true;;
1021 *) false;;
1022 esac
1023}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001026 # Build again with -O1, to compile in the i386 specific inline assembly
1027 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001028 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001029 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001030
1031 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001032 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001033}
Gilles Peskine10726102019-01-06 20:50:38 +00001034support_test_m32_o1 () {
1035 support_test_m32_o0 "$@"
1036}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001037
Gilles Peskine09a24b32019-04-12 20:29:48 +02001038component_test_m32_everest () {
1039 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001040 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1041 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine004206c2019-10-21 17:11:33 +02001042 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine09a24b32019-04-12 20:29:48 +02001043
1044 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1045 make test
1046}
1047support_test_m32_everest () {
1048 support_test_m32_o0 "$@"
1049}
1050
Gilles Peskine8f073122018-11-27 15:58:47 +01001051component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001052 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001053 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001054 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001055
1056 msg "test: 64-bit ILP32, make, gcc"
1057 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001058}
Gilles Peskine10726102019-01-06 20:50:38 +00001059support_test_mx32 () {
1060 case $(uname -m) in
1061 amd64|x86_64) true;;
1062 *) false;;
1063 esac
1064}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001065
Peter Kolbus60c6da22018-12-27 06:59:04 -06001066component_test_min_mpi_window_size () {
1067 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001068 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06001069 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1070 make
1071
1072 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1073 make test
1074}
1075
Gilles Peskine8f073122018-11-27 15:58:47 +01001076component_test_have_int32 () {
1077 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001078 scripts/config.py unset MBEDTLS_HAVE_ASM
1079 scripts/config.py unset MBEDTLS_AESNI_C
1080 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001081 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 msg "test: gcc, force 32-bit bignum limbs"
1084 make test
1085}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001086
Gilles Peskine8f073122018-11-27 15:58:47 +01001087component_test_have_int64 () {
1088 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001089 scripts/config.py unset MBEDTLS_HAVE_ASM
1090 scripts/config.py unset MBEDTLS_AESNI_C
1091 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001093
Gilles Peskine8f073122018-11-27 15:58:47 +01001094 msg "test: gcc, force 64-bit bignum limbs"
1095 make test
1096}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001097
Gilles Peskine8f073122018-11-27 15:58:47 +01001098component_test_no_udbl_division () {
1099 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001100 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001101 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001102 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001103
Gilles Peskine8f073122018-11-27 15:58:47 +01001104 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1105 make test
1106}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001107
Gilles Peskine8f073122018-11-27 15:58:47 +01001108component_test_no_64bit_multiplication () {
1109 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001110 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001111 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001112 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001113
Gilles Peskine8f073122018-11-27 15:58:47 +01001114 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1115 make test
1116}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001117
Gilles Peskine8f073122018-11-27 15:58:47 +01001118component_build_arm_none_eabi_gcc () {
1119 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001120 scripts/config.py baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1122}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001123
Gilles Peskine2c897d72019-08-09 16:05:05 +02001124component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001125 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001126 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001127 # Build for a target platform that's close to what Debian uses
1128 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1129 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1130 # It would be better to build with arm-linux-gnueabi-gcc but
1131 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001132 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 +02001133}
1134
Gilles Peskine8f073122018-11-27 15:58:47 +01001135component_build_arm_none_eabi_gcc_no_udbl_division () {
1136 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001137 scripts/config.py baremetal
1138 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001139 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1140 echo "Checking that software 64-bit division is not required"
1141 if_build_succeeded not grep __aeabi_uldiv library/*.o
1142}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001143
Gilles Peskine8f073122018-11-27 15:58:47 +01001144component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1145 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001146 scripts/config.py baremetal
1147 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001148 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1149 echo "Checking that software 64-bit multiplication is not required"
1150 if_build_succeeded not grep __aeabi_lmul library/*.o
1151}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001152
Gilles Peskine8f073122018-11-27 15:58:47 +01001153component_build_armcc () {
1154 msg "build: ARM Compiler 5, make"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001155 scripts/config.py baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001156
Gilles Peskinee26ab182019-01-06 22:23:42 +00001157 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1158 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001159
Gilles Peskinee26ab182019-01-06 22:23:42 +00001160 # ARM Compiler 6 - Target ARMv7-A
1161 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001162
Gilles Peskinee26ab182019-01-06 22:23:42 +00001163 # ARM Compiler 6 - Target ARMv7-M
1164 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001165
Gilles Peskinee26ab182019-01-06 22:23:42 +00001166 # ARM Compiler 6 - Target ARMv8-A - AArch32
1167 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001168
Gilles Peskinee26ab182019-01-06 22:23:42 +00001169 # ARM Compiler 6 - Target ARMv8-M
1170 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001171
Gilles Peskinee26ab182019-01-06 22:23:42 +00001172 # ARM Compiler 6 - Target ARMv8-A - AArch64
1173 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001174}
Simon Butcher940737f2017-07-23 13:42:36 +02001175
Gilles Peskine8f073122018-11-27 15:58:47 +01001176component_build_mingw () {
1177 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001178 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 +02001179
Gilles Peskine8f073122018-11-27 15:58:47 +01001180 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001181 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01001182 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001183
Gilles Peskine8f073122018-11-27 15:58:47 +01001184 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001185 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
1186 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
Gilles Peskine8f073122018-11-27 15:58:47 +01001187 make WINDOWS_BUILD=1 clean
1188}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001189support_build_mingw() {
1190 case $(i686-w64-mingw32-gcc -dumpversion) in
1191 [0-5]*) false;;
1192 *) true;;
1193 esac
1194}
Simon Butcher002bc622016-11-17 09:27:45 +00001195
Gilles Peskine8f073122018-11-27 15:58:47 +01001196component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001197 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001198 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001199 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1200 make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001201
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001202 msg "test: main suites (MSan)" # ~ 10s
1203 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001204}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001205
Gilles Peskinee8789872019-01-10 00:11:42 +01001206component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001207 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001208 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1209 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001210
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001211 msg "test: main suites valgrind (Release)"
1212 make memcheck
Gilles Peskine8f073122018-11-27 15:58:47 +01001213}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001214
Gilles Peskine8f073122018-11-27 15:58:47 +01001215component_test_cmake_out_of_source () {
1216 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001217 MBEDTLS_ROOT_DIR="$PWD"
1218 mkdir "$OUT_OF_SOURCE_DIR"
1219 cd "$OUT_OF_SOURCE_DIR"
1220 cmake "$MBEDTLS_ROOT_DIR"
1221 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001222
Gilles Peskine8f073122018-11-27 15:58:47 +01001223 msg "test: cmake 'out-of-source' build"
1224 make test
Jaeden Amero9b90f2e2018-11-02 18:34:17 +00001225
Gilles Peskine8f073122018-11-27 15:58:47 +01001226 cd "$MBEDTLS_ROOT_DIR"
1227 rm -rf "$OUT_OF_SOURCE_DIR"
1228 unset MBEDTLS_ROOT_DIR
1229}
Andres AGdc192212016-08-31 17:33:13 +01001230
Jaeden Ameroe8451f22019-06-20 17:38:22 +01001231component_test_cmake_as_subdirectory () {
1232 msg "build: cmake 'as-subdirectory' build"
1233 MBEDTLS_ROOT_DIR="$PWD"
1234
1235 cd programs/test/cmake_subproject
1236 cmake .
1237 make
1238 if_build_succeeded ./cmake_subproject
1239
1240 cd "$MBEDTLS_ROOT_DIR"
1241 unset MBEDTLS_ROOT_DIR
1242}
1243
Gilles Peskine8f073122018-11-27 15:58:47 +01001244component_test_zeroize () {
1245 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1246 # different combinations of compilers and optimization flags by using an
1247 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1248 # system in all cases that the script fails, so we must manually search the
1249 # output to check whether the pass string is present and no failure strings
1250 # were printed.
Gilles Peskine74851d82019-01-06 19:52:22 +00001251
1252 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1253 # about a spurious message if Gdb tries and fails, so suppress that.
1254 gdb_disable_aslr=
1255 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1256 gdb_disable_aslr='set disable-randomization off'
1257 fi
1258
Gilles Peskine8f073122018-11-27 15:58:47 +01001259 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine06b385f2019-01-09 22:28:21 +01001260 for compiler in clang gcc; do
1261 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1262 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine74851d82019-01-06 19:52:22 +00001263 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 +01001264 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1265 if_build_succeeded not grep -i "error" test_zeroize.log
1266 rm -f test_zeroize.log
1267 make clean
1268 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001269 done
Gilles Peskine74851d82019-01-06 19:52:22 +00001270
1271 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001272}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001273
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001274support_check_python_files () {
1275 type pylint3 >/dev/null 2>/dev/null
1276}
Gilles Peskine8f073122018-11-27 15:58:47 +01001277component_check_python_files () {
1278 msg "Lint: Python scripts"
1279 record_status tests/scripts/check-python-files.sh
1280}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001281
Gilles Peskine8f073122018-11-27 15:58:47 +01001282component_check_generate_test_code () {
1283 msg "uint test: generate_test_code.py"
1284 record_status ./tests/scripts/test_generate_test_code.py
1285}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001286
1287################################################################
1288#### Termination
1289################################################################
1290
Gilles Peskine8f073122018-11-27 15:58:47 +01001291post_report () {
1292 msg "Done, cleaning up"
1293 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001294
Gilles Peskine8f073122018-11-27 15:58:47 +01001295 final_report
1296}
1297
1298
1299
1300################################################################
1301#### Run all the things
1302################################################################
1303
Gilles Peskinee48351a2018-11-27 16:06:30 +01001304# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001305run_component () {
Gilles Peskine8ae15dd2019-01-02 18:57:02 +01001306 # Back up the configuration in case the component modifies it.
1307 # The cleanup function will restore it.
1308 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001309 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001310 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001311
1312 # Unconditionally create a seedfile that's sufficiently long.
1313 # Do this before each component, because a previous component may
1314 # have messed it up or shortened it.
1315 dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
1316
1317 # Run the component code.
Gilles Peskine8f073122018-11-27 15:58:47 +01001318 "$@"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001319
1320 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01001321 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001322}
1323
1324# Preliminary setup
1325pre_check_environment
1326pre_initialize_variables
1327pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001328
Gilles Peskine10726102019-01-06 20:50:38 +00001329pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001330
Gilles Peskine10726102019-01-06 20:50:38 +00001331build_status=0
1332if [ $KEEP_GOING -eq 1 ]; then
1333 pre_setup_keep_going
1334else
1335 record_status () {
1336 "$@"
1337 }
1338fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001339pre_prepare_outcome_file
Gilles Peskine10726102019-01-06 20:50:38 +00001340pre_print_configuration
1341pre_check_tools
Gilles Peskine10726102019-01-06 20:50:38 +00001342cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001343
Gilles Peskine1bcb1c82019-01-06 22:11:25 +00001344# Run the requested tests.
1345for component in $RUN_COMPONENTS; do
1346 run_component "component_$component"
1347done
Gilles Peskine8f073122018-11-27 15:58:47 +01001348
1349# We're done.
Gilles Peskine10726102019-01-06 20:50:38 +00001350post_report