Gilles Peskine | f109664 | 2023-11-02 19:23:41 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | help () { |
| 4 | cat <<EOF |
| 5 | Usage: $0 [OPTION] [PLATFORM]... |
| 6 | Run all the metatests whose platform matches any of the given PLATFORM. |
| 7 | A PLATFORM can contain shell wildcards. |
| 8 | |
Gilles Peskine | cce0012 | 2023-11-10 15:36:15 +0100 | [diff] [blame] | 9 | Expected output: a lot of scary-looking error messages, since each |
| 10 | metatest is expected to report a failure. The final line should be |
| 11 | "Ran N metatests, all good." |
| 12 | |
| 13 | If something goes wrong: the final line should be |
| 14 | "Ran N metatests, X unexpected successes". Look for "Unexpected success" |
| 15 | in the logs above. |
| 16 | |
Gilles Peskine | f109664 | 2023-11-02 19:23:41 +0100 | [diff] [blame] | 17 | -l List the available metatests, don't run them. |
| 18 | EOF |
| 19 | } |
| 20 | |
| 21 | # Copyright The Mbed TLS Contributors |
| 22 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 23 | |
| 24 | set -e -u |
| 25 | |
| 26 | if [ -d programs ]; then |
| 27 | METATEST_PROGRAM=programs/test/metatest |
| 28 | elif [ -d ../programs ]; then |
| 29 | METATEST_PROGRAM=../programs/test/metatest |
| 30 | elif [ -d ../../programs ]; then |
| 31 | METATEST_PROGRAM=../../programs/test/metatest |
| 32 | else |
| 33 | echo >&2 "$0: FATAL: programs/test/metatest not found" |
| 34 | exit 120 |
| 35 | fi |
| 36 | |
| 37 | LIST_ONLY= |
| 38 | while getopts hl OPTLET; do |
| 39 | case $OPTLET in |
| 40 | h) help; exit;; |
| 41 | l) LIST_ONLY=1;; |
| 42 | \?) help >&2; exit 120;; |
| 43 | esac |
| 44 | done |
| 45 | shift $((OPTIND - 1)) |
| 46 | |
| 47 | list_matches () { |
| 48 | while read name platform junk; do |
Gilles Peskine | e7fc8a2 | 2023-11-15 16:56:26 +0100 | [diff] [blame] | 49 | for pattern in "$@"; do |
Gilles Peskine | f109664 | 2023-11-02 19:23:41 +0100 | [diff] [blame] | 50 | case $platform in |
| 51 | $pattern) echo "$name"; break;; |
| 52 | esac |
| 53 | done |
| 54 | done |
| 55 | } |
| 56 | |
| 57 | count=0 |
| 58 | errors=0 |
| 59 | run_metatest () { |
| 60 | ret=0 |
| 61 | "$METATEST_PROGRAM" "$1" || ret=$? |
| 62 | if [ $ret -eq 0 ]; then |
| 63 | echo >&2 "$0: Unexpected success: $1" |
| 64 | errors=$((errors + 1)) |
| 65 | fi |
| 66 | count=$((count + 1)) |
| 67 | } |
| 68 | |
| 69 | # Don't pipe the output of metatest so that if it fails, this script exits |
| 70 | # immediately with a failure status. |
| 71 | full_list=$("$METATEST_PROGRAM" list) |
| 72 | matching_list=$(printf '%s\n' "$full_list" | list_matches "$@") |
| 73 | |
| 74 | if [ -n "$LIST_ONLY" ]; then |
| 75 | printf '%s\n' $matching_list |
| 76 | exit |
| 77 | fi |
| 78 | |
| 79 | for name in $matching_list; do |
| 80 | run_metatest "$name" |
| 81 | done |
| 82 | |
| 83 | if [ $errors -eq 0 ]; then |
| 84 | echo "Ran $count metatests, all good." |
| 85 | exit 0 |
| 86 | else |
| 87 | echo "Ran $count metatests, $errors unexpected successes." |
| 88 | exit 1 |
| 89 | fi |