blob: 18181558f1f581c02e55df1ef677652f1a0813a1 [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úti4e9f7122020-06-05 13:02:18 +02006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020013#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020026# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
46#
Bence Szépkúti09b4f192020-05-26 01:54:15 +020047# This file is part of Mbed TLS (https://tls.mbed.org)
Gilles Peskine192c72f2017-12-21 15:59:21 +010048
49
50
51################################################################
52#### Documentation
53################################################################
54
Simon Butcher3ea7f522016-03-07 23:22:10 +000055# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010056# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000057#
SimonB2e23c822016-04-16 21:54:39 +010058# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010059#
Gilles Peskine192c72f2017-12-21 15:59:21 +010060# Notes for users
61# ---------------
62#
SimonB2e23c822016-04-16 21:54:39 +010063# Warning: the test is destructive. It includes various build modes and
64# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010065# configuration. The following files must be committed into git:
66# * include/mbedtls/config.h
67# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
68# After running this script, the CMake cache will be lost and CMake
69# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010070#
Gilles Peskine192c72f2017-12-21 15:59:21 +010071# The script assumes the presence of a number of tools:
72# * Basic Unix tools (Windows users note: a Unix-style find must be before
73# the Windows find in the PATH)
74# * Perl
75# * GNU Make
76# * CMake
77# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
78# * arm-gcc and mingw-gcc
79# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
80# * Yotta build dependencies, unless invoked with --no-yotta
81# * OpenSSL and GnuTLS command line tools, recent enough for the
82# interoperability tests. If they don't support SSLv3 then a legacy
83# version of these tools must be present as well (search for LEGACY
84# below).
85# See the invocation of check_tools below for details.
86#
87# This script must be invoked from the toplevel directory of a git
88# working copy of Mbed TLS.
89#
90# Note that the output is not saved. You may want to run
91# script -c tests/scripts/all.sh
92# or
93# tests/scripts/all.sh >all.log 2>&1
94#
95# Notes for maintainers
96# ---------------------
97#
Gilles Peskine2906a0a2019-01-09 22:29:17 +010098# The bulk of the code is organized into functions that follow one of the
99# following naming conventions:
100# * pre_XXX: things to do before running the tests, in order.
101# * component_XXX: independent components. They can be run in any order.
102# * component_check_XXX: quick tests that aren't worth parallelizing.
103# * component_build_XXX: build things but don't run them.
104# * component_test_XXX: build and test.
105# * support_XXX: if support_XXX exists and returns false then
106# component_XXX is not run by default.
107# * post_XXX: things to do after running the tests.
108# * other: miscellaneous support functions.
109#
110# Each component must start by invoking `msg` with a short informative message.
111#
112# The framework performs some cleanup tasks after each component. This
113# means that components can assume that the working directory is in a
114# cleaned-up state, and don't need to perform the cleanup themselves.
115# * Run `make clean`.
116# * Restore `include/mbedtks/config.h` from a backup made before running
117# the component.
118# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
119# `tests/Makefile` from git. This cleans up after an in-tree use of
120# CMake.
121#
122# Any command that is expected to fail must be protected so that the
123# script keeps running in --keep-going mode despite `set -e`. In keep-going
124# mode, if a protected command fails, this is logged as a failure and the
125# script will exit with a failure status once it has run all components.
126# Commands can be protected in any of the following ways:
127# * `make` is a function which runs the `make` command with protection.
128# Note that you must write `make VAR=value`, not `VAR=value make`,
129# because the `VAR=value make` syntax doesn't work with functions.
130# * Put `report_status` before the command to protect it.
131# * Put `if_build_successful` before a command. This protects it, and
132# additionally skips it if a prior invocation of `make` in the same
133# component failed.
134#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100135# The tests are roughly in order from fastest to slowest. This doesn't
136# have to be exact, but in general you should add slower tests towards
137# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100138
139
140
141################################################################
142#### Initialization and command line parsing
143################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100144
SimonB2e23c822016-04-16 21:54:39 +0100145# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100146set -eu
147
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100148pre_check_environment () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100149 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100150 echo "Must be run from mbed TLS root" >&2
151 exit 1
152 fi
153}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100154
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100155pre_initialize_variables () {
156 CONFIG_H='include/mbedtls/config.h'
157 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200158
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100159 MEMORY=0
160 FORCE=0
161 KEEP_GOING=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100162 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100163
Antonin Décimo8fd91562019-01-23 15:24:37 +0100164 # Default commands, can be overridden by the environment
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100165 : ${OPENSSL:="openssl"}
166 : ${OPENSSL_LEGACY:="$OPENSSL"}
167 : ${GNUTLS_CLI:="gnutls-cli"}
168 : ${GNUTLS_SERV:="gnutls-serv"}
169 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
170 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
171 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
172 : ${ARMC5_BIN_DIR:=/usr/bin}
173 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200174 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100175
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100176 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000177 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100178 export MAKEFLAGS="-j"
179 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100180
Gilles Peskinec20a4052019-10-21 17:11:33 +0200181 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine4c2697f2019-10-21 19:06:33 +0200182 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskinec20a4052019-10-21 17:11:33 +0200183
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100184 # Gather the list of available components. These are the functions
185 # defined in this script whose name starts with "component_".
186 # Parse the script with sed, because in sh there is no way to list
187 # defined functions.
188 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100189
190 # Exclude components that are not supported on this platform.
191 SUPPORTED_COMPONENTS=
192 for component in $ALL_COMPONENTS; do
193 case $(type "support_$component" 2>&1) in
194 *' function'*)
195 if ! support_$component; then continue; fi;;
196 esac
197 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
198 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100199}
Andres AG38495a32016-07-12 16:54:33 +0100200
Gilles Peskineff7238f2019-01-10 00:05:18 +0100201# Test whether the component $1 is included in the command line patterns.
202is_component_included()
Gilles Peskine6e984232018-11-27 21:37:53 +0100203{
204 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100205 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100206 set +f
207 case ${1#component_} in $pattern) return 0;; esac
208 done
209 set +f
210 return 1
211}
212
Simon Butcher41eeccf2016-09-07 00:07:09 +0100213usage()
SimonB2e23c822016-04-16 21:54:39 +0100214{
Gilles Peskine709346a2017-12-10 23:43:39 +0100215 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100216Usage: $0 [OPTION]... [COMPONENT]...
217Run mbedtls release validation tests.
218By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100219COMPONENT can be the name of a component or a shell wildcard pattern.
220
221Examples:
222 $0 "check_*"
223 Run all sanity checks.
224 $0 --no-armcc --except test_memsan
225 Run everything except builds that require armcc and MemSan.
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100226
227Special options:
228 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100229 --list-all-components List all available test components and exit.
230 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100231
232General options:
233 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100234 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100235 -m|--memory Additional optional memory tests.
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200236 --arm-none-eabi-gcc-prefix=<string>
237 Prefix for a cross-compiler for arm-none-eabi
238 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100239 --armcc Run ARM Compiler builds (on by default).
Gilles Peskineff7238f2019-01-10 00:05:18 +0100240 --except Exclude the COMPONENTs listed on the command line,
241 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100242 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100243 --no-force Refuse to overwrite modified files (default).
244 --no-keep-going Stop at the first error (default).
245 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100246 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100247 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100248 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100249 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
250 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100251 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100252
253Tool path options:
254 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
255 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
256 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
257 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
258 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
259 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
260 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
261 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
262EOF
SimonB2e23c822016-04-16 21:54:39 +0100263}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100264
265# remove built files as well as the cmake cache/config
266cleanup()
267{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100268 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
269 cd "$MBEDTLS_ROOT_DIR"
270 fi
271
Gilles Peskine7c652162017-12-11 00:01:40 +0100272 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200273
Gilles Peskine31b07e22018-03-21 12:15:06 +0100274 # Remove CMake artefacts
275 find . -name .git -prune -o -name yotta -prune -o \
276 -iname CMakeFiles -exec rm -rf {} \+ -o \
277 \( -iname cmake_install.cmake -o \
278 -iname CTestTestfile.cmake -o \
279 -iname CMakeCache.txt \) -exec rm {} \+
280 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000281 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200282 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
283 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200284
285 if [ -f "$CONFIG_BAK" ]; then
286 mv "$CONFIG_BAK" "$CONFIG_H"
287 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100288}
289
Gilles Peskine7c652162017-12-11 00:01:40 +0100290# Executed on exit. May be redefined depending on command line options.
291final_report () {
292 :
293}
294
295fatal_signal () {
296 cleanup
297 final_report $1
298 trap - $1
299 kill -$1 $$
300}
301
302trap 'fatal_signal HUP' HUP
303trap 'fatal_signal INT' INT
304trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200305
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100306msg()
307{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100308 if [ -n "${current_component:-}" ]; then
309 current_section="${current_component#component_}: $1"
310 else
311 current_section="$1"
312 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100313 echo ""
314 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100315 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000316 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100317 echo "******************************************************************"
318}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100319
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100320armc6_build_test()
321{
322 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100323
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200324 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100325 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
326 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200327
328 msg "size: ARM Compiler 6 ($FLAGS)"
329 "$ARMC6_FROMELF" -z library/*.o
330
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100331 make clean
332}
Andres AGa5cd9732016-10-17 15:23:10 +0100333
Andres AGd9eba4b2016-08-26 14:42:14 +0100334err_msg()
335{
336 echo "$1" >&2
337}
338
339check_tools()
340{
341 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000342 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100343 err_msg "$TOOL not found!"
344 exit 1
345 fi
346 done
347}
348
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100349pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100350 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100351 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100352 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100353
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100354 while [ $# -gt 0 ]; do
355 case "$1" in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200356 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine53084872019-01-09 23:13:54 +0100357 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100358 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
359 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100360 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100361 --force|-f) FORCE=1;;
362 --gnutls-cli) shift; GNUTLS_CLI="$1";;
363 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
364 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
365 --gnutls-serv) shift; GNUTLS_SERV="$1";;
366 --help|-h) usage; exit;;
367 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100368 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
369 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100370 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100371 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100372 --no-force) FORCE=0;;
373 --no-keep-going) KEEP_GOING=0;;
374 --no-memory) MEMORY=0;;
375 --no-yotta) YOTTA=0;;
376 --openssl) shift; OPENSSL="$1";;
377 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
378 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
379 --random-seed) unset SEED;;
380 --release-test|-r) SEED=1;;
381 --seed|-s) shift; SEED="$1";;
382 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100383 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100384 echo >&2 "Unknown option: $1"
385 echo >&2 "Run $0 --help for usage."
386 exit 120
387 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100388 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100389 esac
390 shift
391 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100392
Gilles Peskineff7238f2019-01-10 00:05:18 +0100393 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100394 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
395 all_except=1
396 fi
397
Gilles Peskine53084872019-01-09 23:13:54 +0100398 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
399 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100400 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100401 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
402 # --no-armcc also disables yotta.
403 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
404 fi
405
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100406 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100407 RUN_COMPONENTS=
408 for component in $SUPPORTED_COMPONENTS; do
409 if is_component_included "$component"; [ $? -eq $all_except ]; then
410 RUN_COMPONENTS="$RUN_COMPONENTS $component"
411 fi
412 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100413
414 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100415 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100416}
SimonB2e23c822016-04-16 21:54:39 +0100417
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100418pre_check_git () {
419 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100420 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100421 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100422 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100423 fi
424 git checkout-index -f -q $CONFIG_H
425 cleanup
426 else
427
428 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
429 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
430 echo "You can either delete your work and retry, or force the test to overwrite the"
431 echo "test by rerunning the script as: $0 --force"
432 exit 1
433 fi
434
435 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
436 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
437 echo "You can either delete this directory manually, or force the test by rerunning"
438 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
439 exit 1
440 fi
441
Gilles Peskinec9663b12019-01-09 22:30:01 +0100442 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100443 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
444 echo "You can either delete or preserve your work, or force the test by rerunning the"
445 echo "script as: $0 --force"
446 exit 1
447 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100448 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100449}
SimonB2e23c822016-04-16 21:54:39 +0100450
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100451pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100452 failure_summary=
453 failure_count=0
454 start_red=
455 end_color=
456 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100457 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100458 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
459 start_red=$(printf '\033[31m')
460 end_color=$(printf '\033[0m')
461 ;;
462 esac
463 fi
464 record_status () {
465 if "$@"; then
466 last_status=0
467 else
468 last_status=$?
469 text="$current_section: $* -> $last_status"
470 failure_summary="$failure_summary
471$text"
472 failure_count=$((failure_count + 1))
473 echo "${start_red}^^^^$text^^^^${end_color}"
474 fi
475 }
476 make () {
477 case "$*" in
478 *test|*check)
479 if [ $build_status -eq 0 ]; then
480 record_status command make "$@"
481 else
482 echo "(skipped because the build failed)"
483 fi
484 ;;
485 *)
486 record_status command make "$@"
487 build_status=$last_status
488 ;;
489 esac
490 }
491 final_report () {
492 if [ $failure_count -gt 0 ]; then
493 echo
494 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
495 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
496 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100497 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100498 elif [ -z "${1-}" ]; then
499 echo "SUCCESS :)"
500 fi
501 if [ -n "${1-}" ]; then
502 echo "Killed by SIG$1."
503 fi
504 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100505}
506
Gilles Peskine7c652162017-12-11 00:01:40 +0100507if_build_succeeded () {
508 if [ $build_status -eq 0 ]; then
509 record_status "$@"
510 fi
511}
512
Gilles Peskine30bc3852019-01-09 23:25:25 +0100513# to be used instead of ! for commands run with
514# record_status or if_build_succeeded
515not() {
516 ! "$@"
517}
518
519
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100520pre_print_configuration () {
521 msg "info: $0 configuration"
522 echo "MEMORY: $MEMORY"
523 echo "FORCE: $FORCE"
524 echo "SEED: ${SEED-"UNSET"}"
525 echo "OPENSSL: $OPENSSL"
526 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
527 echo "GNUTLS_CLI: $GNUTLS_CLI"
528 echo "GNUTLS_SERV: $GNUTLS_SERV"
529 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
530 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
531 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
532 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
533}
Andres AG7770ea82016-10-10 15:46:20 +0100534
Andres AGd9eba4b2016-08-26 14:42:14 +0100535# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100536pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000537 # Build the list of variables to pass to output_env.sh.
538 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100539
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000540 case " $RUN_COMPONENTS " in
541 # Require OpenSSL and GnuTLS if running any tests (as opposed to
542 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
543 # is a good enough approximation in practice.
544 *" test_"*)
545 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
546 # and ssl-opt.sh, we just export the variables they require.
547 export OPENSSL_CMD="$OPENSSL"
548 export GNUTLS_CLI="$GNUTLS_CLI"
549 export GNUTLS_SERV="$GNUTLS_SERV"
550 # Avoid passing --seed flag in every call to ssl-opt.sh
551 if [ -n "${SEED-}" ]; then
552 export SEED
553 fi
554 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
555 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
556 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
557 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
558 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
559 "$GNUTLS_CLI" "$GNUTLS_SERV" \
560 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
561 ;;
562 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100563
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000564 case " $RUN_COMPONENTS " in
565 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
566 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100567
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000568 case " $RUN_COMPONENTS " in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200569 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000570 esac
571
572 case " $RUN_COMPONENTS " in
573 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
574 esac
575
576 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100577 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000578 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
579 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200580 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000581 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
582 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200583 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
584 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
585 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine53084872019-01-09 23:13:54 +0100586 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100587
588 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100589 case $RUN_COMPONENTS in
590 *_armcc*|*_yotta*)
591 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
592 *) set "$@" RUN_ARMCC=0;;
593 esac
594 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100595}
Andres AGd9eba4b2016-08-26 14:42:14 +0100596
Gilles Peskine192c72f2017-12-21 15:59:21 +0100597
598
599################################################################
600#### Basic checks
601################################################################
SimonB2e23c822016-04-16 21:54:39 +0100602
603#
604# Test Suites to be executed
605#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200606# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100607# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200608# and/or are more likely to fail than others (eg I use Clang most of the
609# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200610# 2. Minimize total running time, by avoiding useless rebuilds
611#
612# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100613
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100614component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100615 msg "test: recursion.pl" # < 1s
616 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100617}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100618
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100619component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100620 msg "test: freshness of generated source files" # < 1s
621 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100622}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000623
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100624component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100625 msg "test: doxygen markup outside doxygen blocks" # < 1s
626 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100627}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200628
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100629component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100630 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100631 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100632}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200633
Gilles Peskinec3189252020-05-10 17:40:49 +0200634component_check_changelog () {
635 msg "Check: changelog entries" # < 1s
636 rm -f ChangeLog.new
637 record_status scripts/assemble_changelog.py -o ChangeLog.new
638 if [ -e ChangeLog.new ]; then
639 # Show the diff for information. It isn't an error if the diff is
640 # non-empty.
641 diff -u ChangeLog ChangeLog.new || true
642 rm ChangeLog.new
643 fi
644}
645
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100646component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100647 msg "test/build: declared and exported names" # < 3s
Gilles Peskinee952fdf2019-05-15 17:52:22 +0200648 record_status tests/scripts/check-names.sh -v
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100649}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200650
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100651component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100652 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100653 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100654}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100655
Simon Butcher948f2642018-07-20 21:27:33 +0100656
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100657################################################################
658#### Build and test many configurations and targets
659################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100660
k-stachowiak45d0ba12019-06-04 13:14:58 +0200661component_test_large_ecdsa_key_signature () {
662
663 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
664
665 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
666 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
667 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
668 make
669
670 INEVITABLY_PRESENT_FILE=Makefile
671 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
672
673 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
674 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
675 rm -f $SIGNATURE_FILE
676}
677
Gilles Peskine1270d322019-04-08 17:00:15 +0200678component_test_default_out_of_box () {
679 msg "build: make, default config (out-of-box)" # ~1min
680 make
681
682 msg "test: main suites make, default config (out-of-box)" # ~10s
683 make test
684
685 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinebfda0332020-04-23 23:37:45 +0200686 if_build_succeeded programs/test/selftest
Gilles Peskine1270d322019-04-08 17:00:15 +0200687}
688
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100689component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100690 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
691 # path, and uses whatever version of armcc it finds there.
692 msg "build: create and build yotta module" # ~ 30s
693 record_status tests/scripts/yotta-build.sh
694}
695support_build_yotta () {
696 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100697}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100698
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100699component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100700 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100701 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100702 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200703
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100704 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100705 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100706
Gilles Peskinebfda0332020-04-23 23:37:45 +0200707 msg "test: selftest (ASan build)" # ~ 10s
708 if_build_succeeded programs/test/selftest
709
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100710 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100711 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100712
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100713 msg "test: compat.sh (ASan build)" # ~ 6 min
714 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100715}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000716
Hanno Becker167ae432019-02-26 14:27:09 +0000717component_test_full_cmake_gcc_asan () {
718 msg "build: full config, cmake, gcc, ASan"
719 scripts/config.pl full
720 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
721 make
722
723 msg "test: main suites (inc. selftests) (full config, ASan build)"
724 make test
725
Gilles Peskinebfda0332020-04-23 23:37:45 +0200726 msg "test: selftest (ASan build)" # ~ 10s
727 if_build_succeeded programs/test/selftest
728
Hanno Becker167ae432019-02-26 14:27:09 +0000729 msg "test: ssl-opt.sh (full config, ASan build)"
730 if_build_succeeded tests/ssl-opt.sh
731
732 msg "test: compat.sh (full config, ASan build)"
733 if_build_succeeded tests/compat.sh
734}
735
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100736component_test_zlib_make() {
737 msg "build: zlib enabled, make"
738 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
739 make ZLIB=1 CFLAGS='-Werror -O1'
740
741 msg "test: main suites (zlib, make)"
742 make test
743
744 msg "test: ssl-opt.sh (zlib, make)"
745 if_build_succeeded tests/ssl-opt.sh
746}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100747support_test_zlib_make () {
748 base=support_test_zlib_$$
749 cat <<'EOF' > ${base}.c
750#include "zlib.h"
751int main(void) { return 0; }
752EOF
753 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
754 ret=$?
755 rm -f ${base}.*
756 return $ret
757}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100758
759component_test_zlib_cmake() {
760 msg "build: zlib enabled, cmake"
761 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
762 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
763 make
764
765 msg "test: main suites (zlib, cmake)"
766 make test
767
768 msg "test: ssl-opt.sh (zlib, cmake)"
769 if_build_succeeded tests/ssl-opt.sh
770}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100771support_test_zlib_cmake () {
772 support_test_zlib_make "$@"
773}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100774
Gilles Peskine3484ed82019-01-08 22:51:19 +0100775component_test_ref_configs () {
776 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
777 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
778 record_status tests/scripts/test-ref-configs.pl
779}
780
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100781component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100782 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100783 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
784 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
785 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000786
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100787 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
788 make test
789
790 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
791 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
792 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
793
794 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
795 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100796}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100797
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100798component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100799 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100800 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
801 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
802 make
803
804 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
805 make test
806
807 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
808 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100809}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100810
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100811component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100812 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100813 scripts/config.pl set MBEDTLS_RSA_NO_CRT
814 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
815 make
816
817 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
818 make test
819
820 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
821 if_build_succeeded tests/ssl-opt.sh -f RSA
822
823 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
824 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100825}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100826
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200827component_test_no_ctr_drbg () {
828 msg "build: Full minus CTR_DRBG"
829 scripts/config.pl full
830 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
831
832 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
833 make
834
835 msg "test: no CTR_DRBG"
836 make test
837
Manuel Pégourié-Gonnardcdfa2f92020-06-05 09:29:51 +0200838 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
839}
840
841component_test_no_hmac_drbg () {
842 msg "build: Full minus HMAC_DRBG"
843 scripts/config.pl full
844 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
845 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
846
847 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
848 make
849
850 msg "test: no HMAC_DRBG"
851 make test
852
853 # No ssl-opt.sh/compat.sh as they never use HMAC_DRBG so far,
854 # so there's little value in running those lengthy tests here.
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200855}
856
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100857component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100858 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100859 scripts/config.pl full
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100860 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
861 make
862
863 msg "test: main suites (full config)" # ~ 5s
864 make test
865
866 msg "test: ssl-opt.sh default (full config)" # ~ 1s
867 if_build_succeeded tests/ssl-opt.sh -f Default
868
Andres Amaya Garcia0a0e5b12019-01-08 21:42:27 +0000869 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000870 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 +0100871}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100872
Gilles Peskineadaaddb2020-04-28 14:04:28 +0200873component_test_default_no_deprecated () {
874 # Test that removing the deprecated features from the default
875 # configuration leaves something consistent.
876 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100877 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskineadaaddb2020-04-28 14:04:28 +0200878 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
879
880 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
881 make test
882}
883
884component_test_full_deprecated_warning () {
885 # Test that there is nothing deprecated in the full configuraration.
886 # A deprecated feature would trigger a warning (made fatal) from
887 # MBEDTLS_DEPRECATED_WARNING.
888 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
889 scripts/config.pl full
890 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
891 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
892 # There are currently no tests for any deprecated feature.
893 # If some are added, 'make test' would trigger warnings here.
894 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
895
896 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
897 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100898}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100899
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100900component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100901 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100902 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100903}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100904
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100905component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100906 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100907 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100908}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100909
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100910component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100911 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100912 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100913}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100914
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100915component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100916 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100917 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100918}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100919
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100920component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100921 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100922 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100923}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100924
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100925component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100926 # Full configuration build, without platform support, file IO and net sockets.
927 # This should catch missing mbedtls_printf definitions, and by disabling file
928 # IO, it should catch missing '#include <stdio.h>'
929 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100930 scripts/config.pl full
931 scripts/config.pl unset MBEDTLS_PLATFORM_C
932 scripts/config.pl unset MBEDTLS_NET_C
933 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
934 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
935 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
936 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
937 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
938 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinea21c5e92020-04-28 10:41:20 +0200939 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100940 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100941 scripts/config.pl unset MBEDTLS_FS_IO
942 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
943 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskinec9247122019-09-20 19:23:10 +0200944 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
945 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100946}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100947
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100948component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949 # catch compile bugs in _uninit functions
950 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100951 scripts/config.pl full
952 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
953 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +0200954 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec9247122019-09-20 19:23:10 +0200955 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100956}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100957
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100958component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100959 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100960 scripts/config.pl full
961 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200962 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100963}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100964
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100965component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100966 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100967 scripts/config.pl full
968 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200969 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100970}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100971
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100972component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100973 # Note, C99 compliance can also be tested with the sockets support disabled,
974 # as that requires a POSIX platform (which isn't the same as C99).
975 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100976 scripts/config.pl full
977 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
978 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinec9247122019-09-20 19:23:10 +0200979 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100980}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100981
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400982component_test_memory_buffer_allocator_backtrace () {
983 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000984 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400985 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000986 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9b1c2482019-09-10 02:58:34 -0400987 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400988 CC=gcc cmake .
989 make
990
991 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
992 make test
993}
994
995component_test_memory_buffer_allocator () {
996 msg "build: default config with memory buffer allocator"
997 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Becker7aad93c2019-06-03 16:35:02 +0100998 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000999 CC=gcc cmake .
1000 make
1001
1002 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1003 make test
1004
1005 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek6addfdd2019-09-05 10:09:37 -04001006 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1007 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001008}
1009
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001010component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001011 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001012 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1013 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1014 make
1015
1016 msg "test: ssl-opt.sh, MFL-related tests"
1017 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001018}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001019
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001020component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001021 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001022 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1023 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1024 scripts/config.pl set MBEDTLS_ENTROPY_C
1025 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +02001026 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001027 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1028 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +00001029 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001030 make
1031
1032 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1033 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001034}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001035
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001036component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001037 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001038 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1039 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1040 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1041 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1042 make
1043
1044 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1045 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001046}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001047
Gilles Peskine0981a5d2019-09-17 19:04:38 +02001048component_test_malloc_0_null () {
1049 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1050 scripts/config.pl full
1051 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1052 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'
1053
1054 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1055 make test
1056
1057 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1058 # Just the calloc selftest. "make test" ran the others as part of the
1059 # test suites.
1060 if_build_succeeded programs/test/selftest calloc
1061}
1062
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001063component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001064 msg "build/test: make shared" # ~ 40s
1065 make SHARED=1 all check
Gilles Peskine950de1e2019-07-03 20:43:32 +02001066 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001067}
1068
Gilles Peskine17ecb242019-07-03 20:43:05 +02001069component_test_cmake_shared () {
1070 msg "build/test: cmake shared" # ~ 2min
1071 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1072 make
Gilles Peskine950de1e2019-07-03 20:43:32 +02001073 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine17ecb242019-07-03 20:43:05 +02001074 make test
1075}
1076
Gilles Peskinefa0e8b52019-09-20 19:56:06 +02001077test_build_opt () {
1078 info=$1 cc=$2; shift 2
1079 for opt in "$@"; do
1080 msg "build/test: $cc $opt, $info" # ~ 30s
1081 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1082 # We're confident enough in compilers to not run _all_ the tests,
1083 # but at least run the unit tests. In particular, runs with
1084 # optimizations use inline assembly whereas runs with -O0
1085 # skip inline assembly.
1086 make test # ~30s
1087 make clean
1088 done
1089}
1090
1091component_test_clang_opt () {
1092 scripts/config.pl full
1093 test_build_opt 'full config' clang -O0 -Os -O2
1094}
1095
1096component_test_gcc_opt () {
1097 scripts/config.pl full
1098 test_build_opt 'full config' gcc -O0 -Os -O2
1099}
1100
Gilles Peskinef852f5f2019-07-03 20:42:16 +02001101component_build_mbedtls_config_file () {
1102 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1103 # Use the full config so as to catch a maximum of places where
1104 # the check of MBEDTLS_CONFIG_FILE might be missing.
1105 scripts/config.pl full
1106 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1107 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1108 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1109 rm -f full_config.h
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001110}
1111
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001112component_test_m32_o0 () {
1113 # Build once with -O0, to compile out the i386 specific inline assembly
1114 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1115 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001116 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001117
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001118 msg "test: i386, make, gcc -O0 (ASan build)"
1119 make test
1120}
1121support_test_m32_o0 () {
1122 case $(uname -m) in
1123 *64*) true;;
1124 *) false;;
1125 esac
1126}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001127
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001128component_test_m32_o1 () {
1129 # Build again with -O1, to compile in the i386 specific inline assembly
1130 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1131 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001132 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001133
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001134 msg "test: i386, make, gcc -O1 (ASan build)"
1135 make test
Gilles Peskine11064292019-04-08 16:58:02 +02001136
1137 msg "test ssl-opt.sh, i386, make, gcc-O1"
1138 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001139}
1140support_test_m32_o1 () {
1141 support_test_m32_o0 "$@"
1142}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001143
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001144component_test_mx32 () {
1145 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1146 scripts/config.pl full
Gilles Peskined535f4d2019-06-07 14:50:09 +02001147 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001148
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001149 msg "test: 64-bit ILP32, make, gcc"
1150 make test
1151}
1152support_test_mx32 () {
1153 case $(uname -m) in
1154 amd64|x86_64) true;;
1155 *) false;;
1156 esac
1157}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001158
Peter Kolbus16015dd2018-12-27 06:59:04 -06001159component_test_min_mpi_window_size () {
1160 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1161 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1162 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1163 make
1164
1165 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1166 make test
1167}
1168
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001169component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001170 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001171 scripts/config.pl unset MBEDTLS_HAVE_ASM
1172 scripts/config.pl unset MBEDTLS_AESNI_C
1173 scripts/config.pl unset MBEDTLS_PADLOCK_C
1174 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1175
1176 msg "test: gcc, force 32-bit bignum limbs"
1177 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001178}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001179
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001180component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001181 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001182 scripts/config.pl unset MBEDTLS_HAVE_ASM
1183 scripts/config.pl unset MBEDTLS_AESNI_C
1184 scripts/config.pl unset MBEDTLS_PADLOCK_C
1185 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1186
1187 msg "test: gcc, force 64-bit bignum limbs"
1188 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001189}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001190
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001191component_build_arm_none_eabi_gcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001192 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001193 scripts/config.pl baremetal
Gilles Peskine009908b2020-04-30 22:54:00 +02001194 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 +02001195
1196 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1197 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001198}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001199
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001200component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001201 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001202 scripts/config.pl baremetal
1203 # Build for a target platform that's close to what Debian uses
1204 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1205 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1206 # It would be better to build with arm-linux-gnueabi-gcc but
1207 # we don't have that on our CI at this time.
1208 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 +02001209
1210 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1211 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001212}
1213
Gilles Peskine4fb7a2f2020-04-30 23:00:53 +02001214component_build_arm_none_eabi_gcc_m0plus () {
1215 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1216 scripts/config.pl baremetal
1217 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 +02001218
1219 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1220 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001221}
1222
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001223component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001224 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001225 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001226 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001227 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 +01001228 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +01001229 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001230}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001231
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001232component_build_armcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001233 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001234 scripts/config.pl baremetal
Gilles Peskine53084872019-01-09 23:13:54 +01001235 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001236
1237 msg "size: ARM Compiler 5"
1238 "$ARMC5_FROMELF" -z library/*.o
1239
Gilles Peskine53084872019-01-09 23:13:54 +01001240 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001241
Gilles Peskine53084872019-01-09 23:13:54 +01001242 # ARM Compiler 6 - Target ARMv7-A
1243 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001244
Gilles Peskine53084872019-01-09 23:13:54 +01001245 # ARM Compiler 6 - Target ARMv7-M
1246 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001247
Gilles Peskine53084872019-01-09 23:13:54 +01001248 # ARM Compiler 6 - Target ARMv8-A - AArch32
1249 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001250
Gilles Peskine53084872019-01-09 23:13:54 +01001251 # ARM Compiler 6 - Target ARMv8-M
1252 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001253
Gilles Peskine53084872019-01-09 23:13:54 +01001254 # ARM Compiler 6 - Target ARMv8-A - AArch64
1255 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001256}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001257
Andres Amaya Garciabb13e3b2018-12-05 22:03:56 +00001258component_build_ssl_hw_record_accel() {
1259 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1260 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1261 make CFLAGS='-Werror -O1'
1262}
1263
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001264component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001265 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001266 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1267 make CFLAGS='-Werror -Wall -Wextra'
1268 msg "test: allow SHA1 in certificates by default"
1269 make test
1270 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001271}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001272
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001273component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001274 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001275 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
1276
1277 # note Make tests only builds the tests, but doesn't run them
1278 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1279 make WINDOWS_BUILD=1 clean
1280
1281 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1282 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
1283 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
1284 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001285}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001286
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001287component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001288 msg "build: MSan (clang)" # ~ 1 min 20s
1289 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1290 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1291 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001292
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001293 msg "test: main suites (MSan)" # ~ 10s
1294 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001295
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001296 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1297 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001298
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001299 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001300
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001301 if [ "$MEMORY" -gt 0 ]; then
1302 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1303 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001304 fi
1305}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001306
Gilles Peskine9f553642019-01-10 00:11:42 +01001307component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001308 msg "build: Release (clang)"
1309 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1310 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001311
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001312 msg "test: main suites valgrind (Release)"
1313 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001314
Gilles Peskine26cae712019-04-08 17:00:56 +02001315 # Optional parts (slow; currently broken on OS X because programs don't
1316 # seem to receive signals under valgrind on OS X).
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001317 if [ "$MEMORY" -gt 0 ]; then
1318 msg "test: ssl-opt.sh --memcheck (Release)"
1319 if_build_succeeded tests/ssl-opt.sh --memcheck
1320 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001321
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001322 if [ "$MEMORY" -gt 1 ]; then
1323 msg "test: compat.sh --memcheck (Release)"
1324 if_build_succeeded tests/compat.sh --memcheck
1325 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001326}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001327
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001328component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001329 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001330 MBEDTLS_ROOT_DIR="$PWD"
1331 mkdir "$OUT_OF_SOURCE_DIR"
1332 cd "$OUT_OF_SOURCE_DIR"
1333 cmake "$MBEDTLS_ROOT_DIR"
1334 make
1335
1336 msg "test: cmake 'out-of-source' build"
1337 make test
1338 # Test an SSL option that requires an auxiliary script in test/scripts/.
1339 # Also ensure that there are no error messages such as
1340 # "No such file or directory", which would indicate that some required
1341 # file is missing (ssl-opt.sh tolerates the absence of some files so
1342 # may exit with status 0 but emit errors).
1343 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1344 if [ -s ssl-opt.err ]; then
1345 cat ssl-opt.err >&2
1346 record_status [ ! -s ssl-opt.err ]
1347 rm ssl-opt.err
1348 fi
1349 cd "$MBEDTLS_ROOT_DIR"
1350 rm -rf "$OUT_OF_SOURCE_DIR"
1351 unset MBEDTLS_ROOT_DIR
1352}
Andres AGdc192212016-08-31 17:33:13 +01001353
Gilles Peskine192c72f2017-12-21 15:59:21 +01001354
1355
1356################################################################
1357#### Termination
1358################################################################
1359
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001360post_report () {
1361 msg "Done, cleaning up"
1362 cleanup
1363
1364 final_report
1365}
1366
1367
1368
1369################################################################
1370#### Run all the things
1371################################################################
1372
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001373# Run one component and clean up afterwards.
1374run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001375 # Back up the configuration in case the component modifies it.
1376 # The cleanup function will restore it.
1377 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001378 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001379 "$@"
1380 cleanup
1381}
1382
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001383# Preliminary setup
1384pre_check_environment
1385pre_initialize_variables
1386pre_parse_command_line "$@"
1387
1388pre_check_git
1389build_status=0
1390if [ $KEEP_GOING -eq 1 ]; then
1391 pre_setup_keep_going
1392else
1393 record_status () {
1394 "$@"
1395 }
1396fi
1397pre_print_configuration
1398pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001399cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001400
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001401# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001402for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001403 run_component "component_$component"
1404done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001405
1406# We're done.
1407post_report