blob: e8b616492824bf888c5e9d3e78d39718ccbdf6f8 [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#
28# Usage: basic-build-tests.sh
29#
30
31# Abort on errors (and uninitiliased variables)
32set -eu
33
34if [ -d library -a -d include -a -d tests ]; then :; else
35 echo "Must be run from mbed TLS root" >&2
36 exit 1
37fi
38
Janos Follath7ccac852016-06-06 13:18:39 +010039CONFIG_H='include/mbedtls/config.h'
40CONFIG_BAK="$CONFIG_H.bak"
SimonB21ab9d72016-03-12 20:37:32 +000041
Janos Follathb72c6782016-07-19 14:54:17 +010042# Step 0 - print build environment info
43scripts/output_env.sh
44echo
45
SimonB21ab9d72016-03-12 20:37:32 +000046# Step 1 - Make and instrumented build for code coverage
Simon Butcherc2b0efc2016-03-18 18:28:43 +000047export CFLAGS=' --coverage -g3 -O0 '
SimonB098a3b52016-04-16 21:56:59 +010048make clean
Janos Follath7ccac852016-06-06 13:18:39 +010049cp "$CONFIG_H" "$CONFIG_BAK"
SimonB098a3b52016-04-16 21:56:59 +010050scripts/config.pl full
Simon Butcherae791242016-05-10 21:16:54 +010051scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
Simon Butchercbb90752016-05-19 22:15:34 +010052make -j
SimonB21ab9d72016-03-12 20:37:32 +000053
54
55# Step 2 - Execute the tests
56TEST_OUTPUT=out_${PPID}
57cd tests
58
Paul Bakker4b8bc522016-07-20 09:52:01 +010059# Step 2a - Unit Tests
SimonB21ab9d72016-03-12 20:37:32 +000060perl scripts/run-test-suites.pl -v |tee unit-test-$TEST_OUTPUT
61echo
62
Paul Bakker4b8bc522016-07-20 09:52:01 +010063# Step 2b - System Tests
SimonB21ab9d72016-03-12 20:37:32 +000064sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT
65echo
66
Paul Bakker4b8bc522016-07-20 09:52:01 +010067# Step 2c - Compatibility tests
SimonB21ab9d72016-03-12 20:37:32 +000068sh compat.sh |tee compat-test-$TEST_OUTPUT
69echo
70
71# Step 3 - Process the coverage report
72cd ..
73make lcov |tee tests/cov-$TEST_OUTPUT
74
75
76# Step 4 - Summarise the test report
77echo
78echo "========================================================================="
79echo "Test Report Summary"
80echo
81
82cd tests
83
Paul Bakker4b8bc522016-07-20 09:52:01 +010084# Step 4a - Unit tests
SimonB21ab9d72016-03-12 20:37:32 +000085echo "Unit tests - tests/scripts/run-test-suites.pl"
86
87PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
88SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
89TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
90FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
91
92echo "No test suites : $TOTAL_SUITES"
93echo "Passed : $PASSED_TESTS"
94echo "Failed : $FAILED_TESTS"
95echo "Skipped : $SKIPPED_TESTS"
96echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
97echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
98echo
99
Paul Bakker4b8bc522016-07-20 09:52:01 +0100100TOTAL_PASS=$PASSED_TESTS
101TOTAL_FAIL=$FAILED_TESTS
102TOTAL_SKIP=$SKIPPED_TESTS
103TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
104TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000105
Paul Bakker4b8bc522016-07-20 09:52:01 +0100106# Step 4b - TLS Options tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000107echo "TLS Options tests - tests/ssl-opt.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000108
109PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
110SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p')
111TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p')
112FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS))
113
114echo "Passed : $PASSED_TESTS"
115echo "Failed : $FAILED_TESTS"
116echo "Skipped : $SKIPPED_TESTS"
117echo "Total exec'd tests : $TOTAL_TESTS"
118echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))"
119echo
120
121TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
122TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
123TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
124TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS))
125TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
126
127
Paul Bakker4b8bc522016-07-20 09:52:01 +0100128# Step 4c - System Compatibility tests
Simon Butcherab0c51d2016-03-13 01:23:34 +0000129echo "System/Compatibility tests - tests/compat.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000130
131PASSED_TESTS=$(tail -n5 compat-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
132SKIPPED_TESTS=$(tail -n5 compat-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p')
133EXED_TESTS=$(tail -n5 compat-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p')
134FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS))
135
136echo "Passed : $PASSED_TESTS"
137echo "Failed : $FAILED_TESTS"
138echo "Skipped : $SKIPPED_TESTS"
139echo "Total exec'd tests : $EXED_TESTS"
140echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))"
141echo
142
143TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
144TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
145TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
146TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS))
147TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
148
149
Paul Bakker4b8bc522016-07-20 09:52:01 +0100150# Step 4d - Grand totals
SimonB21ab9d72016-03-12 20:37:32 +0000151echo "-------------------------------------------------------------------------"
152echo "Total tests"
153
154echo "Total Passed : $TOTAL_PASS"
155echo "Total Failed : $TOTAL_FAIL"
156echo "Total Skipped : $TOTAL_SKIP"
157echo "Total exec'd tests : $TOTAL_EXED"
158echo "Total avail tests : $TOTAL_AVAIL"
159echo
160
161
Paul Bakker4b8bc522016-07-20 09:52:01 +0100162# Step 4e - Coverage
SimonB21ab9d72016-03-12 20:37:32 +0000163echo "Coverage"
164
165LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p')
166LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p')
167FUNCS_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 +0000168FUNCS_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 +0000169
170LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL))
171LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))"
172
173FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL))
174FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))"
175
176echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%"
177echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%"
178echo
179
180
SimonB21ab9d72016-03-12 20:37:32 +0000181rm unit-test-$TEST_OUTPUT
182rm sys-test-$TEST_OUTPUT
183rm compat-test-$TEST_OUTPUT
184rm cov-$TEST_OUTPUT
185
186cd ..
Janos Follath7ccac852016-06-06 13:18:39 +0100187
188make clean
189
190if [ -f "$CONFIG_BAK" ]; then
191 mv "$CONFIG_BAK" "$CONFIG_H"
192fi