test-driver revision 079e7944
1079e7944Smrg#! /bin/sh 2079e7944Smrg# test-driver - basic testsuite driver script. 3079e7944Smrg 4079e7944Smrgscriptversion=2012-06-27.10; # UTC 5079e7944Smrg 6079e7944Smrg# Copyright (C) 2011-2013 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}] 47079e7944Smrg [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT 48079e7944SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 49079e7944SmrgEND 50079e7944Smrg} 51079e7944Smrg 52079e7944Smrg# TODO: better error handling in option parsing (in particular, ensure 53079e7944Smrg# TODO: $log_file, $trs_file and $test_name are defined). 54079e7944Smrgtest_name= # Used for reporting. 55079e7944Smrglog_file= # Where to save the output of the test script. 56079e7944Smrgtrs_file= # Where to save the metadata of the test run. 57079e7944Smrgexpect_failure=no 58079e7944Smrgcolor_tests=no 59079e7944Smrgenable_hard_errors=yes 60079e7944Smrgwhile test $# -gt 0; do 61079e7944Smrg case $1 in 62079e7944Smrg --help) print_usage; exit $?;; 63079e7944Smrg --version) echo "test-driver $scriptversion"; exit $?;; 64079e7944Smrg --test-name) test_name=$2; shift;; 65079e7944Smrg --log-file) log_file=$2; shift;; 66079e7944Smrg --trs-file) trs_file=$2; shift;; 67079e7944Smrg --color-tests) color_tests=$2; shift;; 68079e7944Smrg --expect-failure) expect_failure=$2; shift;; 69079e7944Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 70079e7944Smrg --) shift; break;; 71079e7944Smrg -*) usage_error "invalid option: '$1'";; 72079e7944Smrg esac 73079e7944Smrg shift 74079e7944Smrgdone 75079e7944Smrg 76079e7944Smrgif test $color_tests = yes; then 77079e7944Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 78079e7944Smrg red='[0;31m' # Red. 79079e7944Smrg grn='[0;32m' # Green. 80079e7944Smrg lgn='[1;32m' # Light green. 81079e7944Smrg blu='[1;34m' # Blue. 82079e7944Smrg mgn='[0;35m' # Magenta. 83079e7944Smrg std='[m' # No color. 84079e7944Smrgelse 85079e7944Smrg red= grn= lgn= blu= mgn= std= 86079e7944Smrgfi 87079e7944Smrg 88079e7944Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 89079e7944Smrgtrap "st=129; $do_exit" 1 90079e7944Smrgtrap "st=130; $do_exit" 2 91079e7944Smrgtrap "st=141; $do_exit" 13 92079e7944Smrgtrap "st=143; $do_exit" 15 93079e7944Smrg 94079e7944Smrg# Test script is run here. 95079e7944Smrg"$@" >$log_file 2>&1 96079e7944Smrgestatus=$? 97079e7944Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 98079e7944Smrg estatus=1 99079e7944Smrgfi 100079e7944Smrg 101079e7944Smrgcase $estatus:$expect_failure in 102079e7944Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 103079e7944Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 104079e7944Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 105079e7944Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 106079e7944Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 107079e7944Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 108079e7944Smrgesac 109079e7944Smrg 110079e7944Smrg# Report outcome to console. 111079e7944Smrgecho "${col}${res}${std}: $test_name" 112079e7944Smrg 113079e7944Smrg# Register the test result, and other relevant metadata. 114079e7944Smrgecho ":test-result: $res" > $trs_file 115079e7944Smrgecho ":global-test-result: $res" >> $trs_file 116079e7944Smrgecho ":recheck: $recheck" >> $trs_file 117079e7944Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 118079e7944Smrg 119079e7944Smrg# Local Variables: 120079e7944Smrg# mode: shell-script 121079e7944Smrg# sh-indentation: 2 122079e7944Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 123079e7944Smrg# time-stamp-start: "scriptversion=" 124079e7944Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 125079e7944Smrg# time-stamp-time-zone: "UTC" 126079e7944Smrg# time-stamp-end: "; # UTC" 127079e7944Smrg# End: 128