blob: fc9ffd1319c67253c78b4dcc9e0a68b4e6a2e973 [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úti44bfbe32020-08-19 16:54:51 +02005# Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020013#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020026# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
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)
76# * arm-gcc and mingw-gcc
77# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
78# * Yotta build dependencies, unless invoked with --no-yotta
79# * 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 Peskine2906a0a2019-01-09 22:29:17 +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.
100# * 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.
103# * support_XXX: if support_XXX exists and returns false then
104# component_XXX is not run by default.
105# * post_XXX: things to do after running the tests.
106# * other: miscellaneous support functions.
107#
108# 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 Peskine57db6ff2019-01-08 22:04:31 +0100146pre_check_environment () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100147 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine57db6ff2019-01-08 22:04:31 +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 Peskine57db6ff2019-01-08 22:04:31 +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 Peskine57db6ff2019-01-08 22:04:31 +0100157 MEMORY=0
158 FORCE=0
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200159 QUIET=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100160 KEEP_GOING=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100161 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100162
Manuel Pégourié-Gonnard54d95b12020-06-08 12:59:27 +0200163 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnarde4a5c052020-06-22 10:11:47 +0200164 #
165 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
166 # both values are kept in sync. If you change the value here because it
167 # breaks some tests, you'll definitely want to change it in
168 # basic-build-test.sh as well.
Manuel Pégourié-Gonnard54d95b12020-06-08 12:59:27 +0200169 RELEASE_SEED=1
170
Antonin Décimo8fd91562019-01-23 15:24:37 +0100171 # Default commands, can be overridden by the environment
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100172 : ${OPENSSL:="openssl"}
173 : ${OPENSSL_LEGACY:="$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 Peskinef1709bb2020-04-30 18:19:32 +0200181 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100182
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100183 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000184 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100185 export MAKEFLAGS="-j"
186 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100187
Jaeden Amerode97d1f2019-02-07 17:43:39 +0000188 # Include more verbose output for failing tests run by CMake
189 export CTEST_OUTPUT_ON_FAILURE=1
190
Gilles Peskinec20a4052019-10-21 17:11:33 +0200191 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine4c2697f2019-10-21 19:06:33 +0200192 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskinec20a4052019-10-21 17:11:33 +0200193
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100194 # Gather the list of available components. These are the functions
195 # defined in this script whose name starts with "component_".
196 # Parse the script with sed, because in sh there is no way to list
197 # defined functions.
198 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100199
200 # Exclude components that are not supported on this platform.
201 SUPPORTED_COMPONENTS=
202 for component in $ALL_COMPONENTS; do
203 case $(type "support_$component" 2>&1) in
204 *' function'*)
205 if ! support_$component; then continue; fi;;
206 esac
207 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
208 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100209}
Andres AG38495a32016-07-12 16:54:33 +0100210
Gilles Peskineff7238f2019-01-10 00:05:18 +0100211# Test whether the component $1 is included in the command line patterns.
212is_component_included()
Gilles Peskine6e984232018-11-27 21:37:53 +0100213{
214 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100215 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100216 set +f
217 case ${1#component_} in $pattern) return 0;; esac
218 done
219 set +f
220 return 1
221}
222
Simon Butcher41eeccf2016-09-07 00:07:09 +0100223usage()
SimonB2e23c822016-04-16 21:54:39 +0100224{
Gilles Peskine709346a2017-12-10 23:43:39 +0100225 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100226Usage: $0 [OPTION]... [COMPONENT]...
227Run mbedtls release validation tests.
228By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100229COMPONENT can be the name of a component or a shell wildcard pattern.
230
231Examples:
232 $0 "check_*"
233 Run all sanity checks.
234 $0 --no-armcc --except test_memsan
235 Run everything except builds that require armcc and MemSan.
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100236
237Special options:
238 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100239 --list-all-components List all available test components and exit.
240 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100241
242General options:
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200243 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100244 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100245 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100246 -m|--memory Additional optional memory tests.
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200247 --arm-none-eabi-gcc-prefix=<string>
248 Prefix for a cross-compiler for arm-none-eabi
249 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100250 --armcc Run ARM Compiler builds (on by default).
Gilles Peskineff7238f2019-01-10 00:05:18 +0100251 --except Exclude the COMPONENTs listed on the command line,
252 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100253 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100254 --no-force Refuse to overwrite modified files (default).
255 --no-keep-going Stop at the first error (default).
256 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100257 --no-yotta Skip yotta module build.
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200258 --no-quiet Print full ouput from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100259 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100260 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnard54d95b12020-06-08 12:59:27 +0200261 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100262 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100263 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100264
265Tool path options:
266 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
267 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
268 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
269 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
270 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
271 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
272 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
273 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
274EOF
SimonB2e23c822016-04-16 21:54:39 +0100275}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100276
277# remove built files as well as the cmake cache/config
278cleanup()
279{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100280 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
281 cd "$MBEDTLS_ROOT_DIR"
282 fi
283
Gilles Peskine7c652162017-12-11 00:01:40 +0100284 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200285
Gilles Peskine31b07e22018-03-21 12:15:06 +0100286 # Remove CMake artefacts
287 find . -name .git -prune -o -name yotta -prune -o \
288 -iname CMakeFiles -exec rm -rf {} \+ -o \
289 \( -iname cmake_install.cmake -o \
290 -iname CTestTestfile.cmake -o \
291 -iname CMakeCache.txt \) -exec rm {} \+
292 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000293 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200294 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
295 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200296
297 if [ -f "$CONFIG_BAK" ]; then
298 mv "$CONFIG_BAK" "$CONFIG_H"
299 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100300}
301
Gilles Peskine7c652162017-12-11 00:01:40 +0100302# Executed on exit. May be redefined depending on command line options.
303final_report () {
304 :
305}
306
307fatal_signal () {
308 cleanup
309 final_report $1
310 trap - $1
311 kill -$1 $$
312}
313
314trap 'fatal_signal HUP' HUP
315trap 'fatal_signal INT' INT
316trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200317
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100318msg()
319{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100320 if [ -n "${current_component:-}" ]; then
321 current_section="${current_component#component_}: $1"
322 else
323 current_section="$1"
324 fi
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200325
326 if [ $QUIET -eq 1 ]; then
327 return
328 fi
329
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100330 echo ""
331 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100332 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000333 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100334 echo "******************************************************************"
335}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100336
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100337armc6_build_test()
338{
339 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100340
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200341 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100342 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
343 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200344
345 msg "size: ARM Compiler 6 ($FLAGS)"
346 "$ARMC6_FROMELF" -z library/*.o
347
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100348 make clean
349}
Andres AGa5cd9732016-10-17 15:23:10 +0100350
Andres AGd9eba4b2016-08-26 14:42:14 +0100351err_msg()
352{
353 echo "$1" >&2
354}
355
356check_tools()
357{
358 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000359 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100360 err_msg "$TOOL not found!"
361 exit 1
362 fi
363 done
364}
365
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100366pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100367 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100368 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100369 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100370
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100371 while [ $# -gt 0 ]; do
372 case "$1" in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200373 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine53084872019-01-09 23:13:54 +0100374 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100375 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
376 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100377 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100378 --force|-f) FORCE=1;;
379 --gnutls-cli) shift; GNUTLS_CLI="$1";;
380 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
381 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
382 --gnutls-serv) shift; GNUTLS_SERV="$1";;
383 --help|-h) usage; exit;;
384 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100385 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
386 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100387 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100388 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100389 --no-force) FORCE=0;;
390 --no-keep-going) KEEP_GOING=0;;
391 --no-memory) MEMORY=0;;
392 --no-yotta) YOTTA=0;;
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200393 --no-quiet) QUIET=0;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100394 --openssl) shift; OPENSSL="$1";;
395 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
396 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200397 --quiet|-q) QUIET=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100398 --random-seed) unset SEED;;
Manuel Pégourié-Gonnard54d95b12020-06-08 12:59:27 +0200399 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100400 --seed|-s) shift; SEED="$1";;
401 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100402 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100403 echo >&2 "Unknown option: $1"
404 echo >&2 "Run $0 --help for usage."
405 exit 120
406 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100407 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100408 esac
409 shift
410 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100411
Gilles Peskineff7238f2019-01-10 00:05:18 +0100412 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100413 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
414 all_except=1
415 fi
416
Gilles Peskine53084872019-01-09 23:13:54 +0100417 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
418 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100419 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100420 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
421 # --no-armcc also disables yotta.
422 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
423 fi
424
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100425 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100426 RUN_COMPONENTS=
427 for component in $SUPPORTED_COMPONENTS; do
428 if is_component_included "$component"; [ $? -eq $all_except ]; then
429 RUN_COMPONENTS="$RUN_COMPONENTS $component"
430 fi
431 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100432
433 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100434 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100435}
SimonB2e23c822016-04-16 21:54:39 +0100436
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100437pre_check_git () {
438 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100439 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100440 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100441 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100442 fi
443 git checkout-index -f -q $CONFIG_H
444 cleanup
445 else
446
447 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
448 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
449 echo "You can either delete your work and retry, or force the test to overwrite the"
450 echo "test by rerunning the script as: $0 --force"
451 exit 1
452 fi
453
454 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
455 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
456 echo "You can either delete this directory manually, or force the test by rerunning"
457 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
458 exit 1
459 fi
460
Gilles Peskinec9663b12019-01-09 22:30:01 +0100461 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100462 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
463 echo "You can either delete or preserve your work, or force the test by rerunning the"
464 echo "script as: $0 --force"
465 exit 1
466 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100467 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100468}
SimonB2e23c822016-04-16 21:54:39 +0100469
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100470pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100471 failure_summary=
472 failure_count=0
473 start_red=
474 end_color=
475 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100476 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100477 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
478 start_red=$(printf '\033[31m')
479 end_color=$(printf '\033[0m')
480 ;;
481 esac
482 fi
483 record_status () {
484 if "$@"; then
485 last_status=0
486 else
487 last_status=$?
488 text="$current_section: $* -> $last_status"
489 failure_summary="$failure_summary
490$text"
491 failure_count=$((failure_count + 1))
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200492 echo "${start_red}^^^^$text^^^^${end_color}" >&2
Gilles Peskine7c652162017-12-11 00:01:40 +0100493 fi
494 }
495 make () {
496 case "$*" in
497 *test|*check)
498 if [ $build_status -eq 0 ]; then
499 record_status command make "$@"
500 else
501 echo "(skipped because the build failed)"
502 fi
503 ;;
504 *)
505 record_status command make "$@"
506 build_status=$last_status
507 ;;
508 esac
509 }
510 final_report () {
511 if [ $failure_count -gt 0 ]; then
512 echo
513 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
514 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
515 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100516 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100517 elif [ -z "${1-}" ]; then
518 echo "SUCCESS :)"
519 fi
520 if [ -n "${1-}" ]; then
521 echo "Killed by SIG$1."
522 fi
523 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100524}
525
Gilles Peskine7c652162017-12-11 00:01:40 +0100526if_build_succeeded () {
527 if [ $build_status -eq 0 ]; then
528 record_status "$@"
529 fi
530}
531
Gilles Peskine30bc3852019-01-09 23:25:25 +0100532# to be used instead of ! for commands run with
533# record_status or if_build_succeeded
534not() {
535 ! "$@"
536}
537
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200538pre_setup_quiet_redirect () {
539 if [ $QUIET -ne 1 ]; then
540 redirect_out () {
541 "$@"
542 }
543 else
544 redirect_out () {
545 "$@" >/dev/null
546 }
547 fi
548}
Gilles Peskine30bc3852019-01-09 23:25:25 +0100549
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100550pre_print_configuration () {
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200551 if [ $QUIET -eq 1 ]; then
552 return
553 fi
554
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100555 msg "info: $0 configuration"
556 echo "MEMORY: $MEMORY"
557 echo "FORCE: $FORCE"
558 echo "SEED: ${SEED-"UNSET"}"
559 echo "OPENSSL: $OPENSSL"
560 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
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 AG7770ea82016-10-10 15:46:20 +0100568
Andres AGd9eba4b2016-08-26 14:42:14 +0100569# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100570pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000571 # Build the list of variables to pass to output_env.sh.
572 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100573
Gilles Peskine541fb1e2019-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
588 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"
592 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
593 "$GNUTLS_CLI" "$GNUTLS_SERV" \
594 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
595 ;;
596 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100597
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000598 case " $RUN_COMPONENTS " in
599 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
600 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100601
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000602 case " $RUN_COMPONENTS " in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200603 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000604 esac
605
606 case " $RUN_COMPONENTS " in
607 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
608 esac
609
610 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100611 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000612 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
613 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200614 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000615 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
616 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200617 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
618 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
619 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine53084872019-01-09 23:13:54 +0100620 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100621
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +0200622 # past this point, no call to check_tool, only printing output
623 if [ $QUIET -eq 1 ]; then
624 return
625 fi
626
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100627 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100628 case $RUN_COMPONENTS in
629 *_armcc*|*_yotta*)
630 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
631 *) set "$@" RUN_ARMCC=0;;
632 esac
633 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100634}
Andres AGd9eba4b2016-08-26 14:42:14 +0100635
Gilles Peskine192c72f2017-12-21 15:59:21 +0100636
637
638################################################################
639#### Basic checks
640################################################################
SimonB2e23c822016-04-16 21:54:39 +0100641
642#
643# Test Suites to be executed
644#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200645# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100646# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200647# and/or are more likely to fail than others (eg I use Clang most of the
648# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200649# 2. Minimize total running time, by avoiding useless rebuilds
650#
651# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100652
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100653component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100654 msg "test: recursion.pl" # < 1s
655 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100656}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100657
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100658component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100659 msg "test: freshness of generated source files" # < 1s
660 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100661}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000662
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100663component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100664 msg "test: doxygen markup outside doxygen blocks" # < 1s
665 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100666}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200667
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100668component_check_files () {
Gilles Peskine00de8032020-06-25 14:18:34 +0200669 msg "Check: file sanity checks (permissions, encodings)" # < 1s
670 record_status tests/scripts/check_files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100671}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200672
Gilles Peskinec3189252020-05-10 17:40:49 +0200673component_check_changelog () {
674 msg "Check: changelog entries" # < 1s
675 rm -f ChangeLog.new
676 record_status scripts/assemble_changelog.py -o ChangeLog.new
677 if [ -e ChangeLog.new ]; then
678 # Show the diff for information. It isn't an error if the diff is
679 # non-empty.
680 diff -u ChangeLog ChangeLog.new || true
681 rm ChangeLog.new
682 fi
683}
684
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100685component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100686 msg "test/build: declared and exported names" # < 3s
Gilles Peskinee952fdf2019-05-15 17:52:22 +0200687 record_status tests/scripts/check-names.sh -v
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100688}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200689
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100690component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100691 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100692 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100693}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100694
Simon Butcher948f2642018-07-20 21:27:33 +0100695
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100696################################################################
697#### Build and test many configurations and targets
698################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100699
k-stachowiak45d0ba12019-06-04 13:14:58 +0200700component_test_large_ecdsa_key_signature () {
701
702 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
703
704 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
705 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
706 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
707 make
708
709 INEVITABLY_PRESENT_FILE=Makefile
710 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
711
712 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
713 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
714 rm -f $SIGNATURE_FILE
715}
716
Gilles Peskine1270d322019-04-08 17:00:15 +0200717component_test_default_out_of_box () {
718 msg "build: make, default config (out-of-box)" # ~1min
719 make
720
721 msg "test: main suites make, default config (out-of-box)" # ~10s
722 make test
723
724 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinebfda0332020-04-23 23:37:45 +0200725 if_build_succeeded programs/test/selftest
Gilles Peskine1270d322019-04-08 17:00:15 +0200726}
727
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100728component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100729 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
730 # path, and uses whatever version of armcc it finds there.
731 msg "build: create and build yotta module" # ~ 30s
732 record_status tests/scripts/yotta-build.sh
733}
734support_build_yotta () {
735 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100736}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100738component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100739 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100740 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100741 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200742
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100743 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100744 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100745
Gilles Peskinebfda0332020-04-23 23:37:45 +0200746 msg "test: selftest (ASan build)" # ~ 10s
747 if_build_succeeded programs/test/selftest
748
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100749 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100750 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100751
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100752 msg "test: compat.sh (ASan build)" # ~ 6 min
753 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100754}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000755
Hanno Becker167ae432019-02-26 14:27:09 +0000756component_test_full_cmake_gcc_asan () {
757 msg "build: full config, cmake, gcc, ASan"
758 scripts/config.pl full
759 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
760 make
761
762 msg "test: main suites (inc. selftests) (full config, ASan build)"
763 make test
764
Gilles Peskinebfda0332020-04-23 23:37:45 +0200765 msg "test: selftest (ASan build)" # ~ 10s
766 if_build_succeeded programs/test/selftest
767
Hanno Becker167ae432019-02-26 14:27:09 +0000768 msg "test: ssl-opt.sh (full config, ASan build)"
769 if_build_succeeded tests/ssl-opt.sh
770
771 msg "test: compat.sh (full config, ASan build)"
772 if_build_succeeded tests/compat.sh
773}
774
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100775component_test_zlib_make() {
776 msg "build: zlib enabled, make"
777 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
778 make ZLIB=1 CFLAGS='-Werror -O1'
779
780 msg "test: main suites (zlib, make)"
781 make test
782
783 msg "test: ssl-opt.sh (zlib, make)"
784 if_build_succeeded tests/ssl-opt.sh
785}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100786support_test_zlib_make () {
787 base=support_test_zlib_$$
788 cat <<'EOF' > ${base}.c
789#include "zlib.h"
790int main(void) { return 0; }
791EOF
792 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
793 ret=$?
794 rm -f ${base}.*
795 return $ret
796}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100797
798component_test_zlib_cmake() {
799 msg "build: zlib enabled, cmake"
800 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
801 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
802 make
803
804 msg "test: main suites (zlib, cmake)"
805 make test
806
807 msg "test: ssl-opt.sh (zlib, cmake)"
808 if_build_succeeded tests/ssl-opt.sh
809}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100810support_test_zlib_cmake () {
811 support_test_zlib_make "$@"
812}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100813
Gilles Peskine3484ed82019-01-08 22:51:19 +0100814component_test_ref_configs () {
815 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
816 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
817 record_status tests/scripts/test-ref-configs.pl
818}
819
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100820component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100821 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100822 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
823 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
824 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000825
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100826 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
827 make test
828
829 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
830 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
831 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
832
833 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
834 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100835}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100836
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100837component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100838 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100839 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
840 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
841 make
842
843 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
844 make test
845
846 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
847 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100848}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100849
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100850component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100851 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100852 scripts/config.pl set MBEDTLS_RSA_NO_CRT
853 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
854 make
855
856 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
857 make test
858
859 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
860 if_build_succeeded tests/ssl-opt.sh -f RSA
861
862 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
863 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100864}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100865
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200866component_test_no_ctr_drbg () {
867 msg "build: Full minus CTR_DRBG"
868 scripts/config.pl full
869 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
870
871 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
872 make
873
874 msg "test: no CTR_DRBG"
875 make test
876
Manuel Pégourié-Gonnardcdfa2f92020-06-05 09:29:51 +0200877 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
878}
879
880component_test_no_hmac_drbg () {
881 msg "build: Full minus HMAC_DRBG"
882 scripts/config.pl full
883 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
884 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
885
886 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
887 make
888
Gilles Peskineea4cc852020-11-19 22:14:34 +0100889 msg "test: Full minus HMAC_DRBG - main suites"
Manuel Pégourié-Gonnardcdfa2f92020-06-05 09:29:51 +0200890 make test
891
Gilles Peskineea4cc852020-11-19 22:14:34 +0100892 # Normally our ECDSA implementation uses deterministic ECDSA. But since
893 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
894 # instead.
895 # Test SSL with non-deterministic ECDSA. Only test features that
896 # might be affected by how ECDSA signature is performed.
897 msg "test: Full minus HMAC_DRBG - ssl-opt.sh (subset)"
898 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
899
900 # To save time, only test one protocol version, since this part of
901 # the protocol is identical in (D)TLS up to 1.2.
902 msg "test: Full minus HMAC_DRBG - compat.sh (ECDSA)"
903 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA'
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200904}
905
Manuel Pégourié-Gonnard6d614982020-06-16 12:51:42 +0200906component_test_no_drbg_all_hashes () {
907 # this tests the internal ECP DRBG using a KDF based on SHA-512
908 msg "build: Default minus DRBGs"
909 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
910 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
911 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
912 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
913 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
914
915 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
916 make
917
918 msg "test: Default minus DRBGs"
919 make test
920
921 # no SSL tests as they all depend on having a DRBG
922}
923
924component_test_no_drbg_no_sha512 () {
925 # this tests the internal ECP DRBG using a KDF based on SHA-256
926 msg "build: Default minus DRBGs minus SHA-512"
927 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
928 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
929 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
930 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
931 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
932 scripts/config.pl unset MBEDTLS_SHA512_C
933
934 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
935 make
936
937 msg "test: Default minus DRBGs minus SHA-512"
938 make test
939
940 # no SSL tests as they all depend on having a DRBG
941}
942
Manuel Pégourié-Gonnardd90faf92020-05-19 12:38:31 +0200943component_test_ecp_no_internal_rng () {
944 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
945 scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
946 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
947 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
948 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
949 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
950 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
951
952 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
953 make
954
955 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
956 make test
957
958 # no SSL tests as they all depend on having a DRBG
959}
960
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100961component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100962 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100963 scripts/config.pl full
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100964 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
965 make
966
967 msg "test: main suites (full config)" # ~ 5s
968 make test
969
970 msg "test: ssl-opt.sh default (full config)" # ~ 1s
971 if_build_succeeded tests/ssl-opt.sh -f Default
972
Andres Amaya Garcia0a0e5b12019-01-08 21:42:27 +0000973 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000974 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100975}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100976
Manuel Pégourié-Gonnard40597ce2020-07-28 10:53:06 +0200977component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard2b223fd2020-07-22 11:09:28 +0200978 # This tests both (1) accesses to undefined memory, and (2) branches or
979 # memory access depending on secret values. To distinguish between those:
980 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
981 # - or alternatively, change the build type to MemSanDbg, which enables
982 # origin tracking and nicer stack traces (which are useful for debugging
983 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
984 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard40597ce2020-07-28 10:53:06 +0200985 scripts/config.pl full
986 scripts/config.pl set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
987 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
988 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
989 make
990
Manuel Pégourié-Gonnard2b223fd2020-07-22 11:09:28 +0200991 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard40597ce2020-07-28 10:53:06 +0200992 make test
993}
994
Manuel Pégourié-Gonnard426c2d42020-08-25 11:26:37 +0200995component_test_valgrind_constant_flow () {
996 # This tests both (1) everything that valgrind's memcheck usually checks
997 # (heap buffer overflows, use of uninitialized memory, use-after-free,
998 # etc.) and (2) branches or memory access depending on secret values,
999 # which will be reported as uninitialized memory. To distinguish between
1000 # secret and actually uninitialized:
1001 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1002 # - or alternatively, build with debug info and manually run the offending
1003 # test suite with valgrind --track-origins=yes, then check if the origin
1004 # was TEST_CF_SECRET() or something else.
1005 msg "build: cmake release GCC, full config with constant flow testing"
1006 scripts/config.pl full
1007 scripts/config.pl set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1008 cmake -D CMAKE_BUILD_TYPE:String=Release .
1009 make
1010
1011 # this only shows a summary of the results (how many of each type)
1012 # details are left in Testing/<date>/DynamicAnalysis.xml
1013 msg "test: main suites (valgrind + constant flow)"
1014 make memcheck
1015}
1016
Gilles Peskineadaaddb2020-04-28 14:04:28 +02001017component_test_default_no_deprecated () {
1018 # Test that removing the deprecated features from the default
1019 # configuration leaves something consistent.
1020 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001021 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskineadaaddb2020-04-28 14:04:28 +02001022 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1023
1024 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1025 make test
1026}
1027
1028component_test_full_deprecated_warning () {
1029 # Test that there is nothing deprecated in the full configuraration.
1030 # A deprecated feature would trigger a warning (made fatal) from
1031 # MBEDTLS_DEPRECATED_WARNING.
1032 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1033 scripts/config.pl full
1034 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
1035 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
1036 # There are currently no tests for any deprecated feature.
1037 # If some are added, 'make test' would trigger warnings here.
1038 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1039
1040 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
1041 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001042}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001043
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001044component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001045 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001046 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001047}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001048
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001049component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001050 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001051 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001052}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001053
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001054component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001055 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001056 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001057}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001058
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001059component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001060 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001061 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001062}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001063
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001064component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001065 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001066 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001067}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001068
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001069component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001070 # Full configuration build, without platform support, file IO and net sockets.
1071 # This should catch missing mbedtls_printf definitions, and by disabling file
1072 # IO, it should catch missing '#include <stdio.h>'
1073 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001074 scripts/config.pl full
1075 scripts/config.pl unset MBEDTLS_PLATFORM_C
1076 scripts/config.pl unset MBEDTLS_NET_C
1077 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1078 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1079 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1080 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1081 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1082 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinea21c5e92020-04-28 10:41:20 +02001083 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001084 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001085 scripts/config.pl unset MBEDTLS_FS_IO
1086 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1087 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskinec9247122019-09-20 19:23:10 +02001088 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1089 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001090}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001091
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001092component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001093 # catch compile bugs in _uninit functions
1094 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001095 scripts/config.pl full
1096 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1097 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +02001098 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec9247122019-09-20 19:23:10 +02001099 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001100}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001101
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001102component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001103 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001104 scripts/config.pl full
1105 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinec9247122019-09-20 19:23:10 +02001106 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001107}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001108
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001109component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001110 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001111 scripts/config.pl full
1112 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinec9247122019-09-20 19:23:10 +02001113 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001114}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001115
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001116component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001117 # Note, C99 compliance can also be tested with the sockets support disabled,
1118 # as that requires a POSIX platform (which isn't the same as C99).
1119 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001120 scripts/config.pl full
1121 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1122 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinec9247122019-09-20 19:23:10 +02001123 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001124}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001125
Andrzej Kurek9a461a12019-09-05 09:27:47 -04001126component_test_memory_buffer_allocator_backtrace () {
1127 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001128 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek9a461a12019-09-05 09:27:47 -04001129 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001130 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9b1c2482019-09-10 02:58:34 -04001131 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek9a461a12019-09-05 09:27:47 -04001132 CC=gcc cmake .
1133 make
1134
1135 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1136 make test
1137}
1138
1139component_test_memory_buffer_allocator () {
1140 msg "build: default config with memory buffer allocator"
1141 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Becker7aad93c2019-06-03 16:35:02 +01001142 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001143 CC=gcc cmake .
1144 make
1145
1146 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1147 make test
1148
1149 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek6addfdd2019-09-05 10:09:37 -04001150 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1151 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001152}
1153
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001154component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001155 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001156 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1157 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1158 make
1159
1160 msg "test: ssl-opt.sh, MFL-related tests"
1161 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001162}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001163
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001164component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001165 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001166 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1167 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1168 scripts/config.pl set MBEDTLS_ENTROPY_C
1169 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +02001170 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001171 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1172 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +00001173 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001174 make
1175
1176 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1177 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001178}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001179
Raoul Strackx2a8e9582020-06-15 17:03:13 +02001180component_test_no_date_time () {
1181 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
1182 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1183 CC=gcc cmake
1184 make
1185
1186 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
1187 make test
1188}
1189
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001190component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001191 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001192 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1193 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1194 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1195 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1196 make
1197
1198 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1199 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001200}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001201
Gilles Peskine0981a5d2019-09-17 19:04:38 +02001202component_test_malloc_0_null () {
1203 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1204 scripts/config.pl full
1205 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Gilles Peskinea0d5d772021-01-13 22:24:51 +01001206 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine0981a5d2019-09-17 19:04:38 +02001207
1208 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1209 make test
1210
1211 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1212 # Just the calloc selftest. "make test" ran the others as part of the
1213 # test suites.
1214 if_build_succeeded programs/test/selftest calloc
1215}
1216
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001217component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001218 msg "build/test: make shared" # ~ 40s
1219 make SHARED=1 all check
Gilles Peskine950de1e2019-07-03 20:43:32 +02001220 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001221}
1222
Gilles Peskine17ecb242019-07-03 20:43:05 +02001223component_test_cmake_shared () {
1224 msg "build/test: cmake shared" # ~ 2min
1225 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1226 make
Gilles Peskine950de1e2019-07-03 20:43:32 +02001227 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine17ecb242019-07-03 20:43:05 +02001228 make test
1229}
1230
Gilles Peskinefa0e8b52019-09-20 19:56:06 +02001231test_build_opt () {
1232 info=$1 cc=$2; shift 2
1233 for opt in "$@"; do
1234 msg "build/test: $cc $opt, $info" # ~ 30s
1235 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1236 # We're confident enough in compilers to not run _all_ the tests,
1237 # but at least run the unit tests. In particular, runs with
1238 # optimizations use inline assembly whereas runs with -O0
1239 # skip inline assembly.
1240 make test # ~30s
1241 make clean
1242 done
1243}
1244
1245component_test_clang_opt () {
1246 scripts/config.pl full
1247 test_build_opt 'full config' clang -O0 -Os -O2
1248}
1249
1250component_test_gcc_opt () {
1251 scripts/config.pl full
1252 test_build_opt 'full config' gcc -O0 -Os -O2
1253}
1254
Gilles Peskinef852f5f2019-07-03 20:42:16 +02001255component_build_mbedtls_config_file () {
1256 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1257 # Use the full config so as to catch a maximum of places where
1258 # the check of MBEDTLS_CONFIG_FILE might be missing.
1259 scripts/config.pl full
1260 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1261 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1262 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1263 rm -f full_config.h
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001264}
1265
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001266component_test_m32_o0 () {
1267 # Build once with -O0, to compile out the i386 specific inline assembly
1268 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1269 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001270 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001271
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001272 msg "test: i386, make, gcc -O0 (ASan build)"
1273 make test
1274}
1275support_test_m32_o0 () {
1276 case $(uname -m) in
1277 *64*) true;;
1278 *) false;;
1279 esac
1280}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001281
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001282component_test_m32_o1 () {
1283 # Build again with -O1, to compile in the i386 specific inline assembly
1284 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1285 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001286 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001287
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001288 msg "test: i386, make, gcc -O1 (ASan build)"
1289 make test
Gilles Peskine11064292019-04-08 16:58:02 +02001290
1291 msg "test ssl-opt.sh, i386, make, gcc-O1"
1292 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001293}
1294support_test_m32_o1 () {
1295 support_test_m32_o0 "$@"
1296}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001297
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001298component_test_mx32 () {
1299 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1300 scripts/config.pl full
Gilles Peskined535f4d2019-06-07 14:50:09 +02001301 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001302
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001303 msg "test: 64-bit ILP32, make, gcc"
1304 make test
1305}
1306support_test_mx32 () {
1307 case $(uname -m) in
1308 amd64|x86_64) true;;
1309 *) false;;
1310 esac
1311}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001312
Peter Kolbus16015dd2018-12-27 06:59:04 -06001313component_test_min_mpi_window_size () {
1314 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1315 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1316 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1317 make
1318
1319 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1320 make test
1321}
1322
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001323component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001324 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001325 scripts/config.pl unset MBEDTLS_HAVE_ASM
1326 scripts/config.pl unset MBEDTLS_AESNI_C
1327 scripts/config.pl unset MBEDTLS_PADLOCK_C
1328 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1329
1330 msg "test: gcc, force 32-bit bignum limbs"
1331 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001332}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001333
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001334component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001335 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001336 scripts/config.pl unset MBEDTLS_HAVE_ASM
1337 scripts/config.pl unset MBEDTLS_AESNI_C
1338 scripts/config.pl unset MBEDTLS_PADLOCK_C
1339 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1340
1341 msg "test: gcc, force 64-bit bignum limbs"
1342 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001343}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001344
Gilles Peskined754c8b2020-11-09 15:40:05 +01001345component_test_no_strings () {
1346 msg "build: no strings" # ~10s
1347 scripts/config.pl full
1348 # Disable options that activate a large amount of string constants.
1349 scripts/config.pl unset MBEDTLS_DEBUG_C
1350 scripts/config.pl unset MBEDTLS_ERROR_C
1351 scripts/config.pl set MBEDTLS_ERROR_STRERROR_DUMMY
1352 scripts/config.pl unset MBEDTLS_VERSION_FEATURES
1353 make CFLAGS='-Werror -Os'
1354
1355 msg "test: no strings" # ~ 10s
1356 make test
1357}
1358
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001359component_build_arm_none_eabi_gcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001360 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001361 scripts/config.pl baremetal
Gilles Peskine009908b2020-04-30 22:54:00 +02001362 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -O1' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001363
1364 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1365 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001366}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001367
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001368component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001369 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001370 scripts/config.pl baremetal
1371 # Build for a target platform that's close to what Debian uses
1372 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1373 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1374 # It would be better to build with arm-linux-gnueabi-gcc but
1375 # we don't have that on our CI at this time.
1376 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001377
1378 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1379 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001380}
1381
Gilles Peskine4fb7a2f2020-04-30 23:00:53 +02001382component_build_arm_none_eabi_gcc_m0plus () {
1383 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1384 scripts/config.pl baremetal
1385 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001386
1387 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1388 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001389}
1390
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001391component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001392 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001393 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001394 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001395 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001396 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +01001397 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001398}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001399
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001400component_build_armcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001401 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001402 scripts/config.pl baremetal
Gilles Peskine53084872019-01-09 23:13:54 +01001403 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001404
1405 msg "size: ARM Compiler 5"
1406 "$ARMC5_FROMELF" -z library/*.o
1407
Gilles Peskine53084872019-01-09 23:13:54 +01001408 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001409
Gilles Peskine53084872019-01-09 23:13:54 +01001410 # ARM Compiler 6 - Target ARMv7-A
1411 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001412
Gilles Peskine53084872019-01-09 23:13:54 +01001413 # ARM Compiler 6 - Target ARMv7-M
1414 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001415
Gilles Peskine53084872019-01-09 23:13:54 +01001416 # ARM Compiler 6 - Target ARMv8-A - AArch32
1417 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001418
Gilles Peskine53084872019-01-09 23:13:54 +01001419 # ARM Compiler 6 - Target ARMv8-M
1420 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001421
Gilles Peskine53084872019-01-09 23:13:54 +01001422 # ARM Compiler 6 - Target ARMv8-A - AArch64
1423 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001424}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001425
Andres Amaya Garciabb13e3b2018-12-05 22:03:56 +00001426component_build_ssl_hw_record_accel() {
1427 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1428 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1429 make CFLAGS='-Werror -O1'
1430}
1431
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001432component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001433 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001434 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1435 make CFLAGS='-Werror -Wall -Wextra'
1436 msg "test: allow SHA1 in certificates by default"
1437 make test
1438 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001439}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001440
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001441component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001442 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001443 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
1444
1445 # note Make tests only builds the tests, but doesn't run them
1446 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1447 make WINDOWS_BUILD=1 clean
1448
1449 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1450 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
1451 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
1452 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001453}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001454
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001455component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001456 msg "build: MSan (clang)" # ~ 1 min 20s
1457 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1458 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1459 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001460
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001461 msg "test: main suites (MSan)" # ~ 10s
1462 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001463
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001464 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1465 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001466
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001467 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001468
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001469 if [ "$MEMORY" -gt 0 ]; then
1470 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1471 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001472 fi
1473}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001474
Gilles Peskine9f553642019-01-10 00:11:42 +01001475component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001476 msg "build: Release (clang)"
1477 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1478 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001479
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001480 msg "test: main suites valgrind (Release)"
1481 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001482
Gilles Peskine26cae712019-04-08 17:00:56 +02001483 # Optional parts (slow; currently broken on OS X because programs don't
1484 # seem to receive signals under valgrind on OS X).
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001485 if [ "$MEMORY" -gt 0 ]; then
1486 msg "test: ssl-opt.sh --memcheck (Release)"
1487 if_build_succeeded tests/ssl-opt.sh --memcheck
1488 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001489
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001490 if [ "$MEMORY" -gt 1 ]; then
1491 msg "test: compat.sh --memcheck (Release)"
1492 if_build_succeeded tests/compat.sh --memcheck
1493 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001494}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001495
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001496component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001497 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001498 MBEDTLS_ROOT_DIR="$PWD"
1499 mkdir "$OUT_OF_SOURCE_DIR"
1500 cd "$OUT_OF_SOURCE_DIR"
1501 cmake "$MBEDTLS_ROOT_DIR"
1502 make
1503
1504 msg "test: cmake 'out-of-source' build"
1505 make test
1506 # Test an SSL option that requires an auxiliary script in test/scripts/.
1507 # Also ensure that there are no error messages such as
1508 # "No such file or directory", which would indicate that some required
1509 # file is missing (ssl-opt.sh tolerates the absence of some files so
1510 # may exit with status 0 but emit errors).
1511 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1512 if [ -s ssl-opt.err ]; then
1513 cat ssl-opt.err >&2
1514 record_status [ ! -s ssl-opt.err ]
1515 rm ssl-opt.err
1516 fi
1517 cd "$MBEDTLS_ROOT_DIR"
1518 rm -rf "$OUT_OF_SOURCE_DIR"
1519 unset MBEDTLS_ROOT_DIR
1520}
Andres AGdc192212016-08-31 17:33:13 +01001521
Gilles Peskine192c72f2017-12-21 15:59:21 +01001522
1523
1524################################################################
1525#### Termination
1526################################################################
1527
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001528post_report () {
1529 msg "Done, cleaning up"
1530 cleanup
1531
1532 final_report
1533}
1534
1535
1536
1537################################################################
1538#### Run all the things
1539################################################################
1540
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001541# Run one component and clean up afterwards.
1542run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001543 # Back up the configuration in case the component modifies it.
1544 # The cleanup function will restore it.
1545 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001546 current_component="$1"
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +02001547
1548 # Run the component code.
1549 if [ $QUIET -eq 1 ]; then
1550 # msg() is silenced, so just print the component name here
1551 echo "${current_component#component_}"
1552 fi
1553 redirect_out "$@"
1554
1555 # Restore the build tree to a clean state.
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001556 cleanup
Manuel Pégourié-Gonnardc09bb4c2020-06-08 10:59:41 +02001557 unset current_component
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001558}
1559
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001560# Preliminary setup
1561pre_check_environment
1562pre_initialize_variables
1563pre_parse_command_line "$@"
1564
1565pre_check_git
1566build_status=0
1567if [ $KEEP_GOING -eq 1 ]; then
1568 pre_setup_keep_going
1569else
1570 record_status () {
1571 "$@"
1572 }
1573fi
Manuel Pégourié-Gonnard73341a02020-06-02 11:28:07 +02001574pre_setup_quiet_redirect
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001575pre_print_configuration
1576pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001577cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001578
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001579# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001580for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001581 run_component "component_$component"
1582done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001583
1584# We're done.
1585post_report