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 | |
| 9 | -l List the available metatests, don't run them. |
| 10 | EOF |
| 11 | } |
| 12 | |
| 13 | # Copyright The Mbed TLS Contributors |
| 14 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 15 | |
| 16 | set -e -u |
| 17 | |
| 18 | if [ -d programs ]; then |
| 19 | METATEST_PROGRAM=programs/test/metatest |
| 20 | elif [ -d ../programs ]; then |
| 21 | METATEST_PROGRAM=../programs/test/metatest |
| 22 | elif [ -d ../../programs ]; then |
| 23 | METATEST_PROGRAM=../../programs/test/metatest |
| 24 | else |
| 25 | echo >&2 "$0: FATAL: programs/test/metatest not found" |
| 26 | exit 120 |
| 27 | fi |
| 28 | |
| 29 | LIST_ONLY= |
| 30 | while getopts hl OPTLET; do |
| 31 | case $OPTLET in |
| 32 | h) help; exit;; |
| 33 | l) LIST_ONLY=1;; |
| 34 | \?) help >&2; exit 120;; |
| 35 | esac |
| 36 | done |
| 37 | shift $((OPTIND - 1)) |
| 38 | |
| 39 | list_matches () { |
| 40 | while read name platform junk; do |
| 41 | for pattern; do |
| 42 | case $platform in |
| 43 | $pattern) echo "$name"; break;; |
| 44 | esac |
| 45 | done |
| 46 | done |
| 47 | } |
| 48 | |
| 49 | count=0 |
| 50 | errors=0 |
| 51 | run_metatest () { |
| 52 | ret=0 |
| 53 | "$METATEST_PROGRAM" "$1" || ret=$? |
| 54 | if [ $ret -eq 0 ]; then |
| 55 | echo >&2 "$0: Unexpected success: $1" |
| 56 | errors=$((errors + 1)) |
| 57 | fi |
| 58 | count=$((count + 1)) |
| 59 | } |
| 60 | |
| 61 | # Don't pipe the output of metatest so that if it fails, this script exits |
| 62 | # immediately with a failure status. |
| 63 | full_list=$("$METATEST_PROGRAM" list) |
| 64 | matching_list=$(printf '%s\n' "$full_list" | list_matches "$@") |
| 65 | |
| 66 | if [ -n "$LIST_ONLY" ]; then |
| 67 | printf '%s\n' $matching_list |
| 68 | exit |
| 69 | fi |
| 70 | |
| 71 | for name in $matching_list; do |
| 72 | run_metatest "$name" |
| 73 | done |
| 74 | |
| 75 | if [ $errors -eq 0 ]; then |
| 76 | echo "Ran $count metatests, all good." |
| 77 | exit 0 |
| 78 | else |
| 79 | echo "Ran $count metatests, $errors unexpected successes." |
| 80 | exit 1 |
| 81 | fi |