blob: 560ff792812fd336b8e15a12809c9503834e3e10 [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útif744bd72020-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úti51b41d52020-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útif744bd72020-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úti51b41d52020-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)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040078# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010079# * arm-gcc and mingw-gcc
80# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010081# * 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 Peskine8f073122018-11-27 15:58:47 +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.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100102# * 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.
Gilles Peskine878cf602019-01-06 20:50:38 +0000105# * support_XXX: if support_XXX exists and returns false then
106# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +0100107# * post_XXX: things to do after running the tests.
108# * other: miscellaneous support functions.
109#
Gilles Peskinec70637a2019-01-09 22:29:17 +0100110# 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 Peskine8f073122018-11-27 15:58:47 +0100148pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000149 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +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 Peskine8f073122018-11-27 15:58:47 +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 Peskine8f073122018-11-27 15:58:47 +0100159 MEMORY=0
160 FORCE=0
161 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100162
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200163 # Seed value used with the --release-test option.
164 # !!! Keep this in sync with SEED in basic-build-test.sh !!!
165 RELEASE_SEED=1
166
Antonin Décimod5f47592019-01-23 15:24:37 +0100167 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100168 : ${OPENSSL:="openssl"}
169 : ${OPENSSL_LEGACY:="$OPENSSL"}
170 : ${OPENSSL_NEXT:="$OPENSSL"}
171 : ${GNUTLS_CLI:="gnutls-cli"}
172 : ${GNUTLS_SERV:="gnutls-serv"}
173 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
174 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
175 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
176 : ${ARMC5_BIN_DIR:=/usr/bin}
177 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200178 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100179
Gilles Peskine8f073122018-11-27 15:58:47 +0100180 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000181 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100182 export MAKEFLAGS="-j"
183 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000184
Gilles Peskineff26b042019-10-21 17:11:33 +0200185 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskineac479062019-10-21 19:06:33 +0200186 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskineff26b042019-10-21 17:11:33 +0200187
Gilles Peskine878cf602019-01-06 20:50:38 +0000188 # Gather the list of available components. These are the functions
189 # defined in this script whose name starts with "component_".
190 # Parse the script with sed, because in sh there is no way to list
191 # defined functions.
192 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
193
194 # Exclude components that are not supported on this platform.
195 SUPPORTED_COMPONENTS=
196 for component in $ALL_COMPONENTS; do
197 case $(type "support_$component" 2>&1) in
198 *' function'*)
199 if ! support_$component; then continue; fi;;
200 esac
201 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
202 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100203}
Andres AG38495a32016-07-12 16:54:33 +0100204
Gilles Peskinea28db922019-01-10 00:05:18 +0100205# Test whether the component $1 is included in the command line patterns.
206is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100207{
208 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000209 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100210 set +f
211 case ${1#component_} in $pattern) return 0;; esac
212 done
213 set +f
214 return 1
215}
216
Simon Butcher41eeccf2016-09-07 00:07:09 +0100217usage()
SimonB2e23c822016-04-16 21:54:39 +0100218{
Gilles Peskine709346a2017-12-10 23:43:39 +0100219 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100220Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100221Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100222By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100223COMPONENT can be the name of a component or a shell wildcard pattern.
224
225Examples:
226 $0 "check_*"
227 Run all sanity checks.
228 $0 --no-armcc --except test_memsan
229 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100230
231Special options:
232 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000233 --list-all-components List all available test components and exit.
234 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100235
236General options:
237 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100238 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100239 -m|--memory Additional optional memory tests.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200240 --arm-none-eabi-gcc-prefix=<string>
241 Prefix for a cross-compiler for arm-none-eabi
242 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100243 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100244 --except Exclude the COMPONENTs listed on the command line,
245 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100246 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100247 --no-force Refuse to overwrite modified files (default).
248 --no-keep-going Stop at the first error (default).
249 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100250 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100251 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200252 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100253 -s|--seed Integer seed value to use for this test run.
254
255Tool path options:
256 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
257 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
258 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
259 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
260 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
261 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
262 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
263 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100264 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100265EOF
SimonB2e23c822016-04-16 21:54:39 +0100266}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100267
268# remove built files as well as the cmake cache/config
269cleanup()
270{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100271 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
272 cd "$MBEDTLS_ROOT_DIR"
273 fi
274
Gilles Peskine7c652162017-12-11 00:01:40 +0100275 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200276
Gilles Peskine31b07e22018-03-21 12:15:06 +0100277 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100278 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100279 -iname CMakeFiles -exec rm -rf {} \+ -o \
280 \( -iname cmake_install.cmake -o \
281 -iname CTestTestfile.cmake -o \
282 -iname CMakeCache.txt \) -exec rm {} \+
283 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000284 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200285 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
286 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200287
288 if [ -f "$CONFIG_BAK" ]; then
289 mv "$CONFIG_BAK" "$CONFIG_H"
290 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100291}
292
Gilles Peskine7c652162017-12-11 00:01:40 +0100293# Executed on exit. May be redefined depending on command line options.
294final_report () {
295 :
296}
297
298fatal_signal () {
299 cleanup
300 final_report $1
301 trap - $1
302 kill -$1 $$
303}
304
305trap 'fatal_signal HUP' HUP
306trap 'fatal_signal INT' INT
307trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200308
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100309msg()
310{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100311 if [ -n "${current_component:-}" ]; then
312 current_section="${current_component#component_}: $1"
313 else
314 current_section="$1"
315 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100316 echo ""
317 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100318 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000319 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100320 echo "******************************************************************"
321}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100322
Gilles Peskine8f073122018-11-27 15:58:47 +0100323armc6_build_test()
324{
325 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100326
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200327 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100328 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
329 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200330
331 msg "size: ARM Compiler 6 ($FLAGS)"
332 "$ARMC6_FROMELF" -z library/*.o
333
Gilles Peskine8f073122018-11-27 15:58:47 +0100334 make clean
335}
Andres AGa5cd9732016-10-17 15:23:10 +0100336
Andres AGd9eba4b2016-08-26 14:42:14 +0100337err_msg()
338{
339 echo "$1" >&2
340}
341
342check_tools()
343{
344 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000345 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100346 err_msg "$TOOL not found!"
347 exit 1
348 fi
349 done
350}
351
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400352check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600353 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400354 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
355 sort |
356 diff headers.txt -
357 rm headers.txt
358}
359
Gilles Peskine8f073122018-11-27 15:58:47 +0100360pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000361 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100362 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000363 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000364
Gilles Peskine8f073122018-11-27 15:58:47 +0100365 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100366 case "$1" in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200367 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000368 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100369 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
370 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000371 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100372 --force|-f) FORCE=1;;
373 --gnutls-cli) shift; GNUTLS_CLI="$1";;
374 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
375 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
376 --gnutls-serv) shift; GNUTLS_SERV="$1";;
377 --help|-h) usage; exit;;
378 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000379 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
380 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100381 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000382 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100383 --no-force) FORCE=0;;
384 --no-keep-going) KEEP_GOING=0;;
385 --no-memory) MEMORY=0;;
386 --openssl) shift; OPENSSL="$1";;
387 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
388 --openssl-next) shift; OPENSSL_NEXT="$1";;
389 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
390 --random-seed) unset SEED;;
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200391 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100392 --seed|-s) shift; SEED="$1";;
393 -*)
394 echo >&2 "Unknown option: $1"
395 echo >&2 "Run $0 --help for usage."
396 exit 120
397 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000398 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100399 esac
400 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100401 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000402
Gilles Peskinea28db922019-01-10 00:05:18 +0100403 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000404 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
405 all_except=1
406 fi
407
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000408 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
409 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100410 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000411 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
412 fi
413
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000414 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100415 RUN_COMPONENTS=
416 for component in $SUPPORTED_COMPONENTS; do
417 if is_component_included "$component"; [ $? -eq $all_except ]; then
418 RUN_COMPONENTS="$RUN_COMPONENTS $component"
419 fi
420 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000421
422 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000423 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100424}
SimonB2e23c822016-04-16 21:54:39 +0100425
Gilles Peskine8f073122018-11-27 15:58:47 +0100426pre_check_git () {
427 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100428 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100429 git checkout-index -f -q $CONFIG_H
430 cleanup
431 else
SimonB2e23c822016-04-16 21:54:39 +0100432
Gilles Peskine8f073122018-11-27 15:58:47 +0100433 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
434 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
435 echo "You can either delete this directory manually, or force the test by rerunning"
436 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
437 exit 1
438 fi
439
Gilles Peskined1174cf2019-01-09 22:30:01 +0100440 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100441 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
442 echo "You can either delete or preserve your work, or force the test by rerunning the"
443 echo "script as: $0 --force"
444 exit 1
445 fi
Andres AGdc192212016-08-31 17:33:13 +0100446 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100447}
Andres AGdc192212016-08-31 17:33:13 +0100448
Gilles Peskine8f073122018-11-27 15:58:47 +0100449pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100450 failure_summary=
451 failure_count=0
452 start_red=
453 end_color=
454 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100455 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100456 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
457 start_red=$(printf '\033[31m')
458 end_color=$(printf '\033[0m')
459 ;;
460 esac
461 fi
462 record_status () {
463 if "$@"; then
464 last_status=0
465 else
466 last_status=$?
467 text="$current_section: $* -> $last_status"
468 failure_summary="$failure_summary
469$text"
470 failure_count=$((failure_count + 1))
471 echo "${start_red}^^^^$text^^^^${end_color}"
472 fi
473 }
474 make () {
475 case "$*" in
476 *test|*check)
477 if [ $build_status -eq 0 ]; then
478 record_status command make "$@"
479 else
480 echo "(skipped because the build failed)"
481 fi
482 ;;
483 *)
484 record_status command make "$@"
485 build_status=$last_status
486 ;;
487 esac
488 }
489 final_report () {
490 if [ $failure_count -gt 0 ]; then
491 echo
492 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
493 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
494 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100495 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100496 elif [ -z "${1-}" ]; then
497 echo "SUCCESS :)"
498 fi
499 if [ -n "${1-}" ]; then
500 echo "Killed by SIG$1."
501 fi
502 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100503}
504
Gilles Peskine7c652162017-12-11 00:01:40 +0100505if_build_succeeded () {
506 if [ $build_status -eq 0 ]; then
507 record_status "$@"
508 fi
509}
510
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200511# to be used instead of ! for commands run with
512# record_status or if_build_succeeded
513not() {
514 ! "$@"
515}
516
Gilles Peskine8f073122018-11-27 15:58:47 +0100517pre_print_configuration () {
518 msg "info: $0 configuration"
519 echo "MEMORY: $MEMORY"
520 echo "FORCE: $FORCE"
521 echo "SEED: ${SEED-"UNSET"}"
522 echo "OPENSSL: $OPENSSL"
523 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
524 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
525 echo "GNUTLS_CLI: $GNUTLS_CLI"
526 echo "GNUTLS_SERV: $GNUTLS_SERV"
527 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
528 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
529 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
530 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
531}
Andres AG87bb5772016-09-27 15:05:15 +0100532
Gilles Peskine87964262019-01-06 22:40:00 +0000533# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100534pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000535 # Build the list of variables to pass to output_env.sh.
536 set env
537
Gilles Peskine87964262019-01-06 22:40:00 +0000538 case " $RUN_COMPONENTS " in
539 # Require OpenSSL and GnuTLS if running any tests (as opposed to
540 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
541 # is a good enough approximation in practice.
542 *" test_"*)
543 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
544 # and ssl-opt.sh, we just export the variables they require.
545 export OPENSSL_CMD="$OPENSSL"
546 export GNUTLS_CLI="$GNUTLS_CLI"
547 export GNUTLS_SERV="$GNUTLS_SERV"
548 # Avoid passing --seed flag in every call to ssl-opt.sh
549 if [ -n "${SEED-}" ]; then
550 export SEED
551 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000552 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
553 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
554 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
555 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000556 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
557 "$GNUTLS_CLI" "$GNUTLS_SERV" \
558 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
559 ;;
560 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100561
Gilles Peskine87964262019-01-06 22:40:00 +0000562 case " $RUN_COMPONENTS " in
563 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
564 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100565
Gilles Peskine87964262019-01-06 22:40:00 +0000566 case " $RUN_COMPONENTS " in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200567 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000568 esac
Andres AG7770ea82016-10-10 15:46:20 +0100569
Gilles Peskine87964262019-01-06 22:40:00 +0000570 case " $RUN_COMPONENTS " in
571 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
572 esac
573
574 case " $RUN_COMPONENTS " in
575 *" test_zeroize "*) check_tools "gdb";;
576 esac
577
578 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000579 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000580 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
581 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200582 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000583 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
584 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200585 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
586 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
587 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000588 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000589
590 msg "info: output_env.sh"
591 case $RUN_COMPONENTS in
592 *_armcc*)
593 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
594 *) set "$@" RUN_ARMCC=0;;
595 esac
596 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100597}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100598
599
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000600
Gilles Peskine192c72f2017-12-21 15:59:21 +0100601################################################################
602#### Basic checks
603################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100604
SimonB2e23c822016-04-16 21:54:39 +0100605#
606# Test Suites to be executed
607#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200608# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100609# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200610# and/or are more likely to fail than others (eg I use Clang most of the
611# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200612# 2. Minimize total running time, by avoiding useless rebuilds
613#
614# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100615
Gilles Peskine8f073122018-11-27 15:58:47 +0100616component_check_recursion () {
617 msg "test: recursion.pl" # < 1s
618 record_status tests/scripts/recursion.pl library/*.c
619}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621component_check_generated_files () {
622 msg "test: freshness of generated source files" # < 1s
623 record_status tests/scripts/check-generated-files.sh
624}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000625
Gilles Peskine8f073122018-11-27 15:58:47 +0100626component_check_doxy_blocks () {
627 msg "test: doxygen markup outside doxygen blocks" # < 1s
628 record_status tests/scripts/check-doxy-blocks.pl
629}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631component_check_files () {
632 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100633 record_status tests/scripts/check-files.py
634}
Darryl Greena07039c2018-03-13 16:48:16 +0000635
Gilles Peskine3c23c822020-05-10 17:40:49 +0200636component_check_changelog () {
637 msg "Check: changelog entries" # < 1s
638 rm -f ChangeLog.new
639 record_status scripts/assemble_changelog.py -o ChangeLog.new
640 if [ -e ChangeLog.new ]; then
641 # Show the diff for information. It isn't an error if the diff is
642 # non-empty.
643 diff -u ChangeLog ChangeLog.new || true
644 rm ChangeLog.new
645 fi
646}
647
Gilles Peskine8f073122018-11-27 15:58:47 +0100648component_check_names () {
649 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200650 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100651}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200652
Gilles Peskine8f073122018-11-27 15:58:47 +0100653component_check_doxygen_warnings () {
654 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100655 record_status tests/scripts/doxygen.sh
656}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100657
Gilles Peskine192c72f2017-12-21 15:59:21 +0100658
659
660################################################################
661#### Build and test many configurations and targets
662################################################################
663
k-stachowiak11f38e22019-06-04 13:14:58 +0200664component_test_large_ecdsa_key_signature () {
665
666 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
667
668 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
669 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
670 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
671 make
672
673 INEVITABLY_PRESENT_FILE=Makefile
674 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
675
676 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
677 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
678 rm -f $SIGNATURE_FILE
679}
680
Gilles Peskine99a33102019-04-08 17:00:15 +0200681component_test_default_out_of_box () {
682 msg "build: make, default config (out-of-box)" # ~1min
683 make
684
685 msg "test: main suites make, default config (out-of-box)" # ~10s
686 make test
687
688 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200689 if_build_succeeded programs/test/selftest
Gilles Peskine99a33102019-04-08 17:00:15 +0200690}
691
Gilles Peskine8f073122018-11-27 15:58:47 +0100692component_test_default_cmake_gcc_asan () {
693 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
695 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
698 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200699
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200700 msg "test: selftest (ASan build)" # ~ 10s
701 if_build_succeeded programs/test/selftest
702
Gilles Peskine8f073122018-11-27 15:58:47 +0100703 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
704 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200705
Gilles Peskine8f073122018-11-27 15:58:47 +0100706 msg "test: compat.sh (ASan build)" # ~ 6 min
707 if_build_succeeded tests/compat.sh
708}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200709
Hanno Beckerf8799e82019-02-26 14:27:09 +0000710component_test_full_cmake_gcc_asan () {
711 msg "build: full config, cmake, gcc, ASan"
712 scripts/config.pl full
713 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
714 make
715
716 msg "test: main suites (inc. selftests) (full config, ASan build)"
717 make test
718
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200719 msg "test: selftest (ASan build)" # ~ 10s
720 if_build_succeeded programs/test/selftest
721
Hanno Beckerf8799e82019-02-26 14:27:09 +0000722 msg "test: ssl-opt.sh (full config, ASan build)"
723 if_build_succeeded tests/ssl-opt.sh
724
725 msg "test: compat.sh (full config, ASan build)"
726 if_build_succeeded tests/compat.sh
727}
728
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100729component_test_zlib_make() {
730 msg "build: zlib enabled, make"
731 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
732 make ZLIB=1 CFLAGS='-Werror -O1'
733
734 msg "test: main suites (zlib, make)"
735 make test
736
737 msg "test: ssl-opt.sh (zlib, make)"
738 if_build_succeeded tests/ssl-opt.sh
739}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100740support_test_zlib_make () {
741 base=support_test_zlib_$$
742 cat <<'EOF' > ${base}.c
743#include "zlib.h"
744int main(void) { return 0; }
745EOF
746 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
747 ret=$?
748 rm -f ${base}.*
749 return $ret
750}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100751
752component_test_zlib_cmake() {
753 msg "build: zlib enabled, cmake"
754 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
755 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
756 make
757
758 msg "test: main suites (zlib, cmake)"
759 make test
760
761 msg "test: ssl-opt.sh (zlib, cmake)"
762 if_build_succeeded tests/ssl-opt.sh
763}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100764support_test_zlib_cmake () {
765 support_test_zlib_make "$@"
766}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100767
Gilles Peskine782f4112018-11-27 16:11:09 +0100768component_test_ref_configs () {
769 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
770 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
771 record_status tests/scripts/test-ref-configs.pl
772}
773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774component_test_sslv3 () {
775 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100776 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
777 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
778 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000779
Gilles Peskine8f073122018-11-27 15:58:47 +0100780 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
781 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000782
Gilles Peskine8f073122018-11-27 15:58:47 +0100783 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
784 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
785 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000786
Gilles Peskine8f073122018-11-27 15:58:47 +0100787 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
788 if_build_succeeded tests/ssl-opt.sh
789}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791component_test_no_renegotiation () {
792 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100793 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
794 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
795 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100796
Gilles Peskine8f073122018-11-27 15:58:47 +0100797 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
798 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
801 if_build_succeeded tests/ssl-opt.sh
802}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100803
Hanno Beckere562e7d2019-05-10 14:45:37 +0100804component_test_no_pem_no_fs () {
805 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
806 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
807 scripts/config.pl unset MBEDTLS_FS_IO
808 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
809 make
810
811 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
812 make test
813
814 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
815 if_build_succeeded tests/ssl-opt.sh
816}
817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818component_test_rsa_no_crt () {
819 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100820 scripts/config.pl set MBEDTLS_RSA_NO_CRT
821 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
822 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
825 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
828 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
831 if_build_succeeded tests/compat.sh -t RSA
832}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100833
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200834component_test_no_ctr_drbg () {
835 msg "build: Full minus CTR_DRBG"
836 scripts/config.pl full
837 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
838
839 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
840 make
841
842 msg "test: no CTR_DRBG"
843 make test
844
Manuel Pégourié-Gonnardc5243c12020-06-05 09:29:51 +0200845 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
846}
847
848component_test_no_hmac_drbg () {
849 msg "build: Full minus HMAC_DRBG"
850 scripts/config.pl full
851 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
852 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
853
854 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
855 make
856
857 msg "test: no HMAC_DRBG"
858 make test
859
860 # No ssl-opt.sh/compat.sh as they never use HMAC_DRBG so far,
861 # so there's little value in running those lengthy tests here.
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200862}
863
Gilles Peskine8f073122018-11-27 15:58:47 +0100864component_test_small_ssl_out_content_len () {
865 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
867 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
868 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
869 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
872 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
873}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000874
Gilles Peskine8f073122018-11-27 15:58:47 +0100875component_test_small_ssl_in_content_len () {
876 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100877 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
878 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
879 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
880 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000881
Gilles Peskine8f073122018-11-27 15:58:47 +0100882 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
883 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
884}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000885
Gilles Peskine8f073122018-11-27 15:58:47 +0100886component_test_small_ssl_dtls_max_buffering () {
887 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100888 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
889 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
890 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
893 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
894}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100895
Gilles Peskine8f073122018-11-27 15:58:47 +0100896component_test_small_mbedtls_ssl_dtls_max_buffering () {
897 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100898 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
899 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
900 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100901
Gilles Peskine8f073122018-11-27 15:58:47 +0100902 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
903 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
904}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100905
Gilles Peskine8f073122018-11-27 15:58:47 +0100906component_test_full_cmake_clang () {
907 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100908 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +0100909 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
910 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912 msg "test: main suites (full config)" # ~ 5s
913 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200914
Gilles Peskine8f073122018-11-27 15:58:47 +0100915 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
916 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200917
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +0000918 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000919 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'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921 msg "test: compat.sh ARIA + ChachaPoly"
922 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
923}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100924
Gilles Peskine77b1f302020-04-28 14:04:28 +0200925component_test_default_no_deprecated () {
926 # Test that removing the deprecated features from the default
927 # configuration leaves something consistent.
928 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100929 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine77b1f302020-04-28 14:04:28 +0200930 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
931
932 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
933 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100934}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100935
Gilles Peskine77b1f302020-04-28 14:04:28 +0200936component_test_full_deprecated_warning () {
937 # Test that there is nothing deprecated in the full configuration.
938 # A deprecated feature would trigger a warning (made fatal) from
939 # MBEDTLS_DEPRECATED_WARNING.
940 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
941 scripts/config.pl full
942 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
943 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
944 # There are currently no tests for any deprecated feature.
945 # If some are added, 'make test' would trigger warnings here.
946 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
947
948 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
949 make test
950}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200951
Gilles Peskine8f073122018-11-27 15:58:47 +0100952component_test_depends_curves () {
953 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100954 record_status tests/scripts/curves.pl
955}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200956
Gilles Peskine8f073122018-11-27 15:58:47 +0100957component_test_depends_hashes () {
958 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100959 record_status tests/scripts/depends-hashes.pl
960}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200961
Gilles Peskine8f073122018-11-27 15:58:47 +0100962component_test_depends_pkalgs () {
963 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100964 record_status tests/scripts/depends-pkalgs.pl
965}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200966
Gilles Peskine8f073122018-11-27 15:58:47 +0100967component_build_key_exchanges () {
968 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100969 record_status tests/scripts/key-exchanges.pl
970}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100971
Gilles Peskine8f073122018-11-27 15:58:47 +0100972component_build_default_make_gcc_and_cxx () {
973 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100974 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400975
Gilles Peskine8f073122018-11-27 15:58:47 +0100976 msg "test: verify header list in cpp_dummy_build.cpp"
977 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400978
Gilles Peskine8f073122018-11-27 15:58:47 +0100979 msg "build: Unix make, incremental g++"
980 make TEST_CPP=1
981}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000982
Gilles Peskinedcab2022019-06-12 16:05:50 +0200983component_test_check_params_functionality () {
984 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
985 scripts/config.pl full # includes CHECK_PARAMS
986 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
987 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +0200988 # Only build and run tests. Do not build sample programs, because
989 # they don't have a mbedtls_param_failed() function.
990 make CC=gcc CFLAGS='-Werror -O1' lib test
991}
992
Gilles Peskineb28636b2019-01-02 19:06:24 +0100993component_test_check_params_without_platform () {
994 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
995 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200996 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100997 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
998 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
999 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1000 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001001 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskineb28636b2019-01-02 19:06:24 +01001002 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1003 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1004 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1005 scripts/config.pl unset MBEDTLS_PLATFORM_C
1006 make CC=gcc CFLAGS='-Werror -O1' all test
1007}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001008
Gilles Peskineb28636b2019-01-02 19:06:24 +01001009component_test_check_params_silent () {
1010 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
1011 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001012 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001013 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1014 make CC=gcc CFLAGS='-Werror -O1' all test
1015}
Hanno Becker5175ac62017-09-18 15:36:25 +01001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017component_test_no_platform () {
1018 # Full configuration build, without platform support, file IO and net sockets.
1019 # This should catch missing mbedtls_printf definitions, and by disabling file
1020 # IO, it should catch missing '#include <stdio.h>'
1021 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001022 scripts/config.pl full
1023 scripts/config.pl unset MBEDTLS_PLATFORM_C
1024 scripts/config.pl unset MBEDTLS_NET_C
1025 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1026 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1027 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1028 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1029 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1030 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001031 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001032 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01001033 scripts/config.pl unset MBEDTLS_FS_IO
1034 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1035 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine99d70d82019-09-20 19:23:10 +02001036 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1037 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001038}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001039
Gilles Peskine8f073122018-11-27 15:58:47 +01001040component_build_no_std_function () {
1041 # catch compile bugs in _uninit functions
1042 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001043 scripts/config.pl full
1044 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1045 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001046 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine99d70d82019-09-20 19:23:10 +02001047 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001048}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001049
Gilles Peskine8f073122018-11-27 15:58:47 +01001050component_build_no_ssl_srv () {
1051 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001052 scripts/config.pl full
1053 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001054 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001055}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001056
Gilles Peskine8f073122018-11-27 15:58:47 +01001057component_build_no_ssl_cli () {
1058 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001059 scripts/config.pl full
1060 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001061 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001062}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001063
Gilles Peskine8f073122018-11-27 15:58:47 +01001064component_build_no_sockets () {
1065 # Note, C99 compliance can also be tested with the sockets support disabled,
1066 # as that requires a POSIX platform (which isn't the same as C99).
1067 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001068 scripts/config.pl full
1069 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1070 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine99d70d82019-09-20 19:23:10 +02001071 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001072}
Hanno Becker5175ac62017-09-18 15:36:25 +01001073
Andrzej Kurek1d070822019-09-05 09:27:47 -04001074component_test_memory_buffer_allocator_backtrace () {
1075 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +00001076 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -04001077 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001078 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -04001079 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -04001080 CC=gcc cmake .
1081 make
1082
1083 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1084 make test
1085}
1086
1087component_test_memory_buffer_allocator () {
1088 msg "build: default config with memory buffer allocator"
1089 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +01001090 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001091 CC=gcc cmake .
1092 make
1093
1094 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1095 make test
1096
1097 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -04001098 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1099 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +00001100}
1101
Gilles Peskine8f073122018-11-27 15:58:47 +01001102component_test_no_max_fragment_length () {
1103 # Run max fragment length tests with MFL disabled
1104 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001105 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1106 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1107 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001108
Gilles Peskine8f073122018-11-27 15:58:47 +01001109 msg "test: ssl-opt.sh, MFL-related tests"
1110 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1111}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001112
Gilles Peskine8f073122018-11-27 15:58:47 +01001113component_test_no_max_fragment_length_small_ssl_out_content_len () {
1114 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001115 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1116 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1117 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1118 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1119 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001120
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1122 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1123}
Janos Follath06c54002016-06-09 13:57:40 +01001124
Gilles Peskine8f073122018-11-27 15:58:47 +01001125component_test_null_entropy () {
1126 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1128 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1129 scripts/config.pl set MBEDTLS_ENTROPY_C
1130 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001131 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001132 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1133 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001134 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001135 make
Janos Follath06c54002016-06-09 13:57:40 +01001136
Gilles Peskine8f073122018-11-27 15:58:47 +01001137 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1138 make test
1139}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001140
Gilles Peskine8f073122018-11-27 15:58:47 +01001141component_test_platform_calloc_macro () {
1142 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001143 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1144 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1145 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1146 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1147 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001148
Gilles Peskine8f073122018-11-27 15:58:47 +01001149 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1150 make test
1151}
Hanno Becker83ebf782017-07-07 12:29:15 +01001152
Gilles Peskinec6b09862019-09-17 19:04:38 +02001153component_test_malloc_0_null () {
1154 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1155 scripts/config.pl full
1156 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1157 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'
1158
1159 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1160 make test
1161
1162 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1163 # Just the calloc selftest. "make test" ran the others as part of the
1164 # test suites.
1165 if_build_succeeded programs/test/selftest calloc
1166}
1167
Gilles Peskine8f073122018-11-27 15:58:47 +01001168component_test_aes_fewer_tables () {
1169 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001170 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1171 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001172
Gilles Peskine8f073122018-11-27 15:58:47 +01001173 msg "test: AES_FEWER_TABLES"
1174 make test
1175}
Hanno Becker83ebf782017-07-07 12:29:15 +01001176
Gilles Peskine8f073122018-11-27 15:58:47 +01001177component_test_aes_rom_tables () {
1178 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001179 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1180 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001181
Gilles Peskine8f073122018-11-27 15:58:47 +01001182 msg "test: AES_ROM_TABLES"
1183 make test
1184}
Hanno Becker83ebf782017-07-07 12:29:15 +01001185
Gilles Peskine8f073122018-11-27 15:58:47 +01001186component_test_aes_fewer_tables_and_rom_tables () {
1187 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001188 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1189 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1190 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001191
Gilles Peskine8f073122018-11-27 15:58:47 +01001192 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1193 make test
1194}
1195
1196component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001197 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001198 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001199 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001200}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001201
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001202component_test_cmake_shared () {
1203 msg "build/test: cmake shared" # ~ 2min
1204 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1205 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001206 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001207 make test
1208}
1209
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001210test_build_opt () {
1211 info=$1 cc=$2; shift 2
1212 for opt in "$@"; do
1213 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskine313bb502020-04-14 20:08:41 +02001214 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001215 # We're confident enough in compilers to not run _all_ the tests,
1216 # but at least run the unit tests. In particular, runs with
1217 # optimizations use inline assembly whereas runs with -O0
1218 # skip inline assembly.
1219 make test # ~30s
1220 make clean
1221 done
1222}
1223
1224component_test_clang_opt () {
1225 scripts/config.pl full
1226 test_build_opt 'full config' clang -O0 -Os -O2
1227}
1228
1229component_test_gcc_opt () {
1230 scripts/config.pl full
1231 test_build_opt 'full config' gcc -O0 -Os -O2
1232}
1233
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001234component_build_mbedtls_config_file () {
1235 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1236 # Use the full config so as to catch a maximum of places where
1237 # the check of MBEDTLS_CONFIG_FILE might be missing.
1238 scripts/config.pl full
1239 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1240 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1241 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1242 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001243}
1244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001246 # Build once with -O0, to compile out the i386 specific inline assembly
1247 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001248 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001249 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001250
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001251 msg "test: i386, make, gcc -O0 (ASan build)"
1252 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001253}
Gilles Peskine878cf602019-01-06 20:50:38 +00001254support_test_m32_o0 () {
1255 case $(uname -m) in
1256 *64*) true;;
1257 *) false;;
1258 esac
1259}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001260
Gilles Peskine8f073122018-11-27 15:58:47 +01001261component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001262 # Build again with -O1, to compile in the i386 specific inline assembly
1263 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001264 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001265 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001266
1267 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001268 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001269
1270 msg "test ssl-opt.sh, i386, make, gcc-O1"
1271 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001272}
Gilles Peskine878cf602019-01-06 20:50:38 +00001273support_test_m32_o1 () {
1274 support_test_m32_o0 "$@"
1275}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001276
Gilles Peskine8f073122018-11-27 15:58:47 +01001277component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001278 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001279 scripts/config.pl full
Gilles Peskine8118e462019-06-07 14:50:09 +02001280 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001281
1282 msg "test: 64-bit ILP32, make, gcc"
1283 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001284}
Gilles Peskine878cf602019-01-06 20:50:38 +00001285support_test_mx32 () {
1286 case $(uname -m) in
1287 amd64|x86_64) true;;
1288 *) false;;
1289 esac
1290}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001291
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001292component_test_min_mpi_window_size () {
1293 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1294 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1295 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1296 make
1297
1298 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1299 make test
1300}
1301
Gilles Peskine8f073122018-11-27 15:58:47 +01001302component_test_have_int32 () {
1303 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001304 scripts/config.pl unset MBEDTLS_HAVE_ASM
1305 scripts/config.pl unset MBEDTLS_AESNI_C
1306 scripts/config.pl unset MBEDTLS_PADLOCK_C
1307 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001308
Gilles Peskine8f073122018-11-27 15:58:47 +01001309 msg "test: gcc, force 32-bit bignum limbs"
1310 make test
1311}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001312
Gilles Peskine8f073122018-11-27 15:58:47 +01001313component_test_have_int64 () {
1314 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001315 scripts/config.pl unset MBEDTLS_HAVE_ASM
1316 scripts/config.pl unset MBEDTLS_AESNI_C
1317 scripts/config.pl unset MBEDTLS_PADLOCK_C
1318 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001319
Gilles Peskine8f073122018-11-27 15:58:47 +01001320 msg "test: gcc, force 64-bit bignum limbs"
1321 make test
1322}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001323
Gilles Peskine8f073122018-11-27 15:58:47 +01001324component_test_no_udbl_division () {
1325 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001326 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001327 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1328 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001329
Gilles Peskine8f073122018-11-27 15:58:47 +01001330 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1331 make test
1332}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001333
Gilles Peskine8f073122018-11-27 15:58:47 +01001334component_test_no_64bit_multiplication () {
1335 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001336 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001337 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1338 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001339
Gilles Peskine8f073122018-11-27 15:58:47 +01001340 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1341 make test
1342}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001343
Gilles Peskine8f073122018-11-27 15:58:47 +01001344component_build_arm_none_eabi_gcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001345 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001346 scripts/config.pl baremetal
Gilles Peskinefcccfbc2020-04-30 22:54:00 +02001347 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 Peskinee6c0c7d2020-04-30 23:11:54 +02001348
1349 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1350 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01001351}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001352
Gilles Peskine560f3322019-08-09 16:05:05 +02001353component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001354 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001355 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001356 # Build for a target platform that's close to what Debian uses
1357 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1358 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1359 # It would be better to build with arm-linux-gnueabi-gcc but
1360 # we don't have that on our CI at this time.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001361 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 Peskinee6c0c7d2020-04-30 23:11:54 +02001362
1363 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1364 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001365}
1366
Gilles Peskinedac156b2020-04-30 23:00:53 +02001367component_build_arm_none_eabi_gcc_m0plus () {
1368 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1369 scripts/config.pl baremetal
1370 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 Peskinee6c0c7d2020-04-30 23:11:54 +02001371
1372 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1373 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001374}
Andres AG87bb5772016-09-27 15:05:15 +01001375
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001376component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001377 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001378 scripts/config.pl baremetal
Simon Butcher1c719652016-06-27 19:02:12 +01001379 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001380 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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001381 echo "Checking that software 64-bit division is not required"
1382 if_build_succeeded not grep __aeabi_uldiv library/*.o
1383}
1384
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +02001385component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001386 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001387 scripts/config.pl baremetal
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001388 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001389 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001390 echo "Checking that software 64-bit multiplication is not required"
1391 if_build_succeeded not grep __aeabi_lmul library/*.o
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001392}
Simon Butcherbc6a4862016-03-07 17:35:59 +00001393
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001394component_build_armcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001395 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001396 scripts/config.pl baremetal
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001397 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001398
1399 msg "size: ARM Compiler 5"
1400 "$ARMC5_FROMELF" -z library/*.o
1401
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001402 make clean
1403
1404 # ARM Compiler 6 - Target ARMv7-A
1405 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
1406
1407 # ARM Compiler 6 - Target ARMv7-M
Simon Butcher4df5eaf2016-08-24 22:58:31 +03001408 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001409
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001410 # ARM Compiler 6 - Target ARMv8-A - AArch32
1411 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001412
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001413 # ARM Compiler 6 - Target ARMv8-M
1414 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001415
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001416 # ARM Compiler 6 - Target ARMv8-A - AArch64
1417 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001418}
Simon Butcher940737f2017-07-23 13:42:36 +02001419
Andres Amaya Garcia9f3bdb82018-12-05 22:03:56 +00001420component_build_ssl_hw_record_accel() {
1421 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1422 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1423 make CFLAGS='-Werror -O1'
1424}
1425
Gilles Peskine8f073122018-11-27 15:58:47 +01001426component_test_allow_sha1 () {
1427 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001428 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1429 make CFLAGS='-Werror -Wall -Wextra'
1430 msg "test: allow SHA1 in certificates by default"
1431 make test
1432 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1433}
Simon Butcher940737f2017-07-23 13:42:36 +02001434
Gilles Peskine8f073122018-11-27 15:58:47 +01001435component_build_mingw () {
1436 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001437 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Gilles Peskine2a458da2017-05-12 15:26:58 +02001438
Gilles Peskine8f073122018-11-27 15:58:47 +01001439 # note Make tests only builds the tests, but doesn't run them
1440 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1441 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001442
Gilles Peskine8f073122018-11-27 15:58:47 +01001443 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1444 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
1445 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
1446 make WINDOWS_BUILD=1 clean
1447}
Simon Butcher002bc622016-11-17 09:27:45 +00001448
Gilles Peskine8f073122018-11-27 15:58:47 +01001449component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001450 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001451 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1452 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1453 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001454
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001455 msg "test: main suites (MSan)" # ~ 10s
1456 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001457
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001458 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001459 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001460
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001461 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001462
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001463 if [ "$MEMORY" -gt 0 ]; then
1464 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001465 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001466 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001467}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001468
Gilles Peskine69f190e2019-01-10 00:11:42 +01001469component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001470 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001471 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1472 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001473
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001474 msg "test: main suites valgrind (Release)"
1475 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001476
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001477 # Optional parts (slow; currently broken on OS X because programs don't
1478 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001479 if [ "$MEMORY" -gt 0 ]; then
1480 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001481 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001482 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001483
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001484 if [ "$MEMORY" -gt 1 ]; then
1485 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001486 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001487 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001488}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001489
Gilles Peskine8f073122018-11-27 15:58:47 +01001490component_test_cmake_out_of_source () {
1491 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001492 MBEDTLS_ROOT_DIR="$PWD"
1493 mkdir "$OUT_OF_SOURCE_DIR"
1494 cd "$OUT_OF_SOURCE_DIR"
1495 cmake "$MBEDTLS_ROOT_DIR"
1496 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001497
Gilles Peskine8f073122018-11-27 15:58:47 +01001498 msg "test: cmake 'out-of-source' build"
1499 make test
1500 # Test an SSL option that requires an auxiliary script in test/scripts/.
1501 # Also ensure that there are no error messages such as
1502 # "No such file or directory", which would indicate that some required
1503 # file is missing (ssl-opt.sh tolerates the absence of some files so
1504 # may exit with status 0 but emit errors).
1505 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1506 if [ -s ssl-opt.err ]; then
1507 cat ssl-opt.err >&2
1508 record_status [ ! -s ssl-opt.err ]
1509 rm ssl-opt.err
1510 fi
1511 cd "$MBEDTLS_ROOT_DIR"
1512 rm -rf "$OUT_OF_SOURCE_DIR"
1513 unset MBEDTLS_ROOT_DIR
1514}
Andres AGdc192212016-08-31 17:33:13 +01001515
Gilles Peskine8f073122018-11-27 15:58:47 +01001516component_test_zeroize () {
1517 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1518 # different combinations of compilers and optimization flags by using an
1519 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1520 # system in all cases that the script fails, so we must manually search the
1521 # output to check whether the pass string is present and no failure strings
1522 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001523
1524 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1525 # about a spurious message if Gdb tries and fails, so suppress that.
1526 gdb_disable_aslr=
1527 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1528 gdb_disable_aslr='set disable-randomization off'
1529 fi
1530
Gilles Peskine8f073122018-11-27 15:58:47 +01001531 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001532 for compiler in clang gcc; do
1533 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1534 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001535 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01001536 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1537 if_build_succeeded not grep -i "error" test_zeroize.log
1538 rm -f test_zeroize.log
1539 make clean
1540 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001541 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001542
1543 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001544}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001545
Gilles Peskine8f073122018-11-27 15:58:47 +01001546component_check_python_files () {
1547 msg "Lint: Python scripts"
1548 record_status tests/scripts/check-python-files.sh
1549}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001550
Gilles Peskine8f073122018-11-27 15:58:47 +01001551component_check_generate_test_code () {
1552 msg "uint test: generate_test_code.py"
1553 record_status ./tests/scripts/test_generate_test_code.py
1554}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001555
1556################################################################
1557#### Termination
1558################################################################
1559
Gilles Peskine8f073122018-11-27 15:58:47 +01001560post_report () {
1561 msg "Done, cleaning up"
1562 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001563
Gilles Peskine8f073122018-11-27 15:58:47 +01001564 final_report
1565}
1566
1567
1568
1569################################################################
1570#### Run all the things
1571################################################################
1572
Gilles Peskinee48351a2018-11-27 16:06:30 +01001573# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001574run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001575 # Back up the configuration in case the component modifies it.
1576 # The cleanup function will restore it.
1577 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001578 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001579 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001580 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001581}
1582
1583# Preliminary setup
1584pre_check_environment
1585pre_initialize_variables
1586pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001587
Gilles Peskine878cf602019-01-06 20:50:38 +00001588pre_check_git
1589build_status=0
1590if [ $KEEP_GOING -eq 1 ]; then
1591 pre_setup_keep_going
1592else
1593 record_status () {
1594 "$@"
1595 }
1596fi
1597pre_print_configuration
1598pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001599cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001600
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001601# Run the requested tests.
1602for component in $RUN_COMPONENTS; do
1603 run_component "component_$component"
1604done
Gilles Peskine8f073122018-11-27 15:58:47 +01001605
1606# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001607post_report