test-driver revision 40c5344f
19a011757Smrg#! /bin/sh 29a011757Smrg# test-driver - basic testsuite driver script. 39a011757Smrg 440c5344fSmrgscriptversion=2013-07-13.22; # UTC 59a011757Smrg 640c5344fSmrg# Copyright (C) 2011-2014 Free Software Foundation, Inc. 79a011757Smrg# 89a011757Smrg# This program is free software; you can redistribute it and/or modify 99a011757Smrg# it under the terms of the GNU General Public License as published by 109a011757Smrg# the Free Software Foundation; either version 2, or (at your option) 119a011757Smrg# any later version. 129a011757Smrg# 139a011757Smrg# This program is distributed in the hope that it will be useful, 149a011757Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 159a011757Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169a011757Smrg# GNU General Public License for more details. 179a011757Smrg# 189a011757Smrg# You should have received a copy of the GNU General Public License 199a011757Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 209a011757Smrg 219a011757Smrg# As a special exception to the GNU General Public License, if you 229a011757Smrg# distribute this file as part of a program that contains a 239a011757Smrg# configuration script generated by Autoconf, you may include it under 249a011757Smrg# the same distribution terms that you use for the rest of that program. 259a011757Smrg 269a011757Smrg# This file is maintained in Automake, please report 279a011757Smrg# bugs to <bug-automake@gnu.org> or send patches to 289a011757Smrg# <automake-patches@gnu.org>. 299a011757Smrg 309a011757Smrg# Make unconditional expansion of undefined variables an error. This 319a011757Smrg# helps a lot in preventing typo-related bugs. 329a011757Smrgset -u 339a011757Smrg 349a011757Smrgusage_error () 359a011757Smrg{ 369a011757Smrg echo "$0: $*" >&2 379a011757Smrg print_usage >&2 389a011757Smrg exit 2 399a011757Smrg} 409a011757Smrg 419a011757Smrgprint_usage () 429a011757Smrg{ 439a011757Smrg cat <<END 449a011757SmrgUsage: 459a011757Smrg test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 469a011757Smrg [--expect-failure={yes|no}] [--color-tests={yes|no}] 4740c5344fSmrg [--enable-hard-errors={yes|no}] [--] 4840c5344fSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 499a011757SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 509a011757SmrgEND 519a011757Smrg} 529a011757Smrg 539a011757Smrgtest_name= # Used for reporting. 549a011757Smrglog_file= # Where to save the output of the test script. 559a011757Smrgtrs_file= # Where to save the metadata of the test run. 569a011757Smrgexpect_failure=no 579a011757Smrgcolor_tests=no 589a011757Smrgenable_hard_errors=yes 599a011757Smrgwhile test $# -gt 0; do 609a011757Smrg case $1 in 619a011757Smrg --help) print_usage; exit $?;; 629a011757Smrg --version) echo "test-driver $scriptversion"; exit $?;; 639a011757Smrg --test-name) test_name=$2; shift;; 649a011757Smrg --log-file) log_file=$2; shift;; 659a011757Smrg --trs-file) trs_file=$2; shift;; 669a011757Smrg --color-tests) color_tests=$2; shift;; 679a011757Smrg --expect-failure) expect_failure=$2; shift;; 689a011757Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 699a011757Smrg --) shift; break;; 709a011757Smrg -*) usage_error "invalid option: '$1'";; 7140c5344fSmrg *) break;; 729a011757Smrg esac 739a011757Smrg shift 749a011757Smrgdone 759a011757Smrg 7640c5344fSmrgmissing_opts= 7740c5344fSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 7840c5344fSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 7940c5344fSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 8040c5344fSmrgif test x"$missing_opts" != x; then 8140c5344fSmrg usage_error "the following mandatory options are missing:$missing_opts" 8240c5344fSmrgfi 8340c5344fSmrg 8440c5344fSmrgif test $# -eq 0; then 8540c5344fSmrg usage_error "missing argument" 8640c5344fSmrgfi 8740c5344fSmrg 889a011757Smrgif test $color_tests = yes; then 899a011757Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 909a011757Smrg red='[0;31m' # Red. 919a011757Smrg grn='[0;32m' # Green. 929a011757Smrg lgn='[1;32m' # Light green. 939a011757Smrg blu='[1;34m' # Blue. 949a011757Smrg mgn='[0;35m' # Magenta. 959a011757Smrg std='[m' # No color. 969a011757Smrgelse 979a011757Smrg red= grn= lgn= blu= mgn= std= 989a011757Smrgfi 999a011757Smrg 1009a011757Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 1019a011757Smrgtrap "st=129; $do_exit" 1 1029a011757Smrgtrap "st=130; $do_exit" 2 1039a011757Smrgtrap "st=141; $do_exit" 13 1049a011757Smrgtrap "st=143; $do_exit" 15 1059a011757Smrg 1069a011757Smrg# Test script is run here. 1079a011757Smrg"$@" >$log_file 2>&1 1089a011757Smrgestatus=$? 10940c5344fSmrg 1109a011757Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 11140c5344fSmrg tweaked_estatus=1 11240c5344fSmrgelse 11340c5344fSmrg tweaked_estatus=$estatus 1149a011757Smrgfi 1159a011757Smrg 11640c5344fSmrgcase $tweaked_estatus:$expect_failure in 1179a011757Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 1189a011757Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 1199a011757Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 1209a011757Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 1219a011757Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 1229a011757Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 1239a011757Smrgesac 1249a011757Smrg 12540c5344fSmrg# Report the test outcome and exit status in the logs, so that one can 12640c5344fSmrg# know whether the test passed or failed simply by looking at the '.log' 12740c5344fSmrg# file, without the need of also peaking into the corresponding '.trs' 12840c5344fSmrg# file (automake bug#11814). 12940c5344fSmrgecho "$res $test_name (exit status: $estatus)" >>$log_file 13040c5344fSmrg 1319a011757Smrg# Report outcome to console. 1329a011757Smrgecho "${col}${res}${std}: $test_name" 1339a011757Smrg 1349a011757Smrg# Register the test result, and other relevant metadata. 1359a011757Smrgecho ":test-result: $res" > $trs_file 1369a011757Smrgecho ":global-test-result: $res" >> $trs_file 1379a011757Smrgecho ":recheck: $recheck" >> $trs_file 1389a011757Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 1399a011757Smrg 1409a011757Smrg# Local Variables: 1419a011757Smrg# mode: shell-script 1429a011757Smrg# sh-indentation: 2 1439a011757Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 1449a011757Smrg# time-stamp-start: "scriptversion=" 1459a011757Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1469a011757Smrg# time-stamp-time-zone: "UTC" 1479a011757Smrg# time-stamp-end: "; # UTC" 1489a011757Smrg# End: 149