test-driver revision 862bcd1a
1eb411b4bSmrg#! /bin/sh 2eb411b4bSmrg# test-driver - basic testsuite driver script. 3eb411b4bSmrg 40f8248bfSmrgscriptversion=2013-07-13.22; # UTC 5eb411b4bSmrg 6862bcd1aSmrg# Copyright (C) 2011-2014 Free Software Foundation, Inc. 7eb411b4bSmrg# 8eb411b4bSmrg# This program is free software; you can redistribute it and/or modify 9eb411b4bSmrg# it under the terms of the GNU General Public License as published by 10eb411b4bSmrg# the Free Software Foundation; either version 2, or (at your option) 11eb411b4bSmrg# any later version. 12eb411b4bSmrg# 13eb411b4bSmrg# This program is distributed in the hope that it will be useful, 14eb411b4bSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15eb411b4bSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16eb411b4bSmrg# GNU General Public License for more details. 17eb411b4bSmrg# 18eb411b4bSmrg# You should have received a copy of the GNU General Public License 19eb411b4bSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20eb411b4bSmrg 21eb411b4bSmrg# As a special exception to the GNU General Public License, if you 22eb411b4bSmrg# distribute this file as part of a program that contains a 23eb411b4bSmrg# configuration script generated by Autoconf, you may include it under 24eb411b4bSmrg# the same distribution terms that you use for the rest of that program. 25eb411b4bSmrg 26eb411b4bSmrg# This file is maintained in Automake, please report 27eb411b4bSmrg# bugs to <bug-automake@gnu.org> or send patches to 28eb411b4bSmrg# <automake-patches@gnu.org>. 29eb411b4bSmrg 30eb411b4bSmrg# Make unconditional expansion of undefined variables an error. This 31eb411b4bSmrg# helps a lot in preventing typo-related bugs. 32eb411b4bSmrgset -u 33eb411b4bSmrg 34eb411b4bSmrgusage_error () 35eb411b4bSmrg{ 36eb411b4bSmrg echo "$0: $*" >&2 37eb411b4bSmrg print_usage >&2 38eb411b4bSmrg exit 2 39eb411b4bSmrg} 40eb411b4bSmrg 41eb411b4bSmrgprint_usage () 42eb411b4bSmrg{ 43eb411b4bSmrg cat <<END 44eb411b4bSmrgUsage: 45eb411b4bSmrg test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 46eb411b4bSmrg [--expect-failure={yes|no}] [--color-tests={yes|no}] 470f8248bfSmrg [--enable-hard-errors={yes|no}] [--] 480f8248bfSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49eb411b4bSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 50eb411b4bSmrgEND 51eb411b4bSmrg} 52eb411b4bSmrg 53eb411b4bSmrgtest_name= # Used for reporting. 54eb411b4bSmrglog_file= # Where to save the output of the test script. 55eb411b4bSmrgtrs_file= # Where to save the metadata of the test run. 56eb411b4bSmrgexpect_failure=no 57eb411b4bSmrgcolor_tests=no 58eb411b4bSmrgenable_hard_errors=yes 59eb411b4bSmrgwhile test $# -gt 0; do 60eb411b4bSmrg case $1 in 61eb411b4bSmrg --help) print_usage; exit $?;; 62eb411b4bSmrg --version) echo "test-driver $scriptversion"; exit $?;; 63eb411b4bSmrg --test-name) test_name=$2; shift;; 64eb411b4bSmrg --log-file) log_file=$2; shift;; 65eb411b4bSmrg --trs-file) trs_file=$2; shift;; 66eb411b4bSmrg --color-tests) color_tests=$2; shift;; 67eb411b4bSmrg --expect-failure) expect_failure=$2; shift;; 68eb411b4bSmrg --enable-hard-errors) enable_hard_errors=$2; shift;; 69eb411b4bSmrg --) shift; break;; 70eb411b4bSmrg -*) usage_error "invalid option: '$1'";; 710f8248bfSmrg *) break;; 72eb411b4bSmrg esac 73eb411b4bSmrg shift 74eb411b4bSmrgdone 75eb411b4bSmrg 760f8248bfSmrgmissing_opts= 770f8248bfSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 780f8248bfSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 790f8248bfSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 800f8248bfSmrgif test x"$missing_opts" != x; then 810f8248bfSmrg usage_error "the following mandatory options are missing:$missing_opts" 820f8248bfSmrgfi 830f8248bfSmrg 840f8248bfSmrgif test $# -eq 0; then 850f8248bfSmrg usage_error "missing argument" 860f8248bfSmrgfi 870f8248bfSmrg 88eb411b4bSmrgif test $color_tests = yes; then 89eb411b4bSmrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 90eb411b4bSmrg red='[0;31m' # Red. 91eb411b4bSmrg grn='[0;32m' # Green. 92eb411b4bSmrg lgn='[1;32m' # Light green. 93eb411b4bSmrg blu='[1;34m' # Blue. 94eb411b4bSmrg mgn='[0;35m' # Magenta. 95eb411b4bSmrg std='[m' # No color. 96eb411b4bSmrgelse 97eb411b4bSmrg red= grn= lgn= blu= mgn= std= 98eb411b4bSmrgfi 99eb411b4bSmrg 100eb411b4bSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 101eb411b4bSmrgtrap "st=129; $do_exit" 1 102eb411b4bSmrgtrap "st=130; $do_exit" 2 103eb411b4bSmrgtrap "st=141; $do_exit" 13 104eb411b4bSmrgtrap "st=143; $do_exit" 15 105eb411b4bSmrg 106eb411b4bSmrg# Test script is run here. 107eb411b4bSmrg"$@" >$log_file 2>&1 108eb411b4bSmrgestatus=$? 109862bcd1aSmrg 110eb411b4bSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then 111862bcd1aSmrg tweaked_estatus=1 112862bcd1aSmrgelse 113862bcd1aSmrg tweaked_estatus=$estatus 114eb411b4bSmrgfi 115eb411b4bSmrg 116862bcd1aSmrgcase $tweaked_estatus:$expect_failure in 117eb411b4bSmrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 118eb411b4bSmrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 119eb411b4bSmrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 120eb411b4bSmrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 121eb411b4bSmrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 122eb411b4bSmrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 123eb411b4bSmrgesac 124eb411b4bSmrg 125862bcd1aSmrg# Report the test outcome and exit status in the logs, so that one can 126862bcd1aSmrg# know whether the test passed or failed simply by looking at the '.log' 127862bcd1aSmrg# file, without the need of also peaking into the corresponding '.trs' 128862bcd1aSmrg# file (automake bug#11814). 129862bcd1aSmrgecho "$res $test_name (exit status: $estatus)" >>$log_file 130862bcd1aSmrg 131eb411b4bSmrg# Report outcome to console. 132eb411b4bSmrgecho "${col}${res}${std}: $test_name" 133eb411b4bSmrg 134eb411b4bSmrg# Register the test result, and other relevant metadata. 135eb411b4bSmrgecho ":test-result: $res" > $trs_file 136eb411b4bSmrgecho ":global-test-result: $res" >> $trs_file 137eb411b4bSmrgecho ":recheck: $recheck" >> $trs_file 138eb411b4bSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file 139eb411b4bSmrg 140eb411b4bSmrg# Local Variables: 141eb411b4bSmrg# mode: shell-script 142eb411b4bSmrg# sh-indentation: 2 143eb411b4bSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 144eb411b4bSmrg# time-stamp-start: "scriptversion=" 145eb411b4bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 146eb411b4bSmrg# time-stamp-time-zone: "UTC" 147eb411b4bSmrg# time-stamp-end: "; # UTC" 148eb411b4bSmrg# End: 149