SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # basic-build-tests.sh |
| 4 | # |
Simon Butcher | cbb9075 | 2016-05-19 22:15:34 +0100 | [diff] [blame] | 5 | # This file is part of mbed TLS (https://tls.mbed.org) |
| 6 | # |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 7 | # 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: |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 15 | # * Unit tests - executed using tests/scripts/run-test-suite.pl |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 16 | # * Self-tests - executed using the test suites above |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 17 | # |
| 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 Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 22 | # available tests to fluctuate. |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 23 | # |
| 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) |
| 30 | set -eu |
| 31 | |
| 32 | if [ -d library -a -d include -a -d tests ]; then :; else |
| 33 | echo "Must be run from mbed TLS root" >&2 |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 37 | CONFIG_H='include/mbedtls/config.h' |
| 38 | CONFIG_BAK="$CONFIG_H.bak" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 39 | |
Janos Follath | b72c678 | 2016-07-19 14:54:17 +0100 | [diff] [blame] | 40 | # Step 0 - print build environment info |
Jaeden Amero | 9afb2e9 | 2018-11-02 10:51:09 +0000 | [diff] [blame] | 41 | scripts/output_env.sh |
Janos Follath | b72c678 | 2016-07-19 14:54:17 +0100 | [diff] [blame] | 42 | echo |
| 43 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 44 | # Step 1 - Make and instrumented build for code coverage |
Simon Butcher | c2b0efc | 2016-03-18 18:28:43 +0000 | [diff] [blame] | 45 | export CFLAGS=' --coverage -g3 -O0 ' |
Philippe Antoine | 702c659 | 2019-07-09 17:44:53 +0200 | [diff] [blame] | 46 | export LDFLAGS=' --coverage' |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 47 | make clean |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 48 | cp "$CONFIG_H" "$CONFIG_BAK" |
Gilles Peskine | 3bdd412 | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 49 | scripts/config.py full |
| 50 | scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE |
Simon Butcher | cbb9075 | 2016-05-19 22:15:34 +0100 | [diff] [blame] | 51 | make -j |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | # Step 2 - Execute the tests |
| 55 | TEST_OUTPUT=out_${PPID} |
| 56 | cd tests |
Gilles Peskine | 3c8ccc0 | 2019-05-20 11:39:18 +0200 | [diff] [blame] | 57 | if [ ! -f "seedfile" ]; then |
| 58 | dd if=/dev/urandom of="seedfile" bs=32 count=1 |
| 59 | fi |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 60 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 61 | # Step 2a - Unit Tests |
Jaeden Amero | 60ca6e5 | 2018-12-07 13:06:24 +0000 | [diff] [blame] | 62 | perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 63 | echo |
| 64 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 65 | # Step 3 - Process the coverage report |
| 66 | cd .. |
| 67 | make lcov |tee tests/cov-$TEST_OUTPUT |
| 68 | |
| 69 | |
| 70 | # Step 4 - Summarise the test report |
| 71 | echo |
| 72 | echo "=========================================================================" |
| 73 | echo "Test Report Summary" |
| 74 | echo |
| 75 | |
| 76 | cd tests |
| 77 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 78 | # Step 4a - Unit tests |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 79 | echo "Unit tests - tests/scripts/run-test-suites.pl" |
| 80 | |
| 81 | PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 82 | SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 83 | TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') |
| 84 | FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') |
| 85 | |
| 86 | echo "No test suites : $TOTAL_SUITES" |
| 87 | echo "Passed : $PASSED_TESTS" |
| 88 | echo "Failed : $FAILED_TESTS" |
| 89 | echo "Skipped : $SKIPPED_TESTS" |
| 90 | echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" |
| 91 | echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" |
| 92 | echo |
| 93 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 94 | TOTAL_PASS=$PASSED_TESTS |
| 95 | TOTAL_FAIL=$FAILED_TESTS |
| 96 | TOTAL_SKIP=$SKIPPED_TESTS |
| 97 | TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) |
| 98 | TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 99 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 100 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 101 | # Step 4d - Grand totals |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 102 | echo "-------------------------------------------------------------------------" |
| 103 | echo "Total tests" |
| 104 | |
| 105 | echo "Total Passed : $TOTAL_PASS" |
| 106 | echo "Total Failed : $TOTAL_FAIL" |
| 107 | echo "Total Skipped : $TOTAL_SKIP" |
| 108 | echo "Total exec'd tests : $TOTAL_EXED" |
| 109 | echo "Total avail tests : $TOTAL_AVAIL" |
| 110 | echo |
| 111 | |
| 112 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 113 | # Step 4e - Coverage |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 114 | echo "Coverage" |
| 115 | |
| 116 | LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p') |
| 117 | LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p') |
| 118 | FUNCS_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p') |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 119 | FUNCS_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p') |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 120 | |
| 121 | LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL)) |
| 122 | LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))" |
| 123 | |
| 124 | FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL)) |
| 125 | FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))" |
| 126 | |
| 127 | echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%" |
| 128 | echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%" |
| 129 | echo |
| 130 | |
| 131 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 132 | rm unit-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 133 | rm cov-$TEST_OUTPUT |
| 134 | |
| 135 | cd .. |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 136 | |
| 137 | make clean |
| 138 | |
| 139 | if [ -f "$CONFIG_BAK" ]; then |
| 140 | mv "$CONFIG_BAK" "$CONFIG_H" |
| 141 | fi |