test-driver revision 7515ee80
17515ee80Smrg#! /bin/sh
27515ee80Smrg# test-driver - basic testsuite driver script.
37515ee80Smrg
47515ee80Smrgscriptversion=2013-07-13.22; # UTC
57515ee80Smrg
67515ee80Smrg# Copyright (C) 2011-2014 Free Software Foundation, Inc.
77515ee80Smrg#
87515ee80Smrg# This program is free software; you can redistribute it and/or modify
97515ee80Smrg# it under the terms of the GNU General Public License as published by
107515ee80Smrg# the Free Software Foundation; either version 2, or (at your option)
117515ee80Smrg# any later version.
127515ee80Smrg#
137515ee80Smrg# This program is distributed in the hope that it will be useful,
147515ee80Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
157515ee80Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
167515ee80Smrg# GNU General Public License for more details.
177515ee80Smrg#
187515ee80Smrg# You should have received a copy of the GNU General Public License
197515ee80Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
207515ee80Smrg
217515ee80Smrg# As a special exception to the GNU General Public License, if you
227515ee80Smrg# distribute this file as part of a program that contains a
237515ee80Smrg# configuration script generated by Autoconf, you may include it under
247515ee80Smrg# the same distribution terms that you use for the rest of that program.
257515ee80Smrg
267515ee80Smrg# This file is maintained in Automake, please report
277515ee80Smrg# bugs to <bug-automake@gnu.org> or send patches to
287515ee80Smrg# <automake-patches@gnu.org>.
297515ee80Smrg
307515ee80Smrg# Make unconditional expansion of undefined variables an error.  This
317515ee80Smrg# helps a lot in preventing typo-related bugs.
327515ee80Smrgset -u
337515ee80Smrg
347515ee80Smrgusage_error ()
357515ee80Smrg{
367515ee80Smrg  echo "$0: $*" >&2
377515ee80Smrg  print_usage >&2
387515ee80Smrg  exit 2
397515ee80Smrg}
407515ee80Smrg
417515ee80Smrgprint_usage ()
427515ee80Smrg{
437515ee80Smrg  cat <<END
447515ee80SmrgUsage:
457515ee80Smrg  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
467515ee80Smrg              [--expect-failure={yes|no}] [--color-tests={yes|no}]
477515ee80Smrg              [--enable-hard-errors={yes|no}] [--]
487515ee80Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
497515ee80SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
507515ee80SmrgEND
517515ee80Smrg}
527515ee80Smrg
537515ee80Smrgtest_name= # Used for reporting.
547515ee80Smrglog_file=  # Where to save the output of the test script.
557515ee80Smrgtrs_file=  # Where to save the metadata of the test run.
567515ee80Smrgexpect_failure=no
577515ee80Smrgcolor_tests=no
587515ee80Smrgenable_hard_errors=yes
597515ee80Smrgwhile test $# -gt 0; do
607515ee80Smrg  case $1 in
617515ee80Smrg  --help) print_usage; exit $?;;
627515ee80Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
637515ee80Smrg  --test-name) test_name=$2; shift;;
647515ee80Smrg  --log-file) log_file=$2; shift;;
657515ee80Smrg  --trs-file) trs_file=$2; shift;;
667515ee80Smrg  --color-tests) color_tests=$2; shift;;
677515ee80Smrg  --expect-failure) expect_failure=$2; shift;;
687515ee80Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
697515ee80Smrg  --) shift; break;;
707515ee80Smrg  -*) usage_error "invalid option: '$1'";;
717515ee80Smrg   *) break;;
727515ee80Smrg  esac
737515ee80Smrg  shift
747515ee80Smrgdone
757515ee80Smrg
767515ee80Smrgmissing_opts=
777515ee80Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
787515ee80Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
797515ee80Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
807515ee80Smrgif test x"$missing_opts" != x; then
817515ee80Smrg  usage_error "the following mandatory options are missing:$missing_opts"
827515ee80Smrgfi
837515ee80Smrg
847515ee80Smrgif test $# -eq 0; then
857515ee80Smrg  usage_error "missing argument"
867515ee80Smrgfi
877515ee80Smrg
887515ee80Smrgif test $color_tests = yes; then
897515ee80Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
907515ee80Smrg  red='[0;31m' # Red.
917515ee80Smrg  grn='[0;32m' # Green.
927515ee80Smrg  lgn='[1;32m' # Light green.
937515ee80Smrg  blu='[1;34m' # Blue.
947515ee80Smrg  mgn='[0;35m' # Magenta.
957515ee80Smrg  std='[m'     # No color.
967515ee80Smrgelse
977515ee80Smrg  red= grn= lgn= blu= mgn= std=
987515ee80Smrgfi
997515ee80Smrg
1007515ee80Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1017515ee80Smrgtrap "st=129; $do_exit" 1
1027515ee80Smrgtrap "st=130; $do_exit" 2
1037515ee80Smrgtrap "st=141; $do_exit" 13
1047515ee80Smrgtrap "st=143; $do_exit" 15
1057515ee80Smrg
1067515ee80Smrg# Test script is run here.
1077515ee80Smrg"$@" >$log_file 2>&1
1087515ee80Smrgestatus=$?
1097515ee80Smrg
1107515ee80Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
1117515ee80Smrg  tweaked_estatus=1
1127515ee80Smrgelse
1137515ee80Smrg  tweaked_estatus=$estatus
1147515ee80Smrgfi
1157515ee80Smrg
1167515ee80Smrgcase $tweaked_estatus:$expect_failure in
1177515ee80Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1187515ee80Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1197515ee80Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1207515ee80Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1217515ee80Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1227515ee80Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1237515ee80Smrgesac
1247515ee80Smrg
1257515ee80Smrg# Report the test outcome and exit status in the logs, so that one can
1267515ee80Smrg# know whether the test passed or failed simply by looking at the '.log'
1277515ee80Smrg# file, without the need of also peaking into the corresponding '.trs'
1287515ee80Smrg# file (automake bug#11814).
1297515ee80Smrgecho "$res $test_name (exit status: $estatus)" >>$log_file
1307515ee80Smrg
1317515ee80Smrg# Report outcome to console.
1327515ee80Smrgecho "${col}${res}${std}: $test_name"
1337515ee80Smrg
1347515ee80Smrg# Register the test result, and other relevant metadata.
1357515ee80Smrgecho ":test-result: $res" > $trs_file
1367515ee80Smrgecho ":global-test-result: $res" >> $trs_file
1377515ee80Smrgecho ":recheck: $recheck" >> $trs_file
1387515ee80Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1397515ee80Smrg
1407515ee80Smrg# Local Variables:
1417515ee80Smrg# mode: shell-script
1427515ee80Smrg# sh-indentation: 2
1437515ee80Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
1447515ee80Smrg# time-stamp-start: "scriptversion="
1457515ee80Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
1467515ee80Smrg# time-stamp-time-zone: "UTC"
1477515ee80Smrg# time-stamp-end: "; # UTC"
1487515ee80Smrg# End:
149