1#!/bin/sh
2
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# SPDX-License-Identifier: MPL-2.0
6#
7# This Source Code Form is subject to the terms of the Mozilla Public
8# License, v. 2.0.  If a copy of the MPL was not distributed with this
9# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10#
11# See the COPYRIGHT file distributed with this work for additional
12# information regarding copyright ownership.
13
14# shellcheck disable=SC2181
15# shellcheck disable=SC2034
16
17usage() {
18    echo "$0 --test-name=NAME --log-file=PATH.log --trs-file=PATH.trs --color-tests={yes|no} --expect-failure={yes|no} --enable-hard-errors={yes|no}"
19}
20
21#
22# This requires GNU getopt
23#
24getopt --test >/dev/null
25if [ "$?" -ne 4 ]; then
26    echo "fatal: GNU getopt is required"
27    exit 1
28fi
29
30OPTS=$(getopt --shell sh --name "$(basename "$0")" --options '' --longoptions test-name:,log-file:,trs-file:,color-tests:,expect-failure:,enable-hard-errors: -- "$@")
31
32if [ "$?" != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
33
34eval set -- "$OPTS"
35
36TEST_NAME=
37LOG_FILE=
38TRS_FILE=
39COLOR_TESTS=yes
40EXPECT_FAILURE=no
41HARD_ERRORS=yes
42
43while true; do
44    case "$1" in
45	--test-name ) TEST_NAME="$2"; shift; shift ;;
46	--log-file ) LOG_FILE="$2"; shift; shift ;;
47	--trs-file ) TRS_FILE="$2"; shift; shift ;;
48	--color-tests ) COLOR_TESTS="$2"; shift; shift ;;
49	--expect-failure ) EXPECT_FAILURE="$2"; shift; shift ;;
50	--hard-errors ) HARD_ERRORS="$2"; shift; shift ;;
51	-- ) shift; break ;;
52	*) break ;;
53    esac
54done
55
56if [ -z "$1" ]; then
57    echo "fatal: test name required"
58    usage
59    exit 1
60fi
61
62TEST_PROGRAM="$1"
63shift
64
65if [ -z "$TEST_NAME" ]; then
66    TEST_NAME="$(basename "$TEST_PROGRAM")"
67fi
68if [ -z "$LOG_FILE" ]; then
69    LOG_FILE="$TEST_PROGRAM.log"
70fi
71if [ -z "$TRS_FILE" ]; then
72    TRS_FILE="$TEST_PROGRAM.trs"
73fi
74
75echo "Running $TEST_PROGRAM"
76
77./run.sh -p "$(($RANDOM%32000+32000))" "$@" "$TEST_PROGRAM"
78
79exit $?
80