blob: 182bf0410abbce645fb0fc7edfbd7dc99d376f2c [file] [log] [blame]
Gilles Peskinef1096642023-11-02 19:23:41 +01001#!/bin/sh
2
3help () {
4 cat <<EOF
5Usage: $0 [OPTION] [PLATFORM]...
6Run all the metatests whose platform matches any of the given PLATFORM.
7A PLATFORM can contain shell wildcards.
8
9 -l List the available metatests, don't run them.
10EOF
11}
12
13# Copyright The Mbed TLS Contributors
14# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
15
16set -e -u
17
18if [ -d programs ]; then
19 METATEST_PROGRAM=programs/test/metatest
20elif [ -d ../programs ]; then
21 METATEST_PROGRAM=../programs/test/metatest
22elif [ -d ../../programs ]; then
23 METATEST_PROGRAM=../../programs/test/metatest
24else
25 echo >&2 "$0: FATAL: programs/test/metatest not found"
26 exit 120
27fi
28
29LIST_ONLY=
30while getopts hl OPTLET; do
31 case $OPTLET in
32 h) help; exit;;
33 l) LIST_ONLY=1;;
34 \?) help >&2; exit 120;;
35 esac
36done
37shift $((OPTIND - 1))
38
39list_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
49count=0
50errors=0
51run_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.
63full_list=$("$METATEST_PROGRAM" list)
64matching_list=$(printf '%s\n' "$full_list" | list_matches "$@")
65
66if [ -n "$LIST_ONLY" ]; then
67 printf '%s\n' $matching_list
68 exit
69fi
70
71for name in $matching_list; do
72 run_metatest "$name"
73done
74
75if [ $errors -eq 0 ]; then
76 echo "Ran $count metatests, all good."
77 exit 0
78else
79 echo "Ran $count metatests, $errors unexpected successes."
80 exit 1
81fi