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