test-driver revision 5395ea76
15395ea76Smrg#! /bin/sh
25395ea76Smrg# test-driver - basic testsuite driver script.
35395ea76Smrg
45395ea76Smrgscriptversion=2018-03-07.03; # UTC
55395ea76Smrg
65395ea76Smrg# Copyright (C) 2011-2020 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:
455395ea76Smrg  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
465395ea76Smrg              [--expect-failure={yes|no}] [--color-tests={yes|no}]
475395ea76Smrg              [--enable-hard-errors={yes|no}] [--]
485395ea76Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
495395ea76SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
505395ea76SmrgEND
515395ea76Smrg}
525395ea76Smrg
535395ea76Smrgtest_name= # Used for reporting.
545395ea76Smrglog_file=  # Where to save the output of the test script.
555395ea76Smrgtrs_file=  # Where to save the metadata of the test run.
565395ea76Smrgexpect_failure=no
575395ea76Smrgcolor_tests=no
585395ea76Smrgenable_hard_errors=yes
595395ea76Smrgwhile test $# -gt 0; do
605395ea76Smrg  case $1 in
615395ea76Smrg  --help) print_usage; exit $?;;
625395ea76Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
635395ea76Smrg  --test-name) test_name=$2; shift;;
645395ea76Smrg  --log-file) log_file=$2; shift;;
655395ea76Smrg  --trs-file) trs_file=$2; shift;;
665395ea76Smrg  --color-tests) color_tests=$2; shift;;
675395ea76Smrg  --expect-failure) expect_failure=$2; shift;;
685395ea76Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
695395ea76Smrg  --) shift; break;;
705395ea76Smrg  -*) usage_error "invalid option: '$1'";;
715395ea76Smrg   *) break;;
725395ea76Smrg  esac
735395ea76Smrg  shift
745395ea76Smrgdone
755395ea76Smrg
765395ea76Smrgmissing_opts=
775395ea76Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
785395ea76Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
795395ea76Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
805395ea76Smrgif test x"$missing_opts" != x; then
815395ea76Smrg  usage_error "the following mandatory options are missing:$missing_opts"
825395ea76Smrgfi
835395ea76Smrg
845395ea76Smrgif test $# -eq 0; then
855395ea76Smrg  usage_error "missing argument"
865395ea76Smrgfi
875395ea76Smrg
885395ea76Smrgif test $color_tests = yes; then
895395ea76Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
905395ea76Smrg  red='[0;31m' # Red.
915395ea76Smrg  grn='[0;32m' # Green.
925395ea76Smrg  lgn='[1;32m' # Light green.
935395ea76Smrg  blu='[1;34m' # Blue.
945395ea76Smrg  mgn='[0;35m' # Magenta.
955395ea76Smrg  std='[m'     # No color.
965395ea76Smrgelse
975395ea76Smrg  red= grn= lgn= blu= mgn= std=
985395ea76Smrgfi
995395ea76Smrg
1005395ea76Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1015395ea76Smrgtrap "st=129; $do_exit" 1
1025395ea76Smrgtrap "st=130; $do_exit" 2
1035395ea76Smrgtrap "st=141; $do_exit" 13
1045395ea76Smrgtrap "st=143; $do_exit" 15
1055395ea76Smrg
1065395ea76Smrg# Test script is run here.
1075395ea76Smrg"$@" >$log_file 2>&1
1085395ea76Smrgestatus=$?
1095395ea76Smrg
1105395ea76Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
1115395ea76Smrg  tweaked_estatus=1
1125395ea76Smrgelse
1135395ea76Smrg  tweaked_estatus=$estatus
1145395ea76Smrgfi
1155395ea76Smrg
1165395ea76Smrgcase $tweaked_estatus:$expect_failure in
1175395ea76Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1185395ea76Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1195395ea76Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1205395ea76Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1215395ea76Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1225395ea76Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1235395ea76Smrgesac
1245395ea76Smrg
1255395ea76Smrg# Report the test outcome and exit status in the logs, so that one can
1265395ea76Smrg# know whether the test passed or failed simply by looking at the '.log'
1275395ea76Smrg# file, without the need of also peaking into the corresponding '.trs'
1285395ea76Smrg# file (automake bug#11814).
1295395ea76Smrgecho "$res $test_name (exit status: $estatus)" >>$log_file
1305395ea76Smrg
1315395ea76Smrg# Report outcome to console.
1325395ea76Smrgecho "${col}${res}${std}: $test_name"
1335395ea76Smrg
1345395ea76Smrg# Register the test result, and other relevant metadata.
1355395ea76Smrgecho ":test-result: $res" > $trs_file
1365395ea76Smrgecho ":global-test-result: $res" >> $trs_file
1375395ea76Smrgecho ":recheck: $recheck" >> $trs_file
1385395ea76Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1395395ea76Smrg
1405395ea76Smrg# Local Variables:
1415395ea76Smrg# mode: shell-script
1425395ea76Smrg# sh-indentation: 2
1435395ea76Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1445395ea76Smrg# time-stamp-start: "scriptversion="
1455395ea76Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
1465395ea76Smrg# time-stamp-time-zone: "UTC0"
1475395ea76Smrg# time-stamp-end: "; # UTC"
1485395ea76Smrg# End:
149