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