blob: d559fa522ba2ebe147f300e68af85cfc115fd89a [file] [log] [blame]
SimonB21ab9d72016-03-12 20:37:32 +00001#!/bin/sh
2
3# basic-build-tests.sh
4#
Simon Butchercbb90752016-05-19 22:15:34 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
SimonB21ab9d72016-03-12 20:37:32 +00007# Copyright (c) 2016, ARM Limited, All Rights Reserved
8#
9# Purpose
10#
11# Executes the basic test suites, captures the results, and generates a simple
12# test report and code coverage report.
13#
14# The tests include:
SimonB21ab9d72016-03-12 20:37:32 +000015# * Unit tests - executed using tests/scripts/run-test-suite.pl
Paul Bakker4b8bc522016-07-20 09:52:01 +010016# * Self-tests - executed using the test suites above
SimonB21ab9d72016-03-12 20:37:32 +000017# * System tests - executed using tests/ssl-opt.sh
18# * Interoperability tests - executed using tests/compat.sh
19#
20# The tests focus on functionality and do not consider performance.
21#
22# Note the tests self-adapt due to configurations in include/mbedtls/config.h
23# which can lead to some tests being skipped, and can cause the number of
Paul Bakker4b8bc522016-07-20 09:52:01 +010024# available tests to fluctuate.
SimonB21ab9d72016-03-12 20:37:32 +000025#
26# This script has been written to be generic and should work on any shell.
27#
Teppo Järveline06e0392019-11-25 15:22:42 +020028# Usage: basic-build-tests.sh to run all tests
29# basic-build-tests.sh unit_test to run only unit tests
SimonB21ab9d72016-03-12 20:37:32 +000030#
31
32# Abort on errors (and uninitiliased variables)
33set -eu
34
Teppo Järveline06e0392019-11-25 15:22:42 +020035CONFIG_H='include/mbedtls/config.h'
36CONFIG_BAK="$CONFIG_H.bak"
37
38UNIT_TESTS_ONLY=0
39
40echo
41if [ -z ${1+x} ]
42then
43 echo "Running all tests"
44else
45 if [ "$1" = "unit_test" ]
46 then
47 echo "Running only unit tests"
48 UNIT_TESTS_ONLY=1
49 fi
50fi
51echo
52
53# Check test environment. If importer, src and inc folders are present then
54# there is a different directory structure and we need to adapt to it.
55if [ -d importer -a -d inc -a -d src ]; then
56 CONFIG_H='inc/mbedtls/config.h'
57 CONFIG_BAK="$CONFIG_H.bak"
58elif [ -d library -a -d include -a -d tests ]; then :; else
SimonB21ab9d72016-03-12 20:37:32 +000059 echo "Must be run from mbed TLS root" >&2
60 exit 1
61fi
62
Andres AGb2fdd042016-09-22 14:17:46 +010063: ${OPENSSL:="openssl"}
64: ${OPENSSL_LEGACY:="$OPENSSL"}
65: ${GNUTLS_CLI:="gnutls-cli"}
66: ${GNUTLS_SERV:="gnutls-serv"}
67: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
68: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
69
70# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
71# we just export the variables they require
72export OPENSSL_CMD="$OPENSSL"
73export GNUTLS_CLI="$GNUTLS_CLI"
74export GNUTLS_SERV="$GNUTLS_SERV"
75
Janos Follathb72c6782016-07-19 14:54:17 +010076# Step 0 - print build environment info
Andres AGb2fdd042016-09-22 14:17:46 +010077OPENSSL="$OPENSSL" \
78 OPENSSL_LEGACY="$OPENSSL_LEGACY" \
79 GNUTLS_CLI="$GNUTLS_CLI" \
80 GNUTLS_SERV="$GNUTLS_SERV" \
81 GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
82 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" \
83 scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +010084echo
85
SimonB21ab9d72016-03-12 20:37:32 +000086# Step 1 - Make and instrumented build for code coverage
Simon Butcherc2b0efc2016-03-18 18:28:43 +000087export CFLAGS=' --coverage -g3 -O0 '
SimonB098a3b52016-04-16 21:56:59 +010088make clean
Janos Follath7ccac852016-06-06 13:18:39 +010089cp "$CONFIG_H" "$CONFIG_BAK"
SimonB098a3b52016-04-16 21:56:59 +010090scripts/config.pl full
Simon Butcherae791242016-05-10 21:16:54 +010091scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
Simon Butchercbb90752016-05-19 22:15:34 +010092make -j
SimonB21ab9d72016-03-12 20:37:32 +000093
94
95# Step 2 - Execute the tests
96TEST_OUTPUT=out_${PPID}
97cd tests
98
Paul Bakker4b8bc522016-07-20 09:52:01 +010099# Step 2a - Unit Tests
Jaeden Amero60ca6e52018-12-07 13:06:24 +0000100perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000101echo
102
Teppo Järveline06e0392019-11-25 15:22:42 +0200103# only unit test are run?
104if [ $UNIT_TESTS_ONLY -eq 1 ]
105then
106 exit 0
107fi
108
Paul Bakker4b8bc522016-07-20 09:52:01 +0100109# Step 2b - System Tests
SimonB21ab9d72016-03-12 20:37:32 +0000110sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT
111echo
112
Paul Bakker4b8bc522016-07-20 09:52:01 +0100113# Step 2c - Compatibility tests
Andres AGb2fdd042016-09-22 14:17:46 +0100114sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' | \
115 tee compat-test-$TEST_OUTPUT
116OPENSSL_CMD="$OPENSSL_LEGACY" \
117 sh compat.sh -m 'ssl3' |tee -a compat-test-$TEST_OUTPUT
118OPENSSL_CMD="$OPENSSL_LEGACY" \
119 GNUTLS_CLI="$GNUTLS_LEGACY_CLI" \
120 GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000121 sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' | \
Andres AGb2fdd042016-09-22 14:17:46 +0100122 tee -a compat-test-$TEST_OUTPUT
Manuel Pégourié-Gonnard79bf3272018-11-05 11:57:03 +0100123OPENSSL_CMD="$OPENSSL_NEXT" \
124 sh compat.sh -e '^$' -f 'ARIA\|CHACHA' | \
125 tee -a compat-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000126echo
127
128# Step 3 - Process the coverage report
129cd ..
130make lcov |tee tests/cov-$TEST_OUTPUT
131
132
133# Step 4 - Summarise the test report
134echo
135echo "========================================================================="
136echo "Test Report Summary"
137echo
138
139cd tests
140
Paul Bakker4b8bc522016-07-20 09:52:01 +0100141# Step 4a - Unit tests
SimonB21ab9d72016-03-12 20:37:32 +0000142echo "Unit tests - tests/scripts/run-test-suites.pl"
143
144PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
145SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
146TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
147FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
148
149echo "No test suites : $TOTAL_SUITES"
150echo "Passed : $PASSED_TESTS"
151echo "Failed : $FAILED_TESTS"
152echo "Skipped : $SKIPPED_TESTS"
153echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
154echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
155echo
156
Paul Bakker4b8bc522016-07-20 09:52:01 +0100157TOTAL_PASS=$PASSED_TESTS
158TOTAL_FAIL=$FAILED_TESTS
159TOTAL_SKIP=$SKIPPED_TESTS
160TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
161TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000162
Paul Bakker4b8bc522016-07-20 09:52:01 +0100163# Step 4b - TLS Options tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000164echo "TLS Options tests - tests/ssl-opt.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000165
166PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
167SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p')
168TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p')
169FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS))
170
171echo "Passed : $PASSED_TESTS"
172echo "Failed : $FAILED_TESTS"
173echo "Skipped : $SKIPPED_TESTS"
174echo "Total exec'd tests : $TOTAL_TESTS"
175echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))"
176echo
177
178TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
179TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
180TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
181TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS))
182TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
183
184
Paul Bakker4b8bc522016-07-20 09:52:01 +0100185# Step 4c - System Compatibility tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000186echo "System/Compatibility tests - tests/compat.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000187
Andres AGb2fdd042016-09-22 14:17:46 +0100188PASSED_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 }')
189SKIPPED_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 }')
190EXED_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 +0000191FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS))
192
193echo "Passed : $PASSED_TESTS"
194echo "Failed : $FAILED_TESTS"
195echo "Skipped : $SKIPPED_TESTS"
196echo "Total exec'd tests : $EXED_TESTS"
197echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))"
198echo
199
200TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
201TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
202TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
203TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS))
204TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
205
206
Paul Bakker4b8bc522016-07-20 09:52:01 +0100207# Step 4d - Grand totals
SimonB21ab9d72016-03-12 20:37:32 +0000208echo "-------------------------------------------------------------------------"
209echo "Total tests"
210
211echo "Total Passed : $TOTAL_PASS"
212echo "Total Failed : $TOTAL_FAIL"
213echo "Total Skipped : $TOTAL_SKIP"
214echo "Total exec'd tests : $TOTAL_EXED"
215echo "Total avail tests : $TOTAL_AVAIL"
216echo
217
218
Paul Bakker4b8bc522016-07-20 09:52:01 +0100219# Step 4e - Coverage
SimonB21ab9d72016-03-12 20:37:32 +0000220echo "Coverage"
221
222LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p')
223LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p')
224FUNCS_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p')
Simon Butcherab0c51d2016-03-13 01:23:34 +0000225FUNCS_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p')
SimonB21ab9d72016-03-12 20:37:32 +0000226
227LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL))
228LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))"
229
230FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL))
231FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))"
232
233echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%"
234echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%"
235echo
236
237
SimonB21ab9d72016-03-12 20:37:32 +0000238rm unit-test-$TEST_OUTPUT
239rm sys-test-$TEST_OUTPUT
240rm compat-test-$TEST_OUTPUT
241rm cov-$TEST_OUTPUT
242
243cd ..
Janos Follath7ccac852016-06-06 13:18:39 +0100244
245make clean
246
247if [ -f "$CONFIG_BAK" ]; then
248 mv "$CONFIG_BAK" "$CONFIG_H"
249fi