blob: f3ab28b9602831c045dc3f6267c1e566fb9fd2be [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
Gilles Peskine192c72f2017-12-21 15:59:21 +01005# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
Bence Szépkúti51b41d52020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# This file is part of Mbed TLS (https://tls.mbed.org)
Gilles Peskine192c72f2017-12-21 15:59:21 +010021
22
23
24################################################################
25#### Documentation
26################################################################
27
Simon Butcher3ea7f522016-03-07 23:22:10 +000028# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000030#
SimonB2e23c822016-04-16 21:54:39 +010031# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010032#
Gilles Peskine192c72f2017-12-21 15:59:21 +010033# Notes for users
34# ---------------
35#
SimonB2e23c822016-04-16 21:54:39 +010036# Warning: the test is destructive. It includes various build modes and
37# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010038# configuration. The following files must be committed into git:
39# * include/mbedtls/config.h
40# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
41# After running this script, the CMake cache will be lost and CMake
42# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010043#
Gilles Peskine192c72f2017-12-21 15:59:21 +010044# The script assumes the presence of a number of tools:
45# * Basic Unix tools (Windows users note: a Unix-style find must be before
46# the Windows find in the PATH)
47# * Perl
48# * GNU Make
49# * CMake
50# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040051# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010052# * arm-gcc and mingw-gcc
53# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010054# * OpenSSL and GnuTLS command line tools, recent enough for the
55# interoperability tests. If they don't support SSLv3 then a legacy
56# version of these tools must be present as well (search for LEGACY
57# below).
58# See the invocation of check_tools below for details.
59#
60# This script must be invoked from the toplevel directory of a git
61# working copy of Mbed TLS.
62#
63# Note that the output is not saved. You may want to run
64# script -c tests/scripts/all.sh
65# or
66# tests/scripts/all.sh >all.log 2>&1
67#
68# Notes for maintainers
69# ---------------------
70#
Gilles Peskine8f073122018-11-27 15:58:47 +010071# The bulk of the code is organized into functions that follow one of the
72# following naming conventions:
73# * pre_XXX: things to do before running the tests, in order.
74# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010075# * component_check_XXX: quick tests that aren't worth parallelizing.
76# * component_build_XXX: build things but don't run them.
77# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000078# * support_XXX: if support_XXX exists and returns false then
79# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010080# * post_XXX: things to do after running the tests.
81# * other: miscellaneous support functions.
82#
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# Each component must start by invoking `msg` with a short informative message.
84#
85# The framework performs some cleanup tasks after each component. This
86# means that components can assume that the working directory is in a
87# cleaned-up state, and don't need to perform the cleanup themselves.
88# * Run `make clean`.
89# * Restore `include/mbedtks/config.h` from a backup made before running
90# the component.
91# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
92# `tests/Makefile` from git. This cleans up after an in-tree use of
93# CMake.
94#
95# Any command that is expected to fail must be protected so that the
96# script keeps running in --keep-going mode despite `set -e`. In keep-going
97# mode, if a protected command fails, this is logged as a failure and the
98# script will exit with a failure status once it has run all components.
99# Commands can be protected in any of the following ways:
100# * `make` is a function which runs the `make` command with protection.
101# Note that you must write `make VAR=value`, not `VAR=value make`,
102# because the `VAR=value make` syntax doesn't work with functions.
103# * Put `report_status` before the command to protect it.
104# * Put `if_build_successful` before a command. This protects it, and
105# additionally skips it if a prior invocation of `make` in the same
106# component failed.
107#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100108# The tests are roughly in order from fastest to slowest. This doesn't
109# have to be exact, but in general you should add slower tests towards
110# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100111
112
113
114################################################################
115#### Initialization and command line parsing
116################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100117
SimonB2e23c822016-04-16 21:54:39 +0100118# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100119set -eu
120
Gilles Peskine8f073122018-11-27 15:58:47 +0100121pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000122 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100123 echo "Must be run from mbed TLS root" >&2
124 exit 1
125 fi
126}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100127
Gilles Peskine8f073122018-11-27 15:58:47 +0100128pre_initialize_variables () {
129 CONFIG_H='include/mbedtls/config.h'
130 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200131
Gilles Peskine8f073122018-11-27 15:58:47 +0100132 MEMORY=0
133 FORCE=0
134 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100135
Antonin Décimod5f47592019-01-23 15:24:37 +0100136 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 : ${OPENSSL:="openssl"}
138 : ${OPENSSL_LEGACY:="$OPENSSL"}
139 : ${OPENSSL_NEXT:="$OPENSSL"}
140 : ${GNUTLS_CLI:="gnutls-cli"}
141 : ${GNUTLS_SERV:="gnutls-serv"}
142 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
143 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
144 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
145 : ${ARMC5_BIN_DIR:=/usr/bin}
146 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200147 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100148
Gilles Peskine8f073122018-11-27 15:58:47 +0100149 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000150 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100151 export MAKEFLAGS="-j"
152 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000153
Gilles Peskineff26b042019-10-21 17:11:33 +0200154 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskineac479062019-10-21 19:06:33 +0200155 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskineff26b042019-10-21 17:11:33 +0200156
Gilles Peskine878cf602019-01-06 20:50:38 +0000157 # Gather the list of available components. These are the functions
158 # defined in this script whose name starts with "component_".
159 # Parse the script with sed, because in sh there is no way to list
160 # defined functions.
161 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
162
163 # Exclude components that are not supported on this platform.
164 SUPPORTED_COMPONENTS=
165 for component in $ALL_COMPONENTS; do
166 case $(type "support_$component" 2>&1) in
167 *' function'*)
168 if ! support_$component; then continue; fi;;
169 esac
170 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
171 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100172}
Andres AG38495a32016-07-12 16:54:33 +0100173
Gilles Peskinea28db922019-01-10 00:05:18 +0100174# Test whether the component $1 is included in the command line patterns.
175is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100176{
177 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000178 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100179 set +f
180 case ${1#component_} in $pattern) return 0;; esac
181 done
182 set +f
183 return 1
184}
185
Simon Butcher41eeccf2016-09-07 00:07:09 +0100186usage()
SimonB2e23c822016-04-16 21:54:39 +0100187{
Gilles Peskine709346a2017-12-10 23:43:39 +0100188 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100189Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100190Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100191By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100192COMPONENT can be the name of a component or a shell wildcard pattern.
193
194Examples:
195 $0 "check_*"
196 Run all sanity checks.
197 $0 --no-armcc --except test_memsan
198 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100199
200Special options:
201 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000202 --list-all-components List all available test components and exit.
203 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100204
205General options:
206 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100207 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 -m|--memory Additional optional memory tests.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200209 --arm-none-eabi-gcc-prefix=<string>
210 Prefix for a cross-compiler for arm-none-eabi
211 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100212 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100213 --except Exclude the COMPONENTs listed on the command line,
214 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100215 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100216 --no-force Refuse to overwrite modified files (default).
217 --no-keep-going Stop at the first error (default).
218 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100219 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100220 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100221 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
222 -s|--seed Integer seed value to use for this test run.
223
224Tool path options:
225 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
226 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
227 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
228 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
229 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
230 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
231 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
232 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100233 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100234EOF
SimonB2e23c822016-04-16 21:54:39 +0100235}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100236
237# remove built files as well as the cmake cache/config
238cleanup()
239{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100240 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
241 cd "$MBEDTLS_ROOT_DIR"
242 fi
243
Gilles Peskine7c652162017-12-11 00:01:40 +0100244 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200245
Gilles Peskine31b07e22018-03-21 12:15:06 +0100246 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100247 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100248 -iname CMakeFiles -exec rm -rf {} \+ -o \
249 \( -iname cmake_install.cmake -o \
250 -iname CTestTestfile.cmake -o \
251 -iname CMakeCache.txt \) -exec rm {} \+
252 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000253 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200254 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
255 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200256
257 if [ -f "$CONFIG_BAK" ]; then
258 mv "$CONFIG_BAK" "$CONFIG_H"
259 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100260}
261
Gilles Peskine7c652162017-12-11 00:01:40 +0100262# Executed on exit. May be redefined depending on command line options.
263final_report () {
264 :
265}
266
267fatal_signal () {
268 cleanup
269 final_report $1
270 trap - $1
271 kill -$1 $$
272}
273
274trap 'fatal_signal HUP' HUP
275trap 'fatal_signal INT' INT
276trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200277
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100278msg()
279{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100280 if [ -n "${current_component:-}" ]; then
281 current_section="${current_component#component_}: $1"
282 else
283 current_section="$1"
284 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100285 echo ""
286 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100287 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000288 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100289 echo "******************************************************************"
290}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100291
Gilles Peskine8f073122018-11-27 15:58:47 +0100292armc6_build_test()
293{
294 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100295
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200296 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100297 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
298 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200299
300 msg "size: ARM Compiler 6 ($FLAGS)"
301 "$ARMC6_FROMELF" -z library/*.o
302
Gilles Peskine8f073122018-11-27 15:58:47 +0100303 make clean
304}
Andres AGa5cd9732016-10-17 15:23:10 +0100305
Andres AGd9eba4b2016-08-26 14:42:14 +0100306err_msg()
307{
308 echo "$1" >&2
309}
310
311check_tools()
312{
313 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000314 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100315 err_msg "$TOOL not found!"
316 exit 1
317 fi
318 done
319}
320
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400321check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600322 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400323 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
324 sort |
325 diff headers.txt -
326 rm headers.txt
327}
328
Gilles Peskine8f073122018-11-27 15:58:47 +0100329pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000330 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100331 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000332 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000333
Gilles Peskine8f073122018-11-27 15:58:47 +0100334 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100335 case "$1" in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200336 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000337 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100338 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
339 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000340 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 --force|-f) FORCE=1;;
342 --gnutls-cli) shift; GNUTLS_CLI="$1";;
343 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
344 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
345 --gnutls-serv) shift; GNUTLS_SERV="$1";;
346 --help|-h) usage; exit;;
347 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000348 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
349 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100350 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000351 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100352 --no-force) FORCE=0;;
353 --no-keep-going) KEEP_GOING=0;;
354 --no-memory) MEMORY=0;;
355 --openssl) shift; OPENSSL="$1";;
356 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
357 --openssl-next) shift; OPENSSL_NEXT="$1";;
358 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
359 --random-seed) unset SEED;;
360 --release-test|-r) SEED=1;;
361 --seed|-s) shift; SEED="$1";;
362 -*)
363 echo >&2 "Unknown option: $1"
364 echo >&2 "Run $0 --help for usage."
365 exit 120
366 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000367 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100368 esac
369 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100370 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000371
Gilles Peskinea28db922019-01-10 00:05:18 +0100372 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000373 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
374 all_except=1
375 fi
376
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000377 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
378 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100379 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000380 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
381 fi
382
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000383 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100384 RUN_COMPONENTS=
385 for component in $SUPPORTED_COMPONENTS; do
386 if is_component_included "$component"; [ $? -eq $all_except ]; then
387 RUN_COMPONENTS="$RUN_COMPONENTS $component"
388 fi
389 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000390
391 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000392 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100393}
SimonB2e23c822016-04-16 21:54:39 +0100394
Gilles Peskine8f073122018-11-27 15:58:47 +0100395pre_check_git () {
396 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100397 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100398 git checkout-index -f -q $CONFIG_H
399 cleanup
400 else
SimonB2e23c822016-04-16 21:54:39 +0100401
Gilles Peskine8f073122018-11-27 15:58:47 +0100402 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
403 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
404 echo "You can either delete this directory manually, or force the test by rerunning"
405 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
406 exit 1
407 fi
408
Gilles Peskined1174cf2019-01-09 22:30:01 +0100409 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100410 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
411 echo "You can either delete or preserve your work, or force the test by rerunning the"
412 echo "script as: $0 --force"
413 exit 1
414 fi
Andres AGdc192212016-08-31 17:33:13 +0100415 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100416}
Andres AGdc192212016-08-31 17:33:13 +0100417
Gilles Peskine8f073122018-11-27 15:58:47 +0100418pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100419 failure_summary=
420 failure_count=0
421 start_red=
422 end_color=
423 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100424 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100425 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
426 start_red=$(printf '\033[31m')
427 end_color=$(printf '\033[0m')
428 ;;
429 esac
430 fi
431 record_status () {
432 if "$@"; then
433 last_status=0
434 else
435 last_status=$?
436 text="$current_section: $* -> $last_status"
437 failure_summary="$failure_summary
438$text"
439 failure_count=$((failure_count + 1))
440 echo "${start_red}^^^^$text^^^^${end_color}"
441 fi
442 }
443 make () {
444 case "$*" in
445 *test|*check)
446 if [ $build_status -eq 0 ]; then
447 record_status command make "$@"
448 else
449 echo "(skipped because the build failed)"
450 fi
451 ;;
452 *)
453 record_status command make "$@"
454 build_status=$last_status
455 ;;
456 esac
457 }
458 final_report () {
459 if [ $failure_count -gt 0 ]; then
460 echo
461 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
462 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
463 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100464 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100465 elif [ -z "${1-}" ]; then
466 echo "SUCCESS :)"
467 fi
468 if [ -n "${1-}" ]; then
469 echo "Killed by SIG$1."
470 fi
471 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100472}
473
Gilles Peskine7c652162017-12-11 00:01:40 +0100474if_build_succeeded () {
475 if [ $build_status -eq 0 ]; then
476 record_status "$@"
477 fi
478}
479
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200480# to be used instead of ! for commands run with
481# record_status or if_build_succeeded
482not() {
483 ! "$@"
484}
485
Gilles Peskine8f073122018-11-27 15:58:47 +0100486pre_print_configuration () {
487 msg "info: $0 configuration"
488 echo "MEMORY: $MEMORY"
489 echo "FORCE: $FORCE"
490 echo "SEED: ${SEED-"UNSET"}"
491 echo "OPENSSL: $OPENSSL"
492 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
493 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
494 echo "GNUTLS_CLI: $GNUTLS_CLI"
495 echo "GNUTLS_SERV: $GNUTLS_SERV"
496 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
497 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
498 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
499 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
500}
Andres AG87bb5772016-09-27 15:05:15 +0100501
Gilles Peskine87964262019-01-06 22:40:00 +0000502# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100503pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000504 # Build the list of variables to pass to output_env.sh.
505 set env
506
Gilles Peskine87964262019-01-06 22:40:00 +0000507 case " $RUN_COMPONENTS " in
508 # Require OpenSSL and GnuTLS if running any tests (as opposed to
509 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
510 # is a good enough approximation in practice.
511 *" test_"*)
512 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
513 # and ssl-opt.sh, we just export the variables they require.
514 export OPENSSL_CMD="$OPENSSL"
515 export GNUTLS_CLI="$GNUTLS_CLI"
516 export GNUTLS_SERV="$GNUTLS_SERV"
517 # Avoid passing --seed flag in every call to ssl-opt.sh
518 if [ -n "${SEED-}" ]; then
519 export SEED
520 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000521 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
522 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
523 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
524 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000525 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
526 "$GNUTLS_CLI" "$GNUTLS_SERV" \
527 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
528 ;;
529 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100530
Gilles Peskine87964262019-01-06 22:40:00 +0000531 case " $RUN_COMPONENTS " in
532 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
533 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100534
Gilles Peskine87964262019-01-06 22:40:00 +0000535 case " $RUN_COMPONENTS " in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200536 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000537 esac
Andres AG7770ea82016-10-10 15:46:20 +0100538
Gilles Peskine87964262019-01-06 22:40:00 +0000539 case " $RUN_COMPONENTS " in
540 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
541 esac
542
543 case " $RUN_COMPONENTS " in
544 *" test_zeroize "*) check_tools "gdb";;
545 esac
546
547 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000548 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000549 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
550 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200551 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000552 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
553 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200554 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
555 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
556 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000557 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000558
559 msg "info: output_env.sh"
560 case $RUN_COMPONENTS in
561 *_armcc*)
562 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
563 *) set "$@" RUN_ARMCC=0;;
564 esac
565 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100566}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100567
568
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000569
Gilles Peskine192c72f2017-12-21 15:59:21 +0100570################################################################
571#### Basic checks
572################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100573
SimonB2e23c822016-04-16 21:54:39 +0100574#
575# Test Suites to be executed
576#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200577# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100578# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200579# and/or are more likely to fail than others (eg I use Clang most of the
580# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200581# 2. Minimize total running time, by avoiding useless rebuilds
582#
583# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100584
Gilles Peskine8f073122018-11-27 15:58:47 +0100585component_check_recursion () {
586 msg "test: recursion.pl" # < 1s
587 record_status tests/scripts/recursion.pl library/*.c
588}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100589
Gilles Peskine8f073122018-11-27 15:58:47 +0100590component_check_generated_files () {
591 msg "test: freshness of generated source files" # < 1s
592 record_status tests/scripts/check-generated-files.sh
593}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000594
Gilles Peskine8f073122018-11-27 15:58:47 +0100595component_check_doxy_blocks () {
596 msg "test: doxygen markup outside doxygen blocks" # < 1s
597 record_status tests/scripts/check-doxy-blocks.pl
598}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200599
Gilles Peskine8f073122018-11-27 15:58:47 +0100600component_check_files () {
601 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100602 record_status tests/scripts/check-files.py
603}
Darryl Greena07039c2018-03-13 16:48:16 +0000604
Gilles Peskine3c23c822020-05-10 17:40:49 +0200605component_check_changelog () {
606 msg "Check: changelog entries" # < 1s
607 rm -f ChangeLog.new
608 record_status scripts/assemble_changelog.py -o ChangeLog.new
609 if [ -e ChangeLog.new ]; then
610 # Show the diff for information. It isn't an error if the diff is
611 # non-empty.
612 diff -u ChangeLog ChangeLog.new || true
613 rm ChangeLog.new
614 fi
615}
616
Gilles Peskine8f073122018-11-27 15:58:47 +0100617component_check_names () {
618 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200619 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100620}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200621
Gilles Peskine8f073122018-11-27 15:58:47 +0100622component_check_doxygen_warnings () {
623 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100624 record_status tests/scripts/doxygen.sh
625}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100626
Gilles Peskine192c72f2017-12-21 15:59:21 +0100627
628
629################################################################
630#### Build and test many configurations and targets
631################################################################
632
k-stachowiak11f38e22019-06-04 13:14:58 +0200633component_test_large_ecdsa_key_signature () {
634
635 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
636
637 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
638 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
639 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
640 make
641
642 INEVITABLY_PRESENT_FILE=Makefile
643 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
644
645 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
646 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
647 rm -f $SIGNATURE_FILE
648}
649
Gilles Peskine99a33102019-04-08 17:00:15 +0200650component_test_default_out_of_box () {
651 msg "build: make, default config (out-of-box)" # ~1min
652 make
653
654 msg "test: main suites make, default config (out-of-box)" # ~10s
655 make test
656
657 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200658 if_build_succeeded programs/test/selftest
Gilles Peskine99a33102019-04-08 17:00:15 +0200659}
660
Gilles Peskine8f073122018-11-27 15:58:47 +0100661component_test_default_cmake_gcc_asan () {
662 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100663 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
664 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100665
Gilles Peskine8f073122018-11-27 15:58:47 +0100666 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
667 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200668
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200669 msg "test: selftest (ASan build)" # ~ 10s
670 if_build_succeeded programs/test/selftest
671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
673 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200674
Gilles Peskine8f073122018-11-27 15:58:47 +0100675 msg "test: compat.sh (ASan build)" # ~ 6 min
676 if_build_succeeded tests/compat.sh
677}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200678
Hanno Beckerf8799e82019-02-26 14:27:09 +0000679component_test_full_cmake_gcc_asan () {
680 msg "build: full config, cmake, gcc, ASan"
681 scripts/config.pl full
682 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
683 make
684
685 msg "test: main suites (inc. selftests) (full config, ASan build)"
686 make test
687
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200688 msg "test: selftest (ASan build)" # ~ 10s
689 if_build_succeeded programs/test/selftest
690
Hanno Beckerf8799e82019-02-26 14:27:09 +0000691 msg "test: ssl-opt.sh (full config, ASan build)"
692 if_build_succeeded tests/ssl-opt.sh
693
694 msg "test: compat.sh (full config, ASan build)"
695 if_build_succeeded tests/compat.sh
696}
697
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100698component_test_zlib_make() {
699 msg "build: zlib enabled, make"
700 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
701 make ZLIB=1 CFLAGS='-Werror -O1'
702
703 msg "test: main suites (zlib, make)"
704 make test
705
706 msg "test: ssl-opt.sh (zlib, make)"
707 if_build_succeeded tests/ssl-opt.sh
708}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100709support_test_zlib_make () {
710 base=support_test_zlib_$$
711 cat <<'EOF' > ${base}.c
712#include "zlib.h"
713int main(void) { return 0; }
714EOF
715 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
716 ret=$?
717 rm -f ${base}.*
718 return $ret
719}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100720
721component_test_zlib_cmake() {
722 msg "build: zlib enabled, cmake"
723 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
724 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
725 make
726
727 msg "test: main suites (zlib, cmake)"
728 make test
729
730 msg "test: ssl-opt.sh (zlib, cmake)"
731 if_build_succeeded tests/ssl-opt.sh
732}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100733support_test_zlib_cmake () {
734 support_test_zlib_make "$@"
735}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100736
Gilles Peskine782f4112018-11-27 16:11:09 +0100737component_test_ref_configs () {
738 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
739 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
740 record_status tests/scripts/test-ref-configs.pl
741}
742
Gilles Peskine8f073122018-11-27 15:58:47 +0100743component_test_sslv3 () {
744 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100745 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
746 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
747 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000748
Gilles Peskine8f073122018-11-27 15:58:47 +0100749 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
750 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000751
Gilles Peskine8f073122018-11-27 15:58:47 +0100752 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
753 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
754 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000755
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
757 if_build_succeeded tests/ssl-opt.sh
758}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000759
Gilles Peskine8f073122018-11-27 15:58:47 +0100760component_test_no_renegotiation () {
761 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100762 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
763 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
764 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
767 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100768
Gilles Peskine8f073122018-11-27 15:58:47 +0100769 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
770 if_build_succeeded tests/ssl-opt.sh
771}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100772
Hanno Beckere562e7d2019-05-10 14:45:37 +0100773component_test_no_pem_no_fs () {
774 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
775 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
776 scripts/config.pl unset MBEDTLS_FS_IO
777 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
778 make
779
780 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
781 make test
782
783 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
784 if_build_succeeded tests/ssl-opt.sh
785}
786
Gilles Peskine8f073122018-11-27 15:58:47 +0100787component_test_rsa_no_crt () {
788 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100789 scripts/config.pl set MBEDTLS_RSA_NO_CRT
790 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
791 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100792
Gilles Peskine8f073122018-11-27 15:58:47 +0100793 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
794 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100795
Gilles Peskine8f073122018-11-27 15:58:47 +0100796 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
797 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100798
Gilles Peskine8f073122018-11-27 15:58:47 +0100799 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
800 if_build_succeeded tests/compat.sh -t RSA
801}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100802
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200803component_test_no_ctr_drbg () {
804 msg "build: Full minus CTR_DRBG"
805 scripts/config.pl full
806 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
807
808 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
809 make
810
811 msg "test: no CTR_DRBG"
812 make test
813
Manuel Pégourié-Gonnardc5243c12020-06-05 09:29:51 +0200814 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
815}
816
817component_test_no_hmac_drbg () {
818 msg "build: Full minus HMAC_DRBG"
819 scripts/config.pl full
820 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
821 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
822
823 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
824 make
825
826 msg "test: no HMAC_DRBG"
827 make test
828
829 # No ssl-opt.sh/compat.sh as they never use HMAC_DRBG so far,
830 # so there's little value in running those lengthy tests here.
Manuel Pégourié-Gonnard014ff5b2020-05-28 12:55:10 +0200831}
832
Gilles Peskine8f073122018-11-27 15:58:47 +0100833component_test_small_ssl_out_content_len () {
834 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
836 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
837 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
838 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000839
Gilles Peskine8f073122018-11-27 15:58:47 +0100840 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
841 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
842}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000843
Gilles Peskine8f073122018-11-27 15:58:47 +0100844component_test_small_ssl_in_content_len () {
845 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100846 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
847 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
848 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
849 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000850
Gilles Peskine8f073122018-11-27 15:58:47 +0100851 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
852 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
853}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000854
Gilles Peskine8f073122018-11-27 15:58:47 +0100855component_test_small_ssl_dtls_max_buffering () {
856 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100857 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
858 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
859 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100860
Gilles Peskine8f073122018-11-27 15:58:47 +0100861 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
862 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
863}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100864
Gilles Peskine8f073122018-11-27 15:58:47 +0100865component_test_small_mbedtls_ssl_dtls_max_buffering () {
866 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
868 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
869 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
872 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
873}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100874
Gilles Peskine8f073122018-11-27 15:58:47 +0100875component_test_full_cmake_clang () {
876 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100877 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
879 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100880
Gilles Peskine8f073122018-11-27 15:58:47 +0100881 msg "test: main suites (full config)" # ~ 5s
882 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
885 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200886
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +0000887 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000888 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 +0200889
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 msg "test: compat.sh ARIA + ChachaPoly"
891 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
892}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100893
Gilles Peskine77b1f302020-04-28 14:04:28 +0200894component_test_default_no_deprecated () {
895 # Test that removing the deprecated features from the default
896 # configuration leaves something consistent.
897 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100898 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine77b1f302020-04-28 14:04:28 +0200899 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
900
901 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
902 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100903}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100904
Gilles Peskine77b1f302020-04-28 14:04:28 +0200905component_test_full_deprecated_warning () {
906 # Test that there is nothing deprecated in the full configuration.
907 # A deprecated feature would trigger a warning (made fatal) from
908 # MBEDTLS_DEPRECATED_WARNING.
909 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
910 scripts/config.pl full
911 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
912 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
913 # There are currently no tests for any deprecated feature.
914 # If some are added, 'make test' would trigger warnings here.
915 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
916
917 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
918 make test
919}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_test_depends_curves () {
922 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100923 record_status tests/scripts/curves.pl
924}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200925
Gilles Peskine8f073122018-11-27 15:58:47 +0100926component_test_depends_hashes () {
927 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100928 record_status tests/scripts/depends-hashes.pl
929}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200930
Gilles Peskine8f073122018-11-27 15:58:47 +0100931component_test_depends_pkalgs () {
932 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100933 record_status tests/scripts/depends-pkalgs.pl
934}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200935
Gilles Peskine8f073122018-11-27 15:58:47 +0100936component_build_key_exchanges () {
937 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100938 record_status tests/scripts/key-exchanges.pl
939}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100940
Gilles Peskine8f073122018-11-27 15:58:47 +0100941component_build_default_make_gcc_and_cxx () {
942 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100943 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400944
Gilles Peskine8f073122018-11-27 15:58:47 +0100945 msg "test: verify header list in cpp_dummy_build.cpp"
946 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400947
Gilles Peskine8f073122018-11-27 15:58:47 +0100948 msg "build: Unix make, incremental g++"
949 make TEST_CPP=1
950}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000951
Gilles Peskinedcab2022019-06-12 16:05:50 +0200952component_test_check_params_functionality () {
953 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
954 scripts/config.pl full # includes CHECK_PARAMS
955 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
956 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +0200957 # Only build and run tests. Do not build sample programs, because
958 # they don't have a mbedtls_param_failed() function.
959 make CC=gcc CFLAGS='-Werror -O1' lib test
960}
961
Gilles Peskineb28636b2019-01-02 19:06:24 +0100962component_test_check_params_without_platform () {
963 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
964 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200965 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100966 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
967 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
968 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
969 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskinedf4f7c12020-04-28 10:41:20 +0200970 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskineb28636b2019-01-02 19:06:24 +0100971 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
972 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
973 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
974 scripts/config.pl unset MBEDTLS_PLATFORM_C
975 make CC=gcc CFLAGS='-Werror -O1' all test
976}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200977
Gilles Peskineb28636b2019-01-02 19:06:24 +0100978component_test_check_params_silent () {
979 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
980 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200981 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100982 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
983 make CC=gcc CFLAGS='-Werror -O1' all test
984}
Hanno Becker5175ac62017-09-18 15:36:25 +0100985
Gilles Peskine8f073122018-11-27 15:58:47 +0100986component_test_no_platform () {
987 # Full configuration build, without platform support, file IO and net sockets.
988 # This should catch missing mbedtls_printf definitions, and by disabling file
989 # IO, it should catch missing '#include <stdio.h>'
990 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 scripts/config.pl full
992 scripts/config.pl unset MBEDTLS_PLATFORM_C
993 scripts/config.pl unset MBEDTLS_NET_C
994 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
995 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
996 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
997 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
998 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
999 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001000 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001001 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01001002 scripts/config.pl unset MBEDTLS_FS_IO
1003 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1004 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine99d70d82019-09-20 19:23:10 +02001005 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1006 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001007}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009component_build_no_std_function () {
1010 # catch compile bugs in _uninit functions
1011 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001012 scripts/config.pl full
1013 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1014 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001015 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine99d70d82019-09-20 19:23:10 +02001016 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001017}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019component_build_no_ssl_srv () {
1020 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001021 scripts/config.pl full
1022 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001023 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001024}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001025
Gilles Peskine8f073122018-11-27 15:58:47 +01001026component_build_no_ssl_cli () {
1027 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001028 scripts/config.pl full
1029 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskine99d70d82019-09-20 19:23:10 +02001030 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001031}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001032
Gilles Peskine8f073122018-11-27 15:58:47 +01001033component_build_no_sockets () {
1034 # Note, C99 compliance can also be tested with the sockets support disabled,
1035 # as that requires a POSIX platform (which isn't the same as C99).
1036 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001037 scripts/config.pl full
1038 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1039 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine99d70d82019-09-20 19:23:10 +02001040 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001041}
Hanno Becker5175ac62017-09-18 15:36:25 +01001042
Andrzej Kurek1d070822019-09-05 09:27:47 -04001043component_test_memory_buffer_allocator_backtrace () {
1044 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +00001045 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -04001046 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001047 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -04001048 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -04001049 CC=gcc cmake .
1050 make
1051
1052 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1053 make test
1054}
1055
1056component_test_memory_buffer_allocator () {
1057 msg "build: default config with memory buffer allocator"
1058 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +01001059 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001060 CC=gcc cmake .
1061 make
1062
1063 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1064 make test
1065
1066 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -04001067 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1068 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +00001069}
1070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071component_test_no_max_fragment_length () {
1072 # Run max fragment length tests with MFL disabled
1073 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001074 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1075 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1076 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001077
Gilles Peskine8f073122018-11-27 15:58:47 +01001078 msg "test: ssl-opt.sh, MFL-related tests"
1079 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1080}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001081
Gilles Peskine8f073122018-11-27 15:58:47 +01001082component_test_no_max_fragment_length_small_ssl_out_content_len () {
1083 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001084 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1085 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1086 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1087 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1088 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001089
Gilles Peskine8f073122018-11-27 15:58:47 +01001090 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1091 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1092}
Janos Follath06c54002016-06-09 13:57:40 +01001093
Gilles Peskine8f073122018-11-27 15:58:47 +01001094component_test_null_entropy () {
1095 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001096 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1097 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1098 scripts/config.pl set MBEDTLS_ENTROPY_C
1099 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001100 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001101 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1102 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001103 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001104 make
Janos Follath06c54002016-06-09 13:57:40 +01001105
Gilles Peskine8f073122018-11-27 15:58:47 +01001106 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1107 make test
1108}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001109
Gilles Peskine8f073122018-11-27 15:58:47 +01001110component_test_platform_calloc_macro () {
1111 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001112 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1113 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1114 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1115 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1116 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001117
Gilles Peskine8f073122018-11-27 15:58:47 +01001118 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1119 make test
1120}
Hanno Becker83ebf782017-07-07 12:29:15 +01001121
Gilles Peskinec6b09862019-09-17 19:04:38 +02001122component_test_malloc_0_null () {
1123 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1124 scripts/config.pl full
1125 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1126 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O -Werror -Wall -Wextra -fsanitize=address,undefined" LDFLAGS='-fsanitize=address,undefined'
1127
1128 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1129 make test
1130
1131 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1132 # Just the calloc selftest. "make test" ran the others as part of the
1133 # test suites.
1134 if_build_succeeded programs/test/selftest calloc
1135}
1136
Gilles Peskine8f073122018-11-27 15:58:47 +01001137component_test_aes_fewer_tables () {
1138 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001139 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1140 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001141
Gilles Peskine8f073122018-11-27 15:58:47 +01001142 msg "test: AES_FEWER_TABLES"
1143 make test
1144}
Hanno Becker83ebf782017-07-07 12:29:15 +01001145
Gilles Peskine8f073122018-11-27 15:58:47 +01001146component_test_aes_rom_tables () {
1147 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001148 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1149 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001150
Gilles Peskine8f073122018-11-27 15:58:47 +01001151 msg "test: AES_ROM_TABLES"
1152 make test
1153}
Hanno Becker83ebf782017-07-07 12:29:15 +01001154
Gilles Peskine8f073122018-11-27 15:58:47 +01001155component_test_aes_fewer_tables_and_rom_tables () {
1156 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001157 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1158 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1159 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001160
Gilles Peskine8f073122018-11-27 15:58:47 +01001161 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1162 make test
1163}
1164
1165component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001166 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001167 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001168 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001169}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001170
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001171component_test_cmake_shared () {
1172 msg "build/test: cmake shared" # ~ 2min
1173 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1174 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001175 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001176 make test
1177}
1178
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001179test_build_opt () {
1180 info=$1 cc=$2; shift 2
1181 for opt in "$@"; do
1182 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskine313bb502020-04-14 20:08:41 +02001183 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001184 # We're confident enough in compilers to not run _all_ the tests,
1185 # but at least run the unit tests. In particular, runs with
1186 # optimizations use inline assembly whereas runs with -O0
1187 # skip inline assembly.
1188 make test # ~30s
1189 make clean
1190 done
1191}
1192
1193component_test_clang_opt () {
1194 scripts/config.pl full
1195 test_build_opt 'full config' clang -O0 -Os -O2
1196}
1197
1198component_test_gcc_opt () {
1199 scripts/config.pl full
1200 test_build_opt 'full config' gcc -O0 -Os -O2
1201}
1202
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001203component_build_mbedtls_config_file () {
1204 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1205 # Use the full config so as to catch a maximum of places where
1206 # the check of MBEDTLS_CONFIG_FILE might be missing.
1207 scripts/config.pl full
1208 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1209 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1210 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1211 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001212}
1213
Gilles Peskine8f073122018-11-27 15:58:47 +01001214component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001215 # Build once with -O0, to compile out the i386 specific inline assembly
1216 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001217 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001218 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001219
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001220 msg "test: i386, make, gcc -O0 (ASan build)"
1221 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001222}
Gilles Peskine878cf602019-01-06 20:50:38 +00001223support_test_m32_o0 () {
1224 case $(uname -m) in
1225 *64*) true;;
1226 *) false;;
1227 esac
1228}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001229
Gilles Peskine8f073122018-11-27 15:58:47 +01001230component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001231 # Build again with -O1, to compile in the i386 specific inline assembly
1232 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001233 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001234 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001235
1236 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001237 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001238
1239 msg "test ssl-opt.sh, i386, make, gcc-O1"
1240 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001241}
Gilles Peskine878cf602019-01-06 20:50:38 +00001242support_test_m32_o1 () {
1243 support_test_m32_o0 "$@"
1244}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001247 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001248 scripts/config.pl full
Gilles Peskine8118e462019-06-07 14:50:09 +02001249 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001250
1251 msg "test: 64-bit ILP32, make, gcc"
1252 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001253}
Gilles Peskine878cf602019-01-06 20:50:38 +00001254support_test_mx32 () {
1255 case $(uname -m) in
1256 amd64|x86_64) true;;
1257 *) false;;
1258 esac
1259}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001260
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001261component_test_min_mpi_window_size () {
1262 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1263 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1264 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1265 make
1266
1267 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1268 make test
1269}
1270
Gilles Peskine8f073122018-11-27 15:58:47 +01001271component_test_have_int32 () {
1272 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001273 scripts/config.pl unset MBEDTLS_HAVE_ASM
1274 scripts/config.pl unset MBEDTLS_AESNI_C
1275 scripts/config.pl unset MBEDTLS_PADLOCK_C
1276 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278 msg "test: gcc, force 32-bit bignum limbs"
1279 make test
1280}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001281
Gilles Peskine8f073122018-11-27 15:58:47 +01001282component_test_have_int64 () {
1283 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001284 scripts/config.pl unset MBEDTLS_HAVE_ASM
1285 scripts/config.pl unset MBEDTLS_AESNI_C
1286 scripts/config.pl unset MBEDTLS_PADLOCK_C
1287 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001288
Gilles Peskine8f073122018-11-27 15:58:47 +01001289 msg "test: gcc, force 64-bit bignum limbs"
1290 make test
1291}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001292
Gilles Peskine8f073122018-11-27 15:58:47 +01001293component_test_no_udbl_division () {
1294 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001295 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001296 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1297 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001298
Gilles Peskine8f073122018-11-27 15:58:47 +01001299 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1300 make test
1301}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001302
Gilles Peskine8f073122018-11-27 15:58:47 +01001303component_test_no_64bit_multiplication () {
1304 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001305 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001306 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1307 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001308
Gilles Peskine8f073122018-11-27 15:58:47 +01001309 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1310 make test
1311}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001312
Gilles Peskine8f073122018-11-27 15:58:47 +01001313component_build_arm_none_eabi_gcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001314 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001315 scripts/config.pl baremetal
Gilles Peskinefcccfbc2020-04-30 22:54:00 +02001316 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 +02001317
1318 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1319 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01001320}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001321
Gilles Peskine560f3322019-08-09 16:05:05 +02001322component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001323 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001324 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001325 # Build for a target platform that's close to what Debian uses
1326 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1327 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1328 # It would be better to build with arm-linux-gnueabi-gcc but
1329 # we don't have that on our CI at this time.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001330 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001331
1332 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1333 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001334}
1335
Gilles Peskinedac156b2020-04-30 23:00:53 +02001336component_build_arm_none_eabi_gcc_m0plus () {
1337 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1338 scripts/config.pl baremetal
1339 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 +02001340
1341 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1342 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001343}
Andres AG87bb5772016-09-27 15:05:15 +01001344
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001345component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001346 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001347 scripts/config.pl baremetal
Simon Butcher1c719652016-06-27 19:02:12 +01001348 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001349 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 +02001350 echo "Checking that software 64-bit division is not required"
1351 if_build_succeeded not grep __aeabi_uldiv library/*.o
1352}
1353
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +02001354component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001355 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001356 scripts/config.pl baremetal
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001357 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001358 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 +02001359 echo "Checking that software 64-bit multiplication is not required"
1360 if_build_succeeded not grep __aeabi_lmul library/*.o
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001361}
Simon Butcherbc6a4862016-03-07 17:35:59 +00001362
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001363component_build_armcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001364 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001365 scripts/config.pl baremetal
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001366 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001367
1368 msg "size: ARM Compiler 5"
1369 "$ARMC5_FROMELF" -z library/*.o
1370
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001371 make clean
1372
1373 # ARM Compiler 6 - Target ARMv7-A
1374 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
1375
1376 # ARM Compiler 6 - Target ARMv7-M
Simon Butcher4df5eaf2016-08-24 22:58:31 +03001377 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001378
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001379 # ARM Compiler 6 - Target ARMv8-A - AArch32
1380 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001381
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001382 # ARM Compiler 6 - Target ARMv8-M
1383 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001384
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001385 # ARM Compiler 6 - Target ARMv8-A - AArch64
1386 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001387}
Simon Butcher940737f2017-07-23 13:42:36 +02001388
Andres Amaya Garcia9f3bdb82018-12-05 22:03:56 +00001389component_build_ssl_hw_record_accel() {
1390 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1391 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1392 make CFLAGS='-Werror -O1'
1393}
1394
Gilles Peskine8f073122018-11-27 15:58:47 +01001395component_test_allow_sha1 () {
1396 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001397 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1398 make CFLAGS='-Werror -Wall -Wextra'
1399 msg "test: allow SHA1 in certificates by default"
1400 make test
1401 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1402}
Simon Butcher940737f2017-07-23 13:42:36 +02001403
Gilles Peskine8f073122018-11-27 15:58:47 +01001404component_build_mingw () {
1405 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001406 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 +02001407
Gilles Peskine8f073122018-11-27 15:58:47 +01001408 # note Make tests only builds the tests, but doesn't run them
1409 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1410 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001411
Gilles Peskine8f073122018-11-27 15:58:47 +01001412 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1413 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
1414 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
1415 make WINDOWS_BUILD=1 clean
1416}
Simon Butcher002bc622016-11-17 09:27:45 +00001417
Gilles Peskine8f073122018-11-27 15:58:47 +01001418component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001419 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001420 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1421 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1422 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001423
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001424 msg "test: main suites (MSan)" # ~ 10s
1425 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001426
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001427 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001428 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001429
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001430 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001431
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001432 if [ "$MEMORY" -gt 0 ]; then
1433 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001434 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001435 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001436}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001437
Gilles Peskine69f190e2019-01-10 00:11:42 +01001438component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001439 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001440 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1441 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001442
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001443 msg "test: main suites valgrind (Release)"
1444 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001445
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001446 # Optional parts (slow; currently broken on OS X because programs don't
1447 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001448 if [ "$MEMORY" -gt 0 ]; then
1449 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001450 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001451 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001452
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001453 if [ "$MEMORY" -gt 1 ]; then
1454 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001455 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001456 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001457}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001458
Gilles Peskine8f073122018-11-27 15:58:47 +01001459component_test_cmake_out_of_source () {
1460 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001461 MBEDTLS_ROOT_DIR="$PWD"
1462 mkdir "$OUT_OF_SOURCE_DIR"
1463 cd "$OUT_OF_SOURCE_DIR"
1464 cmake "$MBEDTLS_ROOT_DIR"
1465 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001466
Gilles Peskine8f073122018-11-27 15:58:47 +01001467 msg "test: cmake 'out-of-source' build"
1468 make test
1469 # Test an SSL option that requires an auxiliary script in test/scripts/.
1470 # Also ensure that there are no error messages such as
1471 # "No such file or directory", which would indicate that some required
1472 # file is missing (ssl-opt.sh tolerates the absence of some files so
1473 # may exit with status 0 but emit errors).
1474 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1475 if [ -s ssl-opt.err ]; then
1476 cat ssl-opt.err >&2
1477 record_status [ ! -s ssl-opt.err ]
1478 rm ssl-opt.err
1479 fi
1480 cd "$MBEDTLS_ROOT_DIR"
1481 rm -rf "$OUT_OF_SOURCE_DIR"
1482 unset MBEDTLS_ROOT_DIR
1483}
Andres AGdc192212016-08-31 17:33:13 +01001484
Gilles Peskine8f073122018-11-27 15:58:47 +01001485component_test_zeroize () {
1486 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1487 # different combinations of compilers and optimization flags by using an
1488 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1489 # system in all cases that the script fails, so we must manually search the
1490 # output to check whether the pass string is present and no failure strings
1491 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001492
1493 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1494 # about a spurious message if Gdb tries and fails, so suppress that.
1495 gdb_disable_aslr=
1496 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1497 gdb_disable_aslr='set disable-randomization off'
1498 fi
1499
Gilles Peskine8f073122018-11-27 15:58:47 +01001500 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001501 for compiler in clang gcc; do
1502 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1503 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001504 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 +01001505 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1506 if_build_succeeded not grep -i "error" test_zeroize.log
1507 rm -f test_zeroize.log
1508 make clean
1509 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001510 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001511
1512 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001513}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001514
Gilles Peskine8f073122018-11-27 15:58:47 +01001515component_check_python_files () {
1516 msg "Lint: Python scripts"
1517 record_status tests/scripts/check-python-files.sh
1518}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001519
Gilles Peskine8f073122018-11-27 15:58:47 +01001520component_check_generate_test_code () {
1521 msg "uint test: generate_test_code.py"
1522 record_status ./tests/scripts/test_generate_test_code.py
1523}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001524
1525################################################################
1526#### Termination
1527################################################################
1528
Gilles Peskine8f073122018-11-27 15:58:47 +01001529post_report () {
1530 msg "Done, cleaning up"
1531 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001532
Gilles Peskine8f073122018-11-27 15:58:47 +01001533 final_report
1534}
1535
1536
1537
1538################################################################
1539#### Run all the things
1540################################################################
1541
Gilles Peskinee48351a2018-11-27 16:06:30 +01001542# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001543run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001544 # Back up the configuration in case the component modifies it.
1545 # The cleanup function will restore it.
1546 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001547 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001548 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001549 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001550}
1551
1552# Preliminary setup
1553pre_check_environment
1554pre_initialize_variables
1555pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001556
Gilles Peskine878cf602019-01-06 20:50:38 +00001557pre_check_git
1558build_status=0
1559if [ $KEEP_GOING -eq 1 ]; then
1560 pre_setup_keep_going
1561else
1562 record_status () {
1563 "$@"
1564 }
1565fi
1566pre_print_configuration
1567pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001568cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001569
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001570# Run the requested tests.
1571for component in $RUN_COMPONENTS; do
1572 run_component "component_$component"
1573done
Gilles Peskine8f073122018-11-27 15:58:47 +01001574
1575# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001576post_report