11016ad83Smrg#! /bin/sh
21016ad83Smrg# test-driver - basic testsuite driver script.
31016ad83Smrg
4fe12f63cSmrgscriptversion=2018-03-07.03; # UTC
51016ad83Smrg
68ffb90f1Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc.
71016ad83Smrg#
81016ad83Smrg# This program is free software; you can redistribute it and/or modify
91016ad83Smrg# it under the terms of the GNU General Public License as published by
101016ad83Smrg# the Free Software Foundation; either version 2, or (at your option)
111016ad83Smrg# any later version.
121016ad83Smrg#
131016ad83Smrg# This program is distributed in the hope that it will be useful,
141016ad83Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
151016ad83Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161016ad83Smrg# GNU General Public License for more details.
171016ad83Smrg#
181016ad83Smrg# You should have received a copy of the GNU General Public License
19fe12f63cSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
201016ad83Smrg
211016ad83Smrg# As a special exception to the GNU General Public License, if you
221016ad83Smrg# distribute this file as part of a program that contains a
231016ad83Smrg# configuration script generated by Autoconf, you may include it under
241016ad83Smrg# the same distribution terms that you use for the rest of that program.
251016ad83Smrg
261016ad83Smrg# This file is maintained in Automake, please report
271016ad83Smrg# bugs to <bug-automake@gnu.org> or send patches to
281016ad83Smrg# <automake-patches@gnu.org>.
291016ad83Smrg
301016ad83Smrg# Make unconditional expansion of undefined variables an error.  This
311016ad83Smrg# helps a lot in preventing typo-related bugs.
321016ad83Smrgset -u
331016ad83Smrg
341016ad83Smrgusage_error ()
351016ad83Smrg{
361016ad83Smrg  echo "$0: $*" >&2
371016ad83Smrg  print_usage >&2
381016ad83Smrg  exit 2
391016ad83Smrg}
401016ad83Smrg
411016ad83Smrgprint_usage ()
421016ad83Smrg{
431016ad83Smrg  cat <<END
441016ad83SmrgUsage:
458ffb90f1Smrg  test-driver --test-name NAME --log-file PATH --trs-file PATH
468ffb90f1Smrg              [--expect-failure {yes|no}] [--color-tests {yes|no}]
478ffb90f1Smrg              [--enable-hard-errors {yes|no}] [--]
481c7386f4Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
498ffb90f1Smrg
501016ad83SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
518ffb90f1SmrgSee the GNU Automake documentation for information.
521016ad83SmrgEND
531016ad83Smrg}
541016ad83Smrg
551016ad83Smrgtest_name= # Used for reporting.
561016ad83Smrglog_file=  # Where to save the output of the test script.
571016ad83Smrgtrs_file=  # Where to save the metadata of the test run.
581016ad83Smrgexpect_failure=no
591016ad83Smrgcolor_tests=no
601016ad83Smrgenable_hard_errors=yes
611016ad83Smrgwhile test $# -gt 0; do
621016ad83Smrg  case $1 in
631016ad83Smrg  --help) print_usage; exit $?;;
641016ad83Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
651016ad83Smrg  --test-name) test_name=$2; shift;;
661016ad83Smrg  --log-file) log_file=$2; shift;;
671016ad83Smrg  --trs-file) trs_file=$2; shift;;
681016ad83Smrg  --color-tests) color_tests=$2; shift;;
691016ad83Smrg  --expect-failure) expect_failure=$2; shift;;
701016ad83Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
711016ad83Smrg  --) shift; break;;
721016ad83Smrg  -*) usage_error "invalid option: '$1'";;
731c7386f4Smrg   *) break;;
741016ad83Smrg  esac
751016ad83Smrg  shift
761016ad83Smrgdone
771016ad83Smrg
781c7386f4Smrgmissing_opts=
791c7386f4Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
801c7386f4Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
811c7386f4Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
821c7386f4Smrgif test x"$missing_opts" != x; then
831c7386f4Smrg  usage_error "the following mandatory options are missing:$missing_opts"
841c7386f4Smrgfi
851c7386f4Smrg
861c7386f4Smrgif test $# -eq 0; then
871c7386f4Smrg  usage_error "missing argument"
881c7386f4Smrgfi
891c7386f4Smrg
901016ad83Smrgif test $color_tests = yes; then
911016ad83Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
921016ad83Smrg  red='[0;31m' # Red.
931016ad83Smrg  grn='[0;32m' # Green.
941016ad83Smrg  lgn='[1;32m' # Light green.
951016ad83Smrg  blu='[1;34m' # Blue.
961016ad83Smrg  mgn='[0;35m' # Magenta.
971016ad83Smrg  std='[m'     # No color.
981016ad83Smrgelse
991016ad83Smrg  red= grn= lgn= blu= mgn= std=
1001016ad83Smrgfi
1011016ad83Smrg
1021016ad83Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1031016ad83Smrgtrap "st=129; $do_exit" 1
1041016ad83Smrgtrap "st=130; $do_exit" 2
1051016ad83Smrgtrap "st=141; $do_exit" 13
1061016ad83Smrgtrap "st=143; $do_exit" 15
1071016ad83Smrg
1088ffb90f1Smrg# Test script is run here. We create the file first, then append to it,
1098ffb90f1Smrg# to ameliorate tests themselves also writing to the log file. Our tests
1108ffb90f1Smrg# don't, but others can (automake bug#35762).
1118ffb90f1Smrg: >"$log_file"
1128ffb90f1Smrg"$@" >>"$log_file" 2>&1
1131016ad83Smrgestatus=$?
114709d36bbSmrg
1151016ad83Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
116709d36bbSmrg  tweaked_estatus=1
117709d36bbSmrgelse
118709d36bbSmrg  tweaked_estatus=$estatus
1191016ad83Smrgfi
1201016ad83Smrg
121709d36bbSmrgcase $tweaked_estatus:$expect_failure in
1221016ad83Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1231016ad83Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1241016ad83Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1251016ad83Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1261016ad83Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1271016ad83Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1281016ad83Smrgesac
1291016ad83Smrg
130709d36bbSmrg# Report the test outcome and exit status in the logs, so that one can
131709d36bbSmrg# know whether the test passed or failed simply by looking at the '.log'
132709d36bbSmrg# file, without the need of also peaking into the corresponding '.trs'
133709d36bbSmrg# file (automake bug#11814).
1348ffb90f1Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file"
135709d36bbSmrg
1361016ad83Smrg# Report outcome to console.
1371016ad83Smrgecho "${col}${res}${std}: $test_name"
1381016ad83Smrg
1391016ad83Smrg# Register the test result, and other relevant metadata.
1401016ad83Smrgecho ":test-result: $res" > $trs_file
1411016ad83Smrgecho ":global-test-result: $res" >> $trs_file
1421016ad83Smrgecho ":recheck: $recheck" >> $trs_file
1431016ad83Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1441016ad83Smrg
1451016ad83Smrg# Local Variables:
1461016ad83Smrg# mode: shell-script
1471016ad83Smrg# sh-indentation: 2
148fe12f63cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1491016ad83Smrg# time-stamp-start: "scriptversion="
1501016ad83Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
151245c37e9Smrg# time-stamp-time-zone: "UTC0"
1521016ad83Smrg# time-stamp-end: "; # UTC"
1531016ad83Smrg# End:
154