1*01826a49SYabin Cui#! /bin/sh 2*01826a49SYabin Cui# test-driver - basic testsuite driver script. 3*01826a49SYabin Cui 4*01826a49SYabin Cuiscriptversion=2016-01-11.22; # UTC 5*01826a49SYabin Cui 6*01826a49SYabin Cui# Copyright (C) 2011-2015 Free Software Foundation, Inc. 7*01826a49SYabin Cui# 8*01826a49SYabin Cui# This program is free software; you can redistribute it and/or modify 9*01826a49SYabin Cui# it under the terms of the GNU General Public License as published by 10*01826a49SYabin Cui# the Free Software Foundation; either version 2, or (at your option) 11*01826a49SYabin Cui# any later version. 12*01826a49SYabin Cui# 13*01826a49SYabin Cui# This program is distributed in the hope that it will be useful, 14*01826a49SYabin Cui# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*01826a49SYabin Cui# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*01826a49SYabin Cui# GNU General Public License for more details. 17*01826a49SYabin Cui# 18*01826a49SYabin Cui# You should have received a copy of the GNU General Public License 19*01826a49SYabin Cui# along with this program. If not, see <https://www.gnu.org/licenses/>. 20*01826a49SYabin Cui 21*01826a49SYabin Cui# As a special exception to the GNU General Public License, if you 22*01826a49SYabin Cui# distribute this file as part of a program that contains a 23*01826a49SYabin Cui# configuration script generated by Autoconf, you may include it under 24*01826a49SYabin Cui# the same distribution terms that you use for the rest of that program. 25*01826a49SYabin Cui 26*01826a49SYabin Cui# This file is maintained in Automake, please report 27*01826a49SYabin Cui# bugs to <[email protected]> or send patches to 28*01826a49SYabin Cui# <[email protected]>. 29*01826a49SYabin Cui 30*01826a49SYabin Cui# Make unconditional expansion of undefined variables an error. This 31*01826a49SYabin Cui# helps a lot in preventing typo-related bugs. 32*01826a49SYabin Cuiset -u 33*01826a49SYabin Cui 34*01826a49SYabin Cuiusage_error () 35*01826a49SYabin Cui{ 36*01826a49SYabin Cui echo "$0: $*" >&2 37*01826a49SYabin Cui print_usage >&2 38*01826a49SYabin Cui exit 2 39*01826a49SYabin Cui} 40*01826a49SYabin Cui 41*01826a49SYabin Cuiprint_usage () 42*01826a49SYabin Cui{ 43*01826a49SYabin Cui cat <<END 44*01826a49SYabin CuiUsage: 45*01826a49SYabin Cui test-driver --test-name=NAME --log-file=PATH --trs-file=PATH 46*01826a49SYabin Cui [--expect-failure={yes|no}] [--color-tests={yes|no}] 47*01826a49SYabin Cui [--enable-hard-errors={yes|no}] [--] 48*01826a49SYabin Cui TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49*01826a49SYabin CuiThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 50*01826a49SYabin CuiEND 51*01826a49SYabin Cui} 52*01826a49SYabin Cui 53*01826a49SYabin Cuitest_name= # Used for reporting. 54*01826a49SYabin Cuilog_file= # Where to save the output of the test script. 55*01826a49SYabin Cuitrs_file= # Where to save the metadata of the test run. 56*01826a49SYabin Cuiexpect_failure=no 57*01826a49SYabin Cuicolor_tests=no 58*01826a49SYabin Cuienable_hard_errors=yes 59*01826a49SYabin Cuiwhile test $# -gt 0; do 60*01826a49SYabin Cui case $1 in 61*01826a49SYabin Cui --help) print_usage; exit $?;; 62*01826a49SYabin Cui --version) echo "test-driver $scriptversion"; exit $?;; 63*01826a49SYabin Cui --test-name) test_name=$2; shift;; 64*01826a49SYabin Cui --log-file) log_file=$2; shift;; 65*01826a49SYabin Cui --trs-file) trs_file=$2; shift;; 66*01826a49SYabin Cui --color-tests) color_tests=$2; shift;; 67*01826a49SYabin Cui --expect-failure) expect_failure=$2; shift;; 68*01826a49SYabin Cui --enable-hard-errors) enable_hard_errors=$2; shift;; 69*01826a49SYabin Cui --) shift; break;; 70*01826a49SYabin Cui -*) usage_error "invalid option: '$1'";; 71*01826a49SYabin Cui *) break;; 72*01826a49SYabin Cui esac 73*01826a49SYabin Cui shift 74*01826a49SYabin Cuidone 75*01826a49SYabin Cui 76*01826a49SYabin Cuimissing_opts= 77*01826a49SYabin Cuitest x"$test_name" = x && missing_opts="$missing_opts --test-name" 78*01826a49SYabin Cuitest x"$log_file" = x && missing_opts="$missing_opts --log-file" 79*01826a49SYabin Cuitest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 80*01826a49SYabin Cuiif test x"$missing_opts" != x; then 81*01826a49SYabin Cui usage_error "the following mandatory options are missing:$missing_opts" 82*01826a49SYabin Cuifi 83*01826a49SYabin Cui 84*01826a49SYabin Cuiif test $# -eq 0; then 85*01826a49SYabin Cui usage_error "missing argument" 86*01826a49SYabin Cuifi 87*01826a49SYabin Cui 88*01826a49SYabin Cuiif test $color_tests = yes; then 89*01826a49SYabin Cui # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 90*01826a49SYabin Cui red='[0;31m' # Red. 91*01826a49SYabin Cui grn='[0;32m' # Green. 92*01826a49SYabin Cui lgn='[1;32m' # Light green. 93*01826a49SYabin Cui blu='[1;34m' # Blue. 94*01826a49SYabin Cui mgn='[0;35m' # Magenta. 95*01826a49SYabin Cui std='[m' # No color. 96*01826a49SYabin Cuielse 97*01826a49SYabin Cui red= grn= lgn= blu= mgn= std= 98*01826a49SYabin Cuifi 99*01826a49SYabin Cui 100*01826a49SYabin Cuido_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 101*01826a49SYabin Cuitrap "st=129; $do_exit" 1 102*01826a49SYabin Cuitrap "st=130; $do_exit" 2 103*01826a49SYabin Cuitrap "st=141; $do_exit" 13 104*01826a49SYabin Cuitrap "st=143; $do_exit" 15 105*01826a49SYabin Cui 106*01826a49SYabin Cui# Test script is run here. 107*01826a49SYabin Cui"$@" >$log_file 2>&1 108*01826a49SYabin Cuiestatus=$? 109*01826a49SYabin Cui 110*01826a49SYabin Cuiif test $enable_hard_errors = no && test $estatus -eq 99; then 111*01826a49SYabin Cui tweaked_estatus=1 112*01826a49SYabin Cuielse 113*01826a49SYabin Cui tweaked_estatus=$estatus 114*01826a49SYabin Cuifi 115*01826a49SYabin Cui 116*01826a49SYabin Cuicase $tweaked_estatus:$expect_failure in 117*01826a49SYabin Cui 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 118*01826a49SYabin Cui 0:*) col=$grn res=PASS recheck=no gcopy=no;; 119*01826a49SYabin Cui 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 120*01826a49SYabin Cui 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 121*01826a49SYabin Cui *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 122*01826a49SYabin Cui *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 123*01826a49SYabin Cuiesac 124*01826a49SYabin Cui 125*01826a49SYabin Cui# Report the test outcome and exit status in the logs, so that one can 126*01826a49SYabin Cui# know whether the test passed or failed simply by looking at the '.log' 127*01826a49SYabin Cui# file, without the need of also peaking into the corresponding '.trs' 128*01826a49SYabin Cui# file (automake bug#11814). 129*01826a49SYabin Cuiecho "$res $test_name (exit status: $estatus)" >>$log_file 130*01826a49SYabin Cui 131*01826a49SYabin Cui# Report outcome to console. 132*01826a49SYabin Cuiecho "${col}${res}${std}: $test_name" 133*01826a49SYabin Cui 134*01826a49SYabin Cui# Register the test result, and other relevant metadata. 135*01826a49SYabin Cuiecho ":test-result: $res" > $trs_file 136*01826a49SYabin Cuiecho ":global-test-result: $res" >> $trs_file 137*01826a49SYabin Cuiecho ":recheck: $recheck" >> $trs_file 138*01826a49SYabin Cuiecho ":copy-in-global-log: $gcopy" >> $trs_file 139*01826a49SYabin Cui 140*01826a49SYabin Cui# Local Variables: 141*01826a49SYabin Cui# mode: shell-script 142*01826a49SYabin Cui# sh-indentation: 2 143*01826a49SYabin Cui# eval: (add-hook 'write-file-hooks 'time-stamp) 144*01826a49SYabin Cui# time-stamp-start: "scriptversion=" 145*01826a49SYabin Cui# time-stamp-format: "%:y-%02m-%02d.%02H" 146*01826a49SYabin Cui# time-stamp-time-zone: "UTC0" 147*01826a49SYabin Cui# time-stamp-end: "; # UTC" 148*01826a49SYabin Cui# End: 149*01826a49SYabin Cui 150*01826a49SYabin Cuiexit $tweaked_estatus 151