blob: a653001e7d59e11aeb5e126a8c97afb4e8bcc2fb [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 '
SimonB098a3b52016-04-16 21:56:59 +010046make clean
Janos Follath7ccac852016-06-06 13:18:39 +010047cp "$CONFIG_H" "$CONFIG_BAK"
SimonB098a3b52016-04-16 21:56:59 +010048scripts/config.pl full
Simon Butcherae791242016-05-10 21:16:54 +010049scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
Simon Butchercbb90752016-05-19 22:15:34 +010050make -j
SimonB21ab9d72016-03-12 20:37:32 +000051
52
53# Step 2 - Execute the tests
54TEST_OUTPUT=out_${PPID}
55cd tests
56
Paul Bakker4b8bc522016-07-20 09:52:01 +010057# Step 2a - Unit Tests
Jaeden Amero60ca6e52018-12-07 13:06:24 +000058perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +000059echo
60
SimonB21ab9d72016-03-12 20:37:32 +000061# Step 3 - Process the coverage report
62cd ..
63make lcov |tee tests/cov-$TEST_OUTPUT
64
65
66# Step 4 - Summarise the test report
67echo
68echo "========================================================================="
69echo "Test Report Summary"
70echo
71
72cd tests
73
Paul Bakker4b8bc522016-07-20 09:52:01 +010074# Step 4a - Unit tests
SimonB21ab9d72016-03-12 20:37:32 +000075echo "Unit tests - tests/scripts/run-test-suites.pl"
76
77PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
78SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
79TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
80FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
81
82echo "No test suites : $TOTAL_SUITES"
83echo "Passed : $PASSED_TESTS"
84echo "Failed : $FAILED_TESTS"
85echo "Skipped : $SKIPPED_TESTS"
86echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
87echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
88echo
89
Paul Bakker4b8bc522016-07-20 09:52:01 +010090TOTAL_PASS=$PASSED_TESTS
91TOTAL_FAIL=$FAILED_TESTS
92TOTAL_SKIP=$SKIPPED_TESTS
93TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
94TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +000095
SimonB21ab9d72016-03-12 20:37:32 +000096
Paul Bakker4b8bc522016-07-20 09:52:01 +010097# Step 4d - Grand totals
SimonB21ab9d72016-03-12 20:37:32 +000098echo "-------------------------------------------------------------------------"
99echo "Total tests"
100
101echo "Total Passed : $TOTAL_PASS"
102echo "Total Failed : $TOTAL_FAIL"
103echo "Total Skipped : $TOTAL_SKIP"
104echo "Total exec'd tests : $TOTAL_EXED"
105echo "Total avail tests : $TOTAL_AVAIL"
106echo
107
108
Paul Bakker4b8bc522016-07-20 09:52:01 +0100109# Step 4e - Coverage
SimonB21ab9d72016-03-12 20:37:32 +0000110echo "Coverage"
111
112LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p')
113LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p')
114FUNCS_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 +0000115FUNCS_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 +0000116
117LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL))
118LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))"
119
120FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL))
121FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))"
122
123echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%"
124echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%"
125echo
126
127
SimonB21ab9d72016-03-12 20:37:32 +0000128rm unit-test-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000129rm cov-$TEST_OUTPUT
130
131cd ..
Janos Follath7ccac852016-06-06 13:18:39 +0100132
133make clean
134
135if [ -f "$CONFIG_BAK" ]; then
136 mv "$CONFIG_BAK" "$CONFIG_H"
137fi