test-driver revision ffe57424
15395ea76Smrg#! /bin/sh 25395ea76Smrg# test-driver - basic testsuite driver script. 35395ea76Smrg 45395ea76Smrgscriptversion=2018-03-07.03; # UTC 55395ea76Smrg 6ffe57424Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc. 75395ea76Smrg# 85395ea76Smrg# This program is free software; you can redistribute it and/or modify 95395ea76Smrg# it under the terms of the GNU General Public License as published by 105395ea76Smrg# the Free Software Foundation; either version 2, or (at your option) 115395ea76Smrg# any later version. 125395ea76Smrg# 135395ea76Smrg# This program is distributed in the hope that it will be useful, 145395ea76Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 155395ea76Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165395ea76Smrg# GNU General Public License for more details. 175395ea76Smrg# 185395ea76Smrg# You should have received a copy of the GNU General Public License 195395ea76Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 205395ea76Smrg 215395ea76Smrg# As a special exception to the GNU General Public License, if you 225395ea76Smrg# distribute this file as part of a program that contains a 235395ea76Smrg# configuration script generated by Autoconf, you may include it under 245395ea76Smrg# the same distribution terms that you use for the rest of that program. 255395ea76Smrg 265395ea76Smrg# This file is maintained in Automake, please report 275395ea76Smrg# bugs to <bug-automake@gnu.org> or send patches to 285395ea76Smrg# <automake-patches@gnu.org>. 295395ea76Smrg 305395ea76Smrg# Make unconditional expansion of undefined variables an error. This 315395ea76Smrg# helps a lot in preventing typo-related bugs. 325395ea76Smrgset -u 335395ea76Smrg 345395ea76Smrgusage_error () 355395ea76Smrg{ 365395ea76Smrg echo "$0: $*" >&2 375395ea76Smrg print_usage >&2 385395ea76Smrg exit 2 395395ea76Smrg} 405395ea76Smrg 415395ea76Smrgprint_usage () 425395ea76Smrg{ 435395ea76Smrg cat <<END 445395ea76SmrgUsage: 45ffe57424Smrg test-driver --test-name NAME --log-file PATH --trs-file PATH 46ffe57424Smrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 47ffe57424Smrg [--enable-hard-errors {yes|no}] [--] 485395ea76Smrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 49ffe57424Smrg 505395ea76SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 51ffe57424SmrgSee the GNU Automake documentation for information. 525395ea76SmrgEND 535395ea76Smrg} 545395ea76Smrg 555395ea76Smrgtest_name= # Used for reporting. 565395ea76Smrglog_file= # Where to save the output of the test script. 575395ea76Smrgtrs_file= # Where to save the metadata of the test run. 585395ea76Smrgexpect_failure=no 595395ea76Smrgcolor_tests=no 605395ea76Smrgenable_hard_errors=yes 615395ea76Smrgwhile test $# -gt 0; do 625395ea76Smrg case $1 in 635395ea76Smrg --help) print_usage; exit $?;; 645395ea76Smrg --version) echo "test-driver $scriptversion"; exit $?;; 655395ea76Smrg --test-name) test_name=$2; shift;; 665395ea76Smrg --log-file) log_file=$2; shift;; 675395ea76Smrg --trs-file) trs_file=$2; shift;; 685395ea76Smrg --color-tests) color_tests=$2; shift;; 695395ea76Smrg --expect-failure) expect_failure=$2; shift;; 705395ea76Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 715395ea76Smrg --) shift; break;; 725395ea76Smrg -*) usage_error "invalid option: '$1'";; 735395ea76Smrg *) break;; 745395ea76Smrg esac 755395ea76Smrg shift 765395ea76Smrgdone 775395ea76Smrg 785395ea76Smrgmissing_opts= 795395ea76Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 805395ea76Smrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 815395ea76Smrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 825395ea76Smrgif test x"$missing_opts" != x; then 835395ea76Smrg usage_error "the following mandatory options are missing:$missing_opts" 845395ea76Smrgfi 855395ea76Smrg 865395ea76Smrgif test $# -eq 0; then 875395ea76Smrg usage_error "missing argument" 885395ea76Smrgfi 895395ea76Smrg 905395ea76Smrgif test $color_tests = yes; then 915395ea76Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 925395ea76Smrg red='[0;31m' # Red. 935395ea76Smrg grn='[0;32m' # Green. 945395ea76Smrg lgn='[1;32m' # Light green. 955395ea76Smrg blu='[1;34m' # Blue. 965395ea76Smrg mgn='[0;35m' # Magenta. 975395ea76Smrg std='[m' # No color. 985395ea76Smrgelse 995395ea76Smrg red= grn= lgn= blu= mgn= std= 1005395ea76Smrgfi 1015395ea76Smrg 1025395ea76Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 1035395ea76Smrgtrap "st=129; $do_exit" 1 1045395ea76Smrgtrap "st=130; $do_exit" 2 1055395ea76Smrgtrap "st=141; $do_exit" 13 1065395ea76Smrgtrap "st=143; $do_exit" 15 1075395ea76Smrg 108ffe57424Smrg# Test script is run here. We create the file first, then append to it, 109ffe57424Smrg# to ameliorate tests themselves also writing to the log file. Our tests 110ffe57424Smrg# don't, but others can (automake bug#35762). 111ffe57424Smrg: >"$log_file" 112ffe57424Smrg"$@" >>"$log_file" 2>&1 1135395ea76Smrgestatus=$? 1145395ea76Smrg 1155395ea76Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 1165395ea76Smrg tweaked_estatus=1 1175395ea76Smrgelse 1185395ea76Smrg tweaked_estatus=$estatus 1195395ea76Smrgfi 1205395ea76Smrg 1215395ea76Smrgcase $tweaked_estatus:$expect_failure in 1225395ea76Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 1235395ea76Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 1245395ea76Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 1255395ea76Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 1265395ea76Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 1275395ea76Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 1285395ea76Smrgesac 1295395ea76Smrg 1305395ea76Smrg# Report the test outcome and exit status in the logs, so that one can 1315395ea76Smrg# know whether the test passed or failed simply by looking at the '.log' 1325395ea76Smrg# file, without the need of also peaking into the corresponding '.trs' 1335395ea76Smrg# file (automake bug#11814). 134ffe57424Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 1355395ea76Smrg 1365395ea76Smrg# Report outcome to console. 1375395ea76Smrgecho "${col}${res}${std}: $test_name" 1385395ea76Smrg 1395395ea76Smrg# Register the test result, and other relevant metadata. 1405395ea76Smrgecho ":test-result: $res" > $trs_file 1415395ea76Smrgecho ":global-test-result: $res" >> $trs_file 1425395ea76Smrgecho ":recheck: $recheck" >> $trs_file 1435395ea76Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 1445395ea76Smrg 1455395ea76Smrg# Local Variables: 1465395ea76Smrg# mode: shell-script 1475395ea76Smrg# sh-indentation: 2 1485395ea76Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 1495395ea76Smrg# time-stamp-start: "scriptversion=" 1505395ea76Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1515395ea76Smrg# time-stamp-time-zone: "UTC0" 1525395ea76Smrg# time-stamp-end: "; # UTC" 1535395ea76Smrg# End: 154