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