test-driver revision 313a12fd
1313a12fdSmrg#! /bin/sh 2313a12fdSmrg# test-driver - basic testsuite driver script. 3313a12fdSmrg 4313a12fdSmrgscriptversion=2012-06-27.10; # UTC 5313a12fdSmrg 6313a12fdSmrg# Copyright (C) 2011-2013 Free Software Foundation, Inc. 7313a12fdSmrg# 8313a12fdSmrg# This program is free software; you can redistribute it and/or modify 9313a12fdSmrg# it under the terms of the GNU General Public License as published by 10313a12fdSmrg# the Free Software Foundation; either version 2, or (at your option) 11313a12fdSmrg# any later version. 12313a12fdSmrg# 13313a12fdSmrg# This program is distributed in the hope that it will be useful, 14313a12fdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15313a12fdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16313a12fdSmrg# GNU General Public License for more details. 17313a12fdSmrg# 18313a12fdSmrg# You should have received a copy of the GNU General Public License 19313a12fdSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20313a12fdSmrg 21313a12fdSmrg# As a special exception to the GNU General Public License, if you 22313a12fdSmrg# distribute this file as part of a program that contains a 23313a12fdSmrg# configuration script generated by Autoconf, you may include it under 24313a12fdSmrg# the same distribution terms that you use for the rest of that program. 25313a12fdSmrg 26313a12fdSmrg# This file is maintained in Automake, please report 27313a12fdSmrg# bugs to <bug-automake@gnu.org> or send patches to 28313a12fdSmrg# <automake-patches@gnu.org>. 29313a12fdSmrg 30313a12fdSmrg# Make unconditional expansion of undefined variables an error. This 31313a12fdSmrg# helps a lot in preventing typo-related bugs. 32313a12fdSmrgset -u 33313a12fdSmrg 34313a12fdSmrgusage_error () 35313a12fdSmrg{ 36313a12fdSmrg echo "$0: $*" >&2 37313a12fdSmrg print_usage >&2 38313a12fdSmrg exit 2 39313a12fdSmrg} 40313a12fdSmrg 41313a12fdSmrgprint_usage () 42313a12fdSmrg{ 43313a12fdSmrg cat <<END 44313a12fdSmrgUsage: 45313a12fdSmrg test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 46313a12fdSmrg [--expect-failure={yes|no}] [--color-tests={yes|no}] 47313a12fdSmrg [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT 48313a12fdSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 49313a12fdSmrgEND 50313a12fdSmrg} 51313a12fdSmrg 52313a12fdSmrg# TODO: better error handling in option parsing (in particular, ensure 53313a12fdSmrg# TODO: $log_file, $trs_file and $test_name are defined). 54313a12fdSmrgtest_name= # Used for reporting. 55313a12fdSmrglog_file= # Where to save the output of the test script. 56313a12fdSmrgtrs_file= # Where to save the metadata of the test run. 57313a12fdSmrgexpect_failure=no 58313a12fdSmrgcolor_tests=no 59313a12fdSmrgenable_hard_errors=yes 60313a12fdSmrgwhile test $# -gt 0; do 61313a12fdSmrg case $1 in 62313a12fdSmrg --help) print_usage; exit $?;; 63313a12fdSmrg --version) echo "test-driver $scriptversion"; exit $?;; 64313a12fdSmrg --test-name) test_name=$2; shift;; 65313a12fdSmrg --log-file) log_file=$2; shift;; 66313a12fdSmrg --trs-file) trs_file=$2; shift;; 67313a12fdSmrg --color-tests) color_tests=$2; shift;; 68313a12fdSmrg --expect-failure) expect_failure=$2; shift;; 69313a12fdSmrg --enable-hard-errors) enable_hard_errors=$2; shift;; 70313a12fdSmrg --) shift; break;; 71313a12fdSmrg -*) usage_error "invalid option: '$1'";; 72313a12fdSmrg esac 73313a12fdSmrg shift 74313a12fdSmrgdone 75313a12fdSmrg 76313a12fdSmrgif test $color_tests = yes; then 77313a12fdSmrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 78313a12fdSmrg red='[0;31m' # Red. 79313a12fdSmrg grn='[0;32m' # Green. 80313a12fdSmrg lgn='[1;32m' # Light green. 81313a12fdSmrg blu='[1;34m' # Blue. 82313a12fdSmrg mgn='[0;35m' # Magenta. 83313a12fdSmrg std='[m' # No color. 84313a12fdSmrgelse 85313a12fdSmrg red= grn= lgn= blu= mgn= std= 86313a12fdSmrgfi 87313a12fdSmrg 88313a12fdSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 89313a12fdSmrgtrap "st=129; $do_exit" 1 90313a12fdSmrgtrap "st=130; $do_exit" 2 91313a12fdSmrgtrap "st=141; $do_exit" 13 92313a12fdSmrgtrap "st=143; $do_exit" 15 93313a12fdSmrg 94313a12fdSmrg# Test script is run here. 95313a12fdSmrg"$@" >$log_file 2>&1 96313a12fdSmrgestatus=$? 97313a12fdSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then 98313a12fdSmrg estatus=1 99313a12fdSmrgfi 100313a12fdSmrg 101313a12fdSmrgcase $estatus:$expect_failure in 102313a12fdSmrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 103313a12fdSmrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 104313a12fdSmrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 105313a12fdSmrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 106313a12fdSmrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 107313a12fdSmrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 108313a12fdSmrgesac 109313a12fdSmrg 110313a12fdSmrg# Report outcome to console. 111313a12fdSmrgecho "${col}${res}${std}: $test_name" 112313a12fdSmrg 113313a12fdSmrg# Register the test result, and other relevant metadata. 114313a12fdSmrgecho ":test-result: $res" > $trs_file 115313a12fdSmrgecho ":global-test-result: $res" >> $trs_file 116313a12fdSmrgecho ":recheck: $recheck" >> $trs_file 117313a12fdSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file 118313a12fdSmrg 119313a12fdSmrg# Local Variables: 120313a12fdSmrg# mode: shell-script 121313a12fdSmrg# sh-indentation: 2 122313a12fdSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 123313a12fdSmrg# time-stamp-start: "scriptversion=" 124313a12fdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 125313a12fdSmrg# time-stamp-time-zone: "UTC" 126313a12fdSmrg# time-stamp-end: "; # UTC" 127313a12fdSmrg# End: 128