1eb411b4bSmrg#! /bin/sh 2eb411b4bSmrg# test-driver - basic testsuite driver script. 3eb411b4bSmrg 43b4ba46cSmrgscriptversion=2024-06-19.01; # UTC 5eb411b4bSmrg 63b4ba46cSmrg# Copyright (C) 2011-2024 Free Software Foundation, Inc. 7eb411b4bSmrg# 8eb411b4bSmrg# This program is free software; you can redistribute it and/or modify 9eb411b4bSmrg# it under the terms of the GNU General Public License as published by 10eb411b4bSmrg# the Free Software Foundation; either version 2, or (at your option) 11eb411b4bSmrg# any later version. 12eb411b4bSmrg# 13eb411b4bSmrg# This program is distributed in the hope that it will be useful, 14eb411b4bSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15eb411b4bSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16eb411b4bSmrg# GNU General Public License for more details. 17eb411b4bSmrg# 18eb411b4bSmrg# You should have received a copy of the GNU General Public License 197d2c738bSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20eb411b4bSmrg 21eb411b4bSmrg# As a special exception to the GNU General Public License, if you 22eb411b4bSmrg# distribute this file as part of a program that contains a 23eb411b4bSmrg# configuration script generated by Autoconf, you may include it under 24eb411b4bSmrg# the same distribution terms that you use for the rest of that program. 25eb411b4bSmrg 26eb411b4bSmrg# This file is maintained in Automake, please report 27eb411b4bSmrg# bugs to <bug-automake@gnu.org> or send patches to 28eb411b4bSmrg# <automake-patches@gnu.org>. 29eb411b4bSmrg 30eb411b4bSmrg# Make unconditional expansion of undefined variables an error. This 31eb411b4bSmrg# helps a lot in preventing typo-related bugs. 32eb411b4bSmrgset -u 33eb411b4bSmrg 34eb411b4bSmrgusage_error () 35eb411b4bSmrg{ 36eb411b4bSmrg echo "$0: $*" >&2 37eb411b4bSmrg print_usage >&2 38eb411b4bSmrg exit 2 39eb411b4bSmrg} 40eb411b4bSmrg 41eb411b4bSmrgprint_usage () 42eb411b4bSmrg{ 43eb411b4bSmrg cat <<END 44eb411b4bSmrgUsage: 457d2c738bSmrg test-driver --test-name NAME --log-file PATH --trs-file PATH 467d2c738bSmrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 473b4ba46cSmrg [--collect-skipped-logs {yes|no}] 487d2c738bSmrg [--enable-hard-errors {yes|no}] [--] 490f8248bfSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 507d2c738bSmrg 51eb411b4bSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 527d2c738bSmrgSee the GNU Automake documentation for information. 533b4ba46cSmrg 543b4ba46cSmrgReport bugs to <bug-automake@gnu.org>. 553b4ba46cSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 563b4ba46cSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 57eb411b4bSmrgEND 58eb411b4bSmrg} 59eb411b4bSmrg 60eb411b4bSmrgtest_name= # Used for reporting. 61eb411b4bSmrglog_file= # Where to save the output of the test script. 62eb411b4bSmrgtrs_file= # Where to save the metadata of the test run. 63eb411b4bSmrgexpect_failure=no 64eb411b4bSmrgcolor_tests=no 653b4ba46cSmrgcollect_skipped_logs=yes 66eb411b4bSmrgenable_hard_errors=yes 67eb411b4bSmrgwhile test $# -gt 0; do 68eb411b4bSmrg case $1 in 69eb411b4bSmrg --help) print_usage; exit $?;; 703b4ba46cSmrg --version) echo "test-driver (GNU Automake) $scriptversion"; exit $?;; 71eb411b4bSmrg --test-name) test_name=$2; shift;; 72eb411b4bSmrg --log-file) log_file=$2; shift;; 73eb411b4bSmrg --trs-file) trs_file=$2; shift;; 74eb411b4bSmrg --color-tests) color_tests=$2; shift;; 753b4ba46cSmrg --collect-skipped-logs) collect_skipped_logs=$2; shift;; 76eb411b4bSmrg --expect-failure) expect_failure=$2; shift;; 77eb411b4bSmrg --enable-hard-errors) enable_hard_errors=$2; shift;; 78eb411b4bSmrg --) shift; break;; 79eb411b4bSmrg -*) usage_error "invalid option: '$1'";; 800f8248bfSmrg *) break;; 81eb411b4bSmrg esac 82eb411b4bSmrg shift 83eb411b4bSmrgdone 84eb411b4bSmrg 850f8248bfSmrgmissing_opts= 860f8248bfSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 870f8248bfSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 880f8248bfSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 890f8248bfSmrgif test x"$missing_opts" != x; then 900f8248bfSmrg usage_error "the following mandatory options are missing:$missing_opts" 910f8248bfSmrgfi 920f8248bfSmrg 930f8248bfSmrgif test $# -eq 0; then 940f8248bfSmrg usage_error "missing argument" 950f8248bfSmrgfi 960f8248bfSmrg 97eb411b4bSmrgif test $color_tests = yes; then 98eb411b4bSmrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 99eb411b4bSmrg red='[0;31m' # Red. 100eb411b4bSmrg grn='[0;32m' # Green. 101eb411b4bSmrg lgn='[1;32m' # Light green. 102eb411b4bSmrg blu='[1;34m' # Blue. 103eb411b4bSmrg mgn='[0;35m' # Magenta. 104eb411b4bSmrg std='[m' # No color. 105eb411b4bSmrgelse 106eb411b4bSmrg red= grn= lgn= blu= mgn= std= 107eb411b4bSmrgfi 108eb411b4bSmrg 109eb411b4bSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 110eb411b4bSmrgtrap "st=129; $do_exit" 1 111eb411b4bSmrgtrap "st=130; $do_exit" 2 112eb411b4bSmrgtrap "st=141; $do_exit" 13 113eb411b4bSmrgtrap "st=143; $do_exit" 15 114eb411b4bSmrg 1157d2c738bSmrg# Test script is run here. We create the file first, then append to it, 1167d2c738bSmrg# to ameliorate tests themselves also writing to the log file. Our tests 1177d2c738bSmrg# don't, but others can (automake bug#35762). 1187d2c738bSmrg: >"$log_file" 1197d2c738bSmrg"$@" >>"$log_file" 2>&1 120eb411b4bSmrgestatus=$? 121862bcd1aSmrg 122eb411b4bSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then 123862bcd1aSmrg tweaked_estatus=1 124862bcd1aSmrgelse 125862bcd1aSmrg tweaked_estatus=$estatus 126eb411b4bSmrgfi 127eb411b4bSmrg 128862bcd1aSmrgcase $tweaked_estatus:$expect_failure in 129eb411b4bSmrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 130eb411b4bSmrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 1313b4ba46cSmrg 77:*) col=$blu res=SKIP recheck=no gcopy=$collect_skipped_logs;; 132eb411b4bSmrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 133eb411b4bSmrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 134eb411b4bSmrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 135eb411b4bSmrgesac 136eb411b4bSmrg 137862bcd1aSmrg# Report the test outcome and exit status in the logs, so that one can 138862bcd1aSmrg# know whether the test passed or failed simply by looking at the '.log' 139862bcd1aSmrg# file, without the need of also peaking into the corresponding '.trs' 140862bcd1aSmrg# file (automake bug#11814). 1417d2c738bSmrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 142862bcd1aSmrg 143eb411b4bSmrg# Report outcome to console. 144eb411b4bSmrgecho "${col}${res}${std}: $test_name" 145eb411b4bSmrg 146eb411b4bSmrg# Register the test result, and other relevant metadata. 147eb411b4bSmrgecho ":test-result: $res" > $trs_file 148eb411b4bSmrgecho ":global-test-result: $res" >> $trs_file 149eb411b4bSmrgecho ":recheck: $recheck" >> $trs_file 150eb411b4bSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file 151eb411b4bSmrg 152eb411b4bSmrg# Local Variables: 153eb411b4bSmrg# mode: shell-script 154eb411b4bSmrg# sh-indentation: 2 1557d2c738bSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 156eb411b4bSmrg# time-stamp-start: "scriptversion=" 157eb411b4bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1587d2c738bSmrg# time-stamp-time-zone: "UTC0" 159eb411b4bSmrg# time-stamp-end: "; # UTC" 160eb411b4bSmrg# End: 161