11c235774Smrg#! /bin/sh 21c235774Smrg# test-driver - basic testsuite driver script. 31c235774Smrg 474835918Smrgscriptversion=2018-03-07.03; # UTC 51c235774Smrg 674835918Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc. 71c235774Smrg# 81c235774Smrg# This program is free software; you can redistribute it and/or modify 91c235774Smrg# it under the terms of the GNU General Public License as published by 101c235774Smrg# the Free Software Foundation; either version 2, or (at your option) 111c235774Smrg# any later version. 121c235774Smrg# 131c235774Smrg# This program is distributed in the hope that it will be useful, 141c235774Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 151c235774Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 161c235774Smrg# GNU General Public License for more details. 171c235774Smrg# 181c235774Smrg# You should have received a copy of the GNU General Public License 1974835918Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 201c235774Smrg 211c235774Smrg# As a special exception to the GNU General Public License, if you 221c235774Smrg# distribute this file as part of a program that contains a 231c235774Smrg# configuration script generated by Autoconf, you may include it under 241c235774Smrg# the same distribution terms that you use for the rest of that program. 251c235774Smrg 261c235774Smrg# This file is maintained in Automake, please report 271c235774Smrg# bugs to <bug-automake@gnu.org> or send patches to 281c235774Smrg# <automake-patches@gnu.org>. 291c235774Smrg 301c235774Smrg# Make unconditional expansion of undefined variables an error. This 311c235774Smrg# helps a lot in preventing typo-related bugs. 321c235774Smrgset -u 331c235774Smrg 341c235774Smrgusage_error () 351c235774Smrg{ 361c235774Smrg echo "$0: $*" >&2 371c235774Smrg print_usage >&2 381c235774Smrg exit 2 391c235774Smrg} 401c235774Smrg 411c235774Smrgprint_usage () 421c235774Smrg{ 431c235774Smrg cat <<END 441c235774SmrgUsage: 4574835918Smrg test-driver --test-name NAME --log-file PATH --trs-file PATH 4674835918Smrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 4774835918Smrg [--enable-hard-errors {yes|no}] [--] 481c235774Smrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 4974835918Smrg 501c235774SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 5174835918SmrgSee the GNU Automake documentation for information. 521c235774SmrgEND 531c235774Smrg} 541c235774Smrg 551c235774Smrgtest_name= # Used for reporting. 561c235774Smrglog_file= # Where to save the output of the test script. 571c235774Smrgtrs_file= # Where to save the metadata of the test run. 581c235774Smrgexpect_failure=no 591c235774Smrgcolor_tests=no 601c235774Smrgenable_hard_errors=yes 611c235774Smrgwhile test $# -gt 0; do 621c235774Smrg case $1 in 631c235774Smrg --help) print_usage; exit $?;; 641c235774Smrg --version) echo "test-driver $scriptversion"; exit $?;; 651c235774Smrg --test-name) test_name=$2; shift;; 661c235774Smrg --log-file) log_file=$2; shift;; 671c235774Smrg --trs-file) trs_file=$2; shift;; 681c235774Smrg --color-tests) color_tests=$2; shift;; 691c235774Smrg --expect-failure) expect_failure=$2; shift;; 701c235774Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 711c235774Smrg --) shift; break;; 721c235774Smrg -*) usage_error "invalid option: '$1'";; 731c235774Smrg *) break;; 741c235774Smrg esac 751c235774Smrg shift 761c235774Smrgdone 771c235774Smrg 781c235774Smrgmissing_opts= 791c235774Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 801c235774Smrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 811c235774Smrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 821c235774Smrgif test x"$missing_opts" != x; then 831c235774Smrg usage_error "the following mandatory options are missing:$missing_opts" 841c235774Smrgfi 851c235774Smrg 861c235774Smrgif test $# -eq 0; then 871c235774Smrg usage_error "missing argument" 881c235774Smrgfi 891c235774Smrg 901c235774Smrgif test $color_tests = yes; then 911c235774Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 921c235774Smrg red='[0;31m' # Red. 931c235774Smrg grn='[0;32m' # Green. 941c235774Smrg lgn='[1;32m' # Light green. 951c235774Smrg blu='[1;34m' # Blue. 961c235774Smrg mgn='[0;35m' # Magenta. 971c235774Smrg std='[m' # No color. 981c235774Smrgelse 991c235774Smrg red= grn= lgn= blu= mgn= std= 1001c235774Smrgfi 1011c235774Smrg 1021c235774Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 1031c235774Smrgtrap "st=129; $do_exit" 1 1041c235774Smrgtrap "st=130; $do_exit" 2 1051c235774Smrgtrap "st=141; $do_exit" 13 1061c235774Smrgtrap "st=143; $do_exit" 15 1071c235774Smrg 10874835918Smrg# Test script is run here. We create the file first, then append to it, 10974835918Smrg# to ameliorate tests themselves also writing to the log file. Our tests 11074835918Smrg# don't, but others can (automake bug#35762). 11174835918Smrg: >"$log_file" 11274835918Smrg"$@" >>"$log_file" 2>&1 1131c235774Smrgestatus=$? 1141c235774Smrg 1151c235774Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 1161c235774Smrg tweaked_estatus=1 1171c235774Smrgelse 1181c235774Smrg tweaked_estatus=$estatus 1191c235774Smrgfi 1201c235774Smrg 1211c235774Smrgcase $tweaked_estatus:$expect_failure in 1221c235774Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 1231c235774Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 1241c235774Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 1251c235774Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 1261c235774Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 1271c235774Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 1281c235774Smrgesac 1291c235774Smrg 1301c235774Smrg# Report the test outcome and exit status in the logs, so that one can 1311c235774Smrg# know whether the test passed or failed simply by looking at the '.log' 1321c235774Smrg# file, without the need of also peaking into the corresponding '.trs' 1331c235774Smrg# file (automake bug#11814). 13474835918Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 1351c235774Smrg 1361c235774Smrg# Report outcome to console. 1371c235774Smrgecho "${col}${res}${std}: $test_name" 1381c235774Smrg 1391c235774Smrg# Register the test result, and other relevant metadata. 1401c235774Smrgecho ":test-result: $res" > $trs_file 1411c235774Smrgecho ":global-test-result: $res" >> $trs_file 1421c235774Smrgecho ":recheck: $recheck" >> $trs_file 1431c235774Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 1441c235774Smrg 1451c235774Smrg# Local Variables: 1461c235774Smrg# mode: shell-script 1471c235774Smrg# sh-indentation: 2 14874835918Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 1491c235774Smrg# time-stamp-start: "scriptversion=" 1501c235774Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 15174835918Smrg# time-stamp-time-zone: "UTC0" 1521c235774Smrg# time-stamp-end: "; # UTC" 1531c235774Smrg# End: 154