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