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