test-driver revision c82838c1
1e23ec014Smrg#! /bin/sh
235c4bbdfSmrg# test-driver - basic testsuite driver script.
335c4bbdfSmrg
4e23ec014Smrgscriptversion=2018-03-07.03; # UTC
535c4bbdfSmrg
6c82838c1Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc.
735c4bbdfSmrg#
835c4bbdfSmrg# This program is free software; you can redistribute it and/or modify
935c4bbdfSmrg# it under the terms of the GNU General Public License as published by
1035c4bbdfSmrg# the Free Software Foundation; either version 2, or (at your option)
1135c4bbdfSmrg# any later version.
1235c4bbdfSmrg#
1335c4bbdfSmrg# This program is distributed in the hope that it will be useful,
1435c4bbdfSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1535c4bbdfSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1635c4bbdfSmrg# GNU General Public License for more details.
1735c4bbdfSmrg#
1835c4bbdfSmrg# You should have received a copy of the GNU General Public License
19e23ec014Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2035c4bbdfSmrg
2135c4bbdfSmrg# As a special exception to the GNU General Public License, if you
2235c4bbdfSmrg# distribute this file as part of a program that contains a
2335c4bbdfSmrg# configuration script generated by Autoconf, you may include it under
2435c4bbdfSmrg# the same distribution terms that you use for the rest of that program.
2535c4bbdfSmrg
2635c4bbdfSmrg# This file is maintained in Automake, please report
2735c4bbdfSmrg# bugs to <bug-automake@gnu.org> or send patches to
2835c4bbdfSmrg# <automake-patches@gnu.org>.
2935c4bbdfSmrg
3035c4bbdfSmrg# Make unconditional expansion of undefined variables an error.  This
3135c4bbdfSmrg# helps a lot in preventing typo-related bugs.
3235c4bbdfSmrgset -u
3335c4bbdfSmrg
3435c4bbdfSmrgusage_error ()
3535c4bbdfSmrg{
3635c4bbdfSmrg  echo "$0: $*" >&2
3735c4bbdfSmrg  print_usage >&2
3835c4bbdfSmrg  exit 2
3935c4bbdfSmrg}
4035c4bbdfSmrg
4135c4bbdfSmrgprint_usage ()
4235c4bbdfSmrg{
4335c4bbdfSmrg  cat <<END
4435c4bbdfSmrgUsage:
45dc61d50dSmrg  test-driver --test-name NAME --log-file PATH --trs-file PATH
46dc61d50dSmrg              [--expect-failure {yes|no}] [--color-tests {yes|no}]
47dc61d50dSmrg              [--enable-hard-errors {yes|no}] [--]
4835c4bbdfSmrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49dc61d50dSmrg
5035c4bbdfSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
51dc61d50dSmrgSee the GNU Automake documentation for information.
5235c4bbdfSmrgEND
5335c4bbdfSmrg}
5435c4bbdfSmrg
5535c4bbdfSmrgtest_name= # Used for reporting.
5635c4bbdfSmrglog_file=  # Where to save the output of the test script.
5735c4bbdfSmrgtrs_file=  # Where to save the metadata of the test run.
5835c4bbdfSmrgexpect_failure=no
5935c4bbdfSmrgcolor_tests=no
6035c4bbdfSmrgenable_hard_errors=yes
6135c4bbdfSmrgwhile test $# -gt 0; do
6235c4bbdfSmrg  case $1 in
6335c4bbdfSmrg  --help) print_usage; exit $?;;
6435c4bbdfSmrg  --version) echo "test-driver $scriptversion"; exit $?;;
6535c4bbdfSmrg  --test-name) test_name=$2; shift;;
6635c4bbdfSmrg  --log-file) log_file=$2; shift;;
6735c4bbdfSmrg  --trs-file) trs_file=$2; shift;;
6835c4bbdfSmrg  --color-tests) color_tests=$2; shift;;
6935c4bbdfSmrg  --expect-failure) expect_failure=$2; shift;;
7035c4bbdfSmrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
7135c4bbdfSmrg  --) shift; break;;
7235c4bbdfSmrg  -*) usage_error "invalid option: '$1'";;
7335c4bbdfSmrg   *) break;;
7435c4bbdfSmrg  esac
7535c4bbdfSmrg  shift
7635c4bbdfSmrgdone
7735c4bbdfSmrg
7835c4bbdfSmrgmissing_opts=
7935c4bbdfSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
8035c4bbdfSmrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
8135c4bbdfSmrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
8235c4bbdfSmrgif test x"$missing_opts" != x; then
8335c4bbdfSmrg  usage_error "the following mandatory options are missing:$missing_opts"
8435c4bbdfSmrgfi
8535c4bbdfSmrg
8635c4bbdfSmrgif test $# -eq 0; then
8735c4bbdfSmrg  usage_error "missing argument"
8835c4bbdfSmrgfi
8935c4bbdfSmrg
9035c4bbdfSmrgif test $color_tests = yes; then
9135c4bbdfSmrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
9235c4bbdfSmrg  red='[0;31m' # Red.
9335c4bbdfSmrg  grn='[0;32m' # Green.
9435c4bbdfSmrg  lgn='[1;32m' # Light green.
9535c4bbdfSmrg  blu='[1;34m' # Blue.
9635c4bbdfSmrg  mgn='[0;35m' # Magenta.
9735c4bbdfSmrg  std='[m'     # No color.
9835c4bbdfSmrgelse
9935c4bbdfSmrg  red= grn= lgn= blu= mgn= std=
10035c4bbdfSmrgfi
10135c4bbdfSmrg
10235c4bbdfSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
10335c4bbdfSmrgtrap "st=129; $do_exit" 1
10435c4bbdfSmrgtrap "st=130; $do_exit" 2
10535c4bbdfSmrgtrap "st=141; $do_exit" 13
10635c4bbdfSmrgtrap "st=143; $do_exit" 15
10735c4bbdfSmrg
108c82838c1Smrg# Test script is run here. We create the file first, then append to it,
109c82838c1Smrg# to ameliorate tests themselves also writing to the log file. Our tests
110c82838c1Smrg# don't, but others can (automake bug#35762).
111c82838c1Smrg: >"$log_file"
112c82838c1Smrg"$@" >>"$log_file" 2>&1
11335c4bbdfSmrgestatus=$?
11435c4bbdfSmrg
11535c4bbdfSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then
11635c4bbdfSmrg  tweaked_estatus=1
11735c4bbdfSmrgelse
11835c4bbdfSmrg  tweaked_estatus=$estatus
11935c4bbdfSmrgfi
12035c4bbdfSmrg
12135c4bbdfSmrgcase $tweaked_estatus:$expect_failure in
12235c4bbdfSmrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
12335c4bbdfSmrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
12435c4bbdfSmrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
12535c4bbdfSmrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
12635c4bbdfSmrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
12735c4bbdfSmrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
12835c4bbdfSmrgesac
12935c4bbdfSmrg
13035c4bbdfSmrg# Report the test outcome and exit status in the logs, so that one can
13135c4bbdfSmrg# know whether the test passed or failed simply by looking at the '.log'
13235c4bbdfSmrg# file, without the need of also peaking into the corresponding '.trs'
13335c4bbdfSmrg# file (automake bug#11814).
134c82838c1Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file"
13535c4bbdfSmrg
13635c4bbdfSmrg# Report outcome to console.
13735c4bbdfSmrgecho "${col}${res}${std}: $test_name"
13835c4bbdfSmrg
13935c4bbdfSmrg# Register the test result, and other relevant metadata.
14035c4bbdfSmrgecho ":test-result: $res" > $trs_file
14135c4bbdfSmrgecho ":global-test-result: $res" >> $trs_file
14235c4bbdfSmrgecho ":recheck: $recheck" >> $trs_file
14335c4bbdfSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file
14435c4bbdfSmrg
14535c4bbdfSmrg# Local Variables:
14635c4bbdfSmrg# mode: shell-script
14735c4bbdfSmrg# sh-indentation: 2
148e23ec014Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
14935c4bbdfSmrg# time-stamp-start: "scriptversion="
15035c4bbdfSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
1511b5d61b8Smrg# time-stamp-time-zone: "UTC0"
15235c4bbdfSmrg# time-stamp-end: "; # UTC"
15335c4bbdfSmrg# End:
154