test-driver revision 953daeba
1c9710b42Smrg#! /bin/sh 26fc018e4Smrg# test-driver - basic testsuite driver script. 3c9710b42Smrg 4953daebaSmrgscriptversion=2013-07-13.22; # UTC 5c9710b42Smrg 6953daebaSmrg# Copyright (C) 2011-2014 Free Software Foundation, Inc. 7c9710b42Smrg# 8c9710b42Smrg# This program is free software; you can redistribute it and/or modify 9c9710b42Smrg# it under the terms of the GNU General Public License as published by 10c9710b42Smrg# the Free Software Foundation; either version 2, or (at your option) 11c9710b42Smrg# any later version. 12c9710b42Smrg# 13c9710b42Smrg# This program is distributed in the hope that it will be useful, 14c9710b42Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c9710b42Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c9710b42Smrg# GNU General Public License for more details. 17c9710b42Smrg# 18c9710b42Smrg# You should have received a copy of the GNU General Public License 19c9710b42Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 20c9710b42Smrg 21c9710b42Smrg# As a special exception to the GNU General Public License, if you 22c9710b42Smrg# distribute this file as part of a program that contains a 23c9710b42Smrg# configuration script generated by Autoconf, you may include it under 24c9710b42Smrg# the same distribution terms that you use for the rest of that program. 25c9710b42Smrg 26c9710b42Smrg# This file is maintained in Automake, please report 27c9710b42Smrg# bugs to <bug-automake@gnu.org> or send patches to 28c9710b42Smrg# <automake-patches@gnu.org>. 29c9710b42Smrg 30c9710b42Smrg# Make unconditional expansion of undefined variables an error. This 31c9710b42Smrg# helps a lot in preventing typo-related bugs. 32c9710b42Smrgset -u 33c9710b42Smrg 34c9710b42Smrgusage_error () 35c9710b42Smrg{ 36c9710b42Smrg echo "$0: $*" >&2 37c9710b42Smrg print_usage >&2 38c9710b42Smrg exit 2 39c9710b42Smrg} 40c9710b42Smrg 41c9710b42Smrgprint_usage () 42c9710b42Smrg{ 43c9710b42Smrg cat <<END 44c9710b42SmrgUsage: 45c9710b42Smrg test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 46c9710b42Smrg [--expect-failure={yes|no}] [--color-tests={yes|no}] 47953daebaSmrg [--enable-hard-errors={yes|no}] [--] 48953daebaSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49c9710b42SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 50c9710b42SmrgEND 51c9710b42Smrg} 52c9710b42Smrg 53c9710b42Smrgtest_name= # Used for reporting. 54c9710b42Smrglog_file= # Where to save the output of the test script. 55c9710b42Smrgtrs_file= # Where to save the metadata of the test run. 56c9710b42Smrgexpect_failure=no 57c9710b42Smrgcolor_tests=no 58c9710b42Smrgenable_hard_errors=yes 59c9710b42Smrgwhile test $# -gt 0; do 60c9710b42Smrg case $1 in 61c9710b42Smrg --help) print_usage; exit $?;; 62c9710b42Smrg --version) echo "test-driver $scriptversion"; exit $?;; 63c9710b42Smrg --test-name) test_name=$2; shift;; 64c9710b42Smrg --log-file) log_file=$2; shift;; 65c9710b42Smrg --trs-file) trs_file=$2; shift;; 66c9710b42Smrg --color-tests) color_tests=$2; shift;; 67c9710b42Smrg --expect-failure) expect_failure=$2; shift;; 68c9710b42Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 69c9710b42Smrg --) shift; break;; 70c9710b42Smrg -*) usage_error "invalid option: '$1'";; 71953daebaSmrg *) break;; 72c9710b42Smrg esac 73c9710b42Smrg shift 74c9710b42Smrgdone 75c9710b42Smrg 76953daebaSmrgmissing_opts= 77953daebaSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 78953daebaSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 79953daebaSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 80953daebaSmrgif test x"$missing_opts" != x; then 81953daebaSmrg usage_error "the following mandatory options are missing:$missing_opts" 82953daebaSmrgfi 83953daebaSmrg 84953daebaSmrgif test $# -eq 0; then 85953daebaSmrg usage_error "missing argument" 86953daebaSmrgfi 87953daebaSmrg 88c9710b42Smrgif test $color_tests = yes; then 89c9710b42Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 90c9710b42Smrg red='[0;31m' # Red. 91c9710b42Smrg grn='[0;32m' # Green. 92c9710b42Smrg lgn='[1;32m' # Light green. 93c9710b42Smrg blu='[1;34m' # Blue. 94c9710b42Smrg mgn='[0;35m' # Magenta. 95c9710b42Smrg std='[m' # No color. 96c9710b42Smrgelse 97c9710b42Smrg red= grn= lgn= blu= mgn= std= 98c9710b42Smrgfi 99c9710b42Smrg 100c9710b42Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 101c9710b42Smrgtrap "st=129; $do_exit" 1 102c9710b42Smrgtrap "st=130; $do_exit" 2 103c9710b42Smrgtrap "st=141; $do_exit" 13 104c9710b42Smrgtrap "st=143; $do_exit" 15 105c9710b42Smrg 106c9710b42Smrg# Test script is run here. 107c9710b42Smrg"$@" >$log_file 2>&1 108c9710b42Smrgestatus=$? 109953daebaSmrg 110c9710b42Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 111953daebaSmrg tweaked_estatus=1 112953daebaSmrgelse 113953daebaSmrg tweaked_estatus=$estatus 114c9710b42Smrgfi 115c9710b42Smrg 116953daebaSmrgcase $tweaked_estatus:$expect_failure in 117c9710b42Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 118c9710b42Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 119c9710b42Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 120c9710b42Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 121c9710b42Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 122c9710b42Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 123c9710b42Smrgesac 124c9710b42Smrg 125953daebaSmrg# Report the test outcome and exit status in the logs, so that one can 126953daebaSmrg# know whether the test passed or failed simply by looking at the '.log' 127953daebaSmrg# file, without the need of also peaking into the corresponding '.trs' 128953daebaSmrg# file (automake bug#11814). 129953daebaSmrgecho "$res $test_name (exit status: $estatus)" >>$log_file 130953daebaSmrg 131c9710b42Smrg# Report outcome to console. 132c9710b42Smrgecho "${col}${res}${std}: $test_name" 133c9710b42Smrg 134c9710b42Smrg# Register the test result, and other relevant metadata. 135c9710b42Smrgecho ":test-result: $res" > $trs_file 136c9710b42Smrgecho ":global-test-result: $res" >> $trs_file 137c9710b42Smrgecho ":recheck: $recheck" >> $trs_file 138c9710b42Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 139c9710b42Smrg 140c9710b42Smrg# Local Variables: 141c9710b42Smrg# mode: shell-script 142c9710b42Smrg# sh-indentation: 2 143c9710b42Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 144c9710b42Smrg# time-stamp-start: "scriptversion=" 145c9710b42Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 146c9710b42Smrg# time-stamp-time-zone: "UTC" 147c9710b42Smrg# time-stamp-end: "; # UTC" 148c9710b42Smrg# End: 149