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