19e7bcd65Smrg#! /bin/sh 29e7bcd65Smrg# test-driver - basic testsuite driver script. 39e7bcd65Smrg 40568f49bSmrgscriptversion=2018-03-07.03; # UTC 59e7bcd65Smrg 6fdf6a26fSmrg# Copyright (C) 2011-2021 Free Software Foundation, Inc. 79e7bcd65Smrg# 89e7bcd65Smrg# This program is free software; you can redistribute it and/or modify 99e7bcd65Smrg# it under the terms of the GNU General Public License as published by 109e7bcd65Smrg# the Free Software Foundation; either version 2, or (at your option) 119e7bcd65Smrg# any later version. 129e7bcd65Smrg# 139e7bcd65Smrg# This program is distributed in the hope that it will be useful, 149e7bcd65Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 159e7bcd65Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169e7bcd65Smrg# GNU General Public License for more details. 179e7bcd65Smrg# 189e7bcd65Smrg# You should have received a copy of the GNU General Public License 190568f49bSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 209e7bcd65Smrg 219e7bcd65Smrg# As a special exception to the GNU General Public License, if you 229e7bcd65Smrg# distribute this file as part of a program that contains a 239e7bcd65Smrg# configuration script generated by Autoconf, you may include it under 249e7bcd65Smrg# the same distribution terms that you use for the rest of that program. 259e7bcd65Smrg 269e7bcd65Smrg# This file is maintained in Automake, please report 279e7bcd65Smrg# bugs to <bug-automake@gnu.org> or send patches to 289e7bcd65Smrg# <automake-patches@gnu.org>. 299e7bcd65Smrg 309e7bcd65Smrg# Make unconditional expansion of undefined variables an error. This 319e7bcd65Smrg# helps a lot in preventing typo-related bugs. 329e7bcd65Smrgset -u 339e7bcd65Smrg 349e7bcd65Smrgusage_error () 359e7bcd65Smrg{ 369e7bcd65Smrg echo "$0: $*" >&2 379e7bcd65Smrg print_usage >&2 389e7bcd65Smrg exit 2 399e7bcd65Smrg} 409e7bcd65Smrg 419e7bcd65Smrgprint_usage () 429e7bcd65Smrg{ 439e7bcd65Smrg cat <<END 449e7bcd65SmrgUsage: 45fdf6a26fSmrg test-driver --test-name NAME --log-file PATH --trs-file PATH 46fdf6a26fSmrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 47fdf6a26fSmrg [--enable-hard-errors {yes|no}] [--] 48339a7c43Smrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49fdf6a26fSmrg 509e7bcd65SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 51fdf6a26fSmrgSee the GNU Automake documentation for information. 529e7bcd65SmrgEND 539e7bcd65Smrg} 549e7bcd65Smrg 559e7bcd65Smrgtest_name= # Used for reporting. 569e7bcd65Smrglog_file= # Where to save the output of the test script. 579e7bcd65Smrgtrs_file= # Where to save the metadata of the test run. 589e7bcd65Smrgexpect_failure=no 599e7bcd65Smrgcolor_tests=no 609e7bcd65Smrgenable_hard_errors=yes 619e7bcd65Smrgwhile test $# -gt 0; do 629e7bcd65Smrg case $1 in 639e7bcd65Smrg --help) print_usage; exit $?;; 649e7bcd65Smrg --version) echo "test-driver $scriptversion"; exit $?;; 659e7bcd65Smrg --test-name) test_name=$2; shift;; 669e7bcd65Smrg --log-file) log_file=$2; shift;; 679e7bcd65Smrg --trs-file) trs_file=$2; shift;; 689e7bcd65Smrg --color-tests) color_tests=$2; shift;; 699e7bcd65Smrg --expect-failure) expect_failure=$2; shift;; 709e7bcd65Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 719e7bcd65Smrg --) shift; break;; 729e7bcd65Smrg -*) usage_error "invalid option: '$1'";; 73339a7c43Smrg *) break;; 749e7bcd65Smrg esac 759e7bcd65Smrg shift 769e7bcd65Smrgdone 779e7bcd65Smrg 78339a7c43Smrgmissing_opts= 79339a7c43Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 80339a7c43Smrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 81339a7c43Smrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 82339a7c43Smrgif test x"$missing_opts" != x; then 83339a7c43Smrg usage_error "the following mandatory options are missing:$missing_opts" 84339a7c43Smrgfi 85339a7c43Smrg 86339a7c43Smrgif test $# -eq 0; then 87339a7c43Smrg usage_error "missing argument" 88339a7c43Smrgfi 89339a7c43Smrg 909e7bcd65Smrgif test $color_tests = yes; then 919e7bcd65Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 929e7bcd65Smrg red='[0;31m' # Red. 939e7bcd65Smrg grn='[0;32m' # Green. 949e7bcd65Smrg lgn='[1;32m' # Light green. 959e7bcd65Smrg blu='[1;34m' # Blue. 969e7bcd65Smrg mgn='[0;35m' # Magenta. 979e7bcd65Smrg std='[m' # No color. 989e7bcd65Smrgelse 999e7bcd65Smrg red= grn= lgn= blu= mgn= std= 1009e7bcd65Smrgfi 1019e7bcd65Smrg 1029e7bcd65Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 1039e7bcd65Smrgtrap "st=129; $do_exit" 1 1049e7bcd65Smrgtrap "st=130; $do_exit" 2 1059e7bcd65Smrgtrap "st=141; $do_exit" 13 1069e7bcd65Smrgtrap "st=143; $do_exit" 15 1079e7bcd65Smrg 108fdf6a26fSmrg# Test script is run here. We create the file first, then append to it, 109fdf6a26fSmrg# to ameliorate tests themselves also writing to the log file. Our tests 110fdf6a26fSmrg# don't, but others can (automake bug#35762). 111fdf6a26fSmrg: >"$log_file" 112fdf6a26fSmrg"$@" >>"$log_file" 2>&1 1139e7bcd65Smrgestatus=$? 114339a7c43Smrg 1159e7bcd65Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 116339a7c43Smrg tweaked_estatus=1 117339a7c43Smrgelse 118339a7c43Smrg tweaked_estatus=$estatus 1199e7bcd65Smrgfi 1209e7bcd65Smrg 121339a7c43Smrgcase $tweaked_estatus:$expect_failure in 1229e7bcd65Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 1239e7bcd65Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 1249e7bcd65Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 1259e7bcd65Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 1269e7bcd65Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 1279e7bcd65Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 1289e7bcd65Smrgesac 1299e7bcd65Smrg 130339a7c43Smrg# Report the test outcome and exit status in the logs, so that one can 131339a7c43Smrg# know whether the test passed or failed simply by looking at the '.log' 132339a7c43Smrg# file, without the need of also peaking into the corresponding '.trs' 133339a7c43Smrg# file (automake bug#11814). 134fdf6a26fSmrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 135339a7c43Smrg 1369e7bcd65Smrg# Report outcome to console. 1379e7bcd65Smrgecho "${col}${res}${std}: $test_name" 1389e7bcd65Smrg 1399e7bcd65Smrg# Register the test result, and other relevant metadata. 1409e7bcd65Smrgecho ":test-result: $res" > $trs_file 1419e7bcd65Smrgecho ":global-test-result: $res" >> $trs_file 1429e7bcd65Smrgecho ":recheck: $recheck" >> $trs_file 1439e7bcd65Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 1449e7bcd65Smrg 1459e7bcd65Smrg# Local Variables: 1469e7bcd65Smrg# mode: shell-script 1479e7bcd65Smrg# sh-indentation: 2 1480568f49bSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 1499e7bcd65Smrg# time-stamp-start: "scriptversion=" 1509e7bcd65Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1510568f49bSmrg# time-stamp-time-zone: "UTC0" 1529e7bcd65Smrg# time-stamp-end: "; # UTC" 1539e7bcd65Smrg# End: 154