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