blob: 81ab69183c348dac1951f89bb659edfaae5d38dd [file] [log] [blame]
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +02001#!/bin/sh
2
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +02003# This script runs tests in various revisions and configurations and analyses
4# the results in order to highlight any difference in the set of tests skipped
5# in the test suites of interest.
6#
7# It can be used to ensure the testing criteria mentioned in strategy.md,
8# end of section "Supporting builds with drivers without the software
9# implementation" are met, namely:
10#
11# - the sets of tests skipped in the default config and the full config must be
12# the same before and after the PR that implements step 3;
13# - the set of tests skipped in the driver-only build is the same as in an
14# equivalent software-based configuration, or the difference is small enough,
15# justified, and a github issue is created to track it.
16#
17# WARNING: this script checks out a commit other than the head of the current
Manuel Pégourié-Gonnard68429fc2022-07-27 20:37:12 +020018# branch; it checks out the current branch again when running successfully,
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020019# but while the script is running, or if it terminates early in error, you
Manuel Pégourié-Gonnard68429fc2022-07-27 20:37:12 +020020# should be aware that you might be at a different commit than expected.
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020021#
22# NOTE: This is only an example/template script, you should make a copy and
23# edit it to suit your needs. The part that needs editing is at the top.
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020024#
25# Also, you can comment out parts that don't need to be re-done when
26# re-running this script (for example "get numbers before this PR").
27
28# ----- BEGIN edit this -----
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020029# The component in all.sh that builds and tests with drivers.
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020030DRIVER_COMPONENT=test_psa_crypto_config_accel_hash_use_psa
Manuel Pégourié-Gonnardfca4dc62022-07-26 10:10:07 +020031# A similar configuration to that of the component, except without drivers,
32# for comparison.
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020033reference_config () {
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020034 # start with full
35 scripts/config.py full
36 # use PSA config and disable driver-less algs as in the component
37 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
38 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
39 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
40 # disable options as in the component
41 # (no need to disable whole modules, we'll just skip their test suite)
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020042 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020043 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020044}
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +020045# Space-separated list of test suites to ignore:
46# if SSS is in that list, test_suite_SSS and test_suite_SSS.* are ignored.
47IGNORE="md mdx shax" # accelerated
48IGNORE="$IGNORE entropy hmac_drbg random" # disabled (ext. RNG)
49IGNORE="$IGNORE psa_crypto_init" # needs internal RNG
Manuel Pégourié-Gonnard0dc40772022-10-19 12:12:21 +020050IGNORE="$IGNORE hkdf" # disabled in the all.sh component tested
Manuel Pégourié-Gonnardf6e6df92022-10-17 12:24:37 +020051# Compare only "reference vs driver" or also "before vs after"?
52BEFORE_AFTER=1 # 0 or 1
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020053# ----- END edit this -----
54
55set -eu
56
57cleanup() {
58 make clean
59 git checkout -- include/mbedtls/mbedtls_config.h include/psa/crypto_config.h
60}
61
62record() {
63 export MBEDTLS_TEST_OUTCOME_FILE="$PWD/outcome-$1.csv"
64 rm -f $MBEDTLS_TEST_OUTCOME_FILE
65 make check
66}
67
Manuel Pégourié-Gonnardf6e6df92022-10-17 12:24:37 +020068if [ "$BEFORE_AFTER" -eq 1 ]; then
69 # save current HEAD
70 HEAD=$(git branch --show-current)
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020071
Manuel Pégourié-Gonnardf6e6df92022-10-17 12:24:37 +020072 # get the numbers before this PR for default and full
73 cleanup
74 git checkout $(git merge-base HEAD development)
75 record "before-default"
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020076
Manuel Pégourié-Gonnardf6e6df92022-10-17 12:24:37 +020077 cleanup
78 scripts/config.py full
79 record "before-full"
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020080
Manuel Pégourié-Gonnardf6e6df92022-10-17 12:24:37 +020081 # get the numbers now for default and full
82 cleanup
83 git checkout $HEAD
84 record "after-default"
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020085
Manuel Pégourié-Gonnardf6e6df92022-10-17 12:24:37 +020086 cleanup
87 scripts/config.py full
88 record "after-full"
89fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020090
91# get the numbers now for driver-only and reference
92cleanup
93reference_config
94record "reference"
95
96cleanup
97export MBEDTLS_TEST_OUTCOME_FILE="$PWD/outcome-drivers.csv"
Manuel Pégourié-Gonnardd92fb012022-10-18 10:14:31 +020098export SKIP_SSL_OPT_COMPAT_SH=1
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +020099tests/scripts/all.sh -k test_psa_crypto_config_accel_hash_use_psa
100
101# analysis
102
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200103populate_suites () {
104 SUITES=''
105 make generated_files >/dev/null
106 data_files=$(cd tests/suites && echo *.data)
107 for data in $data_files; do
108 suite=${data#test_suite_}
109 suite=${suite%.data}
110 suite_base=${suite%%.*}
111 case " $IGNORE " in
112 *" $suite_base "*) :;;
113 *) SUITES="$SUITES $suite";;
114 esac
115 done
116 make neat
117}
118
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200119compare_suite () {
120 ref="outcome-$1.csv"
121 new="outcome-$2.csv"
122 suite="$3"
123
124 pattern_suite=";test_suite_$suite;"
125 total=$(grep -c "$pattern_suite" "$ref")
126 sed_cmd="s/^.*$pattern_suite\(.*\);SKIP.*/\1/p"
127 sed -n "$sed_cmd" "$ref" > skipped-ref
128 sed -n "$sed_cmd" "$new" > skipped-new
129 nb_ref=$(wc -l <skipped-ref)
130 nb_new=$(wc -l <skipped-new)
131
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200132 printf "%36s: total %4d; skipped %4d -> %4d\n" \
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200133 $suite $total $nb_ref $nb_new
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200134 if diff skipped-ref skipped-new | grep '^> '; then
135 ret=1
136 else
137 ret=0
138 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200139 rm skipped-ref skipped-new
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200140 return $ret
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200141}
142
143compare_builds () {
144 printf "\n*** Comparing $1 -> $2 ***\n"
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200145 failed=''
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200146 for suite in $SUITES; do
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200147 if compare_suite "$1" "$2" "$suite"; then :; else
148 failed="$failed $suite"
149 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200150 done
Manuel Pégourié-Gonnardb51051f2022-10-18 09:42:30 +0200151 if [ -z "$failed" ]; then
152 printf "No coverage gap found.\n"
153 else
154 printf "Suites with less coverage:%s\n" "$failed"
155 fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200156}
157
Manuel Pégourié-Gonnard2bb2f152022-10-12 10:57:31 +0200158populate_suites
Manuel Pégourié-Gonnardf6e6df92022-10-17 12:24:37 +0200159if [ "$BEFORE_AFTER" -eq 1 ]; then
160 compare_builds before-default after-default
161 compare_builds before-full after-full
162fi
Manuel Pégourié-Gonnardfb2ed582022-07-21 11:04:52 +0200163compare_builds reference drivers