test-driver revision 9a011757
19a011757Smrg#! /bin/sh 29a011757Smrg# test-driver - basic testsuite driver script. 39a011757Smrg 49a011757Smrgscriptversion=2012-06-27.10; # UTC 59a011757Smrg 69a011757Smrg# Copyright (C) 2011-2013 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}] 479a011757Smrg [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT 489a011757SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 499a011757SmrgEND 509a011757Smrg} 519a011757Smrg 529a011757Smrg# TODO: better error handling in option parsing (in particular, ensure 539a011757Smrg# TODO: $log_file, $trs_file and $test_name are defined). 549a011757Smrgtest_name= # Used for reporting. 559a011757Smrglog_file= # Where to save the output of the test script. 569a011757Smrgtrs_file= # Where to save the metadata of the test run. 579a011757Smrgexpect_failure=no 589a011757Smrgcolor_tests=no 599a011757Smrgenable_hard_errors=yes 609a011757Smrgwhile test $# -gt 0; do 619a011757Smrg case $1 in 629a011757Smrg --help) print_usage; exit $?;; 639a011757Smrg --version) echo "test-driver $scriptversion"; exit $?;; 649a011757Smrg --test-name) test_name=$2; shift;; 659a011757Smrg --log-file) log_file=$2; shift;; 669a011757Smrg --trs-file) trs_file=$2; shift;; 679a011757Smrg --color-tests) color_tests=$2; shift;; 689a011757Smrg --expect-failure) expect_failure=$2; shift;; 699a011757Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 709a011757Smrg --) shift; break;; 719a011757Smrg -*) usage_error "invalid option: '$1'";; 729a011757Smrg esac 739a011757Smrg shift 749a011757Smrgdone 759a011757Smrg 769a011757Smrgif test $color_tests = yes; then 779a011757Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 789a011757Smrg red='[0;31m' # Red. 799a011757Smrg grn='[0;32m' # Green. 809a011757Smrg lgn='[1;32m' # Light green. 819a011757Smrg blu='[1;34m' # Blue. 829a011757Smrg mgn='[0;35m' # Magenta. 839a011757Smrg std='[m' # No color. 849a011757Smrgelse 859a011757Smrg red= grn= lgn= blu= mgn= std= 869a011757Smrgfi 879a011757Smrg 889a011757Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 899a011757Smrgtrap "st=129; $do_exit" 1 909a011757Smrgtrap "st=130; $do_exit" 2 919a011757Smrgtrap "st=141; $do_exit" 13 929a011757Smrgtrap "st=143; $do_exit" 15 939a011757Smrg 949a011757Smrg# Test script is run here. 959a011757Smrg"$@" >$log_file 2>&1 969a011757Smrgestatus=$? 979a011757Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 989a011757Smrg estatus=1 999a011757Smrgfi 1009a011757Smrg 1019a011757Smrgcase $estatus:$expect_failure in 1029a011757Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 1039a011757Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 1049a011757Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 1059a011757Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 1069a011757Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 1079a011757Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 1089a011757Smrgesac 1099a011757Smrg 1109a011757Smrg# Report outcome to console. 1119a011757Smrgecho "${col}${res}${std}: $test_name" 1129a011757Smrg 1139a011757Smrg# Register the test result, and other relevant metadata. 1149a011757Smrgecho ":test-result: $res" > $trs_file 1159a011757Smrgecho ":global-test-result: $res" >> $trs_file 1169a011757Smrgecho ":recheck: $recheck" >> $trs_file 1179a011757Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 1189a011757Smrg 1199a011757Smrg# Local Variables: 1209a011757Smrg# mode: shell-script 1219a011757Smrg# sh-indentation: 2 1229a011757Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 1239a011757Smrg# time-stamp-start: "scriptversion=" 1249a011757Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1259a011757Smrg# time-stamp-time-zone: "UTC" 1269a011757Smrg# time-stamp-end: "; # UTC" 1279a011757Smrg# End: 128