19dedec0cSmrg#! /bin/sh 29dedec0cSmrg# test-driver - basic testsuite driver script. 39dedec0cSmrg 49dedec0cSmrgscriptversion=2018-03-07.03; # UTC 59dedec0cSmrg 69dedec0cSmrg# Copyright (C) 2011-2021 Free Software Foundation, Inc. 79dedec0cSmrg# 89dedec0cSmrg# This program is free software; you can redistribute it and/or modify 99dedec0cSmrg# it under the terms of the GNU General Public License as published by 109dedec0cSmrg# the Free Software Foundation; either version 2, or (at your option) 119dedec0cSmrg# any later version. 129dedec0cSmrg# 139dedec0cSmrg# This program is distributed in the hope that it will be useful, 149dedec0cSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 159dedec0cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169dedec0cSmrg# GNU General Public License for more details. 179dedec0cSmrg# 189dedec0cSmrg# You should have received a copy of the GNU General Public License 199dedec0cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 209dedec0cSmrg 219dedec0cSmrg# As a special exception to the GNU General Public License, if you 229dedec0cSmrg# distribute this file as part of a program that contains a 239dedec0cSmrg# configuration script generated by Autoconf, you may include it under 249dedec0cSmrg# the same distribution terms that you use for the rest of that program. 259dedec0cSmrg 269dedec0cSmrg# This file is maintained in Automake, please report 279dedec0cSmrg# bugs to <bug-automake@gnu.org> or send patches to 289dedec0cSmrg# <automake-patches@gnu.org>. 299dedec0cSmrg 309dedec0cSmrg# Make unconditional expansion of undefined variables an error. This 319dedec0cSmrg# helps a lot in preventing typo-related bugs. 329dedec0cSmrgset -u 339dedec0cSmrg 349dedec0cSmrgusage_error () 359dedec0cSmrg{ 369dedec0cSmrg echo "$0: $*" >&2 379dedec0cSmrg print_usage >&2 389dedec0cSmrg exit 2 399dedec0cSmrg} 409dedec0cSmrg 419dedec0cSmrgprint_usage () 429dedec0cSmrg{ 439dedec0cSmrg cat <<END 449dedec0cSmrgUsage: 459dedec0cSmrg test-driver --test-name NAME --log-file PATH --trs-file PATH 469dedec0cSmrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 479dedec0cSmrg [--enable-hard-errors {yes|no}] [--] 489dedec0cSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 499dedec0cSmrg 509dedec0cSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 519dedec0cSmrgSee the GNU Automake documentation for information. 529dedec0cSmrgEND 539dedec0cSmrg} 549dedec0cSmrg 559dedec0cSmrgtest_name= # Used for reporting. 569dedec0cSmrglog_file= # Where to save the output of the test script. 579dedec0cSmrgtrs_file= # Where to save the metadata of the test run. 589dedec0cSmrgexpect_failure=no 599dedec0cSmrgcolor_tests=no 609dedec0cSmrgenable_hard_errors=yes 619dedec0cSmrgwhile test $# -gt 0; do 629dedec0cSmrg case $1 in 639dedec0cSmrg --help) print_usage; exit $?;; 649dedec0cSmrg --version) echo "test-driver $scriptversion"; exit $?;; 659dedec0cSmrg --test-name) test_name=$2; shift;; 669dedec0cSmrg --log-file) log_file=$2; shift;; 679dedec0cSmrg --trs-file) trs_file=$2; shift;; 689dedec0cSmrg --color-tests) color_tests=$2; shift;; 699dedec0cSmrg --expect-failure) expect_failure=$2; shift;; 709dedec0cSmrg --enable-hard-errors) enable_hard_errors=$2; shift;; 719dedec0cSmrg --) shift; break;; 729dedec0cSmrg -*) usage_error "invalid option: '$1'";; 739dedec0cSmrg *) break;; 749dedec0cSmrg esac 759dedec0cSmrg shift 769dedec0cSmrgdone 779dedec0cSmrg 789dedec0cSmrgmissing_opts= 799dedec0cSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 809dedec0cSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 819dedec0cSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 829dedec0cSmrgif test x"$missing_opts" != x; then 839dedec0cSmrg usage_error "the following mandatory options are missing:$missing_opts" 849dedec0cSmrgfi 859dedec0cSmrg 869dedec0cSmrgif test $# -eq 0; then 879dedec0cSmrg usage_error "missing argument" 889dedec0cSmrgfi 899dedec0cSmrg 909dedec0cSmrgif test $color_tests = yes; then 919dedec0cSmrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 929dedec0cSmrg red='[0;31m' # Red. 939dedec0cSmrg grn='[0;32m' # Green. 949dedec0cSmrg lgn='[1;32m' # Light green. 959dedec0cSmrg blu='[1;34m' # Blue. 969dedec0cSmrg mgn='[0;35m' # Magenta. 979dedec0cSmrg std='[m' # No color. 989dedec0cSmrgelse 999dedec0cSmrg red= grn= lgn= blu= mgn= std= 1009dedec0cSmrgfi 1019dedec0cSmrg 1029dedec0cSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 1039dedec0cSmrgtrap "st=129; $do_exit" 1 1049dedec0cSmrgtrap "st=130; $do_exit" 2 1059dedec0cSmrgtrap "st=141; $do_exit" 13 1069dedec0cSmrgtrap "st=143; $do_exit" 15 1079dedec0cSmrg 1089dedec0cSmrg# Test script is run here. We create the file first, then append to it, 1099dedec0cSmrg# to ameliorate tests themselves also writing to the log file. Our tests 1109dedec0cSmrg# don't, but others can (automake bug#35762). 1119dedec0cSmrg: >"$log_file" 1129dedec0cSmrg"$@" >>"$log_file" 2>&1 1139dedec0cSmrgestatus=$? 1149dedec0cSmrg 1159dedec0cSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then 1169dedec0cSmrg tweaked_estatus=1 1179dedec0cSmrgelse 1189dedec0cSmrg tweaked_estatus=$estatus 1199dedec0cSmrgfi 1209dedec0cSmrg 1219dedec0cSmrgcase $tweaked_estatus:$expect_failure in 1229dedec0cSmrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 1239dedec0cSmrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 1249dedec0cSmrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 1259dedec0cSmrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 1269dedec0cSmrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 1279dedec0cSmrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 1289dedec0cSmrgesac 1299dedec0cSmrg 1309dedec0cSmrg# Report the test outcome and exit status in the logs, so that one can 1319dedec0cSmrg# know whether the test passed or failed simply by looking at the '.log' 1329dedec0cSmrg# file, without the need of also peaking into the corresponding '.trs' 1339dedec0cSmrg# file (automake bug#11814). 1349dedec0cSmrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 1359dedec0cSmrg 1369dedec0cSmrg# Report outcome to console. 1379dedec0cSmrgecho "${col}${res}${std}: $test_name" 1389dedec0cSmrg 1399dedec0cSmrg# Register the test result, and other relevant metadata. 1409dedec0cSmrgecho ":test-result: $res" > $trs_file 1419dedec0cSmrgecho ":global-test-result: $res" >> $trs_file 1429dedec0cSmrgecho ":recheck: $recheck" >> $trs_file 1439dedec0cSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file 1449dedec0cSmrg 1459dedec0cSmrg# Local Variables: 1469dedec0cSmrg# mode: shell-script 1479dedec0cSmrg# sh-indentation: 2 1489dedec0cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 1499dedec0cSmrg# time-stamp-start: "scriptversion=" 1509dedec0cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1519dedec0cSmrg# time-stamp-time-zone: "UTC0" 1529dedec0cSmrg# time-stamp-end: "; # UTC" 1539dedec0cSmrg# End: 154