1276da39aSCy Schubert#! /bin/sh 2276da39aSCy Schubert# test-driver - basic testsuite driver script. 3276da39aSCy Schubert 4*2d4e511cSCy Schubertscriptversion=2013-07-13.22; # UTC 5276da39aSCy Schubert 6*2d4e511cSCy Schubert# Copyright (C) 2011-2014 Free Software Foundation, Inc. 7276da39aSCy Schubert# 8276da39aSCy Schubert# This program is free software; you can redistribute it and/or modify 9276da39aSCy Schubert# it under the terms of the GNU General Public License as published by 10276da39aSCy Schubert# the Free Software Foundation; either version 2, or (at your option) 11276da39aSCy Schubert# any later version. 12276da39aSCy Schubert# 13276da39aSCy Schubert# This program is distributed in the hope that it will be useful, 14276da39aSCy Schubert# but WITHOUT ANY WARRANTY; without even the implied warranty of 15276da39aSCy Schubert# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16276da39aSCy Schubert# GNU General Public License for more details. 17276da39aSCy Schubert# 18276da39aSCy Schubert# You should have received a copy of the GNU General Public License 19276da39aSCy Schubert# along with this program. If not, see <http://www.gnu.org/licenses/>. 20276da39aSCy Schubert 21276da39aSCy Schubert# As a special exception to the GNU General Public License, if you 22276da39aSCy Schubert# distribute this file as part of a program that contains a 23276da39aSCy Schubert# configuration script generated by Autoconf, you may include it under 24276da39aSCy Schubert# the same distribution terms that you use for the rest of that program. 25276da39aSCy Schubert 26276da39aSCy Schubert# This file is maintained in Automake, please report 27276da39aSCy Schubert# bugs to <bug-automake@gnu.org> or send patches to 28276da39aSCy Schubert# <automake-patches@gnu.org>. 29276da39aSCy Schubert 30276da39aSCy Schubert# Make unconditional expansion of undefined variables an error. This 31276da39aSCy Schubert# helps a lot in preventing typo-related bugs. 32276da39aSCy Schubertset -u 33276da39aSCy Schubert 34276da39aSCy Schubertusage_error () 35276da39aSCy Schubert{ 36276da39aSCy Schubert echo "$0: $*" >&2 37276da39aSCy Schubert print_usage >&2 38276da39aSCy Schubert exit 2 39276da39aSCy Schubert} 40276da39aSCy Schubert 41276da39aSCy Schubertprint_usage () 42276da39aSCy Schubert{ 43276da39aSCy Schubert cat <<END 44276da39aSCy SchubertUsage: 45276da39aSCy Schubert test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 46276da39aSCy Schubert [--expect-failure={yes|no}] [--color-tests={yes|no}] 47276da39aSCy Schubert [--enable-hard-errors={yes|no}] [--] 48276da39aSCy Schubert TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49276da39aSCy SchubertThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 50276da39aSCy SchubertEND 51276da39aSCy Schubert} 52276da39aSCy Schubert 53276da39aSCy Schuberttest_name= # Used for reporting. 54276da39aSCy Schubertlog_file= # Where to save the output of the test script. 55276da39aSCy Schuberttrs_file= # Where to save the metadata of the test run. 56276da39aSCy Schubertexpect_failure=no 57276da39aSCy Schubertcolor_tests=no 58276da39aSCy Schubertenable_hard_errors=yes 59276da39aSCy Schubertwhile test $# -gt 0; do 60276da39aSCy Schubert case $1 in 61276da39aSCy Schubert --help) print_usage; exit $?;; 62276da39aSCy Schubert --version) echo "test-driver $scriptversion"; exit $?;; 63276da39aSCy Schubert --test-name) test_name=$2; shift;; 64276da39aSCy Schubert --log-file) log_file=$2; shift;; 65276da39aSCy Schubert --trs-file) trs_file=$2; shift;; 66276da39aSCy Schubert --color-tests) color_tests=$2; shift;; 67276da39aSCy Schubert --expect-failure) expect_failure=$2; shift;; 68276da39aSCy Schubert --enable-hard-errors) enable_hard_errors=$2; shift;; 69276da39aSCy Schubert --) shift; break;; 70276da39aSCy Schubert -*) usage_error "invalid option: '$1'";; 71276da39aSCy Schubert *) break;; 72276da39aSCy Schubert esac 73276da39aSCy Schubert shift 74276da39aSCy Schubertdone 75276da39aSCy Schubert 76276da39aSCy Schubertmissing_opts= 77276da39aSCy Schuberttest x"$test_name" = x && missing_opts="$missing_opts --test-name" 78276da39aSCy Schuberttest x"$log_file" = x && missing_opts="$missing_opts --log-file" 79276da39aSCy Schuberttest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 80276da39aSCy Schubertif test x"$missing_opts" != x; then 81276da39aSCy Schubert usage_error "the following mandatory options are missing:$missing_opts" 82276da39aSCy Schubertfi 83276da39aSCy Schubert 84276da39aSCy Schubertif test $# -eq 0; then 85276da39aSCy Schubert usage_error "missing argument" 86276da39aSCy Schubertfi 87276da39aSCy Schubert 88276da39aSCy Schubertif test $color_tests = yes; then 89276da39aSCy Schubert # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 90276da39aSCy Schubert red='[0;31m' # Red. 91276da39aSCy Schubert grn='[0;32m' # Green. 92276da39aSCy Schubert lgn='[1;32m' # Light green. 93276da39aSCy Schubert blu='[1;34m' # Blue. 94276da39aSCy Schubert mgn='[0;35m' # Magenta. 95276da39aSCy Schubert std='[m' # No color. 96276da39aSCy Schubertelse 97276da39aSCy Schubert red= grn= lgn= blu= mgn= std= 98276da39aSCy Schubertfi 99276da39aSCy Schubert 100276da39aSCy Schubertdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 101276da39aSCy Schuberttrap "st=129; $do_exit" 1 102276da39aSCy Schuberttrap "st=130; $do_exit" 2 103276da39aSCy Schuberttrap "st=141; $do_exit" 13 104276da39aSCy Schuberttrap "st=143; $do_exit" 15 105276da39aSCy Schubert 106276da39aSCy Schubert# Test script is run here. 107276da39aSCy Schubert"$@" >$log_file 2>&1 108276da39aSCy Schubertestatus=$? 109276da39aSCy Schubert 110276da39aSCy Schubertif test $enable_hard_errors = no && test $estatus -eq 99; then 111276da39aSCy Schubert tweaked_estatus=1 112276da39aSCy Schubertelse 113276da39aSCy Schubert tweaked_estatus=$estatus 114276da39aSCy Schubertfi 115276da39aSCy Schubert 116276da39aSCy Schubertcase $tweaked_estatus:$expect_failure in 117276da39aSCy Schubert 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 118276da39aSCy Schubert 0:*) col=$grn res=PASS recheck=no gcopy=no;; 119276da39aSCy Schubert 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 120276da39aSCy Schubert 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 121276da39aSCy Schubert *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 122276da39aSCy Schubert *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 123276da39aSCy Schubertesac 124276da39aSCy Schubert 125276da39aSCy Schubert# Report the test outcome and exit status in the logs, so that one can 126276da39aSCy Schubert# know whether the test passed or failed simply by looking at the '.log' 127276da39aSCy Schubert# file, without the need of also peaking into the corresponding '.trs' 128276da39aSCy Schubert# file (automake bug#11814). 129276da39aSCy Schubertecho "$res $test_name (exit status: $estatus)" >>$log_file 130276da39aSCy Schubert 131276da39aSCy Schubert# Report outcome to console. 132276da39aSCy Schubertecho "${col}${res}${std}: $test_name" 133276da39aSCy Schubert 134276da39aSCy Schubert# Register the test result, and other relevant metadata. 135276da39aSCy Schubertecho ":test-result: $res" > $trs_file 136276da39aSCy Schubertecho ":global-test-result: $res" >> $trs_file 137276da39aSCy Schubertecho ":recheck: $recheck" >> $trs_file 138276da39aSCy Schubertecho ":copy-in-global-log: $gcopy" >> $trs_file 139276da39aSCy Schubert 140276da39aSCy Schubert# Local Variables: 141276da39aSCy Schubert# mode: shell-script 142276da39aSCy Schubert# sh-indentation: 2 143276da39aSCy Schubert# eval: (add-hook 'write-file-hooks 'time-stamp) 144276da39aSCy Schubert# time-stamp-start: "scriptversion=" 145276da39aSCy Schubert# time-stamp-format: "%:y-%02m-%02d.%02H" 146*2d4e511cSCy Schubert# time-stamp-time-zone: "UTC" 147276da39aSCy Schubert# time-stamp-end: "; # UTC" 148276da39aSCy Schubert# End: 149