blob: 45fa900b99e0721c84a0b97f1df573e528617b8d [file] [log] [blame]
SimonB21ab9d72016-03-12 20:37:32 +00001#!/bin/sh
2
3# basic-build-tests.sh
4#
5# Copyright (c) 2016, ARM Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020013#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020026# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
46#
Bence Szépkúti09b4f192020-05-26 01:54:15 +020047# This file is part of Mbed TLS (https://tls.mbed.org)
SimonB21ab9d72016-03-12 20:37:32 +000048#
49# Purpose
50#
51# Executes the basic test suites, captures the results, and generates a simple
52# test report and code coverage report.
53#
54# The tests include:
SimonB21ab9d72016-03-12 20:37:32 +000055# * Unit tests - executed using tests/scripts/run-test-suite.pl
Paul Bakker4b8bc522016-07-20 09:52:01 +010056# * Self-tests - executed using the test suites above
SimonB21ab9d72016-03-12 20:37:32 +000057# * System tests - executed using tests/ssl-opt.sh
58# * Interoperability tests - executed using tests/compat.sh
59#
60# The tests focus on functionality and do not consider performance.
61#
62# Note the tests self-adapt due to configurations in include/mbedtls/config.h
63# which can lead to some tests being skipped, and can cause the number of
Paul Bakker4b8bc522016-07-20 09:52:01 +010064# available tests to fluctuate.
SimonB21ab9d72016-03-12 20:37:32 +000065#
66# This script has been written to be generic and should work on any shell.
67#
68# Usage: basic-build-tests.sh
69#
70
71# Abort on errors (and uninitiliased variables)
72set -eu
73
74if [ -d library -a -d include -a -d tests ]; then :; else
75 echo "Must be run from mbed TLS root" >&2
76 exit 1
77fi
78
Andres AGb2fdd042016-09-22 14:17:46 +010079: ${OPENSSL:="openssl"}
80: ${OPENSSL_LEGACY:="$OPENSSL"}
81: ${GNUTLS_CLI:="gnutls-cli"}
82: ${GNUTLS_SERV:="gnutls-serv"}
83: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
84: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
85
Manuel Pégourié-Gonnard54d95b12020-06-08 12:59:27 +020086# Used to make ssl-opt.sh deterministic.
87# !!! Keep this in sync with RELEASE_SEED in all.sh !!!
88: ${SEED:=1}
89export SEED
90
Andres AGb2fdd042016-09-22 14:17:46 +010091# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
92# we just export the variables they require
93export OPENSSL_CMD="$OPENSSL"
94export GNUTLS_CLI="$GNUTLS_CLI"
95export GNUTLS_SERV="$GNUTLS_SERV"
96
Janos Follath7ccac852016-06-06 13:18:39 +010097CONFIG_H='include/mbedtls/config.h'
98CONFIG_BAK="$CONFIG_H.bak"
SimonB21ab9d72016-03-12 20:37:32 +000099
Janos Follathb72c6782016-07-19 14:54:17 +0100100# Step 0 - print build environment info
Andres AGb2fdd042016-09-22 14:17:46 +0100101OPENSSL="$OPENSSL" \
102 OPENSSL_LEGACY="$OPENSSL_LEGACY" \
103 GNUTLS_CLI="$GNUTLS_CLI" \
104 GNUTLS_SERV="$GNUTLS_SERV" \
105 GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
106 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" \
107 scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +0100108echo
109
SimonB21ab9d72016-03-12 20:37:32 +0000110# Step 1 - Make and instrumented build for code coverage
Simon Butcherc2b0efc2016-03-18 18:28:43 +0000111export CFLAGS=' --coverage -g3 -O0 '
SimonB098a3b52016-04-16 21:56:59 +0100112make clean
Janos Follath7ccac852016-06-06 13:18:39 +0100113cp "$CONFIG_H" "$CONFIG_BAK"
SimonB098a3b52016-04-16 21:56:59 +0100114scripts/config.pl full
Simon Butchercbb90752016-05-19 22:15:34 +0100115make -j
SimonB21ab9d72016-03-12 20:37:32 +0000116
117
118# Step 2 - Execute the tests
119TEST_OUTPUT=out_${PPID}
120cd tests
121
Gilles Peskine9cc203a2020-04-09 18:33:34 +0200122if [ ! -f "seedfile" ]; then
123 dd if=/dev/urandom of="seedfile" bs=64 count=1
124fi
125
Gilles Peskine27c36f02020-04-09 18:29:42 +0200126# Step 2a - Unit Tests (keep going even if some tests fail)
Jaeden Amero3ee55792018-12-07 13:06:24 +0000127perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000128echo
129
Gilles Peskine27c36f02020-04-09 18:29:42 +0200130# Step 2b - System Tests (keep going even if some tests fail)
SimonB21ab9d72016-03-12 20:37:32 +0000131sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT
132echo
133
Gilles Peskine27c36f02020-04-09 18:29:42 +0200134# Step 2c - Compatibility tests (keep going even if some tests fail)
Andres AGb2fdd042016-09-22 14:17:46 +0100135sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' | \
136 tee compat-test-$TEST_OUTPUT
137OPENSSL_CMD="$OPENSSL_LEGACY" \
138 sh compat.sh -m 'ssl3' |tee -a compat-test-$TEST_OUTPUT
139OPENSSL_CMD="$OPENSSL_LEGACY" \
140 GNUTLS_CLI="$GNUTLS_LEGACY_CLI" \
141 GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000142 sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' | \
Andres AGb2fdd042016-09-22 14:17:46 +0100143 tee -a compat-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000144echo
145
146# Step 3 - Process the coverage report
147cd ..
Gilles Peskineb07541d2020-04-09 18:32:48 +0200148{
149 make lcov
150 echo SUCCESS
151} | tee tests/cov-$TEST_OUTPUT
152
153if [ "$(tail -n1 tests/cov-$TEST_OUTPUT)" != "SUCCESS" ]; then
154 echo >&2 "Fatal: 'make lcov' failed"
155 exit 2
156fi
SimonB21ab9d72016-03-12 20:37:32 +0000157
158
159# Step 4 - Summarise the test report
160echo
161echo "========================================================================="
162echo "Test Report Summary"
163echo
164
165cd tests
166
Paul Bakker4b8bc522016-07-20 09:52:01 +0100167# Step 4a - Unit tests
SimonB21ab9d72016-03-12 20:37:32 +0000168echo "Unit tests - tests/scripts/run-test-suites.pl"
169
170PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
171SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
172TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
173FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
174
175echo "No test suites : $TOTAL_SUITES"
176echo "Passed : $PASSED_TESTS"
177echo "Failed : $FAILED_TESTS"
178echo "Skipped : $SKIPPED_TESTS"
179echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
180echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
181echo
182
Paul Bakker4b8bc522016-07-20 09:52:01 +0100183TOTAL_PASS=$PASSED_TESTS
184TOTAL_FAIL=$FAILED_TESTS
185TOTAL_SKIP=$SKIPPED_TESTS
186TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
187TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000188
Paul Bakker4b8bc522016-07-20 09:52:01 +0100189# Step 4b - TLS Options tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000190echo "TLS Options tests - tests/ssl-opt.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000191
192PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
193SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p')
194TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p')
195FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS))
196
197echo "Passed : $PASSED_TESTS"
198echo "Failed : $FAILED_TESTS"
199echo "Skipped : $SKIPPED_TESTS"
200echo "Total exec'd tests : $TOTAL_TESTS"
201echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))"
202echo
203
204TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
205TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
206TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
207TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS))
208TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
209
210
Paul Bakker4b8bc522016-07-20 09:52:01 +0100211# Step 4c - System Compatibility tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000212echo "System/Compatibility tests - tests/compat.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000213
Andres AGb2fdd042016-09-22 14:17:46 +0100214PASSED_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 }')
215SKIPPED_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 }')
216EXED_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 }')
SimonB21ab9d72016-03-12 20:37:32 +0000217FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS))
218
219echo "Passed : $PASSED_TESTS"
220echo "Failed : $FAILED_TESTS"
221echo "Skipped : $SKIPPED_TESTS"
222echo "Total exec'd tests : $EXED_TESTS"
223echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))"
224echo
225
226TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
227TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
228TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
229TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS))
230TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
231
232
Paul Bakker4b8bc522016-07-20 09:52:01 +0100233# Step 4d - Grand totals
SimonB21ab9d72016-03-12 20:37:32 +0000234echo "-------------------------------------------------------------------------"
235echo "Total tests"
236
237echo "Total Passed : $TOTAL_PASS"
238echo "Total Failed : $TOTAL_FAIL"
239echo "Total Skipped : $TOTAL_SKIP"
240echo "Total exec'd tests : $TOTAL_EXED"
241echo "Total avail tests : $TOTAL_AVAIL"
242echo
243
244
Paul Bakker4b8bc522016-07-20 09:52:01 +0100245# Step 4e - Coverage
SimonB21ab9d72016-03-12 20:37:32 +0000246echo "Coverage"
247
Dan Handleyaba9e222020-05-28 16:20:31 +0100248LINES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p')
249LINES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p')
250FUNCS_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p')
251FUNCS_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p')
252BRANCHES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* branches)$/\1/p')
253BRANCHES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) branches)$/\1/p')
SimonB21ab9d72016-03-12 20:37:32 +0000254
255LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL))
256LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))"
257
258FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL))
259FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))"
260
Dan Handleyaba9e222020-05-28 16:20:31 +0100261BRANCHES_PERCENT=$((1000*$BRANCHES_TESTED/$BRANCHES_TOTAL))
262BRANCHES_PERCENT="$(($BRANCHES_PERCENT/10)).$(($BRANCHES_PERCENT-($BRANCHES_PERCENT/10)*10))"
263
SimonB21ab9d72016-03-12 20:37:32 +0000264echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%"
265echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%"
Dan Handleyaba9e222020-05-28 16:20:31 +0100266echo "Branches Tested : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%"
SimonB21ab9d72016-03-12 20:37:32 +0000267echo
268
SimonB21ab9d72016-03-12 20:37:32 +0000269rm unit-test-$TEST_OUTPUT
270rm sys-test-$TEST_OUTPUT
271rm compat-test-$TEST_OUTPUT
272rm cov-$TEST_OUTPUT
273
274cd ..
Janos Follath7ccac852016-06-06 13:18:39 +0100275
276make clean
277
278if [ -f "$CONFIG_BAK" ]; then
279 mv "$CONFIG_BAK" "$CONFIG_H"
280fi
Gilles Peskinedd7ea382020-04-09 18:28:14 +0200281
282if [ $TOTAL_FAIL -ne 0 ]; then
283 exit 1
284fi