2016-03-12 21:37:32 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# basic-build-tests.sh
|
|
|
|
#
|
2016-05-19 23:15:34 +02:00
|
|
|
# This file is part of mbed TLS (https://tls.mbed.org)
|
|
|
|
#
|
2016-03-12 21:37:32 +01:00
|
|
|
# Copyright (c) 2016, ARM Limited, All Rights Reserved
|
|
|
|
#
|
|
|
|
# Purpose
|
|
|
|
#
|
|
|
|
# Executes the basic test suites, captures the results, and generates a simple
|
|
|
|
# test report and code coverage report.
|
|
|
|
#
|
|
|
|
# The tests include:
|
|
|
|
# * Unit tests - executed using tests/scripts/run-test-suite.pl
|
2016-07-20 10:52:01 +02:00
|
|
|
# * Self-tests - executed using the test suites above
|
2016-03-12 21:37:32 +01:00
|
|
|
#
|
|
|
|
# The tests focus on functionality and do not consider performance.
|
|
|
|
#
|
|
|
|
# Note the tests self-adapt due to configurations in include/mbedtls/config.h
|
|
|
|
# which can lead to some tests being skipped, and can cause the number of
|
2016-07-20 10:52:01 +02:00
|
|
|
# available tests to fluctuate.
|
2016-03-12 21:37:32 +01:00
|
|
|
#
|
|
|
|
# This script has been written to be generic and should work on any shell.
|
|
|
|
#
|
|
|
|
# Usage: basic-build-tests.sh
|
|
|
|
#
|
|
|
|
|
|
|
|
# Abort on errors (and uninitiliased variables)
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
if [ -d library -a -d include -a -d tests ]; then :; else
|
|
|
|
echo "Must be run from mbed TLS root" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-06-06 14:18:39 +02:00
|
|
|
CONFIG_H='include/mbedtls/config.h'
|
|
|
|
CONFIG_BAK="$CONFIG_H.bak"
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2016-07-19 15:54:17 +02:00
|
|
|
# Step 0 - print build environment info
|
2018-11-02 11:51:09 +01:00
|
|
|
scripts/output_env.sh
|
2016-07-19 15:54:17 +02:00
|
|
|
echo
|
|
|
|
|
2016-03-12 21:37:32 +01:00
|
|
|
# Step 1 - Make and instrumented build for code coverage
|
2016-03-18 19:28:43 +01:00
|
|
|
export CFLAGS=' --coverage -g3 -O0 '
|
2019-07-09 17:44:53 +02:00
|
|
|
export LDFLAGS=' --coverage'
|
2016-04-16 22:56:59 +02:00
|
|
|
make clean
|
2016-06-06 14:18:39 +02:00
|
|
|
cp "$CONFIG_H" "$CONFIG_BAK"
|
2016-04-16 22:56:59 +02:00
|
|
|
scripts/config.pl full
|
2016-05-10 22:16:54 +02:00
|
|
|
scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
|
2016-05-19 23:15:34 +02:00
|
|
|
make -j
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Step 2 - Execute the tests
|
|
|
|
TEST_OUTPUT=out_${PPID}
|
|
|
|
cd tests
|
2019-05-20 11:39:18 +02:00
|
|
|
if [ ! -f "seedfile" ]; then
|
|
|
|
dd if=/dev/urandom of="seedfile" bs=32 count=1
|
|
|
|
fi
|
2016-03-12 21:37:32 +01:00
|
|
|
|
2016-07-20 10:52:01 +02:00
|
|
|
# Step 2a - Unit Tests
|
2018-12-07 14:06:24 +01:00
|
|
|
perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
|
2016-03-12 21:37:32 +01:00
|
|
|
echo
|
|
|
|
|
|
|
|
# Step 3 - Process the coverage report
|
|
|
|
cd ..
|
|
|
|
make lcov |tee tests/cov-$TEST_OUTPUT
|
|
|
|
|
|
|
|
|
|
|
|
# Step 4 - Summarise the test report
|
|
|
|
echo
|
|
|
|
echo "========================================================================="
|
|
|
|
echo "Test Report Summary"
|
|
|
|
echo
|
|
|
|
|
|
|
|
cd tests
|
|
|
|
|
2016-07-20 10:52:01 +02:00
|
|
|
# Step 4a - Unit tests
|
2016-03-12 21:37:32 +01:00
|
|
|
echo "Unit tests - tests/scripts/run-test-suites.pl"
|
|
|
|
|
|
|
|
PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
|
|
|
|
SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
|
|
|
|
TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
|
|
|
|
FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
|
|
|
|
|
|
|
|
echo "No test suites : $TOTAL_SUITES"
|
|
|
|
echo "Passed : $PASSED_TESTS"
|
|
|
|
echo "Failed : $FAILED_TESTS"
|
|
|
|
echo "Skipped : $SKIPPED_TESTS"
|
|
|
|
echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
|
|
|
|
echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
|
|
|
|
echo
|
|
|
|
|
2016-07-20 10:52:01 +02:00
|
|
|
TOTAL_PASS=$PASSED_TESTS
|
|
|
|
TOTAL_FAIL=$FAILED_TESTS
|
|
|
|
TOTAL_SKIP=$SKIPPED_TESTS
|
|
|
|
TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
|
|
|
|
TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
|
2016-07-20 10:52:01 +02:00
|
|
|
# Step 4d - Grand totals
|
2016-03-12 21:37:32 +01:00
|
|
|
echo "-------------------------------------------------------------------------"
|
|
|
|
echo "Total tests"
|
|
|
|
|
|
|
|
echo "Total Passed : $TOTAL_PASS"
|
|
|
|
echo "Total Failed : $TOTAL_FAIL"
|
|
|
|
echo "Total Skipped : $TOTAL_SKIP"
|
|
|
|
echo "Total exec'd tests : $TOTAL_EXED"
|
|
|
|
echo "Total avail tests : $TOTAL_AVAIL"
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
2016-07-20 10:52:01 +02:00
|
|
|
# Step 4e - Coverage
|
2016-03-12 21:37:32 +01:00
|
|
|
echo "Coverage"
|
|
|
|
|
|
|
|
LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p')
|
|
|
|
LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p')
|
|
|
|
FUNCS_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p')
|
2016-03-13 02:23:34 +01:00
|
|
|
FUNCS_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p')
|
2016-03-12 21:37:32 +01:00
|
|
|
|
|
|
|
LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL))
|
|
|
|
LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))"
|
|
|
|
|
|
|
|
FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL))
|
|
|
|
FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))"
|
|
|
|
|
|
|
|
echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%"
|
|
|
|
echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%"
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
|
|
rm unit-test-$TEST_OUTPUT
|
|
|
|
rm cov-$TEST_OUTPUT
|
|
|
|
|
|
|
|
cd ..
|
2016-06-06 14:18:39 +02:00
|
|
|
|
|
|
|
make clean
|
|
|
|
|
|
|
|
if [ -f "$CONFIG_BAK" ]; then
|
|
|
|
mv "$CONFIG_BAK" "$CONFIG_H"
|
|
|
|
fi
|