1ed6f5d66Smrg#! /bin/sh 2ed6f5d66Smrg# test-driver - basic testsuite driver script. 3ed6f5d66Smrg 4a3680546Smrgscriptversion=2024-06-19.01; # UTC 5ed6f5d66Smrg 6a3680546Smrg# Copyright (C) 2011-2024 Free Software Foundation, Inc. 7ed6f5d66Smrg# 8ed6f5d66Smrg# This program is free software; you can redistribute it and/or modify 9ed6f5d66Smrg# it under the terms of the GNU General Public License as published by 10ed6f5d66Smrg# the Free Software Foundation; either version 2, or (at your option) 11ed6f5d66Smrg# any later version. 12ed6f5d66Smrg# 13ed6f5d66Smrg# This program is distributed in the hope that it will be useful, 14ed6f5d66Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15ed6f5d66Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16ed6f5d66Smrg# GNU General Public License for more details. 17ed6f5d66Smrg# 18ed6f5d66Smrg# You should have received a copy of the GNU General Public License 193d05230fSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20ed6f5d66Smrg 21ed6f5d66Smrg# As a special exception to the GNU General Public License, if you 22ed6f5d66Smrg# distribute this file as part of a program that contains a 23ed6f5d66Smrg# configuration script generated by Autoconf, you may include it under 24ed6f5d66Smrg# the same distribution terms that you use for the rest of that program. 25ed6f5d66Smrg 26ed6f5d66Smrg# This file is maintained in Automake, please report 27ed6f5d66Smrg# bugs to <bug-automake@gnu.org> or send patches to 28ed6f5d66Smrg# <automake-patches@gnu.org>. 29ed6f5d66Smrg 30ed6f5d66Smrg# Make unconditional expansion of undefined variables an error. This 31ed6f5d66Smrg# helps a lot in preventing typo-related bugs. 32ed6f5d66Smrgset -u 33ed6f5d66Smrg 34ed6f5d66Smrgusage_error () 35ed6f5d66Smrg{ 36ed6f5d66Smrg echo "$0: $*" >&2 37ed6f5d66Smrg print_usage >&2 38ed6f5d66Smrg exit 2 39ed6f5d66Smrg} 40ed6f5d66Smrg 41ed6f5d66Smrgprint_usage () 42ed6f5d66Smrg{ 43ed6f5d66Smrg cat <<END 44ed6f5d66SmrgUsage: 453d05230fSmrg test-driver --test-name NAME --log-file PATH --trs-file PATH 463d05230fSmrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 47a3680546Smrg [--collect-skipped-logs {yes|no}] 483d05230fSmrg [--enable-hard-errors {yes|no}] [--] 49fbc03982Smrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 503d05230fSmrg 51ed6f5d66SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 523d05230fSmrgSee the GNU Automake documentation for information. 53a3680546Smrg 54a3680546SmrgReport bugs to <bug-automake@gnu.org>. 55a3680546SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 56a3680546SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 57ed6f5d66SmrgEND 58ed6f5d66Smrg} 59ed6f5d66Smrg 60ed6f5d66Smrgtest_name= # Used for reporting. 61ed6f5d66Smrglog_file= # Where to save the output of the test script. 62ed6f5d66Smrgtrs_file= # Where to save the metadata of the test run. 63ed6f5d66Smrgexpect_failure=no 64ed6f5d66Smrgcolor_tests=no 65a3680546Smrgcollect_skipped_logs=yes 66ed6f5d66Smrgenable_hard_errors=yes 67ed6f5d66Smrgwhile test $# -gt 0; do 68ed6f5d66Smrg case $1 in 69ed6f5d66Smrg --help) print_usage; exit $?;; 70a3680546Smrg --version) echo "test-driver (GNU Automake) $scriptversion"; exit $?;; 71ed6f5d66Smrg --test-name) test_name=$2; shift;; 72ed6f5d66Smrg --log-file) log_file=$2; shift;; 73ed6f5d66Smrg --trs-file) trs_file=$2; shift;; 74ed6f5d66Smrg --color-tests) color_tests=$2; shift;; 75a3680546Smrg --collect-skipped-logs) collect_skipped_logs=$2; shift;; 76ed6f5d66Smrg --expect-failure) expect_failure=$2; shift;; 77ed6f5d66Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 78ed6f5d66Smrg --) shift; break;; 79ed6f5d66Smrg -*) usage_error "invalid option: '$1'";; 80fbc03982Smrg *) break;; 81ed6f5d66Smrg esac 82ed6f5d66Smrg shift 83ed6f5d66Smrgdone 84ed6f5d66Smrg 85fbc03982Smrgmissing_opts= 86fbc03982Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 87fbc03982Smrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 88fbc03982Smrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 89fbc03982Smrgif test x"$missing_opts" != x; then 90fbc03982Smrg usage_error "the following mandatory options are missing:$missing_opts" 91fbc03982Smrgfi 92fbc03982Smrg 93fbc03982Smrgif test $# -eq 0; then 94fbc03982Smrg usage_error "missing argument" 95fbc03982Smrgfi 96fbc03982Smrg 97ed6f5d66Smrgif test $color_tests = yes; then 98ed6f5d66Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 99ed6f5d66Smrg red='[0;31m' # Red. 100ed6f5d66Smrg grn='[0;32m' # Green. 101ed6f5d66Smrg lgn='[1;32m' # Light green. 102ed6f5d66Smrg blu='[1;34m' # Blue. 103ed6f5d66Smrg mgn='[0;35m' # Magenta. 104ed6f5d66Smrg std='[m' # No color. 105ed6f5d66Smrgelse 106ed6f5d66Smrg red= grn= lgn= blu= mgn= std= 107ed6f5d66Smrgfi 108ed6f5d66Smrg 109ed6f5d66Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 110ed6f5d66Smrgtrap "st=129; $do_exit" 1 111ed6f5d66Smrgtrap "st=130; $do_exit" 2 112ed6f5d66Smrgtrap "st=141; $do_exit" 13 113ed6f5d66Smrgtrap "st=143; $do_exit" 15 114ed6f5d66Smrg 1153d05230fSmrg# Test script is run here. We create the file first, then append to it, 1163d05230fSmrg# to ameliorate tests themselves also writing to the log file. Our tests 1173d05230fSmrg# don't, but others can (automake bug#35762). 1183d05230fSmrg: >"$log_file" 1193d05230fSmrg"$@" >>"$log_file" 2>&1 120ed6f5d66Smrgestatus=$? 121fbc03982Smrg 122ed6f5d66Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 123fbc03982Smrg tweaked_estatus=1 124fbc03982Smrgelse 125fbc03982Smrg tweaked_estatus=$estatus 126ed6f5d66Smrgfi 127ed6f5d66Smrg 128fbc03982Smrgcase $tweaked_estatus:$expect_failure in 129ed6f5d66Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 130ed6f5d66Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 131a3680546Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=$collect_skipped_logs;; 132ed6f5d66Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 133ed6f5d66Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 134ed6f5d66Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 135ed6f5d66Smrgesac 136ed6f5d66Smrg 137fbc03982Smrg# Report the test outcome and exit status in the logs, so that one can 138fbc03982Smrg# know whether the test passed or failed simply by looking at the '.log' 139fbc03982Smrg# file, without the need of also peaking into the corresponding '.trs' 140fbc03982Smrg# file (automake bug#11814). 1413d05230fSmrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 142fbc03982Smrg 143ed6f5d66Smrg# Report outcome to console. 144ed6f5d66Smrgecho "${col}${res}${std}: $test_name" 145ed6f5d66Smrg 146ed6f5d66Smrg# Register the test result, and other relevant metadata. 147ed6f5d66Smrgecho ":test-result: $res" > $trs_file 148ed6f5d66Smrgecho ":global-test-result: $res" >> $trs_file 149ed6f5d66Smrgecho ":recheck: $recheck" >> $trs_file 150ed6f5d66Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 151ed6f5d66Smrg 152ed6f5d66Smrg# Local Variables: 153ed6f5d66Smrg# mode: shell-script 154ed6f5d66Smrg# sh-indentation: 2 1553d05230fSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 156ed6f5d66Smrg# time-stamp-start: "scriptversion=" 157ed6f5d66Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 158fbc03982Smrg# time-stamp-time-zone: "UTC0" 159ed6f5d66Smrg# time-stamp-end: "; # UTC" 160ed6f5d66Smrg# End: 161