blob: e1a5f0999d75b3575b7f6e103dc719ba4b54a1cf [file] [log] [blame]
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +02001#!/bin/sh
2
Manuel Pégourié-Gonnard222bc852022-12-29 13:47:25 +01003# This script runs tests before and after a PR and analyzes the results in
4# order to highlight any difference in the set of tests skipped.
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +02005#
Janos Follath12438962024-12-13 14:36:06 +00006# It can be used to check for unintended consequences when making non-trivial
7# changes to compile time guards: the sets of tests skipped in the default
8# config and the full config must be the same before and after the PR.
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +02009#
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010010# USAGE:
11# - First, commit any uncommited changes. (Also, see warning below.)
Manuel Pégourié-Gonnard5a2e0262023-01-23 12:51:52 +010012# - Then launch --> [SKIP_SSL_OPT=1] docs/architecture/psa-migration/outcome-analysis.sh
13# - SKIP_SSL_OPT=1 can optionally be set to skip ssl-opt.sh tests
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010014#
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020015# WARNING: this script checks out a commit other than the head of the current
Manuel Pégourié-Gonnard68429fc2022-07-27 20:37:12 +020016# branch; it checks out the current branch again when running successfully,
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020017# but while the script is running, or if it terminates early in error, you
Manuel Pégourié-Gonnard68429fc2022-07-27 20:37:12 +020018# should be aware that you might be at a different commit than expected.
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020019#
Manuel Pégourié-Gonnard222bc852022-12-29 13:47:25 +010020# NOTE: you can comment out parts that don't need to be re-done when
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020021# re-running this script (for example "get numbers before this PR").
22
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020023set -eu
24
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010025: ${SKIP_SSL_OPT:=0}
26
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020027cleanup() {
28 make clean
Ronald Cron7e5d61c2024-06-10 14:25:46 +020029 git checkout -- include/mbedtls/mbedtls_config.h tf-psa-crypto/include/psa/crypto_config.h
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020030}
31
32record() {
33 export MBEDTLS_TEST_OUTCOME_FILE="$PWD/outcome-$1.csv"
34 rm -f $MBEDTLS_TEST_OUTCOME_FILE
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010035
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020036 make check
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010037
38 if [ $SKIP_SSL_OPT -eq 0 ]; then
39 make -C programs ssl/ssl_server2 ssl/ssl_client2 \
40 test/udp_proxy test/query_compile_time_config
41 tests/ssl-opt.sh
42 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020043}
44
Valerio Setticcb03442023-07-31 15:07:49 +020045# save current HEAD.
Valerio Settiab02d392023-07-31 16:47:07 +020046# Note: this can optionally be updated to
47# HEAD=$(git branch --show-current)
48# when using a Git version above 2.22
49HEAD=$(git rev-parse --abbrev-ref HEAD)
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020050
Przemek Stekiel93986642022-11-09 15:06:44 +010051# get the numbers before this PR for default and full
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020052cleanup
Przemek Stekiel93986642022-11-09 15:06:44 +010053git checkout $(git merge-base HEAD development)
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010054
Przemek Stekiel93986642022-11-09 15:06:44 +010055record "before-default"
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020056
57cleanup
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010058
Przemek Stekiel93986642022-11-09 15:06:44 +010059scripts/config.py full
60record "before-full"
61
62# get the numbers now for default and full
63cleanup
64git checkout $HEAD
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010065
Przemek Stekiel93986642022-11-09 15:06:44 +010066record "after-default"
67
68cleanup
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010069
Przemek Stekiel93986642022-11-09 15:06:44 +010070scripts/config.py full
71record "after-full"
72
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010073cleanup
74
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020075# analysis
76
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020077populate_suites () {
78 SUITES=''
79 make generated_files >/dev/null
80 data_files=$(cd tests/suites && echo *.data)
81 for data in $data_files; do
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010082 suite=${data%.data}
Manuel Pégourié-Gonnard222bc852022-12-29 13:47:25 +010083 SUITES="$SUITES $suite"
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020084 done
85 make neat
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +010086
87 if [ $SKIP_SSL_OPT -eq 0 ]; then
88 SUITES="$SUITES ssl-opt"
89 extra_files=$(cd tests/opt-testcases && echo *.sh)
90 for extra in $extra_files; do
91 suite=${extra%.sh}
92 SUITES="$SUITES $suite"
93 done
94 fi
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020095}
96
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020097compare_suite () {
98 ref="outcome-$1.csv"
99 new="outcome-$2.csv"
100 suite="$3"
101
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +0100102 pattern_suite=";$suite;"
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200103 total=$(grep -c "$pattern_suite" "$ref")
104 sed_cmd="s/^.*$pattern_suite\(.*\);SKIP.*/\1/p"
105 sed -n "$sed_cmd" "$ref" > skipped-ref
106 sed -n "$sed_cmd" "$new" > skipped-new
107 nb_ref=$(wc -l <skipped-ref)
108 nb_new=$(wc -l <skipped-new)
109
Manuel Pégourié-Gonnard6bbeba62022-12-29 14:02:05 +0100110 name=${suite#test_suite_}
111 printf "%40s: total %4d; skipped %4d -> %4d\n" \
112 $name $total $nb_ref $nb_new
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200113 if diff skipped-ref skipped-new | grep '^> '; then
114 ret=1
115 else
116 ret=0
117 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200118 rm skipped-ref skipped-new
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200119 return $ret
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200120}
121
122compare_builds () {
123 printf "\n*** Comparing $1 -> $2 ***\n"
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200124 failed=''
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200125 for suite in $SUITES; do
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200126 if compare_suite "$1" "$2" "$suite"; then :; else
127 failed="$failed $suite"
128 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200129 done
Manuel Pégourié-Gonnardb51051f2022-10-18 09:42:30 +0200130 if [ -z "$failed" ]; then
131 printf "No coverage gap found.\n"
132 else
133 printf "Suites with less coverage:%s\n" "$failed"
134 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200135}
136
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200137populate_suites
Przemek Stekiel93986642022-11-09 15:06:44 +0100138compare_builds before-default after-default
139compare_builds before-full after-full