blob: 67af9cb1a446104a41f16f78ba056033b8a8599e [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#
Gilles Peskine192c72f2017-12-21 15:59:21 +01005# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
Bence Szépkúti09b4f192020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# This file is part of Mbed TLS (https://tls.mbed.org)
Gilles Peskine192c72f2017-12-21 15:59:21 +010021
22
23
24################################################################
25#### Documentation
26################################################################
27
Simon Butcher3ea7f522016-03-07 23:22:10 +000028# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000030#
SimonB2e23c822016-04-16 21:54:39 +010031# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010032#
Gilles Peskine192c72f2017-12-21 15:59:21 +010033# Notes for users
34# ---------------
35#
SimonB2e23c822016-04-16 21:54:39 +010036# Warning: the test is destructive. It includes various build modes and
37# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010038# configuration. The following files must be committed into git:
39# * include/mbedtls/config.h
40# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
41# After running this script, the CMake cache will be lost and CMake
42# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010043#
Gilles Peskine192c72f2017-12-21 15:59:21 +010044# The script assumes the presence of a number of tools:
45# * Basic Unix tools (Windows users note: a Unix-style find must be before
46# the Windows find in the PATH)
47# * Perl
48# * GNU Make
49# * CMake
50# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
51# * arm-gcc and mingw-gcc
52# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
53# * Yotta build dependencies, unless invoked with --no-yotta
54# * OpenSSL and GnuTLS command line tools, recent enough for the
55# interoperability tests. If they don't support SSLv3 then a legacy
56# version of these tools must be present as well (search for LEGACY
57# below).
58# See the invocation of check_tools below for details.
59#
60# This script must be invoked from the toplevel directory of a git
61# working copy of Mbed TLS.
62#
63# Note that the output is not saved. You may want to run
64# script -c tests/scripts/all.sh
65# or
66# tests/scripts/all.sh >all.log 2>&1
67#
68# Notes for maintainers
69# ---------------------
70#
Gilles Peskine2906a0a2019-01-09 22:29:17 +010071# The bulk of the code is organized into functions that follow one of the
72# following naming conventions:
73# * pre_XXX: things to do before running the tests, in order.
74# * component_XXX: independent components. They can be run in any order.
75# * component_check_XXX: quick tests that aren't worth parallelizing.
76# * component_build_XXX: build things but don't run them.
77# * component_test_XXX: build and test.
78# * support_XXX: if support_XXX exists and returns false then
79# component_XXX is not run by default.
80# * post_XXX: things to do after running the tests.
81# * other: miscellaneous support functions.
82#
83# Each component must start by invoking `msg` with a short informative message.
84#
85# The framework performs some cleanup tasks after each component. This
86# means that components can assume that the working directory is in a
87# cleaned-up state, and don't need to perform the cleanup themselves.
88# * Run `make clean`.
89# * Restore `include/mbedtks/config.h` from a backup made before running
90# the component.
91# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
92# `tests/Makefile` from git. This cleans up after an in-tree use of
93# CMake.
94#
95# Any command that is expected to fail must be protected so that the
96# script keeps running in --keep-going mode despite `set -e`. In keep-going
97# mode, if a protected command fails, this is logged as a failure and the
98# script will exit with a failure status once it has run all components.
99# Commands can be protected in any of the following ways:
100# * `make` is a function which runs the `make` command with protection.
101# Note that you must write `make VAR=value`, not `VAR=value make`,
102# because the `VAR=value make` syntax doesn't work with functions.
103# * Put `report_status` before the command to protect it.
104# * Put `if_build_successful` before a command. This protects it, and
105# additionally skips it if a prior invocation of `make` in the same
106# component failed.
107#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100108# The tests are roughly in order from fastest to slowest. This doesn't
109# have to be exact, but in general you should add slower tests towards
110# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100111
112
113
114################################################################
115#### Initialization and command line parsing
116################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100117
SimonB2e23c822016-04-16 21:54:39 +0100118# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100119set -eu
120
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100121pre_check_environment () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100122 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100123 echo "Must be run from mbed TLS root" >&2
124 exit 1
125 fi
126}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100127
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100128pre_initialize_variables () {
129 CONFIG_H='include/mbedtls/config.h'
130 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200131
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100132 MEMORY=0
133 FORCE=0
134 KEEP_GOING=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100135 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100136
Antonin Décimo8fd91562019-01-23 15:24:37 +0100137 # Default commands, can be overridden by the environment
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100138 : ${OPENSSL:="openssl"}
139 : ${OPENSSL_LEGACY:="$OPENSSL"}
140 : ${GNUTLS_CLI:="gnutls-cli"}
141 : ${GNUTLS_SERV:="gnutls-serv"}
142 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
143 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
144 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
145 : ${ARMC5_BIN_DIR:=/usr/bin}
146 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200147 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100148
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100149 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000150 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100151 export MAKEFLAGS="-j"
152 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100153
Gilles Peskinec20a4052019-10-21 17:11:33 +0200154 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine4c2697f2019-10-21 19:06:33 +0200155 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskinec20a4052019-10-21 17:11:33 +0200156
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100157 # Gather the list of available components. These are the functions
158 # defined in this script whose name starts with "component_".
159 # Parse the script with sed, because in sh there is no way to list
160 # defined functions.
161 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100162
163 # Exclude components that are not supported on this platform.
164 SUPPORTED_COMPONENTS=
165 for component in $ALL_COMPONENTS; do
166 case $(type "support_$component" 2>&1) in
167 *' function'*)
168 if ! support_$component; then continue; fi;;
169 esac
170 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
171 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100172}
Andres AG38495a32016-07-12 16:54:33 +0100173
Gilles Peskineff7238f2019-01-10 00:05:18 +0100174# Test whether the component $1 is included in the command line patterns.
175is_component_included()
Gilles Peskine6e984232018-11-27 21:37:53 +0100176{
177 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100178 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100179 set +f
180 case ${1#component_} in $pattern) return 0;; esac
181 done
182 set +f
183 return 1
184}
185
Simon Butcher41eeccf2016-09-07 00:07:09 +0100186usage()
SimonB2e23c822016-04-16 21:54:39 +0100187{
Gilles Peskine709346a2017-12-10 23:43:39 +0100188 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100189Usage: $0 [OPTION]... [COMPONENT]...
190Run mbedtls release validation tests.
191By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100192COMPONENT can be the name of a component or a shell wildcard pattern.
193
194Examples:
195 $0 "check_*"
196 Run all sanity checks.
197 $0 --no-armcc --except test_memsan
198 Run everything except builds that require armcc and MemSan.
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100199
200Special options:
201 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100202 --list-all-components List all available test components and exit.
203 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100204
205General options:
206 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100207 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 -m|--memory Additional optional memory tests.
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200209 --arm-none-eabi-gcc-prefix=<string>
210 Prefix for a cross-compiler for arm-none-eabi
211 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100212 --armcc Run ARM Compiler builds (on by default).
Gilles Peskineff7238f2019-01-10 00:05:18 +0100213 --except Exclude the COMPONENTs listed on the command line,
214 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100215 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100216 --no-force Refuse to overwrite modified files (default).
217 --no-keep-going Stop at the first error (default).
218 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100219 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100220 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100221 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100222 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
223 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100224 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100225
226Tool path options:
227 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
228 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
229 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
230 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
231 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
232 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
233 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
234 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
235EOF
SimonB2e23c822016-04-16 21:54:39 +0100236}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100237
238# remove built files as well as the cmake cache/config
239cleanup()
240{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100241 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
242 cd "$MBEDTLS_ROOT_DIR"
243 fi
244
Gilles Peskine7c652162017-12-11 00:01:40 +0100245 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200246
Gilles Peskine31b07e22018-03-21 12:15:06 +0100247 # Remove CMake artefacts
248 find . -name .git -prune -o -name yotta -prune -o \
249 -iname CMakeFiles -exec rm -rf {} \+ -o \
250 \( -iname cmake_install.cmake -o \
251 -iname CTestTestfile.cmake -o \
252 -iname CMakeCache.txt \) -exec rm {} \+
253 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000254 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200255 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
256 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200257
258 if [ -f "$CONFIG_BAK" ]; then
259 mv "$CONFIG_BAK" "$CONFIG_H"
260 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100261}
262
Gilles Peskine7c652162017-12-11 00:01:40 +0100263# Executed on exit. May be redefined depending on command line options.
264final_report () {
265 :
266}
267
268fatal_signal () {
269 cleanup
270 final_report $1
271 trap - $1
272 kill -$1 $$
273}
274
275trap 'fatal_signal HUP' HUP
276trap 'fatal_signal INT' INT
277trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200278
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100279msg()
280{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100281 if [ -n "${current_component:-}" ]; then
282 current_section="${current_component#component_}: $1"
283 else
284 current_section="$1"
285 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100286 echo ""
287 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100288 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000289 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100290 echo "******************************************************************"
291}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100292
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100293armc6_build_test()
294{
295 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100296
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200297 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100298 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
299 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200300
301 msg "size: ARM Compiler 6 ($FLAGS)"
302 "$ARMC6_FROMELF" -z library/*.o
303
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100304 make clean
305}
Andres AGa5cd9732016-10-17 15:23:10 +0100306
Andres AGd9eba4b2016-08-26 14:42:14 +0100307err_msg()
308{
309 echo "$1" >&2
310}
311
312check_tools()
313{
314 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000315 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100316 err_msg "$TOOL not found!"
317 exit 1
318 fi
319 done
320}
321
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100322pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100323 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100324 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100325 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100326
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100327 while [ $# -gt 0 ]; do
328 case "$1" in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200329 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine53084872019-01-09 23:13:54 +0100330 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100331 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
332 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100333 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100334 --force|-f) FORCE=1;;
335 --gnutls-cli) shift; GNUTLS_CLI="$1";;
336 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
337 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
338 --gnutls-serv) shift; GNUTLS_SERV="$1";;
339 --help|-h) usage; exit;;
340 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100341 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
342 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100343 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100344 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100345 --no-force) FORCE=0;;
346 --no-keep-going) KEEP_GOING=0;;
347 --no-memory) MEMORY=0;;
348 --no-yotta) YOTTA=0;;
349 --openssl) shift; OPENSSL="$1";;
350 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
351 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
352 --random-seed) unset SEED;;
353 --release-test|-r) SEED=1;;
354 --seed|-s) shift; SEED="$1";;
355 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100356 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100357 echo >&2 "Unknown option: $1"
358 echo >&2 "Run $0 --help for usage."
359 exit 120
360 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100361 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100362 esac
363 shift
364 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100365
Gilles Peskineff7238f2019-01-10 00:05:18 +0100366 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100367 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
368 all_except=1
369 fi
370
Gilles Peskine53084872019-01-09 23:13:54 +0100371 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
372 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100373 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100374 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
375 # --no-armcc also disables yotta.
376 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
377 fi
378
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100379 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100380 RUN_COMPONENTS=
381 for component in $SUPPORTED_COMPONENTS; do
382 if is_component_included "$component"; [ $? -eq $all_except ]; then
383 RUN_COMPONENTS="$RUN_COMPONENTS $component"
384 fi
385 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100386
387 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100388 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100389}
SimonB2e23c822016-04-16 21:54:39 +0100390
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100391pre_check_git () {
392 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100393 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100394 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100395 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100396 fi
397 git checkout-index -f -q $CONFIG_H
398 cleanup
399 else
400
401 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
402 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
403 echo "You can either delete your work and retry, or force the test to overwrite the"
404 echo "test by rerunning the script as: $0 --force"
405 exit 1
406 fi
407
408 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
409 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
410 echo "You can either delete this directory manually, or force the test by rerunning"
411 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
412 exit 1
413 fi
414
Gilles Peskinec9663b12019-01-09 22:30:01 +0100415 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100416 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
417 echo "You can either delete or preserve your work, or force the test by rerunning the"
418 echo "script as: $0 --force"
419 exit 1
420 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100421 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100422}
SimonB2e23c822016-04-16 21:54:39 +0100423
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100424pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100425 failure_summary=
426 failure_count=0
427 start_red=
428 end_color=
429 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100430 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100431 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
432 start_red=$(printf '\033[31m')
433 end_color=$(printf '\033[0m')
434 ;;
435 esac
436 fi
437 record_status () {
438 if "$@"; then
439 last_status=0
440 else
441 last_status=$?
442 text="$current_section: $* -> $last_status"
443 failure_summary="$failure_summary
444$text"
445 failure_count=$((failure_count + 1))
446 echo "${start_red}^^^^$text^^^^${end_color}"
447 fi
448 }
449 make () {
450 case "$*" in
451 *test|*check)
452 if [ $build_status -eq 0 ]; then
453 record_status command make "$@"
454 else
455 echo "(skipped because the build failed)"
456 fi
457 ;;
458 *)
459 record_status command make "$@"
460 build_status=$last_status
461 ;;
462 esac
463 }
464 final_report () {
465 if [ $failure_count -gt 0 ]; then
466 echo
467 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
468 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
469 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100470 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100471 elif [ -z "${1-}" ]; then
472 echo "SUCCESS :)"
473 fi
474 if [ -n "${1-}" ]; then
475 echo "Killed by SIG$1."
476 fi
477 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100478}
479
Gilles Peskine7c652162017-12-11 00:01:40 +0100480if_build_succeeded () {
481 if [ $build_status -eq 0 ]; then
482 record_status "$@"
483 fi
484}
485
Gilles Peskine30bc3852019-01-09 23:25:25 +0100486# to be used instead of ! for commands run with
487# record_status or if_build_succeeded
488not() {
489 ! "$@"
490}
491
492
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100493pre_print_configuration () {
494 msg "info: $0 configuration"
495 echo "MEMORY: $MEMORY"
496 echo "FORCE: $FORCE"
497 echo "SEED: ${SEED-"UNSET"}"
498 echo "OPENSSL: $OPENSSL"
499 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
500 echo "GNUTLS_CLI: $GNUTLS_CLI"
501 echo "GNUTLS_SERV: $GNUTLS_SERV"
502 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
503 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
504 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
505 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
506}
Andres AG7770ea82016-10-10 15:46:20 +0100507
Andres AGd9eba4b2016-08-26 14:42:14 +0100508# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100509pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000510 # Build the list of variables to pass to output_env.sh.
511 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100512
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000513 case " $RUN_COMPONENTS " in
514 # Require OpenSSL and GnuTLS if running any tests (as opposed to
515 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
516 # is a good enough approximation in practice.
517 *" test_"*)
518 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
519 # and ssl-opt.sh, we just export the variables they require.
520 export OPENSSL_CMD="$OPENSSL"
521 export GNUTLS_CLI="$GNUTLS_CLI"
522 export GNUTLS_SERV="$GNUTLS_SERV"
523 # Avoid passing --seed flag in every call to ssl-opt.sh
524 if [ -n "${SEED-}" ]; then
525 export SEED
526 fi
527 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
528 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
529 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
530 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
531 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
532 "$GNUTLS_CLI" "$GNUTLS_SERV" \
533 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
534 ;;
535 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100536
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000537 case " $RUN_COMPONENTS " in
538 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
539 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100540
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000541 case " $RUN_COMPONENTS " in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200542 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000543 esac
544
545 case " $RUN_COMPONENTS " in
546 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
547 esac
548
549 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100550 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000551 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
552 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200553 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000554 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
555 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200556 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
557 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
558 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine53084872019-01-09 23:13:54 +0100559 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100560
561 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100562 case $RUN_COMPONENTS in
563 *_armcc*|*_yotta*)
564 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
565 *) set "$@" RUN_ARMCC=0;;
566 esac
567 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100568}
Andres AGd9eba4b2016-08-26 14:42:14 +0100569
Gilles Peskine192c72f2017-12-21 15:59:21 +0100570
571
572################################################################
573#### Basic checks
574################################################################
SimonB2e23c822016-04-16 21:54:39 +0100575
576#
577# Test Suites to be executed
578#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200579# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100580# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200581# and/or are more likely to fail than others (eg I use Clang most of the
582# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200583# 2. Minimize total running time, by avoiding useless rebuilds
584#
585# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100586
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100587component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100588 msg "test: recursion.pl" # < 1s
589 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100590}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100591
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100592component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100593 msg "test: freshness of generated source files" # < 1s
594 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100595}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000596
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100597component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100598 msg "test: doxygen markup outside doxygen blocks" # < 1s
599 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100600}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200601
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100602component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100603 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100604 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100605}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200606
Gilles Peskinec3189252020-05-10 17:40:49 +0200607component_check_changelog () {
608 msg "Check: changelog entries" # < 1s
609 rm -f ChangeLog.new
610 record_status scripts/assemble_changelog.py -o ChangeLog.new
611 if [ -e ChangeLog.new ]; then
612 # Show the diff for information. It isn't an error if the diff is
613 # non-empty.
614 diff -u ChangeLog ChangeLog.new || true
615 rm ChangeLog.new
616 fi
617}
618
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100619component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100620 msg "test/build: declared and exported names" # < 3s
Gilles Peskinee952fdf2019-05-15 17:52:22 +0200621 record_status tests/scripts/check-names.sh -v
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100622}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200623
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100624component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100625 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100626 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100627}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100628
Simon Butcher948f2642018-07-20 21:27:33 +0100629
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100630################################################################
631#### Build and test many configurations and targets
632################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100633
k-stachowiak45d0ba12019-06-04 13:14:58 +0200634component_test_large_ecdsa_key_signature () {
635
636 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
637
638 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
639 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
640 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
641 make
642
643 INEVITABLY_PRESENT_FILE=Makefile
644 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
645
646 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
647 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
648 rm -f $SIGNATURE_FILE
649}
650
Gilles Peskine1270d322019-04-08 17:00:15 +0200651component_test_default_out_of_box () {
652 msg "build: make, default config (out-of-box)" # ~1min
653 make
654
655 msg "test: main suites make, default config (out-of-box)" # ~10s
656 make test
657
658 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinebfda0332020-04-23 23:37:45 +0200659 if_build_succeeded programs/test/selftest
Gilles Peskine1270d322019-04-08 17:00:15 +0200660}
661
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100662component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100663 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
664 # path, and uses whatever version of armcc it finds there.
665 msg "build: create and build yotta module" # ~ 30s
666 record_status tests/scripts/yotta-build.sh
667}
668support_build_yotta () {
669 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100670}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100671
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100672component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100673 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100674 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100675 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200676
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100677 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100678 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100679
Gilles Peskinebfda0332020-04-23 23:37:45 +0200680 msg "test: selftest (ASan build)" # ~ 10s
681 if_build_succeeded programs/test/selftest
682
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100683 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100684 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100685
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100686 msg "test: compat.sh (ASan build)" # ~ 6 min
687 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100688}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000689
Hanno Becker167ae432019-02-26 14:27:09 +0000690component_test_full_cmake_gcc_asan () {
691 msg "build: full config, cmake, gcc, ASan"
692 scripts/config.pl full
693 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
694 make
695
696 msg "test: main suites (inc. selftests) (full config, ASan build)"
697 make test
698
Gilles Peskinebfda0332020-04-23 23:37:45 +0200699 msg "test: selftest (ASan build)" # ~ 10s
700 if_build_succeeded programs/test/selftest
701
Hanno Becker167ae432019-02-26 14:27:09 +0000702 msg "test: ssl-opt.sh (full config, ASan build)"
703 if_build_succeeded tests/ssl-opt.sh
704
705 msg "test: compat.sh (full config, ASan build)"
706 if_build_succeeded tests/compat.sh
707}
708
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100709component_test_zlib_make() {
710 msg "build: zlib enabled, make"
711 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
712 make ZLIB=1 CFLAGS='-Werror -O1'
713
714 msg "test: main suites (zlib, make)"
715 make test
716
717 msg "test: ssl-opt.sh (zlib, make)"
718 if_build_succeeded tests/ssl-opt.sh
719}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100720support_test_zlib_make () {
721 base=support_test_zlib_$$
722 cat <<'EOF' > ${base}.c
723#include "zlib.h"
724int main(void) { return 0; }
725EOF
726 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
727 ret=$?
728 rm -f ${base}.*
729 return $ret
730}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100731
732component_test_zlib_cmake() {
733 msg "build: zlib enabled, cmake"
734 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
735 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
736 make
737
738 msg "test: main suites (zlib, cmake)"
739 make test
740
741 msg "test: ssl-opt.sh (zlib, cmake)"
742 if_build_succeeded tests/ssl-opt.sh
743}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100744support_test_zlib_cmake () {
745 support_test_zlib_make "$@"
746}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100747
Gilles Peskine3484ed82019-01-08 22:51:19 +0100748component_test_ref_configs () {
749 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
750 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
751 record_status tests/scripts/test-ref-configs.pl
752}
753
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100754component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100755 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100756 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
757 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
758 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000759
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100760 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
761 make test
762
763 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
764 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
765 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
766
767 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
768 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100769}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100770
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100771component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100772 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100773 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
774 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
775 make
776
777 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
778 make test
779
780 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
781 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100782}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100783
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100784component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100785 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100786 scripts/config.pl set MBEDTLS_RSA_NO_CRT
787 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
788 make
789
790 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
791 make test
792
793 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
794 if_build_succeeded tests/ssl-opt.sh -f RSA
795
796 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
797 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100798}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100799
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200800component_test_no_ctr_drbg () {
801 msg "build: Full minus CTR_DRBG"
802 scripts/config.pl full
803 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
804
805 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
806 make
807
808 msg "test: no CTR_DRBG"
809 make test
810
Manuel Pégourié-Gonnardcdfa2f92020-06-05 09:29:51 +0200811 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
812}
813
814component_test_no_hmac_drbg () {
815 msg "build: Full minus HMAC_DRBG"
816 scripts/config.pl full
817 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
818 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
819
820 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
821 make
822
823 msg "test: no HMAC_DRBG"
824 make test
825
826 # No ssl-opt.sh/compat.sh as they never use HMAC_DRBG so far,
827 # so there's little value in running those lengthy tests here.
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200828}
829
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100830component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100831 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100832 scripts/config.pl full
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100833 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
834 make
835
836 msg "test: main suites (full config)" # ~ 5s
837 make test
838
839 msg "test: ssl-opt.sh default (full config)" # ~ 1s
840 if_build_succeeded tests/ssl-opt.sh -f Default
841
Andres Amaya Garcia0a0e5b12019-01-08 21:42:27 +0000842 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000843 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100844}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100845
Gilles Peskineadaaddb2020-04-28 14:04:28 +0200846component_test_default_no_deprecated () {
847 # Test that removing the deprecated features from the default
848 # configuration leaves something consistent.
849 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100850 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskineadaaddb2020-04-28 14:04:28 +0200851 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
852
853 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
854 make test
855}
856
857component_test_full_deprecated_warning () {
858 # Test that there is nothing deprecated in the full configuraration.
859 # A deprecated feature would trigger a warning (made fatal) from
860 # MBEDTLS_DEPRECATED_WARNING.
861 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
862 scripts/config.pl full
863 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
864 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
865 # There are currently no tests for any deprecated feature.
866 # If some are added, 'make test' would trigger warnings here.
867 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
868
869 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
870 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100871}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100872
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100873component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100874 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100875 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100876}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100877
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100878component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100879 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100880 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100881}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100882
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100883component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100884 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100885 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100886}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100887
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100888component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100889 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100890 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100891}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100892
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100893component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100894 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100895 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100896}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100897
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100898component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100899 # Full configuration build, without platform support, file IO and net sockets.
900 # This should catch missing mbedtls_printf definitions, and by disabling file
901 # IO, it should catch missing '#include <stdio.h>'
902 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100903 scripts/config.pl full
904 scripts/config.pl unset MBEDTLS_PLATFORM_C
905 scripts/config.pl unset MBEDTLS_NET_C
906 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
907 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
908 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
909 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
910 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
911 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinea21c5e92020-04-28 10:41:20 +0200912 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100913 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100914 scripts/config.pl unset MBEDTLS_FS_IO
915 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
916 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskinec9247122019-09-20 19:23:10 +0200917 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
918 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100919}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100920
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100921component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100922 # catch compile bugs in _uninit functions
923 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100924 scripts/config.pl full
925 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
926 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +0200927 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec9247122019-09-20 19:23:10 +0200928 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100929}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100930
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100931component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100932 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100933 scripts/config.pl full
934 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200935 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100936}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100937
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100938component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100939 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100940 scripts/config.pl full
941 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200942 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100943}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100944
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100945component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100946 # Note, C99 compliance can also be tested with the sockets support disabled,
947 # as that requires a POSIX platform (which isn't the same as C99).
948 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949 scripts/config.pl full
950 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
951 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinec9247122019-09-20 19:23:10 +0200952 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100953}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100954
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400955component_test_memory_buffer_allocator_backtrace () {
956 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000957 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400958 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000959 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9b1c2482019-09-10 02:58:34 -0400960 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400961 CC=gcc cmake .
962 make
963
964 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
965 make test
966}
967
968component_test_memory_buffer_allocator () {
969 msg "build: default config with memory buffer allocator"
970 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Becker7aad93c2019-06-03 16:35:02 +0100971 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000972 CC=gcc cmake .
973 make
974
975 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
976 make test
977
978 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek6addfdd2019-09-05 10:09:37 -0400979 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
980 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000981}
982
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100983component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100984 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100985 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
986 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
987 make
988
989 msg "test: ssl-opt.sh, MFL-related tests"
990 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100991}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100992
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100993component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100994 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100995 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
996 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
997 scripts/config.pl set MBEDTLS_ENTROPY_C
998 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +0200999 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001000 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1001 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +00001002 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001003 make
1004
1005 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1006 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001007}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001008
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001009component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001010 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001011 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1012 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1013 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1014 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1015 make
1016
1017 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1018 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001019}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001020
Gilles Peskine0981a5d2019-09-17 19:04:38 +02001021component_test_malloc_0_null () {
1022 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1023 scripts/config.pl full
1024 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1025 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O -Werror -Wall -Wextra -fsanitize=address,undefined" LDFLAGS='-fsanitize=address,undefined'
1026
1027 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1028 make test
1029
1030 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1031 # Just the calloc selftest. "make test" ran the others as part of the
1032 # test suites.
1033 if_build_succeeded programs/test/selftest calloc
1034}
1035
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001036component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001037 msg "build/test: make shared" # ~ 40s
1038 make SHARED=1 all check
Gilles Peskine950de1e2019-07-03 20:43:32 +02001039 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001040}
1041
Gilles Peskine17ecb242019-07-03 20:43:05 +02001042component_test_cmake_shared () {
1043 msg "build/test: cmake shared" # ~ 2min
1044 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1045 make
Gilles Peskine950de1e2019-07-03 20:43:32 +02001046 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine17ecb242019-07-03 20:43:05 +02001047 make test
1048}
1049
Gilles Peskinefa0e8b52019-09-20 19:56:06 +02001050test_build_opt () {
1051 info=$1 cc=$2; shift 2
1052 for opt in "$@"; do
1053 msg "build/test: $cc $opt, $info" # ~ 30s
1054 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1055 # We're confident enough in compilers to not run _all_ the tests,
1056 # but at least run the unit tests. In particular, runs with
1057 # optimizations use inline assembly whereas runs with -O0
1058 # skip inline assembly.
1059 make test # ~30s
1060 make clean
1061 done
1062}
1063
1064component_test_clang_opt () {
1065 scripts/config.pl full
1066 test_build_opt 'full config' clang -O0 -Os -O2
1067}
1068
1069component_test_gcc_opt () {
1070 scripts/config.pl full
1071 test_build_opt 'full config' gcc -O0 -Os -O2
1072}
1073
Gilles Peskinef852f5f2019-07-03 20:42:16 +02001074component_build_mbedtls_config_file () {
1075 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1076 # Use the full config so as to catch a maximum of places where
1077 # the check of MBEDTLS_CONFIG_FILE might be missing.
1078 scripts/config.pl full
1079 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1080 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1081 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1082 rm -f full_config.h
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001083}
1084
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001085component_test_m32_o0 () {
1086 # Build once with -O0, to compile out the i386 specific inline assembly
1087 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1088 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001089 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001090
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001091 msg "test: i386, make, gcc -O0 (ASan build)"
1092 make test
1093}
1094support_test_m32_o0 () {
1095 case $(uname -m) in
1096 *64*) true;;
1097 *) false;;
1098 esac
1099}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001100
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001101component_test_m32_o1 () {
1102 # Build again with -O1, to compile in the i386 specific inline assembly
1103 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1104 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001105 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001106
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001107 msg "test: i386, make, gcc -O1 (ASan build)"
1108 make test
Gilles Peskine11064292019-04-08 16:58:02 +02001109
1110 msg "test ssl-opt.sh, i386, make, gcc-O1"
1111 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001112}
1113support_test_m32_o1 () {
1114 support_test_m32_o0 "$@"
1115}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001116
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001117component_test_mx32 () {
1118 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1119 scripts/config.pl full
Gilles Peskined535f4d2019-06-07 14:50:09 +02001120 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001121
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001122 msg "test: 64-bit ILP32, make, gcc"
1123 make test
1124}
1125support_test_mx32 () {
1126 case $(uname -m) in
1127 amd64|x86_64) true;;
1128 *) false;;
1129 esac
1130}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001131
Peter Kolbus16015dd2018-12-27 06:59:04 -06001132component_test_min_mpi_window_size () {
1133 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1134 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1135 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1136 make
1137
1138 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1139 make test
1140}
1141
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001142component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001143 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001144 scripts/config.pl unset MBEDTLS_HAVE_ASM
1145 scripts/config.pl unset MBEDTLS_AESNI_C
1146 scripts/config.pl unset MBEDTLS_PADLOCK_C
1147 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1148
1149 msg "test: gcc, force 32-bit bignum limbs"
1150 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001151}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001152
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001153component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001154 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001155 scripts/config.pl unset MBEDTLS_HAVE_ASM
1156 scripts/config.pl unset MBEDTLS_AESNI_C
1157 scripts/config.pl unset MBEDTLS_PADLOCK_C
1158 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1159
1160 msg "test: gcc, force 64-bit bignum limbs"
1161 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001162}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001163
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001164component_build_arm_none_eabi_gcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001165 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001166 scripts/config.pl baremetal
Gilles Peskine009908b2020-04-30 22:54:00 +02001167 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -O1' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001168
1169 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1170 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001171}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001172
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001173component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001174 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001175 scripts/config.pl baremetal
1176 # Build for a target platform that's close to what Debian uses
1177 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1178 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1179 # It would be better to build with arm-linux-gnueabi-gcc but
1180 # we don't have that on our CI at this time.
1181 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001182
1183 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1184 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001185}
1186
Gilles Peskine4fb7a2f2020-04-30 23:00:53 +02001187component_build_arm_none_eabi_gcc_m0plus () {
1188 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1189 scripts/config.pl baremetal
1190 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001191
1192 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1193 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001194}
1195
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001196component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001197 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001198 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001199 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001200 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001201 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +01001202 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001203}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001204
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001205component_build_armcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001206 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001207 scripts/config.pl baremetal
Gilles Peskine53084872019-01-09 23:13:54 +01001208 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001209
1210 msg "size: ARM Compiler 5"
1211 "$ARMC5_FROMELF" -z library/*.o
1212
Gilles Peskine53084872019-01-09 23:13:54 +01001213 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001214
Gilles Peskine53084872019-01-09 23:13:54 +01001215 # ARM Compiler 6 - Target ARMv7-A
1216 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001217
Gilles Peskine53084872019-01-09 23:13:54 +01001218 # ARM Compiler 6 - Target ARMv7-M
1219 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001220
Gilles Peskine53084872019-01-09 23:13:54 +01001221 # ARM Compiler 6 - Target ARMv8-A - AArch32
1222 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001223
Gilles Peskine53084872019-01-09 23:13:54 +01001224 # ARM Compiler 6 - Target ARMv8-M
1225 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001226
Gilles Peskine53084872019-01-09 23:13:54 +01001227 # ARM Compiler 6 - Target ARMv8-A - AArch64
1228 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001229}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001230
Andres Amaya Garciabb13e3b2018-12-05 22:03:56 +00001231component_build_ssl_hw_record_accel() {
1232 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1233 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1234 make CFLAGS='-Werror -O1'
1235}
1236
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001237component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001238 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001239 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1240 make CFLAGS='-Werror -Wall -Wextra'
1241 msg "test: allow SHA1 in certificates by default"
1242 make test
1243 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001244}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001245
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001246component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001247 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001248 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
1249
1250 # note Make tests only builds the tests, but doesn't run them
1251 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1252 make WINDOWS_BUILD=1 clean
1253
1254 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1255 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
1256 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
1257 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001258}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001259
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001260component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001261 msg "build: MSan (clang)" # ~ 1 min 20s
1262 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1263 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1264 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001265
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001266 msg "test: main suites (MSan)" # ~ 10s
1267 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001268
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001269 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1270 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001271
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001272 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001273
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001274 if [ "$MEMORY" -gt 0 ]; then
1275 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1276 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001277 fi
1278}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001279
Gilles Peskine9f553642019-01-10 00:11:42 +01001280component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001281 msg "build: Release (clang)"
1282 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1283 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001284
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001285 msg "test: main suites valgrind (Release)"
1286 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001287
Gilles Peskine26cae712019-04-08 17:00:56 +02001288 # Optional parts (slow; currently broken on OS X because programs don't
1289 # seem to receive signals under valgrind on OS X).
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001290 if [ "$MEMORY" -gt 0 ]; then
1291 msg "test: ssl-opt.sh --memcheck (Release)"
1292 if_build_succeeded tests/ssl-opt.sh --memcheck
1293 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001294
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001295 if [ "$MEMORY" -gt 1 ]; then
1296 msg "test: compat.sh --memcheck (Release)"
1297 if_build_succeeded tests/compat.sh --memcheck
1298 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001299}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001300
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001301component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001302 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001303 MBEDTLS_ROOT_DIR="$PWD"
1304 mkdir "$OUT_OF_SOURCE_DIR"
1305 cd "$OUT_OF_SOURCE_DIR"
1306 cmake "$MBEDTLS_ROOT_DIR"
1307 make
1308
1309 msg "test: cmake 'out-of-source' build"
1310 make test
1311 # Test an SSL option that requires an auxiliary script in test/scripts/.
1312 # Also ensure that there are no error messages such as
1313 # "No such file or directory", which would indicate that some required
1314 # file is missing (ssl-opt.sh tolerates the absence of some files so
1315 # may exit with status 0 but emit errors).
1316 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1317 if [ -s ssl-opt.err ]; then
1318 cat ssl-opt.err >&2
1319 record_status [ ! -s ssl-opt.err ]
1320 rm ssl-opt.err
1321 fi
1322 cd "$MBEDTLS_ROOT_DIR"
1323 rm -rf "$OUT_OF_SOURCE_DIR"
1324 unset MBEDTLS_ROOT_DIR
1325}
Andres AGdc192212016-08-31 17:33:13 +01001326
Gilles Peskine192c72f2017-12-21 15:59:21 +01001327
1328
1329################################################################
1330#### Termination
1331################################################################
1332
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001333post_report () {
1334 msg "Done, cleaning up"
1335 cleanup
1336
1337 final_report
1338}
1339
1340
1341
1342################################################################
1343#### Run all the things
1344################################################################
1345
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001346# Run one component and clean up afterwards.
1347run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001348 # Back up the configuration in case the component modifies it.
1349 # The cleanup function will restore it.
1350 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001351 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001352 "$@"
1353 cleanup
1354}
1355
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001356# Preliminary setup
1357pre_check_environment
1358pre_initialize_variables
1359pre_parse_command_line "$@"
1360
1361pre_check_git
1362build_status=0
1363if [ $KEEP_GOING -eq 1 ]; then
1364 pre_setup_keep_going
1365else
1366 record_status () {
1367 "$@"
1368 }
1369fi
1370pre_print_configuration
1371pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001372cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001373
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001374# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001375for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001376 run_component "component_$component"
1377done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001378
1379# We're done.
1380post_report