blob: 4005e16bee06dbb1dbb9ab01ecc12b0ac786068d [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#
Bence Szépkútia2947ac2020-08-19 16:37:36 +02005# Copyright The Mbed TLS Contributors
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# **********
Gilles Peskine192c72f2017-12-21 15:59:21 +010046
47
48
49################################################################
50#### Documentation
51################################################################
52
Simon Butcher3ea7f522016-03-07 23:22:10 +000053# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010054# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000055#
SimonB2e23c822016-04-16 21:54:39 +010056# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010057#
Gilles Peskine192c72f2017-12-21 15:59:21 +010058# Notes for users
59# ---------------
60#
SimonB2e23c822016-04-16 21:54:39 +010061# Warning: the test is destructive. It includes various build modes and
62# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010063# configuration. The following files must be committed into git:
64# * include/mbedtls/config.h
65# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
66# After running this script, the CMake cache will be lost and CMake
67# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010068#
Gilles Peskine192c72f2017-12-21 15:59:21 +010069# The script assumes the presence of a number of tools:
70# * Basic Unix tools (Windows users note: a Unix-style find must be before
71# the Windows find in the PATH)
72# * Perl
73# * GNU Make
74# * CMake
75# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040076# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010077# * arm-gcc and mingw-gcc
78# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010079# * OpenSSL and GnuTLS command line tools, recent enough for the
80# interoperability tests. If they don't support SSLv3 then a legacy
81# version of these tools must be present as well (search for LEGACY
82# below).
83# See the invocation of check_tools below for details.
84#
85# This script must be invoked from the toplevel directory of a git
86# working copy of Mbed TLS.
87#
88# Note that the output is not saved. You may want to run
89# script -c tests/scripts/all.sh
90# or
91# tests/scripts/all.sh >all.log 2>&1
92#
93# Notes for maintainers
94# ---------------------
95#
Gilles Peskine8f073122018-11-27 15:58:47 +010096# The bulk of the code is organized into functions that follow one of the
97# following naming conventions:
98# * pre_XXX: things to do before running the tests, in order.
99# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100100# * component_check_XXX: quick tests that aren't worth parallelizing.
101# * component_build_XXX: build things but don't run them.
102# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +0000103# * support_XXX: if support_XXX exists and returns false then
104# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +0100105# * post_XXX: things to do after running the tests.
106# * other: miscellaneous support functions.
107#
Gilles Peskinec70637a2019-01-09 22:29:17 +0100108# Each component must start by invoking `msg` with a short informative message.
109#
110# The framework performs some cleanup tasks after each component. This
111# means that components can assume that the working directory is in a
112# cleaned-up state, and don't need to perform the cleanup themselves.
113# * Run `make clean`.
114# * Restore `include/mbedtks/config.h` from a backup made before running
115# the component.
116# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
117# `tests/Makefile` from git. This cleans up after an in-tree use of
118# CMake.
119#
120# Any command that is expected to fail must be protected so that the
121# script keeps running in --keep-going mode despite `set -e`. In keep-going
122# mode, if a protected command fails, this is logged as a failure and the
123# script will exit with a failure status once it has run all components.
124# Commands can be protected in any of the following ways:
125# * `make` is a function which runs the `make` command with protection.
126# Note that you must write `make VAR=value`, not `VAR=value make`,
127# because the `VAR=value make` syntax doesn't work with functions.
128# * Put `report_status` before the command to protect it.
129# * Put `if_build_successful` before a command. This protects it, and
130# additionally skips it if a prior invocation of `make` in the same
131# component failed.
132#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100133# The tests are roughly in order from fastest to slowest. This doesn't
134# have to be exact, but in general you should add slower tests towards
135# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100136
137
138
139################################################################
140#### Initialization and command line parsing
141################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100142
SimonB2e23c822016-04-16 21:54:39 +0100143# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100144set -eu
145
Gilles Peskine8f073122018-11-27 15:58:47 +0100146pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000147 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100148 echo "Must be run from mbed TLS root" >&2
149 exit 1
150 fi
151}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100152
Gilles Peskine8f073122018-11-27 15:58:47 +0100153pre_initialize_variables () {
154 CONFIG_H='include/mbedtls/config.h'
155 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200156
Gilles Peskine8f073122018-11-27 15:58:47 +0100157 MEMORY=0
158 FORCE=0
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200159 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100160 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100161
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200162 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard1bff6842020-06-22 10:11:47 +0200163 #
164 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
165 # both values are kept in sync. If you change the value here because it
166 # breaks some tests, you'll definitely want to change it in
167 # basic-build-test.sh as well.
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200168 RELEASE_SEED=1
169
Antonin Décimod5f47592019-01-23 15:24:37 +0100170 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100171 : ${OPENSSL:="openssl"}
172 : ${OPENSSL_LEGACY:="$OPENSSL"}
173 : ${OPENSSL_NEXT:="$OPENSSL"}
174 : ${GNUTLS_CLI:="gnutls-cli"}
175 : ${GNUTLS_SERV:="gnutls-serv"}
176 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
177 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
178 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
179 : ${ARMC5_BIN_DIR:=/usr/bin}
180 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200181 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard9d944522020-08-18 10:28:51 +0200182 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Andres AGdc192212016-08-31 17:33:13 +0100183
Gilles Peskine8f073122018-11-27 15:58:47 +0100184 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000185 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100186 export MAKEFLAGS="-j"
187 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000188
Gilles Peskine24180ac2021-09-20 18:57:55 +0200189 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerobd1b89a2019-02-07 17:43:39 +0000190 export CTEST_OUTPUT_ON_FAILURE=1
191
Gilles Peskineff26b042019-10-21 17:11:33 +0200192 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskineac479062019-10-21 19:06:33 +0200193 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskineff26b042019-10-21 17:11:33 +0200194
Gilles Peskine878cf602019-01-06 20:50:38 +0000195 # Gather the list of available components. These are the functions
196 # defined in this script whose name starts with "component_".
197 # Parse the script with sed, because in sh there is no way to list
198 # defined functions.
199 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
200
201 # Exclude components that are not supported on this platform.
202 SUPPORTED_COMPONENTS=
203 for component in $ALL_COMPONENTS; do
204 case $(type "support_$component" 2>&1) in
205 *' function'*)
206 if ! support_$component; then continue; fi;;
207 esac
208 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
209 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100210}
Andres AG38495a32016-07-12 16:54:33 +0100211
Gilles Peskinea28db922019-01-10 00:05:18 +0100212# Test whether the component $1 is included in the command line patterns.
213is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100214{
215 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000216 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100217 set +f
218 case ${1#component_} in $pattern) return 0;; esac
219 done
220 set +f
221 return 1
222}
223
Simon Butcher41eeccf2016-09-07 00:07:09 +0100224usage()
SimonB2e23c822016-04-16 21:54:39 +0100225{
Gilles Peskine709346a2017-12-10 23:43:39 +0100226 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100227Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100228Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100229By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100230COMPONENT can be the name of a component or a shell wildcard pattern.
231
232Examples:
233 $0 "check_*"
234 Run all sanity checks.
235 $0 --no-armcc --except test_memsan
236 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100237
238Special options:
239 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000240 --list-all-components List all available test components and exit.
241 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100242
243General options:
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200244 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100245 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100246 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100247 -m|--memory Additional optional memory tests.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200248 --arm-none-eabi-gcc-prefix=<string>
249 Prefix for a cross-compiler for arm-none-eabi
250 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard9d944522020-08-18 10:28:51 +0200251 --arm-linux-gnueabi-gcc-prefix=<string>
252 Prefix for a cross-compiler for arm-linux-gnueabi
253 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100254 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100255 --except Exclude the COMPONENTs listed on the command line,
256 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100257 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100258 --no-force Refuse to overwrite modified files (default).
259 --no-keep-going Stop at the first error (default).
260 --no-memory No additional memory tests (default).
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200261 --no-quiet Print full ouput from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100262 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100263 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200264 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100265 -s|--seed Integer seed value to use for this test run.
266
267Tool path options:
268 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
269 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
270 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
271 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
272 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
273 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
274 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
275 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100276 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100277EOF
SimonB2e23c822016-04-16 21:54:39 +0100278}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100279
280# remove built files as well as the cmake cache/config
281cleanup()
282{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100283 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
284 cd "$MBEDTLS_ROOT_DIR"
285 fi
286
Gilles Peskine7c652162017-12-11 00:01:40 +0100287 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200288
Gilles Peskine31b07e22018-03-21 12:15:06 +0100289 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100290 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100291 -iname CMakeFiles -exec rm -rf {} \+ -o \
292 \( -iname cmake_install.cmake -o \
293 -iname CTestTestfile.cmake -o \
294 -iname CMakeCache.txt \) -exec rm {} \+
295 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000296 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200297 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
298 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200299
300 if [ -f "$CONFIG_BAK" ]; then
301 mv "$CONFIG_BAK" "$CONFIG_H"
302 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100303}
304
Gilles Peskine7c652162017-12-11 00:01:40 +0100305# Executed on exit. May be redefined depending on command line options.
306final_report () {
307 :
308}
309
310fatal_signal () {
311 cleanup
312 final_report $1
313 trap - $1
314 kill -$1 $$
315}
316
317trap 'fatal_signal HUP' HUP
318trap 'fatal_signal INT' INT
319trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200320
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100321msg()
322{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100323 if [ -n "${current_component:-}" ]; then
324 current_section="${current_component#component_}: $1"
325 else
326 current_section="$1"
327 fi
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200328
329 if [ $QUIET -eq 1 ]; then
330 return
331 fi
332
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100333 echo ""
334 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100335 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000336 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100337 echo "******************************************************************"
338}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100339
Gilles Peskine8f073122018-11-27 15:58:47 +0100340armc6_build_test()
341{
342 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100343
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200344 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100345 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
346 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200347
348 msg "size: ARM Compiler 6 ($FLAGS)"
349 "$ARMC6_FROMELF" -z library/*.o
350
Gilles Peskine8f073122018-11-27 15:58:47 +0100351 make clean
352}
Andres AGa5cd9732016-10-17 15:23:10 +0100353
Andres AGd9eba4b2016-08-26 14:42:14 +0100354err_msg()
355{
356 echo "$1" >&2
357}
358
359check_tools()
360{
361 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000362 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100363 err_msg "$TOOL not found!"
364 exit 1
365 fi
366 done
367}
368
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400369check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600370 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400371 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
372 sort |
373 diff headers.txt -
374 rm headers.txt
375}
376
Gilles Peskine8f073122018-11-27 15:58:47 +0100377pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000378 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100379 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000380 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000381
Gilles Peskine8f073122018-11-27 15:58:47 +0100382 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100383 case "$1" in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200384 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard9d944522020-08-18 10:28:51 +0200385 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000386 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100387 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
388 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000389 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100390 --force|-f) FORCE=1;;
391 --gnutls-cli) shift; GNUTLS_CLI="$1";;
392 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
393 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
394 --gnutls-serv) shift; GNUTLS_SERV="$1";;
395 --help|-h) usage; exit;;
396 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000397 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
398 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100399 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000400 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100401 --no-force) FORCE=0;;
402 --no-keep-going) KEEP_GOING=0;;
403 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200404 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100405 --openssl) shift; OPENSSL="$1";;
406 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
407 --openssl-next) shift; OPENSSL_NEXT="$1";;
408 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200409 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100410 --random-seed) unset SEED;;
Manuel Pégourié-Gonnardc2400d32020-06-08 12:59:27 +0200411 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100412 --seed|-s) shift; SEED="$1";;
413 -*)
414 echo >&2 "Unknown option: $1"
415 echo >&2 "Run $0 --help for usage."
416 exit 120
417 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000418 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100419 esac
420 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100421 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000422
Gilles Peskinea28db922019-01-10 00:05:18 +0100423 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000424 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
425 all_except=1
426 fi
427
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000428 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
429 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100430 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000431 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
432 fi
433
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000434 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100435 RUN_COMPONENTS=
436 for component in $SUPPORTED_COMPONENTS; do
437 if is_component_included "$component"; [ $? -eq $all_except ]; then
438 RUN_COMPONENTS="$RUN_COMPONENTS $component"
439 fi
440 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000441
442 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000443 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100444}
SimonB2e23c822016-04-16 21:54:39 +0100445
Gilles Peskine8f073122018-11-27 15:58:47 +0100446pre_check_git () {
447 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100448 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100449 git checkout-index -f -q $CONFIG_H
450 cleanup
451 else
SimonB2e23c822016-04-16 21:54:39 +0100452
Gilles Peskine8f073122018-11-27 15:58:47 +0100453 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
454 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
455 echo "You can either delete this directory manually, or force the test by rerunning"
456 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
457 exit 1
458 fi
459
Gilles Peskined1174cf2019-01-09 22:30:01 +0100460 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100461 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
462 echo "You can either delete or preserve your work, or force the test by rerunning the"
463 echo "script as: $0 --force"
464 exit 1
465 fi
Andres AGdc192212016-08-31 17:33:13 +0100466 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100467}
Andres AGdc192212016-08-31 17:33:13 +0100468
Gilles Peskine8f073122018-11-27 15:58:47 +0100469pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100470 failure_summary=
471 failure_count=0
472 start_red=
473 end_color=
474 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100475 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100476 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
477 start_red=$(printf '\033[31m')
478 end_color=$(printf '\033[0m')
479 ;;
480 esac
481 fi
482 record_status () {
483 if "$@"; then
484 last_status=0
485 else
486 last_status=$?
487 text="$current_section: $* -> $last_status"
488 failure_summary="$failure_summary
489$text"
490 failure_count=$((failure_count + 1))
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200491 echo "${start_red}^^^^$text^^^^${end_color}" >&2
Gilles Peskine7c652162017-12-11 00:01:40 +0100492 fi
493 }
494 make () {
495 case "$*" in
496 *test|*check)
497 if [ $build_status -eq 0 ]; then
498 record_status command make "$@"
499 else
500 echo "(skipped because the build failed)"
501 fi
502 ;;
503 *)
504 record_status command make "$@"
505 build_status=$last_status
506 ;;
507 esac
508 }
509 final_report () {
510 if [ $failure_count -gt 0 ]; then
511 echo
512 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
513 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
514 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100515 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100516 elif [ -z "${1-}" ]; then
517 echo "SUCCESS :)"
518 fi
519 if [ -n "${1-}" ]; then
520 echo "Killed by SIG$1."
521 fi
522 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100523}
524
Gilles Peskine7c652162017-12-11 00:01:40 +0100525if_build_succeeded () {
526 if [ $build_status -eq 0 ]; then
527 record_status "$@"
528 fi
529}
530
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200531# to be used instead of ! for commands run with
532# record_status or if_build_succeeded
533not() {
534 ! "$@"
535}
536
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200537pre_setup_quiet_redirect () {
538 if [ $QUIET -ne 1 ]; then
539 redirect_out () {
540 "$@"
541 }
542 else
543 redirect_out () {
544 "$@" >/dev/null
545 }
546 fi
547}
548
Gilles Peskine8f073122018-11-27 15:58:47 +0100549pre_print_configuration () {
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200550 if [ $QUIET -eq 1 ]; then
551 return
552 fi
553
Gilles Peskine8f073122018-11-27 15:58:47 +0100554 msg "info: $0 configuration"
555 echo "MEMORY: $MEMORY"
556 echo "FORCE: $FORCE"
557 echo "SEED: ${SEED-"UNSET"}"
558 echo "OPENSSL: $OPENSSL"
559 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
560 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
561 echo "GNUTLS_CLI: $GNUTLS_CLI"
562 echo "GNUTLS_SERV: $GNUTLS_SERV"
563 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
564 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
565 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
566 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
567}
Andres AG87bb5772016-09-27 15:05:15 +0100568
Gilles Peskine87964262019-01-06 22:40:00 +0000569# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100570pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000571 # Build the list of variables to pass to output_env.sh.
572 set env
573
Gilles Peskine87964262019-01-06 22:40:00 +0000574 case " $RUN_COMPONENTS " in
575 # Require OpenSSL and GnuTLS if running any tests (as opposed to
576 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
577 # is a good enough approximation in practice.
578 *" test_"*)
579 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
580 # and ssl-opt.sh, we just export the variables they require.
581 export OPENSSL_CMD="$OPENSSL"
582 export GNUTLS_CLI="$GNUTLS_CLI"
583 export GNUTLS_SERV="$GNUTLS_SERV"
584 # Avoid passing --seed flag in every call to ssl-opt.sh
585 if [ -n "${SEED-}" ]; then
586 export SEED
587 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000588 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
589 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
590 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
591 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000592 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
593 "$GNUTLS_CLI" "$GNUTLS_SERV" \
594 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
595 ;;
596 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100597
Gilles Peskine87964262019-01-06 22:40:00 +0000598 case " $RUN_COMPONENTS " in
599 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
600 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100601
Gilles Peskine87964262019-01-06 22:40:00 +0000602 case " $RUN_COMPONENTS " in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200603 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000604 esac
Andres AG7770ea82016-10-10 15:46:20 +0100605
Gilles Peskine87964262019-01-06 22:40:00 +0000606 case " $RUN_COMPONENTS " in
607 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
608 esac
609
610 case " $RUN_COMPONENTS " in
611 *" test_zeroize "*) check_tools "gdb";;
612 esac
613
614 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000615 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000616 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
617 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200618 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000619 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
620 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200621 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
622 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
623 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000624 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000625
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +0200626 # past this point, no call to check_tool, only printing output
627 if [ $QUIET -eq 1 ]; then
628 return
629 fi
630
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000631 msg "info: output_env.sh"
632 case $RUN_COMPONENTS in
633 *_armcc*)
634 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
635 *) set "$@" RUN_ARMCC=0;;
636 esac
637 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100638}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100639
640
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000641
Gilles Peskine192c72f2017-12-21 15:59:21 +0100642################################################################
643#### Basic checks
644################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100645
SimonB2e23c822016-04-16 21:54:39 +0100646#
647# Test Suites to be executed
648#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200649# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100650# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200651# and/or are more likely to fail than others (eg I use Clang most of the
652# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200653# 2. Minimize total running time, by avoiding useless rebuilds
654#
655# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100656
Gilles Peskine8f073122018-11-27 15:58:47 +0100657component_check_recursion () {
658 msg "test: recursion.pl" # < 1s
659 record_status tests/scripts/recursion.pl library/*.c
660}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662component_check_generated_files () {
663 msg "test: freshness of generated source files" # < 1s
664 record_status tests/scripts/check-generated-files.sh
665}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000666
Gilles Peskine8f073122018-11-27 15:58:47 +0100667component_check_doxy_blocks () {
668 msg "test: doxygen markup outside doxygen blocks" # < 1s
669 record_status tests/scripts/check-doxy-blocks.pl
670}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672component_check_files () {
Gilles Peskineee694772020-06-25 14:18:34 +0200673 msg "Check: file sanity checks (permissions, encodings)" # < 1s
674 record_status tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100675}
Darryl Greena07039c2018-03-13 16:48:16 +0000676
Gilles Peskine3c23c822020-05-10 17:40:49 +0200677component_check_changelog () {
678 msg "Check: changelog entries" # < 1s
679 rm -f ChangeLog.new
680 record_status scripts/assemble_changelog.py -o ChangeLog.new
681 if [ -e ChangeLog.new ]; then
682 # Show the diff for information. It isn't an error if the diff is
683 # non-empty.
684 diff -u ChangeLog ChangeLog.new || true
685 rm ChangeLog.new
686 fi
687}
688
Gilles Peskine8f073122018-11-27 15:58:47 +0100689component_check_names () {
690 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200691 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100692}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694component_check_doxygen_warnings () {
695 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100696 record_status tests/scripts/doxygen.sh
697}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100698
Gilles Peskine3c546f72021-05-06 15:07:29 +0200699component_check_python2 () {
700 # Check that what used to work with Python 2 still works with Python 2.
701 msg "check: python2 compatibility"
702 mkdir -p tests/with_python2 tests/with_python3
703 make -C tests PYTHON=python2 c_files
704 mv tests/test_suite_*.c tests/with_python2/
705 make -C tests PYTHON=python3 c_files
706 mv tests/test_suite_*.c tests/with_python3/
707 diff -r tests/with_python2 tests/with_python3
708 rm -rf tests/with_python2 tests/with_python3
709}
710
Gilles Peskine192c72f2017-12-21 15:59:21 +0100711
712
713################################################################
714#### Build and test many configurations and targets
715################################################################
716
k-stachowiak11f38e22019-06-04 13:14:58 +0200717component_test_large_ecdsa_key_signature () {
718
719 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
720
721 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
722 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
723 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
724 make
725
726 INEVITABLY_PRESENT_FILE=Makefile
727 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
728
729 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
730 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
731 rm -f $SIGNATURE_FILE
732}
733
Gilles Peskine99a33102019-04-08 17:00:15 +0200734component_test_default_out_of_box () {
735 msg "build: make, default config (out-of-box)" # ~1min
736 make
737
738 msg "test: main suites make, default config (out-of-box)" # ~10s
739 make test
740
741 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200742 if_build_succeeded programs/test/selftest
Gilles Peskine99a33102019-04-08 17:00:15 +0200743}
744
Gilles Peskine8f073122018-11-27 15:58:47 +0100745component_test_default_cmake_gcc_asan () {
746 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100747 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
748 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100749
Gilles Peskine8f073122018-11-27 15:58:47 +0100750 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
751 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200752
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200753 msg "test: selftest (ASan build)" # ~ 10s
754 if_build_succeeded programs/test/selftest
755
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
757 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200758
Gilles Peskine8f073122018-11-27 15:58:47 +0100759 msg "test: compat.sh (ASan build)" # ~ 6 min
760 if_build_succeeded tests/compat.sh
761}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200762
Hanno Beckerf8799e82019-02-26 14:27:09 +0000763component_test_full_cmake_gcc_asan () {
764 msg "build: full config, cmake, gcc, ASan"
765 scripts/config.pl full
766 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
767 make
768
769 msg "test: main suites (inc. selftests) (full config, ASan build)"
770 make test
771
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200772 msg "test: selftest (ASan build)" # ~ 10s
773 if_build_succeeded programs/test/selftest
774
Hanno Beckerf8799e82019-02-26 14:27:09 +0000775 msg "test: ssl-opt.sh (full config, ASan build)"
776 if_build_succeeded tests/ssl-opt.sh
777
778 msg "test: compat.sh (full config, ASan build)"
779 if_build_succeeded tests/compat.sh
780}
781
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100782component_test_zlib_make() {
783 msg "build: zlib enabled, make"
784 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
785 make ZLIB=1 CFLAGS='-Werror -O1'
786
787 msg "test: main suites (zlib, make)"
788 make test
789
790 msg "test: ssl-opt.sh (zlib, make)"
791 if_build_succeeded tests/ssl-opt.sh
792}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100793support_test_zlib_make () {
794 base=support_test_zlib_$$
795 cat <<'EOF' > ${base}.c
796#include "zlib.h"
797int main(void) { return 0; }
798EOF
799 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
800 ret=$?
801 rm -f ${base}.*
802 return $ret
803}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100804
805component_test_zlib_cmake() {
806 msg "build: zlib enabled, cmake"
807 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
808 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
809 make
810
811 msg "test: main suites (zlib, cmake)"
812 make test
813
814 msg "test: ssl-opt.sh (zlib, cmake)"
815 if_build_succeeded tests/ssl-opt.sh
816}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100817support_test_zlib_cmake () {
818 support_test_zlib_make "$@"
819}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100820
Gilles Peskine782f4112018-11-27 16:11:09 +0100821component_test_ref_configs () {
822 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
823 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
824 record_status tests/scripts/test-ref-configs.pl
825}
826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827component_test_sslv3 () {
828 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100829 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
830 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
831 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000832
Gilles Peskine8f073122018-11-27 15:58:47 +0100833 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
834 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000835
Gilles Peskine8f073122018-11-27 15:58:47 +0100836 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
837 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
838 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000839
Gilles Peskine8f073122018-11-27 15:58:47 +0100840 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
841 if_build_succeeded tests/ssl-opt.sh
842}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000843
Gilles Peskine8f073122018-11-27 15:58:47 +0100844component_test_no_renegotiation () {
845 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100846 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
847 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
848 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100849
Gilles Peskine8f073122018-11-27 15:58:47 +0100850 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
851 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
854 if_build_succeeded tests/ssl-opt.sh
855}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100856
Hanno Beckere562e7d2019-05-10 14:45:37 +0100857component_test_no_pem_no_fs () {
858 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
859 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
860 scripts/config.pl unset MBEDTLS_FS_IO
861 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
862 make
863
864 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
865 make test
866
867 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
868 if_build_succeeded tests/ssl-opt.sh
869}
870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871component_test_rsa_no_crt () {
872 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100873 scripts/config.pl set MBEDTLS_RSA_NO_CRT
874 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
875 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100876
Gilles Peskine8f073122018-11-27 15:58:47 +0100877 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
878 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100879
Gilles Peskine8f073122018-11-27 15:58:47 +0100880 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
881 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100882
Gilles Peskine8f073122018-11-27 15:58:47 +0100883 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
884 if_build_succeeded tests/compat.sh -t RSA
885}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100886
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200887component_test_no_ctr_drbg () {
888 msg "build: Full minus CTR_DRBG"
889 scripts/config.pl full
890 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
891
892 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
893 make
894
895 msg "test: no CTR_DRBG"
896 make test
897
Manuel Pégourié-Gonnardc5243c12020-06-05 09:29:51 +0200898 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
899}
900
901component_test_no_hmac_drbg () {
902 msg "build: Full minus HMAC_DRBG"
903 scripts/config.pl full
904 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
905 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
906
907 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
908 make
909
Gilles Peskine629fd932020-11-19 22:14:34 +0100910 msg "test: Full minus HMAC_DRBG - main suites"
Manuel Pégourié-Gonnardc5243c12020-06-05 09:29:51 +0200911 make test
912
Gilles Peskine629fd932020-11-19 22:14:34 +0100913 # Normally our ECDSA implementation uses deterministic ECDSA. But since
914 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
915 # instead.
916 # Test SSL with non-deterministic ECDSA. Only test features that
917 # might be affected by how ECDSA signature is performed.
918 msg "test: Full minus HMAC_DRBG - ssl-opt.sh (subset)"
919 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
920
921 # To save time, only test one protocol version, since this part of
922 # the protocol is identical in (D)TLS up to 1.2.
923 msg "test: Full minus HMAC_DRBG - compat.sh (ECDSA)"
924 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA'
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200925}
926
Manuel Pégourié-Gonnard72177e32020-06-16 12:51:42 +0200927component_test_no_drbg_all_hashes () {
928 # this tests the internal ECP DRBG using a KDF based on SHA-512
929 msg "build: Default minus DRBGs"
930 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
931 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
932 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
933 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
934 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
935
936 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
937 make
938
939 msg "test: Default minus DRBGs"
940 make test
941
942 # no SSL tests as they all depend on having a DRBG
943}
944
945component_test_no_drbg_no_sha512 () {
946 # this tests the internal ECP DRBG using a KDF based on SHA-256
947 msg "build: Default minus DRBGs minus SHA-512"
948 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
949 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
950 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
951 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
952 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
953 scripts/config.pl unset MBEDTLS_SHA512_C
954
955 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
956 make
957
958 msg "test: Default minus DRBGs minus SHA-512"
959 make test
960
961 # no SSL tests as they all depend on having a DRBG
962}
963
Manuel Pégourié-Gonnard23983f32020-05-19 12:38:31 +0200964component_test_ecp_no_internal_rng () {
965 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
966 scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
967 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
968 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
969 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
970 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
971 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
972
973 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
974 make
975
976 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
977 make test
978
979 # no SSL tests as they all depend on having a DRBG
980}
981
Manuel Pégourié-Gonnard047986c2020-06-04 09:43:14 +0200982component_test_ecp_restartable_no_internal_rng () {
983 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
984 scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
985 scripts/config.pl set MBEDTLS_ECP_RESTARTABLE
986 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
987 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
988 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
989 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
990 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
991
992 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
993 make
994
995 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
996 make test
997
998 # no SSL tests as they all depend on having a DRBG
999}
1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001001component_test_small_ssl_out_content_len () {
1002 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001003 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1004 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1005 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1006 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001007
Gilles Peskine8f073122018-11-27 15:58:47 +01001008 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
1009 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
1010}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001011
Gilles Peskine8f073122018-11-27 15:58:47 +01001012component_test_small_ssl_in_content_len () {
1013 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001014 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1015 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
1016 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1017 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
1020 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
1021}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023component_test_small_ssl_dtls_max_buffering () {
1024 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +01001025 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
1026 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1027 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
1030 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
1031}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001032
Gilles Peskine8f073122018-11-27 15:58:47 +01001033component_test_small_mbedtls_ssl_dtls_max_buffering () {
1034 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001035 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
1036 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1037 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
1040 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
1041}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001042
Gilles Peskine8f073122018-11-27 15:58:47 +01001043component_test_full_cmake_clang () {
1044 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001045 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001046 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1047 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001048
Gilles Peskine8f073122018-11-27 15:58:47 +01001049 msg "test: main suites (full config)" # ~ 5s
1050 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001051
Gilles Peskine8f073122018-11-27 15:58:47 +01001052 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
1053 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001054
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +00001055 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +00001056 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 +02001057
Gilles Peskine8f073122018-11-27 15:58:47 +01001058 msg "test: compat.sh ARIA + ChachaPoly"
1059 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1060}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001061
Manuel Pégourié-Gonnarda2377222020-07-28 10:53:06 +02001062component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard2b802492020-07-22 11:09:28 +02001063 # This tests both (1) accesses to undefined memory, and (2) branches or
1064 # memory access depending on secret values. To distinguish between those:
1065 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1066 # - or alternatively, change the build type to MemSanDbg, which enables
1067 # origin tracking and nicer stack traces (which are useful for debugging
1068 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1069 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnarda2377222020-07-28 10:53:06 +02001070 scripts/config.pl full
1071 scripts/config.pl set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1072 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1073 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1074 make
1075
Manuel Pégourié-Gonnard2b802492020-07-22 11:09:28 +02001076 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnarda2377222020-07-28 10:53:06 +02001077 make test
1078}
1079
Manuel Pégourié-Gonnardf0828472020-08-25 11:26:37 +02001080component_test_valgrind_constant_flow () {
1081 # This tests both (1) everything that valgrind's memcheck usually checks
1082 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1083 # etc.) and (2) branches or memory access depending on secret values,
1084 # which will be reported as uninitialized memory. To distinguish between
1085 # secret and actually uninitialized:
1086 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1087 # - or alternatively, build with debug info and manually run the offending
1088 # test suite with valgrind --track-origins=yes, then check if the origin
1089 # was TEST_CF_SECRET() or something else.
1090 msg "build: cmake release GCC, full config with constant flow testing"
1091 scripts/config.pl full
1092 scripts/config.pl set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1093 cmake -D CMAKE_BUILD_TYPE:String=Release .
1094 make
1095
1096 # this only shows a summary of the results (how many of each type)
1097 # details are left in Testing/<date>/DynamicAnalysis.xml
1098 msg "test: main suites (valgrind + constant flow)"
1099 make memcheck
1100}
1101
Gilles Peskine77b1f302020-04-28 14:04:28 +02001102component_test_default_no_deprecated () {
1103 # Test that removing the deprecated features from the default
1104 # configuration leaves something consistent.
1105 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001106 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine77b1f302020-04-28 14:04:28 +02001107 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1108
1109 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1110 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001111}
Gilles Peskine0afe6242018-02-21 19:28:12 +01001112
Gilles Peskine77b1f302020-04-28 14:04:28 +02001113component_test_full_deprecated_warning () {
1114 # Test that there is nothing deprecated in the full configuration.
1115 # A deprecated feature would trigger a warning (made fatal) from
1116 # MBEDTLS_DEPRECATED_WARNING.
1117 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1118 scripts/config.pl full
1119 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
1120 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
1121 # There are currently no tests for any deprecated feature.
1122 # If some are added, 'make test' would trigger warnings here.
1123 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1124
1125 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
1126 make test
1127}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001128
Gilles Peskine8f073122018-11-27 15:58:47 +01001129component_test_depends_curves () {
1130 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001131 record_status tests/scripts/curves.pl
1132}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +02001133
Gilles Peskine8f073122018-11-27 15:58:47 +01001134component_test_depends_hashes () {
1135 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001136 record_status tests/scripts/depends-hashes.pl
1137}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001138
Gilles Peskine8f073122018-11-27 15:58:47 +01001139component_test_depends_pkalgs () {
1140 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001141 record_status tests/scripts/depends-pkalgs.pl
1142}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001143
Gilles Peskine8f073122018-11-27 15:58:47 +01001144component_build_key_exchanges () {
1145 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001146 record_status tests/scripts/key-exchanges.pl
1147}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001148
Gilles Peskine8f073122018-11-27 15:58:47 +01001149component_build_default_make_gcc_and_cxx () {
1150 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001151 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001152
Gilles Peskine8f073122018-11-27 15:58:47 +01001153 msg "test: verify header list in cpp_dummy_build.cpp"
1154 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001155
Gilles Peskine8f073122018-11-27 15:58:47 +01001156 msg "build: Unix make, incremental g++"
1157 make TEST_CPP=1
1158}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001159
Gilles Peskinedcab2022019-06-12 16:05:50 +02001160component_test_check_params_functionality () {
1161 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
1162 scripts/config.pl full # includes CHECK_PARAMS
1163 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
1164 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +02001165 # Only build and run tests. Do not build sample programs, because
1166 # they don't have a mbedtls_param_failed() function.
1167 make CC=gcc CFLAGS='-Werror -O1' lib test
1168}
1169
Gilles Peskineb28636b2019-01-02 19:06:24 +01001170component_test_check_params_without_platform () {
1171 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
1172 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001173 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001174 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
1175 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1176 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1177 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001178 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskineb28636b2019-01-02 19:06:24 +01001179 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1180 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1181 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1182 scripts/config.pl unset MBEDTLS_PLATFORM_C
1183 make CC=gcc CFLAGS='-Werror -O1' all test
1184}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001185
Gilles Peskineb28636b2019-01-02 19:06:24 +01001186component_test_check_params_silent () {
1187 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
1188 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001189 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001190 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1191 make CC=gcc CFLAGS='-Werror -O1' all test
1192}
Hanno Becker5175ac62017-09-18 15:36:25 +01001193
Gilles Peskine8f073122018-11-27 15:58:47 +01001194component_test_no_platform () {
1195 # Full configuration build, without platform support, file IO and net sockets.
1196 # This should catch missing mbedtls_printf definitions, and by disabling file
1197 # IO, it should catch missing '#include <stdio.h>'
1198 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001199 scripts/config.pl full
1200 scripts/config.pl unset MBEDTLS_PLATFORM_C
1201 scripts/config.pl unset MBEDTLS_NET_C
1202 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1203 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1204 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1205 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1206 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1207 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001208 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001209 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01001210 scripts/config.pl unset MBEDTLS_FS_IO
1211 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1212 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine99d70d82019-09-20 19:23:10 +02001213 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1214 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001215}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001216
Gilles Peskine8f073122018-11-27 15:58:47 +01001217component_build_no_std_function () {
1218 # catch compile bugs in _uninit functions
1219 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001220 scripts/config.pl full
1221 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1222 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001223 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine99d70d82019-09-20 19:23:10 +02001224 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001225}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001226
Gilles Peskine8f073122018-11-27 15:58:47 +01001227component_build_no_ssl_srv () {
1228 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001229 scripts/config.pl full
1230 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001231 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001232}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001233
Gilles Peskine8f073122018-11-27 15:58:47 +01001234component_build_no_ssl_cli () {
1235 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001236 scripts/config.pl full
1237 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001238 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001239}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001240
Gilles Peskine8f073122018-11-27 15:58:47 +01001241component_build_no_sockets () {
1242 # Note, C99 compliance can also be tested with the sockets support disabled,
1243 # as that requires a POSIX platform (which isn't the same as C99).
1244 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001245 scripts/config.pl full
1246 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1247 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine99d70d82019-09-20 19:23:10 +02001248 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001249}
Hanno Becker5175ac62017-09-18 15:36:25 +01001250
Andrzej Kurek1d070822019-09-05 09:27:47 -04001251component_test_memory_buffer_allocator_backtrace () {
1252 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +00001253 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -04001254 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001255 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -04001256 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -04001257 CC=gcc cmake .
1258 make
1259
1260 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1261 make test
1262}
1263
1264component_test_memory_buffer_allocator () {
1265 msg "build: default config with memory buffer allocator"
1266 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +01001267 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001268 CC=gcc cmake .
1269 make
1270
1271 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1272 make test
1273
1274 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -04001275 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1276 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +00001277}
1278
Gilles Peskine8f073122018-11-27 15:58:47 +01001279component_test_no_max_fragment_length () {
1280 # Run max fragment length tests with MFL disabled
1281 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001282 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1283 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1284 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001285
Gilles Peskine8f073122018-11-27 15:58:47 +01001286 msg "test: ssl-opt.sh, MFL-related tests"
1287 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1288}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001289
Gilles Peskine8f073122018-11-27 15:58:47 +01001290component_test_no_max_fragment_length_small_ssl_out_content_len () {
1291 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001292 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1293 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1294 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1295 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1296 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001297
Gilles Peskine8f073122018-11-27 15:58:47 +01001298 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1299 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1300}
Janos Follath06c54002016-06-09 13:57:40 +01001301
Gilles Peskine8f073122018-11-27 15:58:47 +01001302component_test_null_entropy () {
1303 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001304 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1305 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1306 scripts/config.pl set MBEDTLS_ENTROPY_C
1307 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001308 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001309 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1310 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001311 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001312 make
Janos Follath06c54002016-06-09 13:57:40 +01001313
Gilles Peskine8f073122018-11-27 15:58:47 +01001314 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1315 make test
1316}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001317
Raoul Strackx75475d82020-06-15 17:03:13 +02001318component_test_no_date_time () {
1319 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
1320 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1321 CC=gcc cmake
1322 make
1323
1324 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
1325 make test
1326}
1327
Gilles Peskine8f073122018-11-27 15:58:47 +01001328component_test_platform_calloc_macro () {
1329 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001330 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1331 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1332 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1333 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1334 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001335
Gilles Peskine8f073122018-11-27 15:58:47 +01001336 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1337 make test
1338}
Hanno Becker83ebf782017-07-07 12:29:15 +01001339
Gilles Peskinec6b09862019-09-17 19:04:38 +02001340component_test_malloc_0_null () {
1341 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1342 scripts/config.pl full
1343 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Gilles Peskine7f652ad2021-01-13 22:24:51 +01001344 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec6b09862019-09-17 19:04:38 +02001345
1346 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1347 make test
1348
1349 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1350 # Just the calloc selftest. "make test" ran the others as part of the
1351 # test suites.
1352 if_build_succeeded programs/test/selftest calloc
1353}
1354
Gilles Peskine8f073122018-11-27 15:58:47 +01001355component_test_aes_fewer_tables () {
1356 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001357 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1358 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001359
Gilles Peskine8f073122018-11-27 15:58:47 +01001360 msg "test: AES_FEWER_TABLES"
1361 make test
1362}
Hanno Becker83ebf782017-07-07 12:29:15 +01001363
Gilles Peskine8f073122018-11-27 15:58:47 +01001364component_test_aes_rom_tables () {
1365 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001366 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1367 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001368
Gilles Peskine8f073122018-11-27 15:58:47 +01001369 msg "test: AES_ROM_TABLES"
1370 make test
1371}
Hanno Becker83ebf782017-07-07 12:29:15 +01001372
Gilles Peskine8f073122018-11-27 15:58:47 +01001373component_test_aes_fewer_tables_and_rom_tables () {
1374 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001375 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1376 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1377 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001378
Gilles Peskine8f073122018-11-27 15:58:47 +01001379 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1380 make test
1381}
1382
1383component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001384 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001385 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001386 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001387}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001388
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001389component_test_cmake_shared () {
1390 msg "build/test: cmake shared" # ~ 2min
1391 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1392 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001393 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001394 make test
1395}
1396
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001397test_build_opt () {
1398 info=$1 cc=$2; shift 2
1399 for opt in "$@"; do
1400 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskine313bb502020-04-14 20:08:41 +02001401 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001402 # We're confident enough in compilers to not run _all_ the tests,
1403 # but at least run the unit tests. In particular, runs with
1404 # optimizations use inline assembly whereas runs with -O0
1405 # skip inline assembly.
1406 make test # ~30s
1407 make clean
1408 done
1409}
1410
1411component_test_clang_opt () {
1412 scripts/config.pl full
1413 test_build_opt 'full config' clang -O0 -Os -O2
1414}
1415
1416component_test_gcc_opt () {
1417 scripts/config.pl full
1418 test_build_opt 'full config' gcc -O0 -Os -O2
1419}
1420
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001421component_build_mbedtls_config_file () {
1422 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1423 # Use the full config so as to catch a maximum of places where
1424 # the check of MBEDTLS_CONFIG_FILE might be missing.
1425 scripts/config.pl full
1426 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1427 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1428 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1429 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001430}
1431
Gilles Peskine8f073122018-11-27 15:58:47 +01001432component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001433 # Build once with -O0, to compile out the i386 specific inline assembly
1434 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001435 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001436 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001437
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001438 msg "test: i386, make, gcc -O0 (ASan build)"
1439 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001440}
Gilles Peskine878cf602019-01-06 20:50:38 +00001441support_test_m32_o0 () {
1442 case $(uname -m) in
1443 *64*) true;;
1444 *) false;;
1445 esac
1446}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001447
Gilles Peskine8f073122018-11-27 15:58:47 +01001448component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001449 # Build again with -O1, to compile in the i386 specific inline assembly
1450 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001451 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001452 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001453
1454 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001455 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001456
1457 msg "test ssl-opt.sh, i386, make, gcc-O1"
1458 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001459}
Gilles Peskine878cf602019-01-06 20:50:38 +00001460support_test_m32_o1 () {
1461 support_test_m32_o0 "$@"
1462}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001463
Gilles Peskine8f073122018-11-27 15:58:47 +01001464component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001465 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001466 scripts/config.pl full
Gilles Peskine8118e462019-06-07 14:50:09 +02001467 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001468
1469 msg "test: 64-bit ILP32, make, gcc"
1470 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001471}
Gilles Peskine878cf602019-01-06 20:50:38 +00001472support_test_mx32 () {
1473 case $(uname -m) in
1474 amd64|x86_64) true;;
1475 *) false;;
1476 esac
1477}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001478
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001479component_test_min_mpi_window_size () {
1480 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1481 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1482 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1483 make
1484
1485 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1486 make test
1487}
1488
Gilles Peskine8f073122018-11-27 15:58:47 +01001489component_test_have_int32 () {
1490 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001491 scripts/config.pl unset MBEDTLS_HAVE_ASM
1492 scripts/config.pl unset MBEDTLS_AESNI_C
1493 scripts/config.pl unset MBEDTLS_PADLOCK_C
1494 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001495
Gilles Peskine8f073122018-11-27 15:58:47 +01001496 msg "test: gcc, force 32-bit bignum limbs"
1497 make test
1498}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001499
Gilles Peskine8f073122018-11-27 15:58:47 +01001500component_test_have_int64 () {
1501 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001502 scripts/config.pl unset MBEDTLS_HAVE_ASM
1503 scripts/config.pl unset MBEDTLS_AESNI_C
1504 scripts/config.pl unset MBEDTLS_PADLOCK_C
1505 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001506
Gilles Peskine8f073122018-11-27 15:58:47 +01001507 msg "test: gcc, force 64-bit bignum limbs"
1508 make test
1509}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001510
Gilles Peskine8f073122018-11-27 15:58:47 +01001511component_test_no_udbl_division () {
1512 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001513 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001514 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1515 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001516
Gilles Peskine8f073122018-11-27 15:58:47 +01001517 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1518 make test
1519}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001520
Gilles Peskine8f073122018-11-27 15:58:47 +01001521component_test_no_64bit_multiplication () {
1522 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001523 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001524 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1525 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001526
Gilles Peskine8f073122018-11-27 15:58:47 +01001527 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1528 make test
1529}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001530
Gilles Peskine8ffc1582020-11-09 15:40:05 +01001531component_test_no_strings () {
1532 msg "build: no strings" # ~10s
1533 scripts/config.pl full
1534 # Disable options that activate a large amount of string constants.
1535 scripts/config.pl unset MBEDTLS_DEBUG_C
1536 scripts/config.pl unset MBEDTLS_ERROR_C
1537 scripts/config.pl set MBEDTLS_ERROR_STRERROR_DUMMY
1538 scripts/config.pl unset MBEDTLS_VERSION_FEATURES
1539 make CFLAGS='-Werror -Os'
1540
1541 msg "test: no strings" # ~ 10s
1542 make test
1543}
1544
Gilles Peskine8f073122018-11-27 15:58:47 +01001545component_build_arm_none_eabi_gcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001546 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001547 scripts/config.pl baremetal
Gilles Peskinefcccfbc2020-04-30 22:54:00 +02001548 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 +02001549
1550 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1551 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01001552}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001553
Manuel Pégourié-Gonnard9d944522020-08-18 10:28:51 +02001554component_build_arm_linux_gnueabi_gcc_arm5vte () {
1555 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001556 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001557 # Build for a target platform that's close to what Debian uses
1558 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1559 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard9d944522020-08-18 10:28:51 +02001560 # Build everything including programs, see for example
1561 # https://github.com/ARMmbed/mbedtls/pull/3449#issuecomment-675313720
1562 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te'
1563
1564 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1"
1565 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
1566}
1567support_build_arm_linux_gnueabi_gcc_arm5vte () {
1568 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
1569}
1570
1571component_build_arm_none_eabi_gcc_arm5vte () {
1572 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
1573 scripts/config.pl baremetal
1574 # This is an imperfect substitute for
1575 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard0a1a9e72021-07-06 09:44:59 +02001576 # in case the gcc-arm-linux-gnueabi toolchain is not available
Manuel Pégourié-Gonnard9d944522020-08-18 10:28:51 +02001577 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-std=c99 -Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001578
1579 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1580 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001581}
1582
Gilles Peskinedac156b2020-04-30 23:00:53 +02001583component_build_arm_none_eabi_gcc_m0plus () {
1584 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1585 scripts/config.pl baremetal
1586 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 +02001587
1588 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1589 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001590}
Andres AG87bb5772016-09-27 15:05:15 +01001591
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001592component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001593 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001594 scripts/config.pl baremetal
Simon Butcher1c719652016-06-27 19:02:12 +01001595 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001596 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 +02001597 echo "Checking that software 64-bit division is not required"
1598 if_build_succeeded not grep __aeabi_uldiv library/*.o
1599}
1600
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +02001601component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001602 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001603 scripts/config.pl baremetal
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001604 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001605 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 +02001606 echo "Checking that software 64-bit multiplication is not required"
1607 if_build_succeeded not grep __aeabi_lmul library/*.o
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001608}
Simon Butcherbc6a4862016-03-07 17:35:59 +00001609
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001610component_build_armcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001611 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001612 scripts/config.pl baremetal
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001613 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001614
1615 msg "size: ARM Compiler 5"
1616 "$ARMC5_FROMELF" -z library/*.o
1617
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001618 make clean
1619
1620 # ARM Compiler 6 - Target ARMv7-A
1621 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
1622
1623 # ARM Compiler 6 - Target ARMv7-M
Simon Butcher4df5eaf2016-08-24 22:58:31 +03001624 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001625
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001626 # ARM Compiler 6 - Target ARMv8-A - AArch32
1627 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001628
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001629 # ARM Compiler 6 - Target ARMv8-M
1630 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001631
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001632 # ARM Compiler 6 - Target ARMv8-A - AArch64
1633 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001634}
Simon Butcher940737f2017-07-23 13:42:36 +02001635
Andres Amaya Garcia9f3bdb82018-12-05 22:03:56 +00001636component_build_ssl_hw_record_accel() {
1637 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1638 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1639 make CFLAGS='-Werror -O1'
1640}
1641
Gilles Peskine8f073122018-11-27 15:58:47 +01001642component_test_allow_sha1 () {
1643 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001644 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1645 make CFLAGS='-Werror -Wall -Wextra'
1646 msg "test: allow SHA1 in certificates by default"
1647 make test
1648 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1649}
Simon Butcher940737f2017-07-23 13:42:36 +02001650
Gilles Peskine8f073122018-11-27 15:58:47 +01001651component_build_mingw () {
1652 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001653 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 +02001654
Gilles Peskine8f073122018-11-27 15:58:47 +01001655 # note Make tests only builds the tests, but doesn't run them
1656 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1657 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001658
Gilles Peskine8f073122018-11-27 15:58:47 +01001659 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1660 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
1661 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
1662 make WINDOWS_BUILD=1 clean
1663}
Simon Butcher002bc622016-11-17 09:27:45 +00001664
Gilles Peskine8f073122018-11-27 15:58:47 +01001665component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001666 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001667 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1668 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1669 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001670
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001671 msg "test: main suites (MSan)" # ~ 10s
1672 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001673
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001674 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001675 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001676
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001677 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001678
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001679 if [ "$MEMORY" -gt 0 ]; then
1680 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001681 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001682 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001683}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001684
Gilles Peskine69f190e2019-01-10 00:11:42 +01001685component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001686 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001687 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1688 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001689
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001690 msg "test: main suites valgrind (Release)"
1691 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001692
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001693 # Optional parts (slow; currently broken on OS X because programs don't
1694 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001695 if [ "$MEMORY" -gt 0 ]; then
1696 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001697 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001698 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001699
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001700 if [ "$MEMORY" -gt 1 ]; then
1701 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001702 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001703 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001704}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001705
Gilles Peskine8f073122018-11-27 15:58:47 +01001706component_test_cmake_out_of_source () {
1707 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001708 MBEDTLS_ROOT_DIR="$PWD"
1709 mkdir "$OUT_OF_SOURCE_DIR"
1710 cd "$OUT_OF_SOURCE_DIR"
1711 cmake "$MBEDTLS_ROOT_DIR"
1712 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001713
Gilles Peskine8f073122018-11-27 15:58:47 +01001714 msg "test: cmake 'out-of-source' build"
1715 make test
1716 # Test an SSL option that requires an auxiliary script in test/scripts/.
1717 # Also ensure that there are no error messages such as
1718 # "No such file or directory", which would indicate that some required
1719 # file is missing (ssl-opt.sh tolerates the absence of some files so
1720 # may exit with status 0 but emit errors).
1721 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1722 if [ -s ssl-opt.err ]; then
1723 cat ssl-opt.err >&2
1724 record_status [ ! -s ssl-opt.err ]
1725 rm ssl-opt.err
1726 fi
1727 cd "$MBEDTLS_ROOT_DIR"
1728 rm -rf "$OUT_OF_SOURCE_DIR"
1729 unset MBEDTLS_ROOT_DIR
1730}
Andres AGdc192212016-08-31 17:33:13 +01001731
Gilles Peskine8f073122018-11-27 15:58:47 +01001732component_test_zeroize () {
1733 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1734 # different combinations of compilers and optimization flags by using an
1735 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1736 # system in all cases that the script fails, so we must manually search the
1737 # output to check whether the pass string is present and no failure strings
1738 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001739
1740 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1741 # about a spurious message if Gdb tries and fails, so suppress that.
1742 gdb_disable_aslr=
1743 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1744 gdb_disable_aslr='set disable-randomization off'
1745 fi
1746
Gilles Peskine8f073122018-11-27 15:58:47 +01001747 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001748 for compiler in clang gcc; do
1749 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1750 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001751 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 +01001752 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1753 if_build_succeeded not grep -i "error" test_zeroize.log
1754 rm -f test_zeroize.log
1755 make clean
1756 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001757 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001758
1759 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001760}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001761
Gilles Peskine8f073122018-11-27 15:58:47 +01001762component_check_python_files () {
1763 msg "Lint: Python scripts"
1764 record_status tests/scripts/check-python-files.sh
1765}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001766
Gilles Peskine8f073122018-11-27 15:58:47 +01001767component_check_generate_test_code () {
1768 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnard1ee68502020-06-02 11:40:08 +02001769 # unittest writes out mundane stuff like number or tests run on stderr.
1770 # Our convention is to reserve stderr for actual errors, and write
1771 # harmless info on stdout so it can be suppress with --quiet.
1772 record_status ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01001773}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001774
1775################################################################
1776#### Termination
1777################################################################
1778
Gilles Peskine8f073122018-11-27 15:58:47 +01001779post_report () {
1780 msg "Done, cleaning up"
1781 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001782
Gilles Peskine8f073122018-11-27 15:58:47 +01001783 final_report
1784}
1785
1786
1787
1788################################################################
1789#### Run all the things
1790################################################################
1791
Gilles Peskinee48351a2018-11-27 16:06:30 +01001792# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001793run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001794 # Back up the configuration in case the component modifies it.
1795 # The cleanup function will restore it.
1796 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001797 current_component="$1"
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +02001798
1799 # Run the component code.
1800 if [ $QUIET -eq 1 ]; then
1801 # msg() is silenced, so just print the component name here
1802 echo "${current_component#component_}"
1803 fi
1804 redirect_out "$@"
1805
1806 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01001807 cleanup
Manuel Pégourié-Gonnard805b1462020-06-08 10:59:41 +02001808 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01001809}
1810
1811# Preliminary setup
1812pre_check_environment
1813pre_initialize_variables
1814pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001815
Gilles Peskine878cf602019-01-06 20:50:38 +00001816pre_check_git
1817build_status=0
1818if [ $KEEP_GOING -eq 1 ]; then
1819 pre_setup_keep_going
1820else
1821 record_status () {
1822 "$@"
1823 }
1824fi
Manuel Pégourié-Gonnardde4ad2d2020-06-02 11:28:07 +02001825pre_setup_quiet_redirect
Gilles Peskine878cf602019-01-06 20:50:38 +00001826pre_print_configuration
1827pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001828cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001829
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001830# Run the requested tests.
1831for component in $RUN_COMPONENTS; do
1832 run_component "component_$component"
1833done
Gilles Peskine8f073122018-11-27 15:58:47 +01001834
1835# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001836post_report