outcome-analysis.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/sh
  2. # This script runs tests before and after a PR and analyzes the results in
  3. # order to highlight any difference in the set of tests skipped.
  4. #
  5. # It can be used to check the first testing criterion mentioned in strategy.md,
  6. # end of section "Supporting builds with drivers without the software
  7. # implementation", namely: the sets of tests skipped in the default config and
  8. # the full config must be the same before and after the PR.
  9. #
  10. # USAGE:
  11. # - First, commit any uncommited changes. (Also, see warning below.)
  12. # - 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
  14. #
  15. # WARNING: this script checks out a commit other than the head of the current
  16. # branch; it checks out the current branch again when running successfully,
  17. # but while the script is running, or if it terminates early in error, you
  18. # should be aware that you might be at a different commit than expected.
  19. #
  20. # NOTE: you can comment out parts that don't need to be re-done when
  21. # re-running this script (for example "get numbers before this PR").
  22. set -eu
  23. : ${SKIP_SSL_OPT:=0}
  24. cleanup() {
  25. make clean
  26. git checkout -- include/mbedtls/mbedtls_config.h include/psa/crypto_config.h
  27. }
  28. record() {
  29. export MBEDTLS_TEST_OUTCOME_FILE="$PWD/outcome-$1.csv"
  30. rm -f $MBEDTLS_TEST_OUTCOME_FILE
  31. make check
  32. if [ $SKIP_SSL_OPT -eq 0 ]; then
  33. make -C programs ssl/ssl_server2 ssl/ssl_client2 \
  34. test/udp_proxy test/query_compile_time_config
  35. tests/ssl-opt.sh
  36. fi
  37. }
  38. # save current HEAD
  39. HEAD=$(git branch --show-current)
  40. # get the numbers before this PR for default and full
  41. cleanup
  42. git checkout $(git merge-base HEAD development)
  43. record "before-default"
  44. cleanup
  45. scripts/config.py full
  46. record "before-full"
  47. # get the numbers now for default and full
  48. cleanup
  49. git checkout $HEAD
  50. record "after-default"
  51. cleanup
  52. scripts/config.py full
  53. record "after-full"
  54. cleanup
  55. # analysis
  56. populate_suites () {
  57. SUITES=''
  58. make generated_files >/dev/null
  59. data_files=$(cd tests/suites && echo *.data)
  60. for data in $data_files; do
  61. suite=${data%.data}
  62. SUITES="$SUITES $suite"
  63. done
  64. make neat
  65. if [ $SKIP_SSL_OPT -eq 0 ]; then
  66. SUITES="$SUITES ssl-opt"
  67. extra_files=$(cd tests/opt-testcases && echo *.sh)
  68. for extra in $extra_files; do
  69. suite=${extra%.sh}
  70. SUITES="$SUITES $suite"
  71. done
  72. fi
  73. }
  74. compare_suite () {
  75. ref="outcome-$1.csv"
  76. new="outcome-$2.csv"
  77. suite="$3"
  78. pattern_suite=";$suite;"
  79. total=$(grep -c "$pattern_suite" "$ref")
  80. sed_cmd="s/^.*$pattern_suite\(.*\);SKIP.*/\1/p"
  81. sed -n "$sed_cmd" "$ref" > skipped-ref
  82. sed -n "$sed_cmd" "$new" > skipped-new
  83. nb_ref=$(wc -l <skipped-ref)
  84. nb_new=$(wc -l <skipped-new)
  85. name=${suite#test_suite_}
  86. printf "%40s: total %4d; skipped %4d -> %4d\n" \
  87. $name $total $nb_ref $nb_new
  88. if diff skipped-ref skipped-new | grep '^> '; then
  89. ret=1
  90. else
  91. ret=0
  92. fi
  93. rm skipped-ref skipped-new
  94. return $ret
  95. }
  96. compare_builds () {
  97. printf "\n*** Comparing $1 -> $2 ***\n"
  98. failed=''
  99. for suite in $SUITES; do
  100. if compare_suite "$1" "$2" "$suite"; then :; else
  101. failed="$failed $suite"
  102. fi
  103. done
  104. if [ -z "$failed" ]; then
  105. printf "No coverage gap found.\n"
  106. else
  107. printf "Suites with less coverage:%s\n" "$failed"
  108. fi
  109. }
  110. populate_suites
  111. compare_builds before-default after-default
  112. compare_builds before-full after-full