1fc544a13Smrg#! /bin/sh 2fc544a13Smrg# test-driver - basic testsuite driver script. 3fc544a13Smrg 4515ec619Smrgscriptversion=2018-03-07.03; # UTC 5fc544a13Smrg 6515ec619Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc. 7fc544a13Smrg# 8fc544a13Smrg# This program is free software; you can redistribute it and/or modify 9fc544a13Smrg# it under the terms of the GNU General Public License as published by 10fc544a13Smrg# the Free Software Foundation; either version 2, or (at your option) 11fc544a13Smrg# any later version. 12fc544a13Smrg# 13fc544a13Smrg# This program is distributed in the hope that it will be useful, 14fc544a13Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15fc544a13Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16fc544a13Smrg# GNU General Public License for more details. 17fc544a13Smrg# 18fc544a13Smrg# You should have received a copy of the GNU General Public License 19515ec619Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20fc544a13Smrg 21fc544a13Smrg# As a special exception to the GNU General Public License, if you 22fc544a13Smrg# distribute this file as part of a program that contains a 23fc544a13Smrg# configuration script generated by Autoconf, you may include it under 24fc544a13Smrg# the same distribution terms that you use for the rest of that program. 25fc544a13Smrg 26fc544a13Smrg# This file is maintained in Automake, please report 27fc544a13Smrg# bugs to <bug-automake@gnu.org> or send patches to 28fc544a13Smrg# <automake-patches@gnu.org>. 29fc544a13Smrg 30fc544a13Smrg# Make unconditional expansion of undefined variables an error. This 31fc544a13Smrg# helps a lot in preventing typo-related bugs. 32fc544a13Smrgset -u 33fc544a13Smrg 34fc544a13Smrgusage_error () 35fc544a13Smrg{ 36fc544a13Smrg echo "$0: $*" >&2 37fc544a13Smrg print_usage >&2 38fc544a13Smrg exit 2 39fc544a13Smrg} 40fc544a13Smrg 41fc544a13Smrgprint_usage () 42fc544a13Smrg{ 43fc544a13Smrg cat <<END 44fc544a13SmrgUsage: 45515ec619Smrg test-driver --test-name NAME --log-file PATH --trs-file PATH 46515ec619Smrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 47515ec619Smrg [--enable-hard-errors {yes|no}] [--] 48fc544a13Smrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49515ec619Smrg 50fc544a13SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 51515ec619SmrgSee the GNU Automake documentation for information. 52fc544a13SmrgEND 53fc544a13Smrg} 54fc544a13Smrg 55fc544a13Smrgtest_name= # Used for reporting. 56fc544a13Smrglog_file= # Where to save the output of the test script. 57fc544a13Smrgtrs_file= # Where to save the metadata of the test run. 58fc544a13Smrgexpect_failure=no 59fc544a13Smrgcolor_tests=no 60fc544a13Smrgenable_hard_errors=yes 61fc544a13Smrgwhile test $# -gt 0; do 62fc544a13Smrg case $1 in 63fc544a13Smrg --help) print_usage; exit $?;; 64fc544a13Smrg --version) echo "test-driver $scriptversion"; exit $?;; 65fc544a13Smrg --test-name) test_name=$2; shift;; 66fc544a13Smrg --log-file) log_file=$2; shift;; 67fc544a13Smrg --trs-file) trs_file=$2; shift;; 68fc544a13Smrg --color-tests) color_tests=$2; shift;; 69fc544a13Smrg --expect-failure) expect_failure=$2; shift;; 70fc544a13Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 71fc544a13Smrg --) shift; break;; 72fc544a13Smrg -*) usage_error "invalid option: '$1'";; 73fc544a13Smrg *) break;; 74fc544a13Smrg esac 75fc544a13Smrg shift 76fc544a13Smrgdone 77fc544a13Smrg 78fc544a13Smrgmissing_opts= 79fc544a13Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 80fc544a13Smrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 81fc544a13Smrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 82fc544a13Smrgif test x"$missing_opts" != x; then 83fc544a13Smrg usage_error "the following mandatory options are missing:$missing_opts" 84fc544a13Smrgfi 85fc544a13Smrg 86fc544a13Smrgif test $# -eq 0; then 87fc544a13Smrg usage_error "missing argument" 88fc544a13Smrgfi 89fc544a13Smrg 90fc544a13Smrgif test $color_tests = yes; then 91fc544a13Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 92fc544a13Smrg red='[0;31m' # Red. 93fc544a13Smrg grn='[0;32m' # Green. 94fc544a13Smrg lgn='[1;32m' # Light green. 95fc544a13Smrg blu='[1;34m' # Blue. 96fc544a13Smrg mgn='[0;35m' # Magenta. 97fc544a13Smrg std='[m' # No color. 98fc544a13Smrgelse 99fc544a13Smrg red= grn= lgn= blu= mgn= std= 100fc544a13Smrgfi 101fc544a13Smrg 102fc544a13Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 103fc544a13Smrgtrap "st=129; $do_exit" 1 104fc544a13Smrgtrap "st=130; $do_exit" 2 105fc544a13Smrgtrap "st=141; $do_exit" 13 106fc544a13Smrgtrap "st=143; $do_exit" 15 107fc544a13Smrg 108515ec619Smrg# Test script is run here. We create the file first, then append to it, 109515ec619Smrg# to ameliorate tests themselves also writing to the log file. Our tests 110515ec619Smrg# don't, but others can (automake bug#35762). 111515ec619Smrg: >"$log_file" 112515ec619Smrg"$@" >>"$log_file" 2>&1 113fc544a13Smrgestatus=$? 114fc544a13Smrg 115fc544a13Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 116fc544a13Smrg tweaked_estatus=1 117fc544a13Smrgelse 118fc544a13Smrg tweaked_estatus=$estatus 119fc544a13Smrgfi 120fc544a13Smrg 121fc544a13Smrgcase $tweaked_estatus:$expect_failure in 122fc544a13Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 123fc544a13Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 124fc544a13Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 125fc544a13Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 126fc544a13Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 127fc544a13Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 128fc544a13Smrgesac 129fc544a13Smrg 130fc544a13Smrg# Report the test outcome and exit status in the logs, so that one can 131fc544a13Smrg# know whether the test passed or failed simply by looking at the '.log' 132fc544a13Smrg# file, without the need of also peaking into the corresponding '.trs' 133fc544a13Smrg# file (automake bug#11814). 134515ec619Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 135fc544a13Smrg 136fc544a13Smrg# Report outcome to console. 137fc544a13Smrgecho "${col}${res}${std}: $test_name" 138fc544a13Smrg 139fc544a13Smrg# Register the test result, and other relevant metadata. 140fc544a13Smrgecho ":test-result: $res" > $trs_file 141fc544a13Smrgecho ":global-test-result: $res" >> $trs_file 142fc544a13Smrgecho ":recheck: $recheck" >> $trs_file 143fc544a13Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 144fc544a13Smrg 145fc544a13Smrg# Local Variables: 146fc544a13Smrg# mode: shell-script 147fc544a13Smrg# sh-indentation: 2 148515ec619Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 149fc544a13Smrg# time-stamp-start: "scriptversion=" 150fc544a13Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 151515ec619Smrg# time-stamp-time-zone: "UTC0" 152fc544a13Smrg# time-stamp-end: "; # UTC" 153fc544a13Smrg# End: 154