blob: dab4cf2d533e9e01b96e5b8678b66db16f827061 [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ú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)
SimonB21ab9d72016-03-12 20:37:32 +000021#
22# Purpose
23#
24# Executes the basic test suites, captures the results, and generates a simple
25# test report and code coverage report.
26#
27# The tests include:
SimonB21ab9d72016-03-12 20:37:32 +000028# * Unit tests - executed using tests/scripts/run-test-suite.pl
Paul Bakker4b8bc522016-07-20 09:52:01 +010029# * Self-tests - executed using the test suites above
SimonB21ab9d72016-03-12 20:37:32 +000030# * System tests - executed using tests/ssl-opt.sh
31# * Interoperability tests - executed using tests/compat.sh
32#
33# The tests focus on functionality and do not consider performance.
34#
35# Note the tests self-adapt due to configurations in include/mbedtls/config.h
36# which can lead to some tests being skipped, and can cause the number of
Paul Bakker4b8bc522016-07-20 09:52:01 +010037# available tests to fluctuate.
SimonB21ab9d72016-03-12 20:37:32 +000038#
39# This script has been written to be generic and should work on any shell.
40#
41# Usage: basic-build-tests.sh
42#
43
44# Abort on errors (and uninitiliased variables)
45set -eu
46
47if [ -d library -a -d include -a -d tests ]; then :; else
48 echo "Must be run from mbed TLS root" >&2
49 exit 1
50fi
51
Andres AGb2fdd042016-09-22 14:17:46 +010052: ${OPENSSL:="openssl"}
53: ${OPENSSL_LEGACY:="$OPENSSL"}
54: ${GNUTLS_CLI:="gnutls-cli"}
55: ${GNUTLS_SERV:="gnutls-serv"}
56: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
57: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
58
59# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
60# we just export the variables they require
61export OPENSSL_CMD="$OPENSSL"
62export GNUTLS_CLI="$GNUTLS_CLI"
63export GNUTLS_SERV="$GNUTLS_SERV"
64
Janos Follath7ccac852016-06-06 13:18:39 +010065CONFIG_H='include/mbedtls/config.h'
66CONFIG_BAK="$CONFIG_H.bak"
SimonB21ab9d72016-03-12 20:37:32 +000067
Janos Follathb72c6782016-07-19 14:54:17 +010068# Step 0 - print build environment info
Andres AGb2fdd042016-09-22 14:17:46 +010069OPENSSL="$OPENSSL" \
70 OPENSSL_LEGACY="$OPENSSL_LEGACY" \
71 GNUTLS_CLI="$GNUTLS_CLI" \
72 GNUTLS_SERV="$GNUTLS_SERV" \
73 GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
74 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" \
75 scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +010076echo
77
SimonB21ab9d72016-03-12 20:37:32 +000078# Step 1 - Make and instrumented build for code coverage
Simon Butcherc2b0efc2016-03-18 18:28:43 +000079export CFLAGS=' --coverage -g3 -O0 '
SimonB098a3b52016-04-16 21:56:59 +010080make clean
Janos Follath7ccac852016-06-06 13:18:39 +010081cp "$CONFIG_H" "$CONFIG_BAK"
SimonB098a3b52016-04-16 21:56:59 +010082scripts/config.pl full
Simon Butchercbb90752016-05-19 22:15:34 +010083make -j
SimonB21ab9d72016-03-12 20:37:32 +000084
85
86# Step 2 - Execute the tests
87TEST_OUTPUT=out_${PPID}
88cd tests
89
Gilles Peskined9701ae2020-04-09 18:33:34 +020090if [ ! -f "seedfile" ]; then
91 dd if=/dev/urandom of="seedfile" bs=64 count=1
92fi
93
Gilles Peskine8bfe12b2020-04-09 18:29:42 +020094# Step 2a - Unit Tests (keep going even if some tests fail)
Jaeden Amero60ca6e52018-12-07 13:06:24 +000095perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +000096echo
97
Gilles Peskine8bfe12b2020-04-09 18:29:42 +020098# Step 2b - System Tests (keep going even if some tests fail)
SimonB21ab9d72016-03-12 20:37:32 +000099sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT
100echo
101
Gilles Peskine8bfe12b2020-04-09 18:29:42 +0200102# Step 2c - Compatibility tests (keep going even if some tests fail)
Andres AGb2fdd042016-09-22 14:17:46 +0100103sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' | \
104 tee compat-test-$TEST_OUTPUT
105OPENSSL_CMD="$OPENSSL_LEGACY" \
106 sh compat.sh -m 'ssl3' |tee -a compat-test-$TEST_OUTPUT
107OPENSSL_CMD="$OPENSSL_LEGACY" \
108 GNUTLS_CLI="$GNUTLS_LEGACY_CLI" \
109 GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000110 sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' | \
Andres AGb2fdd042016-09-22 14:17:46 +0100111 tee -a compat-test-$TEST_OUTPUT
Manuel Pégourié-Gonnard79bf3272018-11-05 11:57:03 +0100112OPENSSL_CMD="$OPENSSL_NEXT" \
113 sh compat.sh -e '^$' -f 'ARIA\|CHACHA' | \
114 tee -a compat-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000115echo
116
117# Step 3 - Process the coverage report
118cd ..
Gilles Peskineed1f6732020-04-09 18:32:48 +0200119{
120 make lcov
121 echo SUCCESS
122} | tee tests/cov-$TEST_OUTPUT
123
124if [ "$(tail -n1 tests/cov-$TEST_OUTPUT)" != "SUCCESS" ]; then
125 echo >&2 "Fatal: 'make lcov' failed"
126 exit 2
127fi
SimonB21ab9d72016-03-12 20:37:32 +0000128
129
130# Step 4 - Summarise the test report
131echo
132echo "========================================================================="
133echo "Test Report Summary"
134echo
135
136cd tests
137
Paul Bakker4b8bc522016-07-20 09:52:01 +0100138# Step 4a - Unit tests
SimonB21ab9d72016-03-12 20:37:32 +0000139echo "Unit tests - tests/scripts/run-test-suites.pl"
140
141PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
142SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
143TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
144FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
145
146echo "No test suites : $TOTAL_SUITES"
147echo "Passed : $PASSED_TESTS"
148echo "Failed : $FAILED_TESTS"
149echo "Skipped : $SKIPPED_TESTS"
150echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
151echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
152echo
153
Paul Bakker4b8bc522016-07-20 09:52:01 +0100154TOTAL_PASS=$PASSED_TESTS
155TOTAL_FAIL=$FAILED_TESTS
156TOTAL_SKIP=$SKIPPED_TESTS
157TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
158TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000159
Paul Bakker4b8bc522016-07-20 09:52:01 +0100160# Step 4b - TLS Options tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000161echo "TLS Options tests - tests/ssl-opt.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000162
163PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
164SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p')
165TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p')
166FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS))
167
168echo "Passed : $PASSED_TESTS"
169echo "Failed : $FAILED_TESTS"
170echo "Skipped : $SKIPPED_TESTS"
171echo "Total exec'd tests : $TOTAL_TESTS"
172echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))"
173echo
174
175TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
176TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
177TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
178TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS))
179TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
180
181
Paul Bakker4b8bc522016-07-20 09:52:01 +0100182# Step 4c - System Compatibility tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000183echo "System/Compatibility tests - tests/compat.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000184
Andres AGb2fdd042016-09-22 14:17:46 +0100185PASSED_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 }')
186SKIPPED_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 }')
187EXED_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 +0000188FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS))
189
190echo "Passed : $PASSED_TESTS"
191echo "Failed : $FAILED_TESTS"
192echo "Skipped : $SKIPPED_TESTS"
193echo "Total exec'd tests : $EXED_TESTS"
194echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))"
195echo
196
197TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
198TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
199TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
200TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS))
201TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
202
203
Paul Bakker4b8bc522016-07-20 09:52:01 +0100204# Step 4d - Grand totals
SimonB21ab9d72016-03-12 20:37:32 +0000205echo "-------------------------------------------------------------------------"
206echo "Total tests"
207
208echo "Total Passed : $TOTAL_PASS"
209echo "Total Failed : $TOTAL_FAIL"
210echo "Total Skipped : $TOTAL_SKIP"
211echo "Total exec'd tests : $TOTAL_EXED"
212echo "Total avail tests : $TOTAL_AVAIL"
213echo
214
215
Paul Bakker4b8bc522016-07-20 09:52:01 +0100216# Step 4e - Coverage
SimonB21ab9d72016-03-12 20:37:32 +0000217echo "Coverage"
218
Dan Handley8cb19812020-05-28 16:20:31 +0100219LINES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p')
220LINES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p')
221FUNCS_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p')
222FUNCS_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p')
223BRANCHES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* branches)$/\1/p')
224BRANCHES_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 +0000225
226LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL))
227LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))"
228
229FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL))
230FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))"
231
Dan Handley8cb19812020-05-28 16:20:31 +0100232BRANCHES_PERCENT=$((1000*$BRANCHES_TESTED/$BRANCHES_TOTAL))
233BRANCHES_PERCENT="$(($BRANCHES_PERCENT/10)).$(($BRANCHES_PERCENT-($BRANCHES_PERCENT/10)*10))"
234
SimonB21ab9d72016-03-12 20:37:32 +0000235echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%"
236echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%"
Dan Handley8cb19812020-05-28 16:20:31 +0100237echo "Branches Tested : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%"
SimonB21ab9d72016-03-12 20:37:32 +0000238echo
239
SimonB21ab9d72016-03-12 20:37:32 +0000240rm unit-test-$TEST_OUTPUT
241rm sys-test-$TEST_OUTPUT
242rm compat-test-$TEST_OUTPUT
243rm cov-$TEST_OUTPUT
244
245cd ..
Janos Follath7ccac852016-06-06 13:18:39 +0100246
247make clean
248
249if [ -f "$CONFIG_BAK" ]; then
250 mv "$CONFIG_BAK" "$CONFIG_H"
251fi
Gilles Peskinef54a5de2020-04-09 18:28:14 +0200252
253if [ $TOTAL_FAIL -ne 0 ]; then
254 exit 1
255fi