1284990Scy#! /bin/sh 2284990Scy# test-driver - basic testsuite driver script. 3284990Scy 4358659Scyscriptversion=2013-07-13.22; # UTC 5284990Scy 6358659Scy# Copyright (C) 2011-2014 Free Software Foundation, Inc. 7284990Scy# 8284990Scy# This program is free software; you can redistribute it and/or modify 9284990Scy# it under the terms of the GNU General Public License as published by 10284990Scy# the Free Software Foundation; either version 2, or (at your option) 11284990Scy# any later version. 12284990Scy# 13284990Scy# This program is distributed in the hope that it will be useful, 14284990Scy# but WITHOUT ANY WARRANTY; without even the implied warranty of 15284990Scy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16284990Scy# GNU General Public License for more details. 17284990Scy# 18284990Scy# You should have received a copy of the GNU General Public License 19284990Scy# along with this program. If not, see <http://www.gnu.org/licenses/>. 20284990Scy 21284990Scy# As a special exception to the GNU General Public License, if you 22284990Scy# distribute this file as part of a program that contains a 23284990Scy# configuration script generated by Autoconf, you may include it under 24284990Scy# the same distribution terms that you use for the rest of that program. 25284990Scy 26284990Scy# This file is maintained in Automake, please report 27284990Scy# bugs to <bug-automake@gnu.org> or send patches to 28284990Scy# <automake-patches@gnu.org>. 29284990Scy 30284990Scy# Make unconditional expansion of undefined variables an error. This 31284990Scy# helps a lot in preventing typo-related bugs. 32284990Scyset -u 33284990Scy 34284990Scyusage_error () 35284990Scy{ 36284990Scy echo "$0: $*" >&2 37284990Scy print_usage >&2 38284990Scy exit 2 39284990Scy} 40284990Scy 41284990Scyprint_usage () 42284990Scy{ 43284990Scy cat <<END 44284990ScyUsage: 45284990Scy test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 46284990Scy [--expect-failure={yes|no}] [--color-tests={yes|no}] 47284990Scy [--enable-hard-errors={yes|no}] [--] 48284990Scy TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49284990ScyThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 50284990ScyEND 51284990Scy} 52284990Scy 53284990Scytest_name= # Used for reporting. 54284990Scylog_file= # Where to save the output of the test script. 55284990Scytrs_file= # Where to save the metadata of the test run. 56284990Scyexpect_failure=no 57284990Scycolor_tests=no 58284990Scyenable_hard_errors=yes 59284990Scywhile test $# -gt 0; do 60284990Scy case $1 in 61284990Scy --help) print_usage; exit $?;; 62284990Scy --version) echo "test-driver $scriptversion"; exit $?;; 63284990Scy --test-name) test_name=$2; shift;; 64284990Scy --log-file) log_file=$2; shift;; 65284990Scy --trs-file) trs_file=$2; shift;; 66284990Scy --color-tests) color_tests=$2; shift;; 67284990Scy --expect-failure) expect_failure=$2; shift;; 68284990Scy --enable-hard-errors) enable_hard_errors=$2; shift;; 69284990Scy --) shift; break;; 70284990Scy -*) usage_error "invalid option: '$1'";; 71284990Scy *) break;; 72284990Scy esac 73284990Scy shift 74284990Scydone 75284990Scy 76284990Scymissing_opts= 77284990Scytest x"$test_name" = x && missing_opts="$missing_opts --test-name" 78284990Scytest x"$log_file" = x && missing_opts="$missing_opts --log-file" 79284990Scytest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 80284990Scyif test x"$missing_opts" != x; then 81284990Scy usage_error "the following mandatory options are missing:$missing_opts" 82284990Scyfi 83284990Scy 84284990Scyif test $# -eq 0; then 85284990Scy usage_error "missing argument" 86284990Scyfi 87284990Scy 88284990Scyif test $color_tests = yes; then 89284990Scy # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 90284990Scy red='[0;31m' # Red. 91284990Scy grn='[0;32m' # Green. 92284990Scy lgn='[1;32m' # Light green. 93284990Scy blu='[1;34m' # Blue. 94284990Scy mgn='[0;35m' # Magenta. 95284990Scy std='[m' # No color. 96284990Scyelse 97284990Scy red= grn= lgn= blu= mgn= std= 98284990Scyfi 99284990Scy 100284990Scydo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 101284990Scytrap "st=129; $do_exit" 1 102284990Scytrap "st=130; $do_exit" 2 103284990Scytrap "st=141; $do_exit" 13 104284990Scytrap "st=143; $do_exit" 15 105284990Scy 106284990Scy# Test script is run here. 107284990Scy"$@" >$log_file 2>&1 108284990Scyestatus=$? 109284990Scy 110284990Scyif test $enable_hard_errors = no && test $estatus -eq 99; then 111284990Scy tweaked_estatus=1 112284990Scyelse 113284990Scy tweaked_estatus=$estatus 114284990Scyfi 115284990Scy 116284990Scycase $tweaked_estatus:$expect_failure in 117284990Scy 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 118284990Scy 0:*) col=$grn res=PASS recheck=no gcopy=no;; 119284990Scy 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 120284990Scy 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 121284990Scy *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 122284990Scy *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 123284990Scyesac 124284990Scy 125284990Scy# Report the test outcome and exit status in the logs, so that one can 126284990Scy# know whether the test passed or failed simply by looking at the '.log' 127284990Scy# file, without the need of also peaking into the corresponding '.trs' 128284990Scy# file (automake bug#11814). 129284990Scyecho "$res $test_name (exit status: $estatus)" >>$log_file 130284990Scy 131284990Scy# Report outcome to console. 132284990Scyecho "${col}${res}${std}: $test_name" 133284990Scy 134284990Scy# Register the test result, and other relevant metadata. 135284990Scyecho ":test-result: $res" > $trs_file 136284990Scyecho ":global-test-result: $res" >> $trs_file 137284990Scyecho ":recheck: $recheck" >> $trs_file 138284990Scyecho ":copy-in-global-log: $gcopy" >> $trs_file 139284990Scy 140284990Scy# Local Variables: 141284990Scy# mode: shell-script 142284990Scy# sh-indentation: 2 143284990Scy# eval: (add-hook 'write-file-hooks 'time-stamp) 144284990Scy# time-stamp-start: "scriptversion=" 145284990Scy# time-stamp-format: "%:y-%02m-%02d.%02H" 146358659Scy# time-stamp-time-zone: "UTC" 147284990Scy# time-stamp-end: "; # UTC" 148284990Scy# End: 149