test-driver revision 339a7c43
19e7bcd65Smrg#! /bin/sh
29e7bcd65Smrg# test-driver - basic testsuite driver script.
39e7bcd65Smrg
4339a7c43Smrgscriptversion=2013-07-13.22; # UTC
59e7bcd65Smrg
6339a7c43Smrg# Copyright (C) 2011-2014 Free Software Foundation, Inc.
79e7bcd65Smrg#
89e7bcd65Smrg# This program is free software; you can redistribute it and/or modify
99e7bcd65Smrg# it under the terms of the GNU General Public License as published by
109e7bcd65Smrg# the Free Software Foundation; either version 2, or (at your option)
119e7bcd65Smrg# any later version.
129e7bcd65Smrg#
139e7bcd65Smrg# This program is distributed in the hope that it will be useful,
149e7bcd65Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
159e7bcd65Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
169e7bcd65Smrg# GNU General Public License for more details.
179e7bcd65Smrg#
189e7bcd65Smrg# You should have received a copy of the GNU General Public License
199e7bcd65Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
209e7bcd65Smrg
219e7bcd65Smrg# As a special exception to the GNU General Public License, if you
229e7bcd65Smrg# distribute this file as part of a program that contains a
239e7bcd65Smrg# configuration script generated by Autoconf, you may include it under
249e7bcd65Smrg# the same distribution terms that you use for the rest of that program.
259e7bcd65Smrg
269e7bcd65Smrg# This file is maintained in Automake, please report
279e7bcd65Smrg# bugs to <bug-automake@gnu.org> or send patches to
289e7bcd65Smrg# <automake-patches@gnu.org>.
299e7bcd65Smrg
309e7bcd65Smrg# Make unconditional expansion of undefined variables an error.  This
319e7bcd65Smrg# helps a lot in preventing typo-related bugs.
329e7bcd65Smrgset -u
339e7bcd65Smrg
349e7bcd65Smrgusage_error ()
359e7bcd65Smrg{
369e7bcd65Smrg  echo "$0: $*" >&2
379e7bcd65Smrg  print_usage >&2
389e7bcd65Smrg  exit 2
399e7bcd65Smrg}
409e7bcd65Smrg
419e7bcd65Smrgprint_usage ()
429e7bcd65Smrg{
439e7bcd65Smrg  cat <<END
449e7bcd65SmrgUsage:
459e7bcd65Smrg  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
469e7bcd65Smrg              [--expect-failure={yes|no}] [--color-tests={yes|no}]
47339a7c43Smrg              [--enable-hard-errors={yes|no}] [--]
48339a7c43Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
499e7bcd65SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
509e7bcd65SmrgEND
519e7bcd65Smrg}
529e7bcd65Smrg
539e7bcd65Smrgtest_name= # Used for reporting.
549e7bcd65Smrglog_file=  # Where to save the output of the test script.
559e7bcd65Smrgtrs_file=  # Where to save the metadata of the test run.
569e7bcd65Smrgexpect_failure=no
579e7bcd65Smrgcolor_tests=no
589e7bcd65Smrgenable_hard_errors=yes
599e7bcd65Smrgwhile test $# -gt 0; do
609e7bcd65Smrg  case $1 in
619e7bcd65Smrg  --help) print_usage; exit $?;;
629e7bcd65Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
639e7bcd65Smrg  --test-name) test_name=$2; shift;;
649e7bcd65Smrg  --log-file) log_file=$2; shift;;
659e7bcd65Smrg  --trs-file) trs_file=$2; shift;;
669e7bcd65Smrg  --color-tests) color_tests=$2; shift;;
679e7bcd65Smrg  --expect-failure) expect_failure=$2; shift;;
689e7bcd65Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
699e7bcd65Smrg  --) shift; break;;
709e7bcd65Smrg  -*) usage_error "invalid option: '$1'";;
71339a7c43Smrg   *) break;;
729e7bcd65Smrg  esac
739e7bcd65Smrg  shift
749e7bcd65Smrgdone
759e7bcd65Smrg
76339a7c43Smrgmissing_opts=
77339a7c43Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
78339a7c43Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
79339a7c43Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
80339a7c43Smrgif test x"$missing_opts" != x; then
81339a7c43Smrg  usage_error "the following mandatory options are missing:$missing_opts"
82339a7c43Smrgfi
83339a7c43Smrg
84339a7c43Smrgif test $# -eq 0; then
85339a7c43Smrg  usage_error "missing argument"
86339a7c43Smrgfi
87339a7c43Smrg
889e7bcd65Smrgif test $color_tests = yes; then
899e7bcd65Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
909e7bcd65Smrg  red='[0;31m' # Red.
919e7bcd65Smrg  grn='[0;32m' # Green.
929e7bcd65Smrg  lgn='[1;32m' # Light green.
939e7bcd65Smrg  blu='[1;34m' # Blue.
949e7bcd65Smrg  mgn='[0;35m' # Magenta.
959e7bcd65Smrg  std='[m'     # No color.
969e7bcd65Smrgelse
979e7bcd65Smrg  red= grn= lgn= blu= mgn= std=
989e7bcd65Smrgfi
999e7bcd65Smrg
1009e7bcd65Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1019e7bcd65Smrgtrap "st=129; $do_exit" 1
1029e7bcd65Smrgtrap "st=130; $do_exit" 2
1039e7bcd65Smrgtrap "st=141; $do_exit" 13
1049e7bcd65Smrgtrap "st=143; $do_exit" 15
1059e7bcd65Smrg
1069e7bcd65Smrg# Test script is run here.
1079e7bcd65Smrg"$@" >$log_file 2>&1
1089e7bcd65Smrgestatus=$?
109339a7c43Smrg
1109e7bcd65Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
111339a7c43Smrg  tweaked_estatus=1
112339a7c43Smrgelse
113339a7c43Smrg  tweaked_estatus=$estatus
1149e7bcd65Smrgfi
1159e7bcd65Smrg
116339a7c43Smrgcase $tweaked_estatus:$expect_failure in
1179e7bcd65Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1189e7bcd65Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1199e7bcd65Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1209e7bcd65Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1219e7bcd65Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1229e7bcd65Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1239e7bcd65Smrgesac
1249e7bcd65Smrg
125339a7c43Smrg# Report the test outcome and exit status in the logs, so that one can
126339a7c43Smrg# know whether the test passed or failed simply by looking at the '.log'
127339a7c43Smrg# file, without the need of also peaking into the corresponding '.trs'
128339a7c43Smrg# file (automake bug#11814).
129339a7c43Smrgecho "$res $test_name (exit status: $estatus)" >>$log_file
130339a7c43Smrg
1319e7bcd65Smrg# Report outcome to console.
1329e7bcd65Smrgecho "${col}${res}${std}: $test_name"
1339e7bcd65Smrg
1349e7bcd65Smrg# Register the test result, and other relevant metadata.
1359e7bcd65Smrgecho ":test-result: $res" > $trs_file
1369e7bcd65Smrgecho ":global-test-result: $res" >> $trs_file
1379e7bcd65Smrgecho ":recheck: $recheck" >> $trs_file
1389e7bcd65Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1399e7bcd65Smrg
1409e7bcd65Smrg# Local Variables:
1419e7bcd65Smrg# mode: shell-script
1429e7bcd65Smrg# sh-indentation: 2
1439e7bcd65Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
1449e7bcd65Smrg# time-stamp-start: "scriptversion="
1459e7bcd65Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
1469e7bcd65Smrg# time-stamp-time-zone: "UTC"
1479e7bcd65Smrg# time-stamp-end: "; # UTC"
1489e7bcd65Smrg# End:
149