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