2016-03-12 21:37:32 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-11-30 12:13:00 +01:00
|
|
|
# basic-build-test.sh
|
2016-03-12 21:37:32 +01:00
|
|
|
#
|
2020-08-07 13:07:28 +02:00
|
|
|
# Copyright The Mbed TLS Contributors
|
2020-05-26 01:54:15 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2016-03-12 21:37:32 +01:00
|
|
|
# Purpose
|
|
|
|
#
|
|
|
|
# Executes the basic test suites, captures the results, and generates a simple
|
|
|
|
# test report and code coverage report.
|
|
|
|
#
|
|
|
|
# The tests include:
|
|
|
|
# * Unit tests - executed using tests/scripts/run-test-suite.pl
|
2016-07-20 10:52:01 +02:00
|
|
|
# * Self-tests - executed using the test suites above
|
2016-03-12 21:37:32 +01:00
|
|
|
# * System tests - executed using tests/ssl-opt.sh
|
|
|
|
# * Interoperability tests - executed using tests/compat.sh
|
|
|
|
#
|
|
|
|
# The tests focus on functionality and do not consider performance.
|
|
|
|
#
|
2021-05-28 09:42:25 +02:00
|
|
|
# Note the tests self-adapt due to configurations in include/mbedtls/mbedtls_config.h
|
2016-03-12 21:37:32 +01:00
|
|
|
# which can lead to some tests being skipped, and can cause the number of
|
2016-07-20 10:52:01 +02:00
|
|
|
# available tests to fluctuate.
|
2016-03-12 21:37:32 +01:00
|
|
|
#
|
|
|
|
# This script has been written to be generic and should work on any shell.
|
|
|
|
#
|
2022-11-30 12:13:00 +01:00
|
|
|
# Usage: basic-build-test.sh
|
2016-03-12 21:37:32 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
# Abort on errors (and uninitiliased variables)
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
if [ -d library -a -d include -a -d tests ]; then :; else
|
2023-08-03 17:45:20 +02:00
|
|
|
echo "Must be run from Mbed TLS root" >&2
|
2016-03-12 21:37:32 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-09-22 15:17:46 +02:00
|
|
|
: ${OPENSSL:="openssl"}
|
|
|
|
: ${GNUTLS_CLI:="gnutls-cli"}
|
|
|
|
: ${GNUTLS_SERV:="gnutls-serv"}
|
|
|
|
|
2020-06-08 12:59:27 +02:00
|
|
|
# Used to make ssl-opt.sh deterministic.
|
2020-06-22 10:11:47 +02:00
|
|
|
#
|
|
|
|
# See also RELEASE_SEED in all.sh. Debugging is easier if both values are kept
|
|
|
|
# in sync. If you change the value here because it breaks some tests, you'll
|
|
|
|
# definitely want to change it in all.sh as well.
|
2020-06-08 12:59:27 +02:00
|
|
|
: ${SEED:=1}
|
|
|
|
export SEED
|
|
|
|
|
2021-07-13 23:23:23 +02:00
|
|
|
# if MAKEFLAGS is not set add the -j option to speed up invocations of make
|
|
|
|
if [ -z "${MAKEFLAGS+set}" ]; then
|
|
|
|
export MAKEFLAGS="-j"
|
|
|
|
fi
|
|
|
|
|
2016-09-22 15:17:46 +02:00
|
|
|
# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
|
|
|
|
# we just export the variables they require
|
Use OPENSSL everywhere, not OPENSSL_CMD
These variables were both uses to select the default version of OpenSSL
to use for tests:
- when running compat.sh or ssl-opt.sh directly, OPENSSL_CMD was used;
- when running all.sh, OPENSSL was used.
This caused surprising situations if you had one but not the other set
in your environment. For example I used to have OPENSSL_CMD set but not
OPENSSL, so ssl-opt.sh was failing in some all.sh components but passing
when I ran it manually in the same configuration and build, a rather
unpleasant experience.
The natural name would be OPENSSL, and that's what set in the Docker
images used by the CI. However back in the 1.3.x days, that name was
already used in library/Makefile, so it was preferable to pick a
different one, hence OPENSSL_CMD. However the build system has not been
using this name since at least Mbed TLS 2.0.0, so it's now free for use
again (as demonstrated by the fact that it's been set in the CI without
causing any trouble).
So, unify things and use OPENSSL everywhere. Just leave an error message
for the benefit of developers which might have OPENSSL_CMD, not OPENSSL,
set in their environment from the old days.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-12-19 11:42:12 +01:00
|
|
|
export OPENSSL="$OPENSSL"
|
2016-09-22 15:17:46 +02:00
|
|
|
export GNUTLS_CLI="$GNUTLS_CLI"
|
|
|
|
export GNUTLS_SERV="$GNUTLS_SERV"
|
|
|
|
|
2021-05-28 09:42:25 +02:00
|
|
|
CONFIG_H='include/mbedtls/mbedtls_config.h'
|
2016-06-06 14:18:39 +02:00
|
|
|
CONFIG_BAK="$CONFIG_H.bak"
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2016-07-19 15:54:17 +02:00
|
|
|
# Step 0 - print build environment info
|
2016-09-22 15:17:46 +02:00
|
|
|
OPENSSL="$OPENSSL" \
|
|
|
|
GNUTLS_CLI="$GNUTLS_CLI" \
|
|
|
|
GNUTLS_SERV="$GNUTLS_SERV" \
|
|
|
|
scripts/output_env.sh
|
2016-07-19 15:54:17 +02:00
|
|
|
echo
|
|
|
|
|
2016-03-12 21:37:32 +01:00
|
|
|
# Step 1 - Make and instrumented build for code coverage
|
2016-03-18 19:28:43 +01:00
|
|
|
export CFLAGS=' --coverage -g3 -O0 '
|
2019-07-09 17:44:53 +02:00
|
|
|
export LDFLAGS=' --coverage'
|
2016-04-16 22:56:59 +02:00
|
|
|
make clean
|
2016-06-06 14:18:39 +02:00
|
|
|
cp "$CONFIG_H" "$CONFIG_BAK"
|
2019-07-27 23:52:53 +02:00
|
|
|
scripts/config.py full
|
2021-07-13 23:23:23 +02:00
|
|
|
make
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Step 2 - Execute the tests
|
|
|
|
TEST_OUTPUT=out_${PPID}
|
|
|
|
cd tests
|
2019-05-20 11:39:18 +02:00
|
|
|
if [ ! -f "seedfile" ]; then
|
2020-04-09 18:33:34 +02:00
|
|
|
dd if=/dev/urandom of="seedfile" bs=64 count=1
|
2019-05-20 11:39:18 +02:00
|
|
|
fi
|
2020-04-09 18:50:08 +02:00
|
|
|
echo
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2020-04-09 18:29:42 +02:00
|
|
|
# Step 2a - Unit Tests (keep going even if some tests fail)
|
2020-04-09 18:50:08 +02:00
|
|
|
echo '################ Unit tests ################'
|
2018-12-07 14:06:24 +01:00
|
|
|
perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
|
2020-04-09 18:50:08 +02:00
|
|
|
echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^'
|
2016-03-12 21:37:32 +01:00
|
|
|
echo
|
|
|
|
|
2020-04-09 18:29:42 +02:00
|
|
|
# Step 2b - System Tests (keep going even if some tests fail)
|
2020-04-09 18:50:08 +02:00
|
|
|
echo
|
|
|
|
echo '################ ssl-opt.sh ################'
|
2021-07-13 23:26:00 +02:00
|
|
|
echo "ssl-opt.sh will use SEED=$SEED for udp_proxy"
|
2016-03-12 21:37:32 +01:00
|
|
|
sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT
|
2020-04-09 18:50:08 +02:00
|
|
|
echo '^^^^^^^^^^^^^^^^ ssl-opt.sh ^^^^^^^^^^^^^^^^'
|
2016-03-12 21:37:32 +01:00
|
|
|
echo
|
|
|
|
|
2020-04-09 18:29:42 +02:00
|
|
|
# Step 2c - Compatibility tests (keep going even if some tests fail)
|
2020-04-09 18:50:08 +02:00
|
|
|
echo '################ compat.sh ################'
|
|
|
|
{
|
|
|
|
echo '#### compat.sh: Default versions'
|
2022-04-14 09:12:10 +02:00
|
|
|
sh compat.sh
|
2020-04-09 18:50:08 +02:00
|
|
|
echo
|
|
|
|
|
2023-08-27 21:43:00 +02:00
|
|
|
echo '#### compat.sh: null cipher'
|
2022-04-06 13:28:27 +02:00
|
|
|
sh compat.sh -e '^$' -f 'NULL'
|
2020-04-09 18:50:08 +02:00
|
|
|
echo
|
|
|
|
|
|
|
|
echo '#### compat.sh: next (ARIA, ChaCha)'
|
Use OPENSSL everywhere, not OPENSSL_CMD
These variables were both uses to select the default version of OpenSSL
to use for tests:
- when running compat.sh or ssl-opt.sh directly, OPENSSL_CMD was used;
- when running all.sh, OPENSSL was used.
This caused surprising situations if you had one but not the other set
in your environment. For example I used to have OPENSSL_CMD set but not
OPENSSL, so ssl-opt.sh was failing in some all.sh components but passing
when I ran it manually in the same configuration and build, a rather
unpleasant experience.
The natural name would be OPENSSL, and that's what set in the Docker
images used by the CI. However back in the 1.3.x days, that name was
already used in library/Makefile, so it was preferable to pick a
different one, hence OPENSSL_CMD. However the build system has not been
using this name since at least Mbed TLS 2.0.0, so it's now free for use
again (as demonstrated by the fact that it's been set in the CI without
causing any trouble).
So, unify things and use OPENSSL everywhere. Just leave an error message
for the benefit of developers which might have OPENSSL_CMD, not OPENSSL,
set in their environment from the old days.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-12-19 11:42:12 +01:00
|
|
|
OPENSSL="$OPENSSL_NEXT" sh compat.sh -e '^$' -f 'ARIA\|CHACHA'
|
2020-04-09 18:50:08 +02:00
|
|
|
echo
|
|
|
|
} | tee compat-test-$TEST_OUTPUT
|
|
|
|
echo '^^^^^^^^^^^^^^^^ compat.sh ^^^^^^^^^^^^^^^^'
|
2016-03-12 21:37:32 +01:00
|
|
|
echo
|
|
|
|
|
|
|
|
# Step 3 - Process the coverage report
|
|
|
|
cd ..
|
2020-04-09 18:32:48 +02:00
|
|
|
{
|
|
|
|
make lcov
|
|
|
|
echo SUCCESS
|
|
|
|
} | tee tests/cov-$TEST_OUTPUT
|
|
|
|
|
|
|
|
if [ "$(tail -n1 tests/cov-$TEST_OUTPUT)" != "SUCCESS" ]; then
|
|
|
|
echo >&2 "Fatal: 'make lcov' failed"
|
|
|
|
exit 2
|
|
|
|
fi
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Step 4 - Summarise the test report
|
|
|
|
echo
|
|
|
|
echo "========================================================================="
|
|
|
|
echo "Test Report Summary"
|
|
|
|
echo
|
|
|
|
|
2021-07-22 11:08:30 +02:00
|
|
|
# A failure of the left-hand side of a pipe is ignored (this is a limitation
|
|
|
|
# of sh). We'll use the presence of this file as a marker that the generation
|
|
|
|
# of the report succeeded.
|
2021-07-22 12:29:27 +02:00
|
|
|
rm -f "tests/basic-build-test-$$.ok"
|
2021-07-22 11:08:30 +02:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
{
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
cd tests
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
# Step 4a - Unit tests
|
|
|
|
echo "Unit tests - tests/scripts/run-test-suites.pl"
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
|
|
|
|
SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
|
|
|
|
TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
|
|
|
|
FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
echo "No test suites : $TOTAL_SUITES"
|
|
|
|
echo "Passed : $PASSED_TESTS"
|
|
|
|
echo "Failed : $FAILED_TESTS"
|
|
|
|
echo "Skipped : $SKIPPED_TESTS"
|
|
|
|
echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
|
|
|
|
echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
|
|
|
|
echo
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
TOTAL_PASS=$PASSED_TESTS
|
|
|
|
TOTAL_FAIL=$FAILED_TESTS
|
|
|
|
TOTAL_SKIP=$SKIPPED_TESTS
|
|
|
|
TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
|
|
|
|
TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
|
|
|
|
|
|
|
|
# Step 4b - TLS Options tests
|
|
|
|
echo "TLS Options tests - tests/ssl-opt.sh"
|
|
|
|
|
|
|
|
PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
|
|
|
|
SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p')
|
|
|
|
TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p')
|
|
|
|
FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS))
|
|
|
|
|
|
|
|
echo "Passed : $PASSED_TESTS"
|
|
|
|
echo "Failed : $FAILED_TESTS"
|
|
|
|
echo "Skipped : $SKIPPED_TESTS"
|
|
|
|
echo "Total exec'd tests : $TOTAL_TESTS"
|
|
|
|
echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))"
|
|
|
|
echo
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
|
|
|
|
TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
|
|
|
|
TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
|
|
|
|
TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS))
|
|
|
|
TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
# Step 4c - System Compatibility tests
|
|
|
|
echo "System/Compatibility tests - tests/compat.sh"
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
PASSED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }')
|
|
|
|
SKIPPED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }')
|
|
|
|
EXED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }')
|
|
|
|
FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS))
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
echo "Passed : $PASSED_TESTS"
|
|
|
|
echo "Failed : $FAILED_TESTS"
|
|
|
|
echo "Skipped : $SKIPPED_TESTS"
|
|
|
|
echo "Total exec'd tests : $EXED_TESTS"
|
|
|
|
echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))"
|
|
|
|
echo
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
|
|
|
|
TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
|
|
|
|
TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
|
|
|
|
TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS))
|
|
|
|
TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
# Step 4d - Grand totals
|
|
|
|
echo "-------------------------------------------------------------------------"
|
|
|
|
echo "Total tests"
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
echo "Total Passed : $TOTAL_PASS"
|
|
|
|
echo "Total Failed : $TOTAL_FAIL"
|
|
|
|
echo "Total Skipped : $TOTAL_SKIP"
|
|
|
|
echo "Total exec'd tests : $TOTAL_EXED"
|
|
|
|
echo "Total avail tests : $TOTAL_AVAIL"
|
|
|
|
echo
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
|
2022-12-16 12:03:39 +01:00
|
|
|
# Step 4e - Coverage report
|
|
|
|
echo "Coverage statistics:"
|
|
|
|
sed -n '1,/^Overall coverage/d; /%/p' cov-$TEST_OUTPUT
|
|
|
|
echo
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-13 23:27:01 +02:00
|
|
|
rm unit-test-$TEST_OUTPUT
|
|
|
|
rm sys-test-$TEST_OUTPUT
|
|
|
|
rm compat-test-$TEST_OUTPUT
|
|
|
|
rm cov-$TEST_OUTPUT
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2021-07-22 12:29:27 +02:00
|
|
|
# Mark the report generation as having succeeded. This must be the
|
|
|
|
# last thing in the report generation.
|
2021-07-22 11:08:30 +02:00
|
|
|
touch "basic-build-test-$$.ok"
|
2021-07-13 23:27:01 +02:00
|
|
|
} | tee coverage-summary.txt
|
2016-06-06 14:18:39 +02:00
|
|
|
|
|
|
|
make clean
|
|
|
|
|
|
|
|
if [ -f "$CONFIG_BAK" ]; then
|
|
|
|
mv "$CONFIG_BAK" "$CONFIG_H"
|
|
|
|
fi
|
2020-04-09 18:28:14 +02:00
|
|
|
|
2021-07-22 11:08:30 +02:00
|
|
|
# The file must exist, otherwise it means something went wrong while generating
|
|
|
|
# the coverage report. If something did go wrong, rm will complain so this
|
|
|
|
# script will exit with a failure status.
|
2021-07-22 12:29:27 +02:00
|
|
|
rm "tests/basic-build-test-$$.ok"
|