blob: 7ed0372ab76cfcb6211dbc35ef543044ece010ed [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#
18# The tests focus on functionality and do not consider performance.
19#
20# Note the tests self-adapt due to configurations in include/mbedtls/config.h
21# which can lead to some tests being skipped, and can cause the number of
Paul Bakker4b8bc522016-07-20 09:52:01 +010022# available tests to fluctuate.
SimonB21ab9d72016-03-12 20:37:32 +000023#
24# This script has been written to be generic and should work on any shell.
25#
26# Usage: basic-build-tests.sh
27#
28
29# Abort on errors (and uninitiliased variables)
30set -eu
31
32if [ -d library -a -d include -a -d tests ]; then :; else
33 echo "Must be run from mbed TLS root" >&2
34 exit 1
35fi
36
Janos Follath7ccac852016-06-06 13:18:39 +010037CONFIG_H='include/mbedtls/config.h'
38CONFIG_BAK="$CONFIG_H.bak"
SimonB21ab9d72016-03-12 20:37:32 +000039
Janos Follathb72c6782016-07-19 14:54:17 +010040# Step 0 - print build environment info
Jaeden Amero9afb2e92018-11-02 10:51:09 +000041scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +010042echo
43
SimonB21ab9d72016-03-12 20:37:32 +000044# Step 1 - Make and instrumented build for code coverage
Simon Butcherc2b0efc2016-03-18 18:28:43 +000045export CFLAGS=' --coverage -g3 -O0 '
Philippe Antoine702c6592019-07-09 17:44:53 +020046export LDFLAGS=' --coverage'
SimonB098a3b52016-04-16 21:56:59 +010047make clean
Janos Follath7ccac852016-06-06 13:18:39 +010048cp "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine3bdd4122019-07-27 23:52:53 +020049scripts/config.py full
50scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE
Simon Butchercbb90752016-05-19 22:15:34 +010051make -j
SimonB21ab9d72016-03-12 20:37:32 +000052
53
54# Step 2 - Execute the tests
55TEST_OUTPUT=out_${PPID}
56cd tests
Gilles Peskine3c8ccc02019-05-20 11:39:18 +020057if [ ! -f "seedfile" ]; then
58 dd if=/dev/urandom of="seedfile" bs=32 count=1
59fi
SimonB21ab9d72016-03-12 20:37:32 +000060
Paul Bakker4b8bc522016-07-20 09:52:01 +010061# Step 2a - Unit Tests
Jaeden Amero60ca6e52018-12-07 13:06:24 +000062perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +000063echo
64
SimonB21ab9d72016-03-12 20:37:32 +000065# Step 3 - Process the coverage report
66cd ..
67make lcov |tee tests/cov-$TEST_OUTPUT
68
69
70# Step 4 - Summarise the test report
71echo
72echo "========================================================================="
73echo "Test Report Summary"
74echo
75
76cd tests
77
Paul Bakker4b8bc522016-07-20 09:52:01 +010078# Step 4a - Unit tests
SimonB21ab9d72016-03-12 20:37:32 +000079echo "Unit tests - tests/scripts/run-test-suites.pl"
80
81PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
82SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
83TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
84FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
85
86echo "No test suites : $TOTAL_SUITES"
87echo "Passed : $PASSED_TESTS"
88echo "Failed : $FAILED_TESTS"
89echo "Skipped : $SKIPPED_TESTS"
90echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
91echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
92echo
93
Paul Bakker4b8bc522016-07-20 09:52:01 +010094TOTAL_PASS=$PASSED_TESTS
95TOTAL_FAIL=$FAILED_TESTS
96TOTAL_SKIP=$SKIPPED_TESTS
97TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
98TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +000099
SimonB21ab9d72016-03-12 20:37:32 +0000100
Paul Bakker4b8bc522016-07-20 09:52:01 +0100101# Step 4d - Grand totals
SimonB21ab9d72016-03-12 20:37:32 +0000102echo "-------------------------------------------------------------------------"
103echo "Total tests"
104
105echo "Total Passed : $TOTAL_PASS"
106echo "Total Failed : $TOTAL_FAIL"
107echo "Total Skipped : $TOTAL_SKIP"
108echo "Total exec'd tests : $TOTAL_EXED"
109echo "Total avail tests : $TOTAL_AVAIL"
110echo
111
112
Paul Bakker4b8bc522016-07-20 09:52:01 +0100113# Step 4e - Coverage
SimonB21ab9d72016-03-12 20:37:32 +0000114echo "Coverage"
115
116LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p')
117LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p')
118FUNCS_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 +0000119FUNCS_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 +0000120
121LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL))
122LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))"
123
124FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL))
125FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))"
126
127echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%"
128echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%"
129echo
130
131
SimonB21ab9d72016-03-12 20:37:32 +0000132rm unit-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000133rm cov-$TEST_OUTPUT
134
135cd ..
Janos Follath7ccac852016-06-06 13:18:39 +0100136
137make clean
138
139if [ -f "$CONFIG_BAK" ]; then
140 mv "$CONFIG_BAK" "$CONFIG_H"
141fi