test-driver revision b2f5b1db
1079e7944Smrg#! /bin/sh 2079e7944Smrg# test-driver - basic testsuite driver script. 3079e7944Smrg 4b2f5b1dbSmrgscriptversion=2013-07-13.22; # UTC 5079e7944Smrg 6b2f5b1dbSmrg# Copyright (C) 2011-2014 Free Software Foundation, Inc. 7079e7944Smrg# 8079e7944Smrg# This program is free software; you can redistribute it and/or modify 9079e7944Smrg# it under the terms of the GNU General Public License as published by 10079e7944Smrg# the Free Software Foundation; either version 2, or (at your option) 11079e7944Smrg# any later version. 12079e7944Smrg# 13079e7944Smrg# This program is distributed in the hope that it will be useful, 14079e7944Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15079e7944Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16079e7944Smrg# GNU General Public License for more details. 17079e7944Smrg# 18079e7944Smrg# You should have received a copy of the GNU General Public License 19079e7944Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20079e7944Smrg 21079e7944Smrg# As a special exception to the GNU General Public License, if you 22079e7944Smrg# distribute this file as part of a program that contains a 23079e7944Smrg# configuration script generated by Autoconf, you may include it under 24079e7944Smrg# the same distribution terms that you use for the rest of that program. 25079e7944Smrg 26079e7944Smrg# This file is maintained in Automake, please report 27079e7944Smrg# bugs to <bug-automake@gnu.org> or send patches to 28079e7944Smrg# <automake-patches@gnu.org>. 29079e7944Smrg 30079e7944Smrg# Make unconditional expansion of undefined variables an error. This 31079e7944Smrg# helps a lot in preventing typo-related bugs. 32079e7944Smrgset -u 33079e7944Smrg 34079e7944Smrgusage_error () 35079e7944Smrg{ 36079e7944Smrg echo "$0: $*" >&2 37079e7944Smrg print_usage >&2 38079e7944Smrg exit 2 39079e7944Smrg} 40079e7944Smrg 41079e7944Smrgprint_usage () 42079e7944Smrg{ 43079e7944Smrg cat <<END 44079e7944SmrgUsage: 45079e7944Smrg test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 46079e7944Smrg [--expect-failure={yes|no}] [--color-tests={yes|no}] 47b2f5b1dbSmrg [--enable-hard-errors={yes|no}] [--] 48b2f5b1dbSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49079e7944SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 50079e7944SmrgEND 51079e7944Smrg} 52079e7944Smrg 53079e7944Smrgtest_name= # Used for reporting. 54079e7944Smrglog_file= # Where to save the output of the test script. 55079e7944Smrgtrs_file= # Where to save the metadata of the test run. 56079e7944Smrgexpect_failure=no 57079e7944Smrgcolor_tests=no 58079e7944Smrgenable_hard_errors=yes 59079e7944Smrgwhile test $# -gt 0; do 60079e7944Smrg case $1 in 61079e7944Smrg --help) print_usage; exit $?;; 62079e7944Smrg --version) echo "test-driver $scriptversion"; exit $?;; 63079e7944Smrg --test-name) test_name=$2; shift;; 64079e7944Smrg --log-file) log_file=$2; shift;; 65079e7944Smrg --trs-file) trs_file=$2; shift;; 66079e7944Smrg --color-tests) color_tests=$2; shift;; 67079e7944Smrg --expect-failure) expect_failure=$2; shift;; 68079e7944Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 69079e7944Smrg --) shift; break;; 70079e7944Smrg -*) usage_error "invalid option: '$1'";; 71b2f5b1dbSmrg *) break;; 72079e7944Smrg esac 73079e7944Smrg shift 74079e7944Smrgdone 75079e7944Smrg 76b2f5b1dbSmrgmissing_opts= 77b2f5b1dbSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 78b2f5b1dbSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 79b2f5b1dbSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 80b2f5b1dbSmrgif test x"$missing_opts" != x; then 81b2f5b1dbSmrg usage_error "the following mandatory options are missing:$missing_opts" 82b2f5b1dbSmrgfi 83b2f5b1dbSmrg 84b2f5b1dbSmrgif test $# -eq 0; then 85b2f5b1dbSmrg usage_error "missing argument" 86b2f5b1dbSmrgfi 87b2f5b1dbSmrg 88079e7944Smrgif test $color_tests = yes; then 89079e7944Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 90079e7944Smrg red='[0;31m' # Red. 91079e7944Smrg grn='[0;32m' # Green. 92079e7944Smrg lgn='[1;32m' # Light green. 93079e7944Smrg blu='[1;34m' # Blue. 94079e7944Smrg mgn='[0;35m' # Magenta. 95079e7944Smrg std='[m' # No color. 96079e7944Smrgelse 97079e7944Smrg red= grn= lgn= blu= mgn= std= 98079e7944Smrgfi 99079e7944Smrg 100079e7944Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 101079e7944Smrgtrap "st=129; $do_exit" 1 102079e7944Smrgtrap "st=130; $do_exit" 2 103079e7944Smrgtrap "st=141; $do_exit" 13 104079e7944Smrgtrap "st=143; $do_exit" 15 105079e7944Smrg 106079e7944Smrg# Test script is run here. 107079e7944Smrg"$@" >$log_file 2>&1 108079e7944Smrgestatus=$? 109b2f5b1dbSmrg 110079e7944Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 111b2f5b1dbSmrg tweaked_estatus=1 112b2f5b1dbSmrgelse 113b2f5b1dbSmrg tweaked_estatus=$estatus 114079e7944Smrgfi 115079e7944Smrg 116b2f5b1dbSmrgcase $tweaked_estatus:$expect_failure in 117079e7944Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 118079e7944Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 119079e7944Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 120079e7944Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 121079e7944Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 122079e7944Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 123079e7944Smrgesac 124079e7944Smrg 125b2f5b1dbSmrg# Report the test outcome and exit status in the logs, so that one can 126b2f5b1dbSmrg# know whether the test passed or failed simply by looking at the '.log' 127b2f5b1dbSmrg# file, without the need of also peaking into the corresponding '.trs' 128b2f5b1dbSmrg# file (automake bug#11814). 129b2f5b1dbSmrgecho "$res $test_name (exit status: $estatus)" >>$log_file 130b2f5b1dbSmrg 131079e7944Smrg# Report outcome to console. 132079e7944Smrgecho "${col}${res}${std}: $test_name" 133079e7944Smrg 134079e7944Smrg# Register the test result, and other relevant metadata. 135079e7944Smrgecho ":test-result: $res" > $trs_file 136079e7944Smrgecho ":global-test-result: $res" >> $trs_file 137079e7944Smrgecho ":recheck: $recheck" >> $trs_file 138079e7944Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 139079e7944Smrg 140079e7944Smrg# Local Variables: 141079e7944Smrg# mode: shell-script 142079e7944Smrg# sh-indentation: 2 143079e7944Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 144079e7944Smrg# time-stamp-start: "scriptversion=" 145079e7944Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 146079e7944Smrg# time-stamp-time-zone: "UTC" 147079e7944Smrg# time-stamp-end: "; # UTC" 148079e7944Smrg# End: 149