blob: f7ca01b454fd5a4ee572e54763946bae786364bc [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#
Manuel Pégourié-Gonnard222bc852022-12-29 13:47:25 +01006# It can be used to check the first testing criterion mentioned in strategy.md,
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +02007# end of section "Supporting builds with drivers without the software
Manuel Pégourié-Gonnard222bc852022-12-29 13:47:25 +01008# implementation", namely: the sets of tests skipped in the default config and
9# the full config must be the same before and after the PR.
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020010#
11# WARNING: this script checks out a commit other than the head of the current
Manuel Pégourié-Gonnard68429fc2022-07-27 20:37:12 +020012# branch; it checks out the current branch again when running successfully,
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020013# but while the script is running, or if it terminates early in error, you
Manuel Pégourié-Gonnard68429fc2022-07-27 20:37:12 +020014# should be aware that you might be at a different commit than expected.
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020015#
Manuel Pégourié-Gonnard222bc852022-12-29 13:47:25 +010016# NOTE: you can comment out parts that don't need to be re-done when
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020017# re-running this script (for example "get numbers before this PR").
18
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020019set -eu
20
21cleanup() {
22 make clean
23 git checkout -- include/mbedtls/mbedtls_config.h include/psa/crypto_config.h
24}
25
26record() {
27 export MBEDTLS_TEST_OUTCOME_FILE="$PWD/outcome-$1.csv"
28 rm -f $MBEDTLS_TEST_OUTCOME_FILE
29 make check
30}
31
Przemek Stekiel93986642022-11-09 15:06:44 +010032# save current HEAD
33HEAD=$(git branch --show-current)
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020034
Przemek Stekiel93986642022-11-09 15:06:44 +010035# get the numbers before this PR for default and full
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020036cleanup
Przemek Stekiel93986642022-11-09 15:06:44 +010037git checkout $(git merge-base HEAD development)
38record "before-default"
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020039
40cleanup
Przemek Stekiel93986642022-11-09 15:06:44 +010041scripts/config.py full
42record "before-full"
43
44# get the numbers now for default and full
45cleanup
46git checkout $HEAD
47record "after-default"
48
49cleanup
50scripts/config.py full
51record "after-full"
52
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020053# analysis
54
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020055populate_suites () {
56 SUITES=''
57 make generated_files >/dev/null
58 data_files=$(cd tests/suites && echo *.data)
59 for data in $data_files; do
60 suite=${data#test_suite_}
61 suite=${suite%.data}
Manuel Pégourié-Gonnard222bc852022-12-29 13:47:25 +010062 SUITES="$SUITES $suite"
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020063 done
64 make neat
65}
66
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020067compare_suite () {
68 ref="outcome-$1.csv"
69 new="outcome-$2.csv"
70 suite="$3"
71
72 pattern_suite=";test_suite_$suite;"
73 total=$(grep -c "$pattern_suite" "$ref")
74 sed_cmd="s/^.*$pattern_suite\(.*\);SKIP.*/\1/p"
75 sed -n "$sed_cmd" "$ref" > skipped-ref
76 sed -n "$sed_cmd" "$new" > skipped-new
77 nb_ref=$(wc -l <skipped-ref)
78 nb_new=$(wc -l <skipped-new)
79
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020080 printf "%36s: total %4d; skipped %4d -> %4d\n" \
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020081 $suite $total $nb_ref $nb_new
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020082 if diff skipped-ref skipped-new | grep '^> '; then
83 ret=1
84 else
85 ret=0
86 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020087 rm skipped-ref skipped-new
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020088 return $ret
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020089}
90
91compare_builds () {
92 printf "\n*** Comparing $1 -> $2 ***\n"
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020093 failed=''
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020094 for suite in $SUITES; do
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020095 if compare_suite "$1" "$2" "$suite"; then :; else
96 failed="$failed $suite"
97 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020098 done
Manuel Pégourié-Gonnardb51051f2022-10-18 09:42:30 +020099 if [ -z "$failed" ]; then
100 printf "No coverage gap found.\n"
101 else
102 printf "Suites with less coverage:%s\n" "$failed"
103 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200104}
105
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200106populate_suites
Przemek Stekiel93986642022-11-09 15:06:44 +0100107compare_builds before-default after-default
108compare_builds before-full after-full