test-driver revision 245c37e9
11016ad83Smrg#! /bin/sh
21016ad83Smrg# test-driver - basic testsuite driver script.
31016ad83Smrg
4245c37e9Smrgscriptversion=2016-01-11.22; # UTC
51016ad83Smrg
6245c37e9Smrg# Copyright (C) 2011-2017 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
191016ad83Smrg# along with this program.  If not, see <http://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:
451016ad83Smrg  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
461016ad83Smrg              [--expect-failure={yes|no}] [--color-tests={yes|no}]
471c7386f4Smrg              [--enable-hard-errors={yes|no}] [--]
481c7386f4Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
491016ad83SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
501016ad83SmrgEND
511016ad83Smrg}
521016ad83Smrg
531016ad83Smrgtest_name= # Used for reporting.
541016ad83Smrglog_file=  # Where to save the output of the test script.
551016ad83Smrgtrs_file=  # Where to save the metadata of the test run.
561016ad83Smrgexpect_failure=no
571016ad83Smrgcolor_tests=no
581016ad83Smrgenable_hard_errors=yes
591016ad83Smrgwhile test $# -gt 0; do
601016ad83Smrg  case $1 in
611016ad83Smrg  --help) print_usage; exit $?;;
621016ad83Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
631016ad83Smrg  --test-name) test_name=$2; shift;;
641016ad83Smrg  --log-file) log_file=$2; shift;;
651016ad83Smrg  --trs-file) trs_file=$2; shift;;
661016ad83Smrg  --color-tests) color_tests=$2; shift;;
671016ad83Smrg  --expect-failure) expect_failure=$2; shift;;
681016ad83Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
691016ad83Smrg  --) shift; break;;
701016ad83Smrg  -*) usage_error "invalid option: '$1'";;
711c7386f4Smrg   *) break;;
721016ad83Smrg  esac
731016ad83Smrg  shift
741016ad83Smrgdone
751016ad83Smrg
761c7386f4Smrgmissing_opts=
771c7386f4Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
781c7386f4Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
791c7386f4Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
801c7386f4Smrgif test x"$missing_opts" != x; then
811c7386f4Smrg  usage_error "the following mandatory options are missing:$missing_opts"
821c7386f4Smrgfi
831c7386f4Smrg
841c7386f4Smrgif test $# -eq 0; then
851c7386f4Smrg  usage_error "missing argument"
861c7386f4Smrgfi
871c7386f4Smrg
881016ad83Smrgif test $color_tests = yes; then
891016ad83Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
901016ad83Smrg  red='[0;31m' # Red.
911016ad83Smrg  grn='[0;32m' # Green.
921016ad83Smrg  lgn='[1;32m' # Light green.
931016ad83Smrg  blu='[1;34m' # Blue.
941016ad83Smrg  mgn='[0;35m' # Magenta.
951016ad83Smrg  std='[m'     # No color.
961016ad83Smrgelse
971016ad83Smrg  red= grn= lgn= blu= mgn= std=
981016ad83Smrgfi
991016ad83Smrg
1001016ad83Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1011016ad83Smrgtrap "st=129; $do_exit" 1
1021016ad83Smrgtrap "st=130; $do_exit" 2
1031016ad83Smrgtrap "st=141; $do_exit" 13
1041016ad83Smrgtrap "st=143; $do_exit" 15
1051016ad83Smrg
1061016ad83Smrg# Test script is run here.
1071016ad83Smrg"$@" >$log_file 2>&1
1081016ad83Smrgestatus=$?
109709d36bbSmrg
1101016ad83Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
111709d36bbSmrg  tweaked_estatus=1
112709d36bbSmrgelse
113709d36bbSmrg  tweaked_estatus=$estatus
1141016ad83Smrgfi
1151016ad83Smrg
116709d36bbSmrgcase $tweaked_estatus:$expect_failure in
1171016ad83Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1181016ad83Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1191016ad83Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1201016ad83Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1211016ad83Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1221016ad83Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1231016ad83Smrgesac
1241016ad83Smrg
125709d36bbSmrg# Report the test outcome and exit status in the logs, so that one can
126709d36bbSmrg# know whether the test passed or failed simply by looking at the '.log'
127709d36bbSmrg# file, without the need of also peaking into the corresponding '.trs'
128709d36bbSmrg# file (automake bug#11814).
129709d36bbSmrgecho "$res $test_name (exit status: $estatus)" >>$log_file
130709d36bbSmrg
1311016ad83Smrg# Report outcome to console.
1321016ad83Smrgecho "${col}${res}${std}: $test_name"
1331016ad83Smrg
1341016ad83Smrg# Register the test result, and other relevant metadata.
1351016ad83Smrgecho ":test-result: $res" > $trs_file
1361016ad83Smrgecho ":global-test-result: $res" >> $trs_file
1371016ad83Smrgecho ":recheck: $recheck" >> $trs_file
1381016ad83Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1391016ad83Smrg
1401016ad83Smrg# Local Variables:
1411016ad83Smrg# mode: shell-script
1421016ad83Smrg# sh-indentation: 2
1431016ad83Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
1441016ad83Smrg# time-stamp-start: "scriptversion="
1451016ad83Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
146245c37e9Smrg# time-stamp-time-zone: "UTC0"
1471016ad83Smrg# time-stamp-end: "; # UTC"
1481016ad83Smrg# End:
149