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 ' |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 46 | make clean |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 47 | cp "$CONFIG_H" "$CONFIG_BAK" |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 48 | scripts/config.pl full |
Simon Butcher | ae79124 | 2016-05-10 21:16:54 +0100 | [diff] [blame] | 49 | scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE |
Simon Butcher | cbb9075 | 2016-05-19 22:15:34 +0100 | [diff] [blame] | 50 | make -j |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | # Step 2 - Execute the tests |
| 54 | TEST_OUTPUT=out_${PPID} |
| 55 | cd tests |
| 56 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 57 | # Step 2a - Unit Tests |
Jaeden Amero | 60ca6e5 | 2018-12-07 13:06:24 +0000 | [diff] [blame] | 58 | perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 59 | echo |
| 60 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 61 | # Step 3 - Process the coverage report |
| 62 | cd .. |
| 63 | make lcov |tee tests/cov-$TEST_OUTPUT |
| 64 | |
| 65 | |
| 66 | # Step 4 - Summarise the test report |
| 67 | echo |
| 68 | echo "=========================================================================" |
| 69 | echo "Test Report Summary" |
| 70 | echo |
| 71 | |
| 72 | cd tests |
| 73 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 74 | # Step 4a - Unit tests |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 75 | echo "Unit tests - tests/scripts/run-test-suites.pl" |
| 76 | |
| 77 | PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 78 | SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 79 | TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') |
| 80 | FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') |
| 81 | |
| 82 | echo "No test suites : $TOTAL_SUITES" |
| 83 | echo "Passed : $PASSED_TESTS" |
| 84 | echo "Failed : $FAILED_TESTS" |
| 85 | echo "Skipped : $SKIPPED_TESTS" |
| 86 | echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" |
| 87 | echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" |
| 88 | echo |
| 89 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 90 | TOTAL_PASS=$PASSED_TESTS |
| 91 | TOTAL_FAIL=$FAILED_TESTS |
| 92 | TOTAL_SKIP=$SKIPPED_TESTS |
| 93 | TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) |
| 94 | TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 95 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 96 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 97 | # Step 4d - Grand totals |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 98 | echo "-------------------------------------------------------------------------" |
| 99 | echo "Total tests" |
| 100 | |
| 101 | echo "Total Passed : $TOTAL_PASS" |
| 102 | echo "Total Failed : $TOTAL_FAIL" |
| 103 | echo "Total Skipped : $TOTAL_SKIP" |
| 104 | echo "Total exec'd tests : $TOTAL_EXED" |
| 105 | echo "Total avail tests : $TOTAL_AVAIL" |
| 106 | echo |
| 107 | |
| 108 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 109 | # Step 4e - Coverage |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 110 | echo "Coverage" |
| 111 | |
| 112 | LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p') |
| 113 | LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p') |
| 114 | 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] | 115 | 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] | 116 | |
| 117 | LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL)) |
| 118 | LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))" |
| 119 | |
| 120 | FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL)) |
| 121 | FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))" |
| 122 | |
| 123 | echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%" |
| 124 | echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%" |
| 125 | echo |
| 126 | |
| 127 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 128 | rm unit-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 129 | rm cov-$TEST_OUTPUT |
| 130 | |
| 131 | cd .. |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 132 | |
| 133 | make clean |
| 134 | |
| 135 | if [ -f "$CONFIG_BAK" ]; then |
| 136 | mv "$CONFIG_BAK" "$CONFIG_H" |
| 137 | fi |