blob: 02f61d6e3c0fbd52717b8725d7eac5a64f6a2665 [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
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200161 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100162 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100163
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200164 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard1bff6842020-06-22 10:11:47 +0200165 #
166 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
167 # both values are kept in sync. If you change the value here because it
168 # breaks some tests, you'll definitely want to change it in
169 # basic-build-test.sh as well.
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200170 RELEASE_SEED=1
171
Antonin Décimod5f47592019-01-23 15:24:37 +0100172 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100173 : ${OPENSSL:="openssl"}
174 : ${OPENSSL_LEGACY:="$OPENSSL"}
175 : ${OPENSSL_NEXT:="$OPENSSL"}
176 : ${GNUTLS_CLI:="gnutls-cli"}
177 : ${GNUTLS_SERV:="gnutls-serv"}
178 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
179 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
180 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
181 : ${ARMC5_BIN_DIR:=/usr/bin}
182 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200183 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100184
Gilles Peskine8f073122018-11-27 15:58:47 +0100185 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000186 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100187 export MAKEFLAGS="-j"
188 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000189
Gilles Peskineff26b042019-10-21 17:11:33 +0200190 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskineac479062019-10-21 19:06:33 +0200191 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskineff26b042019-10-21 17:11:33 +0200192
Gilles Peskine878cf602019-01-06 20:50:38 +0000193 # Gather the list of available components. These are the functions
194 # defined in this script whose name starts with "component_".
195 # Parse the script with sed, because in sh there is no way to list
196 # defined functions.
197 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
198
199 # Exclude components that are not supported on this platform.
200 SUPPORTED_COMPONENTS=
201 for component in $ALL_COMPONENTS; do
202 case $(type "support_$component" 2>&1) in
203 *' function'*)
204 if ! support_$component; then continue; fi;;
205 esac
206 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
207 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100208}
Andres AG38495a32016-07-12 16:54:33 +0100209
Gilles Peskinea28db922019-01-10 00:05:18 +0100210# Test whether the component $1 is included in the command line patterns.
211is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100212{
213 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000214 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100215 set +f
216 case ${1#component_} in $pattern) return 0;; esac
217 done
218 set +f
219 return 1
220}
221
Simon Butcher41eeccf2016-09-07 00:07:09 +0100222usage()
SimonB2e23c822016-04-16 21:54:39 +0100223{
Gilles Peskine709346a2017-12-10 23:43:39 +0100224 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100225Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100226Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100227By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100228COMPONENT can be the name of a component or a shell wildcard pattern.
229
230Examples:
231 $0 "check_*"
232 Run all sanity checks.
233 $0 --no-armcc --except test_memsan
234 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100235
236Special options:
237 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000238 --list-all-components List all available test components and exit.
239 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100240
241General options:
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200242 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100243 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100244 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100245 -m|--memory Additional optional memory tests.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200246 --arm-none-eabi-gcc-prefix=<string>
247 Prefix for a cross-compiler for arm-none-eabi
248 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100249 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100250 --except Exclude the COMPONENTs listed on the command line,
251 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100252 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100253 --no-force Refuse to overwrite modified files (default).
254 --no-keep-going Stop at the first error (default).
255 --no-memory No additional memory tests (default).
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200256 --no-quiet Print full ouput from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100257 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100258 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200259 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100260 -s|--seed Integer seed value to use for this test run.
261
262Tool path options:
263 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
264 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
265 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
266 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
267 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
268 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
269 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
270 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100271 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100272EOF
SimonB2e23c822016-04-16 21:54:39 +0100273}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100274
275# remove built files as well as the cmake cache/config
276cleanup()
277{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100278 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
279 cd "$MBEDTLS_ROOT_DIR"
280 fi
281
Gilles Peskine7c652162017-12-11 00:01:40 +0100282 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200283
Gilles Peskine31b07e22018-03-21 12:15:06 +0100284 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100285 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100286 -iname CMakeFiles -exec rm -rf {} \+ -o \
287 \( -iname cmake_install.cmake -o \
288 -iname CTestTestfile.cmake -o \
289 -iname CMakeCache.txt \) -exec rm {} \+
290 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000291 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200292 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
293 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200294
295 if [ -f "$CONFIG_BAK" ]; then
296 mv "$CONFIG_BAK" "$CONFIG_H"
297 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100298}
299
Gilles Peskine7c652162017-12-11 00:01:40 +0100300# Executed on exit. May be redefined depending on command line options.
301final_report () {
302 :
303}
304
305fatal_signal () {
306 cleanup
307 final_report $1
308 trap - $1
309 kill -$1 $$
310}
311
312trap 'fatal_signal HUP' HUP
313trap 'fatal_signal INT' INT
314trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200315
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100316msg()
317{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100318 if [ -n "${current_component:-}" ]; then
319 current_section="${current_component#component_}: $1"
320 else
321 current_section="$1"
322 fi
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200323
324 if [ $QUIET -eq 1 ]; then
325 return
326 fi
327
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100328 echo ""
329 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100330 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000331 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100332 echo "******************************************************************"
333}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100334
Gilles Peskine8f073122018-11-27 15:58:47 +0100335armc6_build_test()
336{
337 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100338
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200339 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100340 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
341 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200342
343 msg "size: ARM Compiler 6 ($FLAGS)"
344 "$ARMC6_FROMELF" -z library/*.o
345
Gilles Peskine8f073122018-11-27 15:58:47 +0100346 make clean
347}
Andres AGa5cd9732016-10-17 15:23:10 +0100348
Andres AGd9eba4b2016-08-26 14:42:14 +0100349err_msg()
350{
351 echo "$1" >&2
352}
353
354check_tools()
355{
356 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000357 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100358 err_msg "$TOOL not found!"
359 exit 1
360 fi
361 done
362}
363
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400364check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600365 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400366 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
367 sort |
368 diff headers.txt -
369 rm headers.txt
370}
371
Gilles Peskine8f073122018-11-27 15:58:47 +0100372pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000373 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100374 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000375 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000376
Gilles Peskine8f073122018-11-27 15:58:47 +0100377 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100378 case "$1" in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200379 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000380 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100381 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
382 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000383 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100384 --force|-f) FORCE=1;;
385 --gnutls-cli) shift; GNUTLS_CLI="$1";;
386 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
387 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
388 --gnutls-serv) shift; GNUTLS_SERV="$1";;
389 --help|-h) usage; exit;;
390 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000391 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
392 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100393 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000394 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100395 --no-force) FORCE=0;;
396 --no-keep-going) KEEP_GOING=0;;
397 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200398 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100399 --openssl) shift; OPENSSL="$1";;
400 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
401 --openssl-next) shift; OPENSSL_NEXT="$1";;
402 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200403 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100404 --random-seed) unset SEED;;
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200405 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100406 --seed|-s) shift; SEED="$1";;
407 -*)
408 echo >&2 "Unknown option: $1"
409 echo >&2 "Run $0 --help for usage."
410 exit 120
411 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000412 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100413 esac
414 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100415 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000416
Gilles Peskinea28db922019-01-10 00:05:18 +0100417 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000418 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
419 all_except=1
420 fi
421
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000422 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
423 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100424 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000425 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
426 fi
427
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000428 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100429 RUN_COMPONENTS=
430 for component in $SUPPORTED_COMPONENTS; do
431 if is_component_included "$component"; [ $? -eq $all_except ]; then
432 RUN_COMPONENTS="$RUN_COMPONENTS $component"
433 fi
434 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000435
436 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000437 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100438}
SimonB2e23c822016-04-16 21:54:39 +0100439
Gilles Peskine8f073122018-11-27 15:58:47 +0100440pre_check_git () {
441 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100442 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100443 git checkout-index -f -q $CONFIG_H
444 cleanup
445 else
SimonB2e23c822016-04-16 21:54:39 +0100446
Gilles Peskine8f073122018-11-27 15:58:47 +0100447 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
448 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
449 echo "You can either delete this directory manually, or force the test by rerunning"
450 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
451 exit 1
452 fi
453
Gilles Peskined1174cf2019-01-09 22:30:01 +0100454 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100455 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
456 echo "You can either delete or preserve your work, or force the test by rerunning the"
457 echo "script as: $0 --force"
458 exit 1
459 fi
Andres AGdc192212016-08-31 17:33:13 +0100460 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100461}
Andres AGdc192212016-08-31 17:33:13 +0100462
Gilles Peskine8f073122018-11-27 15:58:47 +0100463pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100464 failure_summary=
465 failure_count=0
466 start_red=
467 end_color=
468 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100469 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100470 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
471 start_red=$(printf '\033[31m')
472 end_color=$(printf '\033[0m')
473 ;;
474 esac
475 fi
476 record_status () {
477 if "$@"; then
478 last_status=0
479 else
480 last_status=$?
481 text="$current_section: $* -> $last_status"
482 failure_summary="$failure_summary
483$text"
484 failure_count=$((failure_count + 1))
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200485 echo "${start_red}^^^^$text^^^^${end_color}" >&2
Gilles Peskine7c652162017-12-11 00:01:40 +0100486 fi
487 }
488 make () {
489 case "$*" in
490 *test|*check)
491 if [ $build_status -eq 0 ]; then
492 record_status command make "$@"
493 else
494 echo "(skipped because the build failed)"
495 fi
496 ;;
497 *)
498 record_status command make "$@"
499 build_status=$last_status
500 ;;
501 esac
502 }
503 final_report () {
504 if [ $failure_count -gt 0 ]; then
505 echo
506 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
507 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
508 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100509 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100510 elif [ -z "${1-}" ]; then
511 echo "SUCCESS :)"
512 fi
513 if [ -n "${1-}" ]; then
514 echo "Killed by SIG$1."
515 fi
516 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100517}
518
Gilles Peskine7c652162017-12-11 00:01:40 +0100519if_build_succeeded () {
520 if [ $build_status -eq 0 ]; then
521 record_status "$@"
522 fi
523}
524
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200525# to be used instead of ! for commands run with
526# record_status or if_build_succeeded
527not() {
528 ! "$@"
529}
530
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200531pre_setup_quiet_redirect () {
532 if [ $QUIET -ne 1 ]; then
533 redirect_out () {
534 "$@"
535 }
536 else
537 redirect_out () {
538 "$@" >/dev/null
539 }
540 fi
541}
542
Gilles Peskine8f073122018-11-27 15:58:47 +0100543pre_print_configuration () {
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200544 if [ $QUIET -eq 1 ]; then
545 return
546 fi
547
Gilles Peskine8f073122018-11-27 15:58:47 +0100548 msg "info: $0 configuration"
549 echo "MEMORY: $MEMORY"
550 echo "FORCE: $FORCE"
551 echo "SEED: ${SEED-"UNSET"}"
552 echo "OPENSSL: $OPENSSL"
553 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
554 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
555 echo "GNUTLS_CLI: $GNUTLS_CLI"
556 echo "GNUTLS_SERV: $GNUTLS_SERV"
557 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
558 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
559 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
560 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
561}
Andres AG87bb5772016-09-27 15:05:15 +0100562
Gilles Peskine87964262019-01-06 22:40:00 +0000563# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100564pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000565 # Build the list of variables to pass to output_env.sh.
566 set env
567
Gilles Peskine87964262019-01-06 22:40:00 +0000568 case " $RUN_COMPONENTS " in
569 # Require OpenSSL and GnuTLS if running any tests (as opposed to
570 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
571 # is a good enough approximation in practice.
572 *" test_"*)
573 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
574 # and ssl-opt.sh, we just export the variables they require.
575 export OPENSSL_CMD="$OPENSSL"
576 export GNUTLS_CLI="$GNUTLS_CLI"
577 export GNUTLS_SERV="$GNUTLS_SERV"
578 # Avoid passing --seed flag in every call to ssl-opt.sh
579 if [ -n "${SEED-}" ]; then
580 export SEED
581 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000582 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
583 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
584 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
585 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000586 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
587 "$GNUTLS_CLI" "$GNUTLS_SERV" \
588 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
589 ;;
590 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100591
Gilles Peskine87964262019-01-06 22:40:00 +0000592 case " $RUN_COMPONENTS " in
593 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
594 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100595
Gilles Peskine87964262019-01-06 22:40:00 +0000596 case " $RUN_COMPONENTS " in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200597 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000598 esac
Andres AG7770ea82016-10-10 15:46:20 +0100599
Gilles Peskine87964262019-01-06 22:40:00 +0000600 case " $RUN_COMPONENTS " in
601 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
602 esac
603
604 case " $RUN_COMPONENTS " in
605 *" test_zeroize "*) check_tools "gdb";;
606 esac
607
608 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000609 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000610 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
611 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200612 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000613 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
614 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200615 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
616 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
617 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000618 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000619
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200620 # past this point, no call to check_tool, only printing output
621 if [ $QUIET -eq 1 ]; then
622 return
623 fi
624
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000625 msg "info: output_env.sh"
626 case $RUN_COMPONENTS in
627 *_armcc*)
628 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
629 *) set "$@" RUN_ARMCC=0;;
630 esac
631 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100632}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100633
634
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000635
Gilles Peskine192c72f2017-12-21 15:59:21 +0100636################################################################
637#### Basic checks
638################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100639
SimonB2e23c822016-04-16 21:54:39 +0100640#
641# Test Suites to be executed
642#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200643# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100644# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200645# and/or are more likely to fail than others (eg I use Clang most of the
646# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200647# 2. Minimize total running time, by avoiding useless rebuilds
648#
649# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651component_check_recursion () {
652 msg "test: recursion.pl" # < 1s
653 record_status tests/scripts/recursion.pl library/*.c
654}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656component_check_generated_files () {
657 msg "test: freshness of generated source files" # < 1s
658 record_status tests/scripts/check-generated-files.sh
659}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000660
Gilles Peskine8f073122018-11-27 15:58:47 +0100661component_check_doxy_blocks () {
662 msg "test: doxygen markup outside doxygen blocks" # < 1s
663 record_status tests/scripts/check-doxy-blocks.pl
664}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200665
Gilles Peskine8f073122018-11-27 15:58:47 +0100666component_check_files () {
Gilles Peskineee694772020-06-25 14:18:34 +0200667 msg "Check: file sanity checks (permissions, encodings)" # < 1s
668 record_status tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100669}
Darryl Greena07039c2018-03-13 16:48:16 +0000670
Gilles Peskine3c23c822020-05-10 17:40:49 +0200671component_check_changelog () {
672 msg "Check: changelog entries" # < 1s
673 rm -f ChangeLog.new
674 record_status scripts/assemble_changelog.py -o ChangeLog.new
675 if [ -e ChangeLog.new ]; then
676 # Show the diff for information. It isn't an error if the diff is
677 # non-empty.
678 diff -u ChangeLog ChangeLog.new || true
679 rm ChangeLog.new
680 fi
681}
682
Gilles Peskine8f073122018-11-27 15:58:47 +0100683component_check_names () {
684 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200685 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100686}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200687
Gilles Peskine8f073122018-11-27 15:58:47 +0100688component_check_doxygen_warnings () {
689 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 record_status tests/scripts/doxygen.sh
691}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100692
Gilles Peskine192c72f2017-12-21 15:59:21 +0100693
694
695################################################################
696#### Build and test many configurations and targets
697################################################################
698
k-stachowiak11f38e22019-06-04 13:14:58 +0200699component_test_large_ecdsa_key_signature () {
700
701 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
702
703 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
704 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
705 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
706 make
707
708 INEVITABLY_PRESENT_FILE=Makefile
709 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
710
711 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
712 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
713 rm -f $SIGNATURE_FILE
714}
715
Gilles Peskine99a33102019-04-08 17:00:15 +0200716component_test_default_out_of_box () {
717 msg "build: make, default config (out-of-box)" # ~1min
718 make
719
720 msg "test: main suites make, default config (out-of-box)" # ~10s
721 make test
722
723 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200724 if_build_succeeded programs/test/selftest
Gilles Peskine99a33102019-04-08 17:00:15 +0200725}
726
Gilles Peskine8f073122018-11-27 15:58:47 +0100727component_test_default_cmake_gcc_asan () {
728 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
730 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
733 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200734
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200735 msg "test: selftest (ASan build)" # ~ 10s
736 if_build_succeeded programs/test/selftest
737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
739 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200740
Gilles Peskine8f073122018-11-27 15:58:47 +0100741 msg "test: compat.sh (ASan build)" # ~ 6 min
742 if_build_succeeded tests/compat.sh
743}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200744
Hanno Beckerf8799e82019-02-26 14:27:09 +0000745component_test_full_cmake_gcc_asan () {
746 msg "build: full config, cmake, gcc, ASan"
747 scripts/config.pl full
748 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
749 make
750
751 msg "test: main suites (inc. selftests) (full config, ASan build)"
752 make test
753
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200754 msg "test: selftest (ASan build)" # ~ 10s
755 if_build_succeeded programs/test/selftest
756
Hanno Beckerf8799e82019-02-26 14:27:09 +0000757 msg "test: ssl-opt.sh (full config, ASan build)"
758 if_build_succeeded tests/ssl-opt.sh
759
760 msg "test: compat.sh (full config, ASan build)"
761 if_build_succeeded tests/compat.sh
762}
763
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100764component_test_zlib_make() {
765 msg "build: zlib enabled, make"
766 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
767 make ZLIB=1 CFLAGS='-Werror -O1'
768
769 msg "test: main suites (zlib, make)"
770 make test
771
772 msg "test: ssl-opt.sh (zlib, make)"
773 if_build_succeeded tests/ssl-opt.sh
774}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100775support_test_zlib_make () {
776 base=support_test_zlib_$$
777 cat <<'EOF' > ${base}.c
778#include "zlib.h"
779int main(void) { return 0; }
780EOF
781 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
782 ret=$?
783 rm -f ${base}.*
784 return $ret
785}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100786
787component_test_zlib_cmake() {
788 msg "build: zlib enabled, cmake"
789 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
790 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
791 make
792
793 msg "test: main suites (zlib, cmake)"
794 make test
795
796 msg "test: ssl-opt.sh (zlib, cmake)"
797 if_build_succeeded tests/ssl-opt.sh
798}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100799support_test_zlib_cmake () {
800 support_test_zlib_make "$@"
801}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100802
Gilles Peskine782f4112018-11-27 16:11:09 +0100803component_test_ref_configs () {
804 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
805 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
806 record_status tests/scripts/test-ref-configs.pl
807}
808
Gilles Peskine8f073122018-11-27 15:58:47 +0100809component_test_sslv3 () {
810 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100811 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
812 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
813 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000814
Gilles Peskine8f073122018-11-27 15:58:47 +0100815 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
816 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
819 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
820 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
823 if_build_succeeded tests/ssl-opt.sh
824}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826component_test_no_renegotiation () {
827 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100828 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
829 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
830 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100831
Gilles Peskine8f073122018-11-27 15:58:47 +0100832 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
833 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
836 if_build_succeeded tests/ssl-opt.sh
837}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100838
Hanno Beckere562e7d2019-05-10 14:45:37 +0100839component_test_no_pem_no_fs () {
840 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
841 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
842 scripts/config.pl unset MBEDTLS_FS_IO
843 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
844 make
845
846 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
847 make test
848
849 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
850 if_build_succeeded tests/ssl-opt.sh
851}
852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853component_test_rsa_no_crt () {
854 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100855 scripts/config.pl set MBEDTLS_RSA_NO_CRT
856 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
857 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100858
Gilles Peskine8f073122018-11-27 15:58:47 +0100859 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
860 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
863 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100864
Gilles Peskine8f073122018-11-27 15:58:47 +0100865 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
866 if_build_succeeded tests/compat.sh -t RSA
867}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100868
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200869component_test_no_ctr_drbg () {
870 msg "build: Full minus CTR_DRBG"
871 scripts/config.pl full
872 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
873
874 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
875 make
876
877 msg "test: no CTR_DRBG"
878 make test
879
Manuel Pégourié-Gonnardc5243c12020-06-05 09:29:51 +0200880 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
881}
882
883component_test_no_hmac_drbg () {
884 msg "build: Full minus HMAC_DRBG"
885 scripts/config.pl full
886 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
887 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
888
889 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
890 make
891
892 msg "test: no HMAC_DRBG"
893 make test
894
895 # No ssl-opt.sh/compat.sh as they never use HMAC_DRBG so far,
896 # so there's little value in running those lengthy tests here.
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200897}
898
Manuel Pégourié-Gonnard72177e32020-06-16 12:51:42 +0200899component_test_no_drbg_all_hashes () {
900 # this tests the internal ECP DRBG using a KDF based on SHA-512
901 msg "build: Default minus DRBGs"
902 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
903 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
904 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
905 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
906 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
907
908 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
909 make
910
911 msg "test: Default minus DRBGs"
912 make test
913
914 # no SSL tests as they all depend on having a DRBG
915}
916
917component_test_no_drbg_no_sha512 () {
918 # this tests the internal ECP DRBG using a KDF based on SHA-256
919 msg "build: Default minus DRBGs minus SHA-512"
920 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
921 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
922 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
923 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
924 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
925 scripts/config.pl unset MBEDTLS_SHA512_C
926
927 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
928 make
929
930 msg "test: Default minus DRBGs minus SHA-512"
931 make test
932
933 # no SSL tests as they all depend on having a DRBG
934}
935
Manuel Pégourié-Gonnard23983f32020-05-19 12:38:31 +0200936component_test_ecp_no_internal_rng () {
937 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
938 scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
939 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
940 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
941 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
942 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
943 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
944
945 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
946 make
947
948 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
949 make test
950
951 # no SSL tests as they all depend on having a DRBG
952}
953
Manuel Pégourié-Gonnard047986c2020-06-04 09:43:14 +0200954component_test_ecp_restartable_no_internal_rng () {
955 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
956 scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
957 scripts/config.pl set MBEDTLS_ECP_RESTARTABLE
958 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
959 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
960 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
961 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
962 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
963
964 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
965 make
966
967 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
968 make test
969
970 # no SSL tests as they all depend on having a DRBG
971}
972
Gilles Peskine8f073122018-11-27 15:58:47 +0100973component_test_small_ssl_out_content_len () {
974 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100975 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
976 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
977 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
978 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000979
Gilles Peskine8f073122018-11-27 15:58:47 +0100980 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
981 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
982}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984component_test_small_ssl_in_content_len () {
985 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100986 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
987 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
988 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
989 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
992 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
993}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000994
Gilles Peskine8f073122018-11-27 15:58:47 +0100995component_test_small_ssl_dtls_max_buffering () {
996 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100997 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
998 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
999 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001000
Gilles Peskine8f073122018-11-27 15:58:47 +01001001 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
1002 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
1003}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001004
Gilles Peskine8f073122018-11-27 15:58:47 +01001005component_test_small_mbedtls_ssl_dtls_max_buffering () {
1006 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001007 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
1008 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1009 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001010
Gilles Peskine8f073122018-11-27 15:58:47 +01001011 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
1012 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
1013}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001014
Gilles Peskine8f073122018-11-27 15:58:47 +01001015component_test_full_cmake_clang () {
1016 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001017 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001018 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1019 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021 msg "test: main suites (full config)" # ~ 5s
1022 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001023
Gilles Peskine8f073122018-11-27 15:58:47 +01001024 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
1025 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001026
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +00001027 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +00001028 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 +02001029
Gilles Peskine8f073122018-11-27 15:58:47 +01001030 msg "test: compat.sh ARIA + ChachaPoly"
1031 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1032}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001033
Manuel Pégourié-Gonnarda2377222020-07-28 10:53:06 +02001034component_test_memsan_constant_flow () {
1035 msg "build: cmake memsan, full config with constant flow testing"
1036 scripts/config.pl full
1037 scripts/config.pl set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1038 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1039 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1040 make
1041
1042 msg "test: main suites (memsan constant flow)"
1043 make test
1044}
1045
Gilles Peskine77b1f302020-04-28 14:04:28 +02001046component_test_default_no_deprecated () {
1047 # Test that removing the deprecated features from the default
1048 # configuration leaves something consistent.
1049 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001050 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine77b1f302020-04-28 14:04:28 +02001051 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1052
1053 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1054 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001055}
Gilles Peskine0afe6242018-02-21 19:28:12 +01001056
Gilles Peskine77b1f302020-04-28 14:04:28 +02001057component_test_full_deprecated_warning () {
1058 # Test that there is nothing deprecated in the full configuration.
1059 # A deprecated feature would trigger a warning (made fatal) from
1060 # MBEDTLS_DEPRECATED_WARNING.
1061 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1062 scripts/config.pl full
1063 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
1064 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
1065 # There are currently no tests for any deprecated feature.
1066 # If some are added, 'make test' would trigger warnings here.
1067 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1068
1069 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
1070 make test
1071}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001072
Gilles Peskine8f073122018-11-27 15:58:47 +01001073component_test_depends_curves () {
1074 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001075 record_status tests/scripts/curves.pl
1076}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +02001077
Gilles Peskine8f073122018-11-27 15:58:47 +01001078component_test_depends_hashes () {
1079 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 record_status tests/scripts/depends-hashes.pl
1081}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083component_test_depends_pkalgs () {
1084 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001085 record_status tests/scripts/depends-pkalgs.pl
1086}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001087
Gilles Peskine8f073122018-11-27 15:58:47 +01001088component_build_key_exchanges () {
1089 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001090 record_status tests/scripts/key-exchanges.pl
1091}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001092
Gilles Peskine8f073122018-11-27 15:58:47 +01001093component_build_default_make_gcc_and_cxx () {
1094 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001096
Gilles Peskine8f073122018-11-27 15:58:47 +01001097 msg "test: verify header list in cpp_dummy_build.cpp"
1098 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001099
Gilles Peskine8f073122018-11-27 15:58:47 +01001100 msg "build: Unix make, incremental g++"
1101 make TEST_CPP=1
1102}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001103
Gilles Peskinedcab2022019-06-12 16:05:50 +02001104component_test_check_params_functionality () {
1105 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
1106 scripts/config.pl full # includes CHECK_PARAMS
1107 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
1108 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +02001109 # Only build and run tests. Do not build sample programs, because
1110 # they don't have a mbedtls_param_failed() function.
1111 make CC=gcc CFLAGS='-Werror -O1' lib test
1112}
1113
Gilles Peskineb28636b2019-01-02 19:06:24 +01001114component_test_check_params_without_platform () {
1115 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
1116 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001117 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001118 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
1119 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1120 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1121 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001122 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskineb28636b2019-01-02 19:06:24 +01001123 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1124 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1125 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1126 scripts/config.pl unset MBEDTLS_PLATFORM_C
1127 make CC=gcc CFLAGS='-Werror -O1' all test
1128}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001129
Gilles Peskineb28636b2019-01-02 19:06:24 +01001130component_test_check_params_silent () {
1131 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
1132 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001133 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001134 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1135 make CC=gcc CFLAGS='-Werror -O1' all test
1136}
Hanno Becker5175ac62017-09-18 15:36:25 +01001137
Gilles Peskine8f073122018-11-27 15:58:47 +01001138component_test_no_platform () {
1139 # Full configuration build, without platform support, file IO and net sockets.
1140 # This should catch missing mbedtls_printf definitions, and by disabling file
1141 # IO, it should catch missing '#include <stdio.h>'
1142 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001143 scripts/config.pl full
1144 scripts/config.pl unset MBEDTLS_PLATFORM_C
1145 scripts/config.pl unset MBEDTLS_NET_C
1146 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1147 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1148 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1149 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1150 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1151 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001152 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001153 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01001154 scripts/config.pl unset MBEDTLS_FS_IO
1155 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1156 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine99d70d82019-09-20 19:23:10 +02001157 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1158 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001159}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001160
Gilles Peskine8f073122018-11-27 15:58:47 +01001161component_build_no_std_function () {
1162 # catch compile bugs in _uninit functions
1163 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001164 scripts/config.pl full
1165 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1166 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001167 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine99d70d82019-09-20 19:23:10 +02001168 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001169}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001170
Gilles Peskine8f073122018-11-27 15:58:47 +01001171component_build_no_ssl_srv () {
1172 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001173 scripts/config.pl full
1174 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001175 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001176}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001177
Gilles Peskine8f073122018-11-27 15:58:47 +01001178component_build_no_ssl_cli () {
1179 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001180 scripts/config.pl full
1181 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001182 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001183}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001184
Gilles Peskine8f073122018-11-27 15:58:47 +01001185component_build_no_sockets () {
1186 # Note, C99 compliance can also be tested with the sockets support disabled,
1187 # as that requires a POSIX platform (which isn't the same as C99).
1188 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001189 scripts/config.pl full
1190 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1191 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine99d70d82019-09-20 19:23:10 +02001192 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001193}
Hanno Becker5175ac62017-09-18 15:36:25 +01001194
Andrzej Kurek1d070822019-09-05 09:27:47 -04001195component_test_memory_buffer_allocator_backtrace () {
1196 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +00001197 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -04001198 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001199 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -04001200 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -04001201 CC=gcc cmake .
1202 make
1203
1204 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1205 make test
1206}
1207
1208component_test_memory_buffer_allocator () {
1209 msg "build: default config with memory buffer allocator"
1210 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +01001211 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001212 CC=gcc cmake .
1213 make
1214
1215 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1216 make test
1217
1218 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -04001219 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1220 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +00001221}
1222
Gilles Peskine8f073122018-11-27 15:58:47 +01001223component_test_no_max_fragment_length () {
1224 # Run max fragment length tests with MFL disabled
1225 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001226 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1227 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1228 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001229
Gilles Peskine8f073122018-11-27 15:58:47 +01001230 msg "test: ssl-opt.sh, MFL-related tests"
1231 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1232}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001233
Gilles Peskine8f073122018-11-27 15:58:47 +01001234component_test_no_max_fragment_length_small_ssl_out_content_len () {
1235 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001236 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1237 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1238 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1239 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1240 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001241
Gilles Peskine8f073122018-11-27 15:58:47 +01001242 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1243 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1244}
Janos Follath06c54002016-06-09 13:57:40 +01001245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246component_test_null_entropy () {
1247 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001248 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1249 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1250 scripts/config.pl set MBEDTLS_ENTROPY_C
1251 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001252 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001253 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1254 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001255 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001256 make
Janos Follath06c54002016-06-09 13:57:40 +01001257
Gilles Peskine8f073122018-11-27 15:58:47 +01001258 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1259 make test
1260}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001261
Gilles Peskine8f073122018-11-27 15:58:47 +01001262component_test_platform_calloc_macro () {
1263 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001264 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1265 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1266 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1267 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1268 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001269
Gilles Peskine8f073122018-11-27 15:58:47 +01001270 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1271 make test
1272}
Hanno Becker83ebf782017-07-07 12:29:15 +01001273
Gilles Peskinec6b09862019-09-17 19:04:38 +02001274component_test_malloc_0_null () {
1275 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1276 scripts/config.pl full
1277 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1278 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'
1279
1280 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1281 make test
1282
1283 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1284 # Just the calloc selftest. "make test" ran the others as part of the
1285 # test suites.
1286 if_build_succeeded programs/test/selftest calloc
1287}
1288
Gilles Peskine8f073122018-11-27 15:58:47 +01001289component_test_aes_fewer_tables () {
1290 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001291 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1292 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001293
Gilles Peskine8f073122018-11-27 15:58:47 +01001294 msg "test: AES_FEWER_TABLES"
1295 make test
1296}
Hanno Becker83ebf782017-07-07 12:29:15 +01001297
Gilles Peskine8f073122018-11-27 15:58:47 +01001298component_test_aes_rom_tables () {
1299 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001300 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1301 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001302
Gilles Peskine8f073122018-11-27 15:58:47 +01001303 msg "test: AES_ROM_TABLES"
1304 make test
1305}
Hanno Becker83ebf782017-07-07 12:29:15 +01001306
Gilles Peskine8f073122018-11-27 15:58:47 +01001307component_test_aes_fewer_tables_and_rom_tables () {
1308 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001309 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1310 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1311 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001312
Gilles Peskine8f073122018-11-27 15:58:47 +01001313 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1314 make test
1315}
1316
1317component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001318 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001319 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001320 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001321}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001322
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001323component_test_cmake_shared () {
1324 msg "build/test: cmake shared" # ~ 2min
1325 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1326 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001327 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001328 make test
1329}
1330
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001331test_build_opt () {
1332 info=$1 cc=$2; shift 2
1333 for opt in "$@"; do
1334 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskine313bb502020-04-14 20:08:41 +02001335 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001336 # We're confident enough in compilers to not run _all_ the tests,
1337 # but at least run the unit tests. In particular, runs with
1338 # optimizations use inline assembly whereas runs with -O0
1339 # skip inline assembly.
1340 make test # ~30s
1341 make clean
1342 done
1343}
1344
1345component_test_clang_opt () {
1346 scripts/config.pl full
1347 test_build_opt 'full config' clang -O0 -Os -O2
1348}
1349
1350component_test_gcc_opt () {
1351 scripts/config.pl full
1352 test_build_opt 'full config' gcc -O0 -Os -O2
1353}
1354
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001355component_build_mbedtls_config_file () {
1356 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1357 # Use the full config so as to catch a maximum of places where
1358 # the check of MBEDTLS_CONFIG_FILE might be missing.
1359 scripts/config.pl full
1360 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1361 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1362 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1363 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001364}
1365
Gilles Peskine8f073122018-11-27 15:58:47 +01001366component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001367 # Build once with -O0, to compile out the i386 specific inline assembly
1368 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001369 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001370 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001371
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001372 msg "test: i386, make, gcc -O0 (ASan build)"
1373 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001374}
Gilles Peskine878cf602019-01-06 20:50:38 +00001375support_test_m32_o0 () {
1376 case $(uname -m) in
1377 *64*) true;;
1378 *) false;;
1379 esac
1380}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001381
Gilles Peskine8f073122018-11-27 15:58:47 +01001382component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001383 # Build again with -O1, to compile in the i386 specific inline assembly
1384 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001385 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001386 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001387
1388 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001389 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001390
1391 msg "test ssl-opt.sh, i386, make, gcc-O1"
1392 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001393}
Gilles Peskine878cf602019-01-06 20:50:38 +00001394support_test_m32_o1 () {
1395 support_test_m32_o0 "$@"
1396}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001397
Gilles Peskine8f073122018-11-27 15:58:47 +01001398component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001399 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001400 scripts/config.pl full
Gilles Peskine8118e462019-06-07 14:50:09 +02001401 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001402
1403 msg "test: 64-bit ILP32, make, gcc"
1404 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001405}
Gilles Peskine878cf602019-01-06 20:50:38 +00001406support_test_mx32 () {
1407 case $(uname -m) in
1408 amd64|x86_64) true;;
1409 *) false;;
1410 esac
1411}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001412
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001413component_test_min_mpi_window_size () {
1414 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1415 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1416 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1417 make
1418
1419 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1420 make test
1421}
1422
Gilles Peskine8f073122018-11-27 15:58:47 +01001423component_test_have_int32 () {
1424 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001425 scripts/config.pl unset MBEDTLS_HAVE_ASM
1426 scripts/config.pl unset MBEDTLS_AESNI_C
1427 scripts/config.pl unset MBEDTLS_PADLOCK_C
1428 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001429
Gilles Peskine8f073122018-11-27 15:58:47 +01001430 msg "test: gcc, force 32-bit bignum limbs"
1431 make test
1432}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001433
Gilles Peskine8f073122018-11-27 15:58:47 +01001434component_test_have_int64 () {
1435 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001436 scripts/config.pl unset MBEDTLS_HAVE_ASM
1437 scripts/config.pl unset MBEDTLS_AESNI_C
1438 scripts/config.pl unset MBEDTLS_PADLOCK_C
1439 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001440
Gilles Peskine8f073122018-11-27 15:58:47 +01001441 msg "test: gcc, force 64-bit bignum limbs"
1442 make test
1443}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001444
Gilles Peskine8f073122018-11-27 15:58:47 +01001445component_test_no_udbl_division () {
1446 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001447 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001448 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1449 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001450
Gilles Peskine8f073122018-11-27 15:58:47 +01001451 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1452 make test
1453}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001454
Gilles Peskine8f073122018-11-27 15:58:47 +01001455component_test_no_64bit_multiplication () {
1456 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001457 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001458 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1459 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001460
Gilles Peskine8f073122018-11-27 15:58:47 +01001461 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1462 make test
1463}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001464
Gilles Peskine8f073122018-11-27 15:58:47 +01001465component_build_arm_none_eabi_gcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001466 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001467 scripts/config.pl baremetal
Gilles Peskinefcccfbc2020-04-30 22:54:00 +02001468 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 +02001469
1470 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1471 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01001472}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001473
Gilles Peskine560f3322019-08-09 16:05:05 +02001474component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001475 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001476 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001477 # Build for a target platform that's close to what Debian uses
1478 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1479 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1480 # It would be better to build with arm-linux-gnueabi-gcc but
1481 # we don't have that on our CI at this time.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001482 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 +02001483
1484 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1485 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001486}
1487
Gilles Peskinedac156b2020-04-30 23:00:53 +02001488component_build_arm_none_eabi_gcc_m0plus () {
1489 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1490 scripts/config.pl baremetal
1491 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 +02001492
1493 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1494 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001495}
Andres AG87bb5772016-09-27 15:05:15 +01001496
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001497component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001498 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001499 scripts/config.pl baremetal
Simon Butcher1c719652016-06-27 19:02:12 +01001500 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001501 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 +02001502 echo "Checking that software 64-bit division is not required"
1503 if_build_succeeded not grep __aeabi_uldiv library/*.o
1504}
1505
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +02001506component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001507 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001508 scripts/config.pl baremetal
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001509 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001510 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 +02001511 echo "Checking that software 64-bit multiplication is not required"
1512 if_build_succeeded not grep __aeabi_lmul library/*.o
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001513}
Simon Butcherbc6a4862016-03-07 17:35:59 +00001514
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001515component_build_armcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001516 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001517 scripts/config.pl baremetal
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001518 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001519
1520 msg "size: ARM Compiler 5"
1521 "$ARMC5_FROMELF" -z library/*.o
1522
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001523 make clean
1524
1525 # ARM Compiler 6 - Target ARMv7-A
1526 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
1527
1528 # ARM Compiler 6 - Target ARMv7-M
Simon Butcher4df5eaf2016-08-24 22:58:31 +03001529 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001530
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001531 # ARM Compiler 6 - Target ARMv8-A - AArch32
1532 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001533
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001534 # ARM Compiler 6 - Target ARMv8-M
1535 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001536
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001537 # ARM Compiler 6 - Target ARMv8-A - AArch64
1538 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001539}
Simon Butcher940737f2017-07-23 13:42:36 +02001540
Andres Amaya Garcia9f3bdb82018-12-05 22:03:56 +00001541component_build_ssl_hw_record_accel() {
1542 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1543 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1544 make CFLAGS='-Werror -O1'
1545}
1546
Gilles Peskine8f073122018-11-27 15:58:47 +01001547component_test_allow_sha1 () {
1548 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001549 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1550 make CFLAGS='-Werror -Wall -Wextra'
1551 msg "test: allow SHA1 in certificates by default"
1552 make test
1553 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1554}
Simon Butcher940737f2017-07-23 13:42:36 +02001555
Gilles Peskine8f073122018-11-27 15:58:47 +01001556component_build_mingw () {
1557 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001558 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 +02001559
Gilles Peskine8f073122018-11-27 15:58:47 +01001560 # note Make tests only builds the tests, but doesn't run them
1561 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1562 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001563
Gilles Peskine8f073122018-11-27 15:58:47 +01001564 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1565 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
1566 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
1567 make WINDOWS_BUILD=1 clean
1568}
Simon Butcher002bc622016-11-17 09:27:45 +00001569
Gilles Peskine8f073122018-11-27 15:58:47 +01001570component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001571 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001572 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1573 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1574 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001575
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001576 msg "test: main suites (MSan)" # ~ 10s
1577 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001578
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001579 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001580 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001581
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001582 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001583
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001584 if [ "$MEMORY" -gt 0 ]; then
1585 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001586 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001587 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001588}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001589
Gilles Peskine69f190e2019-01-10 00:11:42 +01001590component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001591 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001592 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1593 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001594
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001595 msg "test: main suites valgrind (Release)"
1596 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001597
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001598 # Optional parts (slow; currently broken on OS X because programs don't
1599 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001600 if [ "$MEMORY" -gt 0 ]; then
1601 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001602 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001603 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001604
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001605 if [ "$MEMORY" -gt 1 ]; then
1606 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001607 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001608 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001609}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001610
Gilles Peskine8f073122018-11-27 15:58:47 +01001611component_test_cmake_out_of_source () {
1612 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001613 MBEDTLS_ROOT_DIR="$PWD"
1614 mkdir "$OUT_OF_SOURCE_DIR"
1615 cd "$OUT_OF_SOURCE_DIR"
1616 cmake "$MBEDTLS_ROOT_DIR"
1617 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001618
Gilles Peskine8f073122018-11-27 15:58:47 +01001619 msg "test: cmake 'out-of-source' build"
1620 make test
1621 # Test an SSL option that requires an auxiliary script in test/scripts/.
1622 # Also ensure that there are no error messages such as
1623 # "No such file or directory", which would indicate that some required
1624 # file is missing (ssl-opt.sh tolerates the absence of some files so
1625 # may exit with status 0 but emit errors).
1626 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1627 if [ -s ssl-opt.err ]; then
1628 cat ssl-opt.err >&2
1629 record_status [ ! -s ssl-opt.err ]
1630 rm ssl-opt.err
1631 fi
1632 cd "$MBEDTLS_ROOT_DIR"
1633 rm -rf "$OUT_OF_SOURCE_DIR"
1634 unset MBEDTLS_ROOT_DIR
1635}
Andres AGdc192212016-08-31 17:33:13 +01001636
Gilles Peskine8f073122018-11-27 15:58:47 +01001637component_test_zeroize () {
1638 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1639 # different combinations of compilers and optimization flags by using an
1640 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1641 # system in all cases that the script fails, so we must manually search the
1642 # output to check whether the pass string is present and no failure strings
1643 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001644
1645 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1646 # about a spurious message if Gdb tries and fails, so suppress that.
1647 gdb_disable_aslr=
1648 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1649 gdb_disable_aslr='set disable-randomization off'
1650 fi
1651
Gilles Peskine8f073122018-11-27 15:58:47 +01001652 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001653 for compiler in clang gcc; do
1654 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1655 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001656 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 +01001657 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1658 if_build_succeeded not grep -i "error" test_zeroize.log
1659 rm -f test_zeroize.log
1660 make clean
1661 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001662 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001663
1664 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001665}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001666
Gilles Peskine8f073122018-11-27 15:58:47 +01001667component_check_python_files () {
1668 msg "Lint: Python scripts"
1669 record_status tests/scripts/check-python-files.sh
1670}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001671
Gilles Peskine8f073122018-11-27 15:58:47 +01001672component_check_generate_test_code () {
1673 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnard1ee68502020-06-02 11:40:08 +02001674 # unittest writes out mundane stuff like number or tests run on stderr.
1675 # Our convention is to reserve stderr for actual errors, and write
1676 # harmless info on stdout so it can be suppress with --quiet.
1677 record_status ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01001678}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001679
1680################################################################
1681#### Termination
1682################################################################
1683
Gilles Peskine8f073122018-11-27 15:58:47 +01001684post_report () {
1685 msg "Done, cleaning up"
1686 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001687
Gilles Peskine8f073122018-11-27 15:58:47 +01001688 final_report
1689}
1690
1691
1692
1693################################################################
1694#### Run all the things
1695################################################################
1696
Gilles Peskinee48351a2018-11-27 16:06:30 +01001697# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001698run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001699 # Back up the configuration in case the component modifies it.
1700 # The cleanup function will restore it.
1701 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001702 current_component="$1"
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +02001703
1704 # Run the component code.
1705 if [ $QUIET -eq 1 ]; then
1706 # msg() is silenced, so just print the component name here
1707 echo "${current_component#component_}"
1708 fi
1709 redirect_out "$@"
1710
1711 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01001712 cleanup
Manuel Pégourié-Gonnard805b1462020-06-08 10:59:41 +02001713 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01001714}
1715
1716# Preliminary setup
1717pre_check_environment
1718pre_initialize_variables
1719pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001720
Gilles Peskine878cf602019-01-06 20:50:38 +00001721pre_check_git
1722build_status=0
1723if [ $KEEP_GOING -eq 1 ]; then
1724 pre_setup_keep_going
1725else
1726 record_status () {
1727 "$@"
1728 }
1729fi
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +02001730pre_setup_quiet_redirect
Gilles Peskine878cf602019-01-06 20:50:38 +00001731pre_print_configuration
1732pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001733cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001734
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001735# Run the requested tests.
1736for component in $RUN_COMPONENTS; do
1737 run_component "component_$component"
1738done
Gilles Peskine8f073122018-11-27 15:58:47 +01001739
1740# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001741post_report