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