1255365Sdes#! /bin/sh
2255365Sdes# test-driver - basic testsuite driver script.
3255365Sdes
4255365Sdesscriptversion=2012-06-27.10; # UTC
5255365Sdes
6255365Sdes# Copyright (C) 2011-2013 Free Software Foundation, Inc.
7255365Sdes#
8255365Sdes# This program is free software; you can redistribute it and/or modify
9255365Sdes# it under the terms of the GNU General Public License as published by
10255365Sdes# the Free Software Foundation; either version 2, or (at your option)
11255365Sdes# any later version.
12255365Sdes#
13255365Sdes# This program is distributed in the hope that it will be useful,
14255365Sdes# but WITHOUT ANY WARRANTY; without even the implied warranty of
15255365Sdes# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16255365Sdes# GNU General Public License for more details.
17255365Sdes#
18255365Sdes# You should have received a copy of the GNU General Public License
19255365Sdes# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20255365Sdes
21255365Sdes# As a special exception to the GNU General Public License, if you
22255365Sdes# distribute this file as part of a program that contains a
23255365Sdes# configuration script generated by Autoconf, you may include it under
24255365Sdes# the same distribution terms that you use for the rest of that program.
25255365Sdes
26255365Sdes# This file is maintained in Automake, please report
27255365Sdes# bugs to <bug-automake@gnu.org> or send patches to
28255365Sdes# <automake-patches@gnu.org>.
29255365Sdes
30255365Sdes# Make unconditional expansion of undefined variables an error.  This
31255365Sdes# helps a lot in preventing typo-related bugs.
32255365Sdesset -u
33255365Sdes
34255365Sdesusage_error ()
35255365Sdes{
36255365Sdes  echo "$0: $*" >&2
37255365Sdes  print_usage >&2
38255365Sdes  exit 2
39255365Sdes}
40255365Sdes
41255365Sdesprint_usage ()
42255365Sdes{
43255365Sdes  cat <<END
44255365SdesUsage:
45255365Sdes  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
46255365Sdes              [--expect-failure={yes|no}] [--color-tests={yes|no}]
47255365Sdes              [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT
48255365SdesThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
49255365SdesEND
50255365Sdes}
51255365Sdes
52255365Sdes# TODO: better error handling in option parsing (in particular, ensure
53255365Sdes# TODO: $log_file, $trs_file and $test_name are defined).
54255365Sdestest_name= # Used for reporting.
55255365Sdeslog_file=  # Where to save the output of the test script.
56255365Sdestrs_file=  # Where to save the metadata of the test run.
57255365Sdesexpect_failure=no
58255365Sdescolor_tests=no
59255365Sdesenable_hard_errors=yes
60255365Sdeswhile test $# -gt 0; do
61255365Sdes  case $1 in
62255365Sdes  --help) print_usage; exit $?;;
63255365Sdes  --version) echo "test-driver $scriptversion"; exit $?;;
64255365Sdes  --test-name) test_name=$2; shift;;
65255365Sdes  --log-file) log_file=$2; shift;;
66255365Sdes  --trs-file) trs_file=$2; shift;;
67255365Sdes  --color-tests) color_tests=$2; shift;;
68255365Sdes  --expect-failure) expect_failure=$2; shift;;
69255365Sdes  --enable-hard-errors) enable_hard_errors=$2; shift;;
70255365Sdes  --) shift; break;;
71255365Sdes  -*) usage_error "invalid option: '$1'";;
72255365Sdes  esac
73255365Sdes  shift
74255365Sdesdone
75255365Sdes
76255365Sdesif test $color_tests = yes; then
77255365Sdes  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
78255365Sdes  red='[0;31m' # Red.
79255365Sdes  grn='[0;32m' # Green.
80255365Sdes  lgn='[1;32m' # Light green.
81255365Sdes  blu='[1;34m' # Blue.
82255365Sdes  mgn='[0;35m' # Magenta.
83255365Sdes  std='[m'     # No color.
84255365Sdeselse
85255365Sdes  red= grn= lgn= blu= mgn= std=
86255365Sdesfi
87255365Sdes
88255365Sdesdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
89255365Sdestrap "st=129; $do_exit" 1
90255365Sdestrap "st=130; $do_exit" 2
91255365Sdestrap "st=141; $do_exit" 13
92255365Sdestrap "st=143; $do_exit" 15
93255365Sdes
94255365Sdes# Test script is run here.
95255365Sdes"$@" >$log_file 2>&1
96255365Sdesestatus=$?
97255365Sdesif test $enable_hard_errors = no && test $estatus -eq 99; then
98255365Sdes  estatus=1
99255365Sdesfi
100255365Sdes
101255365Sdescase $estatus:$expect_failure in
102255365Sdes  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
103255365Sdes  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
104255365Sdes  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
105255365Sdes  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
106255365Sdes  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
107255365Sdes  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
108255365Sdesesac
109255365Sdes
110255365Sdes# Report outcome to console.
111255365Sdesecho "${col}${res}${std}: $test_name"
112255365Sdes
113255365Sdes# Register the test result, and other relevant metadata.
114255365Sdesecho ":test-result: $res" > $trs_file
115255365Sdesecho ":global-test-result: $res" >> $trs_file
116255365Sdesecho ":recheck: $recheck" >> $trs_file
117255365Sdesecho ":copy-in-global-log: $gcopy" >> $trs_file
118255365Sdes
119255365Sdes# Local Variables:
120255365Sdes# mode: shell-script
121255365Sdes# sh-indentation: 2
122255365Sdes# eval: (add-hook 'write-file-hooks 'time-stamp)
123255365Sdes# time-stamp-start: "scriptversion="
124255365Sdes# time-stamp-format: "%:y-%02m-%02d.%02H"
125255365Sdes# time-stamp-time-zone: "UTC"
126255365Sdes# time-stamp-end: "; # UTC"
127255365Sdes# End:
128