test-driver revision 95b7a5c8
1313a12fdSmrg#! /bin/sh 2313a12fdSmrg# test-driver - basic testsuite driver script. 3313a12fdSmrg 495b7a5c8Smrgscriptversion=2018-03-07.03; # UTC 5313a12fdSmrg 695b7a5c8Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc. 7313a12fdSmrg# 8313a12fdSmrg# This program is free software; you can redistribute it and/or modify 9313a12fdSmrg# it under the terms of the GNU General Public License as published by 10313a12fdSmrg# the Free Software Foundation; either version 2, or (at your option) 11313a12fdSmrg# any later version. 12313a12fdSmrg# 13313a12fdSmrg# This program is distributed in the hope that it will be useful, 14313a12fdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15313a12fdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16313a12fdSmrg# GNU General Public License for more details. 17313a12fdSmrg# 18313a12fdSmrg# You should have received a copy of the GNU General Public License 1995b7a5c8Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20313a12fdSmrg 21313a12fdSmrg# As a special exception to the GNU General Public License, if you 22313a12fdSmrg# distribute this file as part of a program that contains a 23313a12fdSmrg# configuration script generated by Autoconf, you may include it under 24313a12fdSmrg# the same distribution terms that you use for the rest of that program. 25313a12fdSmrg 26313a12fdSmrg# This file is maintained in Automake, please report 27313a12fdSmrg# bugs to <bug-automake@gnu.org> or send patches to 28313a12fdSmrg# <automake-patches@gnu.org>. 29313a12fdSmrg 30313a12fdSmrg# Make unconditional expansion of undefined variables an error. This 31313a12fdSmrg# helps a lot in preventing typo-related bugs. 32313a12fdSmrgset -u 33313a12fdSmrg 34313a12fdSmrgusage_error () 35313a12fdSmrg{ 36313a12fdSmrg echo "$0: $*" >&2 37313a12fdSmrg print_usage >&2 38313a12fdSmrg exit 2 39313a12fdSmrg} 40313a12fdSmrg 41313a12fdSmrgprint_usage () 42313a12fdSmrg{ 43313a12fdSmrg cat <<END 44313a12fdSmrgUsage: 4595b7a5c8Smrg test-driver --test-name NAME --log-file PATH --trs-file PATH 4695b7a5c8Smrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 4795b7a5c8Smrg [--enable-hard-errors {yes|no}] [--] 487cea3689Smrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 4995b7a5c8Smrg 50313a12fdSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 5195b7a5c8SmrgSee the GNU Automake documentation for information. 52313a12fdSmrgEND 53313a12fdSmrg} 54313a12fdSmrg 55313a12fdSmrgtest_name= # Used for reporting. 56313a12fdSmrglog_file= # Where to save the output of the test script. 57313a12fdSmrgtrs_file= # Where to save the metadata of the test run. 58313a12fdSmrgexpect_failure=no 59313a12fdSmrgcolor_tests=no 60313a12fdSmrgenable_hard_errors=yes 61313a12fdSmrgwhile test $# -gt 0; do 62313a12fdSmrg case $1 in 63313a12fdSmrg --help) print_usage; exit $?;; 64313a12fdSmrg --version) echo "test-driver $scriptversion"; exit $?;; 65313a12fdSmrg --test-name) test_name=$2; shift;; 66313a12fdSmrg --log-file) log_file=$2; shift;; 67313a12fdSmrg --trs-file) trs_file=$2; shift;; 68313a12fdSmrg --color-tests) color_tests=$2; shift;; 69313a12fdSmrg --expect-failure) expect_failure=$2; shift;; 70313a12fdSmrg --enable-hard-errors) enable_hard_errors=$2; shift;; 71313a12fdSmrg --) shift; break;; 72313a12fdSmrg -*) usage_error "invalid option: '$1'";; 737cea3689Smrg *) break;; 74313a12fdSmrg esac 75313a12fdSmrg shift 76313a12fdSmrgdone 77313a12fdSmrg 787cea3689Smrgmissing_opts= 797cea3689Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 807cea3689Smrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 817cea3689Smrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 827cea3689Smrgif test x"$missing_opts" != x; then 837cea3689Smrg usage_error "the following mandatory options are missing:$missing_opts" 847cea3689Smrgfi 857cea3689Smrg 867cea3689Smrgif test $# -eq 0; then 877cea3689Smrg usage_error "missing argument" 887cea3689Smrgfi 897cea3689Smrg 90313a12fdSmrgif test $color_tests = yes; then 91313a12fdSmrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 92313a12fdSmrg red='[0;31m' # Red. 93313a12fdSmrg grn='[0;32m' # Green. 94313a12fdSmrg lgn='[1;32m' # Light green. 95313a12fdSmrg blu='[1;34m' # Blue. 96313a12fdSmrg mgn='[0;35m' # Magenta. 97313a12fdSmrg std='[m' # No color. 98313a12fdSmrgelse 99313a12fdSmrg red= grn= lgn= blu= mgn= std= 100313a12fdSmrgfi 101313a12fdSmrg 102313a12fdSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 103313a12fdSmrgtrap "st=129; $do_exit" 1 104313a12fdSmrgtrap "st=130; $do_exit" 2 105313a12fdSmrgtrap "st=141; $do_exit" 13 106313a12fdSmrgtrap "st=143; $do_exit" 15 107313a12fdSmrg 10895b7a5c8Smrg# Test script is run here. We create the file first, then append to it, 10995b7a5c8Smrg# to ameliorate tests themselves also writing to the log file. Our tests 11095b7a5c8Smrg# don't, but others can (automake bug#35762). 11195b7a5c8Smrg: >"$log_file" 11295b7a5c8Smrg"$@" >>"$log_file" 2>&1 113313a12fdSmrgestatus=$? 1147cea3689Smrg 115313a12fdSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then 1167cea3689Smrg tweaked_estatus=1 1177cea3689Smrgelse 1187cea3689Smrg tweaked_estatus=$estatus 119313a12fdSmrgfi 120313a12fdSmrg 1217cea3689Smrgcase $tweaked_estatus:$expect_failure in 122313a12fdSmrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 123313a12fdSmrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 124313a12fdSmrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 125313a12fdSmrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 126313a12fdSmrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 127313a12fdSmrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 128313a12fdSmrgesac 129313a12fdSmrg 1307cea3689Smrg# Report the test outcome and exit status in the logs, so that one can 1317cea3689Smrg# know whether the test passed or failed simply by looking at the '.log' 1327cea3689Smrg# file, without the need of also peaking into the corresponding '.trs' 1337cea3689Smrg# file (automake bug#11814). 13495b7a5c8Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 1357cea3689Smrg 136313a12fdSmrg# Report outcome to console. 137313a12fdSmrgecho "${col}${res}${std}: $test_name" 138313a12fdSmrg 139313a12fdSmrg# Register the test result, and other relevant metadata. 140313a12fdSmrgecho ":test-result: $res" > $trs_file 141313a12fdSmrgecho ":global-test-result: $res" >> $trs_file 142313a12fdSmrgecho ":recheck: $recheck" >> $trs_file 143313a12fdSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file 144313a12fdSmrg 145313a12fdSmrg# Local Variables: 146313a12fdSmrg# mode: shell-script 147313a12fdSmrg# sh-indentation: 2 14895b7a5c8Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 149313a12fdSmrg# time-stamp-start: "scriptversion=" 150313a12fdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 15195b7a5c8Smrg# time-stamp-time-zone: "UTC0" 152313a12fdSmrg# time-stamp-end: "; # UTC" 153313a12fdSmrg# End: 154