test-driver revision 1b5d61b8
11b5d61b8Smrg#!/bin/sh 235c4bbdfSmrg# test-driver - basic testsuite driver script. 335c4bbdfSmrg 41b5d61b8Smrgscriptversion=2016-01-11.22; # UTC 535c4bbdfSmrg 61b5d61b8Smrg# Copyright (C) 2011-2017 Free Software Foundation, Inc. 735c4bbdfSmrg# 835c4bbdfSmrg# This program is free software; you can redistribute it and/or modify 935c4bbdfSmrg# it under the terms of the GNU General Public License as published by 1035c4bbdfSmrg# the Free Software Foundation; either version 2, or (at your option) 1135c4bbdfSmrg# any later version. 1235c4bbdfSmrg# 1335c4bbdfSmrg# This program is distributed in the hope that it will be useful, 1435c4bbdfSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1535c4bbdfSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1635c4bbdfSmrg# GNU General Public License for more details. 1735c4bbdfSmrg# 1835c4bbdfSmrg# You should have received a copy of the GNU General Public License 1935c4bbdfSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 2035c4bbdfSmrg 2135c4bbdfSmrg# As a special exception to the GNU General Public License, if you 2235c4bbdfSmrg# distribute this file as part of a program that contains a 2335c4bbdfSmrg# configuration script generated by Autoconf, you may include it under 2435c4bbdfSmrg# the same distribution terms that you use for the rest of that program. 2535c4bbdfSmrg 2635c4bbdfSmrg# This file is maintained in Automake, please report 2735c4bbdfSmrg# bugs to <bug-automake@gnu.org> or send patches to 2835c4bbdfSmrg# <automake-patches@gnu.org>. 2935c4bbdfSmrg 3035c4bbdfSmrg# Make unconditional expansion of undefined variables an error. This 3135c4bbdfSmrg# helps a lot in preventing typo-related bugs. 3235c4bbdfSmrgset -u 3335c4bbdfSmrg 3435c4bbdfSmrgusage_error () 3535c4bbdfSmrg{ 3635c4bbdfSmrg echo "$0: $*" >&2 3735c4bbdfSmrg print_usage >&2 3835c4bbdfSmrg exit 2 3935c4bbdfSmrg} 4035c4bbdfSmrg 4135c4bbdfSmrgprint_usage () 4235c4bbdfSmrg{ 4335c4bbdfSmrg cat <<END 4435c4bbdfSmrgUsage: 4535c4bbdfSmrg test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 4635c4bbdfSmrg [--expect-failure={yes|no}] [--color-tests={yes|no}] 4735c4bbdfSmrg [--enable-hard-errors={yes|no}] [--] 4835c4bbdfSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 4935c4bbdfSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 5035c4bbdfSmrgEND 5135c4bbdfSmrg} 5235c4bbdfSmrg 5335c4bbdfSmrgtest_name= # Used for reporting. 5435c4bbdfSmrglog_file= # Where to save the output of the test script. 5535c4bbdfSmrgtrs_file= # Where to save the metadata of the test run. 5635c4bbdfSmrgexpect_failure=no 5735c4bbdfSmrgcolor_tests=no 5835c4bbdfSmrgenable_hard_errors=yes 5935c4bbdfSmrgwhile test $# -gt 0; do 6035c4bbdfSmrg case $1 in 6135c4bbdfSmrg --help) print_usage; exit $?;; 6235c4bbdfSmrg --version) echo "test-driver $scriptversion"; exit $?;; 6335c4bbdfSmrg --test-name) test_name=$2; shift;; 6435c4bbdfSmrg --log-file) log_file=$2; shift;; 6535c4bbdfSmrg --trs-file) trs_file=$2; shift;; 6635c4bbdfSmrg --color-tests) color_tests=$2; shift;; 6735c4bbdfSmrg --expect-failure) expect_failure=$2; shift;; 6835c4bbdfSmrg --enable-hard-errors) enable_hard_errors=$2; shift;; 6935c4bbdfSmrg --) shift; break;; 7035c4bbdfSmrg -*) usage_error "invalid option: '$1'";; 7135c4bbdfSmrg *) break;; 7235c4bbdfSmrg esac 7335c4bbdfSmrg shift 7435c4bbdfSmrgdone 7535c4bbdfSmrg 7635c4bbdfSmrgmissing_opts= 7735c4bbdfSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 7835c4bbdfSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 7935c4bbdfSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 8035c4bbdfSmrgif test x"$missing_opts" != x; then 8135c4bbdfSmrg usage_error "the following mandatory options are missing:$missing_opts" 8235c4bbdfSmrgfi 8335c4bbdfSmrg 8435c4bbdfSmrgif test $# -eq 0; then 8535c4bbdfSmrg usage_error "missing argument" 8635c4bbdfSmrgfi 8735c4bbdfSmrg 8835c4bbdfSmrgif test $color_tests = yes; then 8935c4bbdfSmrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 9035c4bbdfSmrg red='[0;31m' # Red. 9135c4bbdfSmrg grn='[0;32m' # Green. 9235c4bbdfSmrg lgn='[1;32m' # Light green. 9335c4bbdfSmrg blu='[1;34m' # Blue. 9435c4bbdfSmrg mgn='[0;35m' # Magenta. 9535c4bbdfSmrg std='[m' # No color. 9635c4bbdfSmrgelse 9735c4bbdfSmrg red= grn= lgn= blu= mgn= std= 9835c4bbdfSmrgfi 9935c4bbdfSmrg 10035c4bbdfSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 10135c4bbdfSmrgtrap "st=129; $do_exit" 1 10235c4bbdfSmrgtrap "st=130; $do_exit" 2 10335c4bbdfSmrgtrap "st=141; $do_exit" 13 10435c4bbdfSmrgtrap "st=143; $do_exit" 15 10535c4bbdfSmrg 10635c4bbdfSmrg# Test script is run here. 10735c4bbdfSmrg"$@" >$log_file 2>&1 10835c4bbdfSmrgestatus=$? 10935c4bbdfSmrg 11035c4bbdfSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then 11135c4bbdfSmrg tweaked_estatus=1 11235c4bbdfSmrgelse 11335c4bbdfSmrg tweaked_estatus=$estatus 11435c4bbdfSmrgfi 11535c4bbdfSmrg 11635c4bbdfSmrgcase $tweaked_estatus:$expect_failure in 11735c4bbdfSmrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 11835c4bbdfSmrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 11935c4bbdfSmrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 12035c4bbdfSmrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 12135c4bbdfSmrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 12235c4bbdfSmrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 12335c4bbdfSmrgesac 12435c4bbdfSmrg 12535c4bbdfSmrg# Report the test outcome and exit status in the logs, so that one can 12635c4bbdfSmrg# know whether the test passed or failed simply by looking at the '.log' 12735c4bbdfSmrg# file, without the need of also peaking into the corresponding '.trs' 12835c4bbdfSmrg# file (automake bug#11814). 12935c4bbdfSmrgecho "$res $test_name (exit status: $estatus)" >>$log_file 13035c4bbdfSmrg 13135c4bbdfSmrg# Report outcome to console. 13235c4bbdfSmrgecho "${col}${res}${std}: $test_name" 13335c4bbdfSmrg 13435c4bbdfSmrg# Register the test result, and other relevant metadata. 13535c4bbdfSmrgecho ":test-result: $res" > $trs_file 13635c4bbdfSmrgecho ":global-test-result: $res" >> $trs_file 13735c4bbdfSmrgecho ":recheck: $recheck" >> $trs_file 13835c4bbdfSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file 13935c4bbdfSmrg 14035c4bbdfSmrg# Local Variables: 14135c4bbdfSmrg# mode: shell-script 14235c4bbdfSmrg# sh-indentation: 2 14335c4bbdfSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 14435c4bbdfSmrg# time-stamp-start: "scriptversion=" 14535c4bbdfSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1461b5d61b8Smrg# time-stamp-time-zone: "UTC0" 14735c4bbdfSmrg# time-stamp-end: "; # UTC" 14835c4bbdfSmrg# End: 149