test-driver revision 1c235774
11c235774Smrg#! /bin/sh
21c235774Smrg# test-driver - basic testsuite driver script.
31c235774Smrg
41c235774Smrgscriptversion=2013-07-13.22; # UTC
51c235774Smrg
61c235774Smrg# Copyright (C) 2011-2014 Free Software Foundation, Inc.
71c235774Smrg#
81c235774Smrg# This program is free software; you can redistribute it and/or modify
91c235774Smrg# it under the terms of the GNU General Public License as published by
101c235774Smrg# the Free Software Foundation; either version 2, or (at your option)
111c235774Smrg# any later version.
121c235774Smrg#
131c235774Smrg# This program is distributed in the hope that it will be useful,
141c235774Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
151c235774Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161c235774Smrg# GNU General Public License for more details.
171c235774Smrg#
181c235774Smrg# You should have received a copy of the GNU General Public License
191c235774Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
201c235774Smrg
211c235774Smrg# As a special exception to the GNU General Public License, if you
221c235774Smrg# distribute this file as part of a program that contains a
231c235774Smrg# configuration script generated by Autoconf, you may include it under
241c235774Smrg# the same distribution terms that you use for the rest of that program.
251c235774Smrg
261c235774Smrg# This file is maintained in Automake, please report
271c235774Smrg# bugs to <bug-automake@gnu.org> or send patches to
281c235774Smrg# <automake-patches@gnu.org>.
291c235774Smrg
301c235774Smrg# Make unconditional expansion of undefined variables an error.  This
311c235774Smrg# helps a lot in preventing typo-related bugs.
321c235774Smrgset -u
331c235774Smrg
341c235774Smrgusage_error ()
351c235774Smrg{
361c235774Smrg  echo "$0: $*" >&2
371c235774Smrg  print_usage >&2
381c235774Smrg  exit 2
391c235774Smrg}
401c235774Smrg
411c235774Smrgprint_usage ()
421c235774Smrg{
431c235774Smrg  cat <<END
441c235774SmrgUsage:
451c235774Smrg  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
461c235774Smrg              [--expect-failure={yes|no}] [--color-tests={yes|no}]
471c235774Smrg              [--enable-hard-errors={yes|no}] [--]
481c235774Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
491c235774SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
501c235774SmrgEND
511c235774Smrg}
521c235774Smrg
531c235774Smrgtest_name= # Used for reporting.
541c235774Smrglog_file=  # Where to save the output of the test script.
551c235774Smrgtrs_file=  # Where to save the metadata of the test run.
561c235774Smrgexpect_failure=no
571c235774Smrgcolor_tests=no
581c235774Smrgenable_hard_errors=yes
591c235774Smrgwhile test $# -gt 0; do
601c235774Smrg  case $1 in
611c235774Smrg  --help) print_usage; exit $?;;
621c235774Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
631c235774Smrg  --test-name) test_name=$2; shift;;
641c235774Smrg  --log-file) log_file=$2; shift;;
651c235774Smrg  --trs-file) trs_file=$2; shift;;
661c235774Smrg  --color-tests) color_tests=$2; shift;;
671c235774Smrg  --expect-failure) expect_failure=$2; shift;;
681c235774Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
691c235774Smrg  --) shift; break;;
701c235774Smrg  -*) usage_error "invalid option: '$1'";;
711c235774Smrg   *) break;;
721c235774Smrg  esac
731c235774Smrg  shift
741c235774Smrgdone
751c235774Smrg
761c235774Smrgmissing_opts=
771c235774Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
781c235774Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
791c235774Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
801c235774Smrgif test x"$missing_opts" != x; then
811c235774Smrg  usage_error "the following mandatory options are missing:$missing_opts"
821c235774Smrgfi
831c235774Smrg
841c235774Smrgif test $# -eq 0; then
851c235774Smrg  usage_error "missing argument"
861c235774Smrgfi
871c235774Smrg
881c235774Smrgif test $color_tests = yes; then
891c235774Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
901c235774Smrg  red='[0;31m' # Red.
911c235774Smrg  grn='[0;32m' # Green.
921c235774Smrg  lgn='[1;32m' # Light green.
931c235774Smrg  blu='[1;34m' # Blue.
941c235774Smrg  mgn='[0;35m' # Magenta.
951c235774Smrg  std='[m'     # No color.
961c235774Smrgelse
971c235774Smrg  red= grn= lgn= blu= mgn= std=
981c235774Smrgfi
991c235774Smrg
1001c235774Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1011c235774Smrgtrap "st=129; $do_exit" 1
1021c235774Smrgtrap "st=130; $do_exit" 2
1031c235774Smrgtrap "st=141; $do_exit" 13
1041c235774Smrgtrap "st=143; $do_exit" 15
1051c235774Smrg
1061c235774Smrg# Test script is run here.
1071c235774Smrg"$@" >$log_file 2>&1
1081c235774Smrgestatus=$?
1091c235774Smrg
1101c235774Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
1111c235774Smrg  tweaked_estatus=1
1121c235774Smrgelse
1131c235774Smrg  tweaked_estatus=$estatus
1141c235774Smrgfi
1151c235774Smrg
1161c235774Smrgcase $tweaked_estatus:$expect_failure in
1171c235774Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1181c235774Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1191c235774Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1201c235774Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1211c235774Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1221c235774Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1231c235774Smrgesac
1241c235774Smrg
1251c235774Smrg# Report the test outcome and exit status in the logs, so that one can
1261c235774Smrg# know whether the test passed or failed simply by looking at the '.log'
1271c235774Smrg# file, without the need of also peaking into the corresponding '.trs'
1281c235774Smrg# file (automake bug#11814).
1291c235774Smrgecho "$res $test_name (exit status: $estatus)" >>$log_file
1301c235774Smrg
1311c235774Smrg# Report outcome to console.
1321c235774Smrgecho "${col}${res}${std}: $test_name"
1331c235774Smrg
1341c235774Smrg# Register the test result, and other relevant metadata.
1351c235774Smrgecho ":test-result: $res" > $trs_file
1361c235774Smrgecho ":global-test-result: $res" >> $trs_file
1371c235774Smrgecho ":recheck: $recheck" >> $trs_file
1381c235774Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1391c235774Smrg
1401c235774Smrg# Local Variables:
1411c235774Smrg# mode: shell-script
1421c235774Smrg# sh-indentation: 2
1431c235774Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
1441c235774Smrg# time-stamp-start: "scriptversion="
1451c235774Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
1461c235774Smrg# time-stamp-time-zone: "UTC"
1471c235774Smrg# time-stamp-end: "; # UTC"
1481c235774Smrg# End:
149