#! /bin/sh1#2# SPDX-License-Identifier: BSD-2-Clause3#4# Copyright (c) 2018-2025 Gavin D. Howard and contributors.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions are met:8#9# * Redistributions of source code must retain the above copyright notice, this10# list of conditions and the following disclaimer.11#12# * Redistributions in binary form must reproduce the above copyright notice,13# this list of conditions and the following disclaimer in the documentation14# and/or other materials provided with the distribution.15#16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE26# POSSIBILITY OF SUCH DAMAGE.27#2829script="$0"3031testdir=$(dirname "${script}")3233. "$testdir/../scripts/functions.sh"3435# Just print the usage and exit with an error. This can receive a message to36# print.37# @param 1 A message to print.38usage() {39if [ $# -eq 1 ]; then40printf '%s\n\n' "$1"41fi42printf 'usage: %s [-n] dir [run_extra_tests] [run_stack_tests] [generate_tests] [exec args...]\n' "$script"43exit 144}4546pids=""4748# We need to figure out if we should run stuff in parallel.49pll=15051while getopts "n" opt; do5253case "$opt" in54n) pll=0 ; set -e ;;55?) usage "Invalid option: $opt" ;;56esac5758done59shift $(($OPTIND - 1))6061# Command-line processing.62if [ "$#" -eq 0 ]; then63usage "Need at least 1 argument"64else65d="$1"66shift67check_d_arg "$d"68fi6970if [ "$#" -gt 0 ]; then71run_extra_tests="$1"72shift73check_bool_arg "$run_extra_tests"74else75run_extra_tests=176check_bool_arg "$run_extra_tests"77fi7879if [ "$#" -gt 0 ]; then80run_stack_tests="$1"81shift82check_bool_arg "$run_stack_tests"83else84run_stack_tests=185check_bool_arg "$run_stack_tests"86fi8788if [ "$#" -gt 0 ]; then89generate="$1"90shift91check_bool_arg "$generate"92else93generate=194check_bool_arg "$generate"95fi9697if [ "$#" -gt 0 ]; then98exe="$1"99shift100check_exec_arg "$exe"101else102exe="$testdir/../bin/$d"103check_exec_arg "$exe"104fi105106scriptdir="$testdir/$d/scripts"107108scripts=$(cat "$scriptdir/all.txt")109110# Run each script test individually.111for s in $scripts; do112113f=$(basename "$s")114115if [ "$pll" -ne 0 ]; then116sh "$testdir/script.sh" "$d" "$f" "$run_extra_tests" "$run_stack_tests" \117"$generate" "$exe" "$@" &118pids="$pids $!"119else120sh "$testdir/script.sh" "$d" "$f" "$run_extra_tests" "$run_stack_tests" \121"$generate" "$exe" "$@"122fi123124done125126if [ "$pll" -ne 0 ]; then127128exit_err=0129130for p in $pids; do131132wait "$p"133err="$?"134135if [ "$err" -ne 0 ]; then136printf 'A script failed!\n'137exit_err=1138fi139140done141142if [ "$exit_err" -ne 0 ]; then143exit 1144fi145146fi147148149