1a4f78defSmrg#! /bin/sh
2a4f78defSmrg# test-driver - basic testsuite driver script.
3a4f78defSmrg
4fb570538Smrgscriptversion=2018-03-07.03; # UTC
5a4f78defSmrg
6fb570538Smrg# Copyright (C) 2011-2018 Free Software Foundation, Inc.
7a4f78defSmrg#
8a4f78defSmrg# This program is free software; you can redistribute it and/or modify
9a4f78defSmrg# it under the terms of the GNU General Public License as published by
10a4f78defSmrg# the Free Software Foundation; either version 2, or (at your option)
11a4f78defSmrg# any later version.
12a4f78defSmrg#
13a4f78defSmrg# This program is distributed in the hope that it will be useful,
14a4f78defSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15a4f78defSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a4f78defSmrg# GNU General Public License for more details.
17a4f78defSmrg#
18a4f78defSmrg# You should have received a copy of the GNU General Public License
19fb570538Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20a4f78defSmrg
21a4f78defSmrg# As a special exception to the GNU General Public License, if you
22a4f78defSmrg# distribute this file as part of a program that contains a
23a4f78defSmrg# configuration script generated by Autoconf, you may include it under
24a4f78defSmrg# the same distribution terms that you use for the rest of that program.
25a4f78defSmrg
26a4f78defSmrg# This file is maintained in Automake, please report
27a4f78defSmrg# bugs to <bug-automake@gnu.org> or send patches to
28a4f78defSmrg# <automake-patches@gnu.org>.
29a4f78defSmrg
30a4f78defSmrg# Make unconditional expansion of undefined variables an error.  This
31a4f78defSmrg# helps a lot in preventing typo-related bugs.
32a4f78defSmrgset -u
33a4f78defSmrg
34a4f78defSmrgusage_error ()
35a4f78defSmrg{
36a4f78defSmrg  echo "$0: $*" >&2
37a4f78defSmrg  print_usage >&2
38a4f78defSmrg  exit 2
39a4f78defSmrg}
40a4f78defSmrg
41a4f78defSmrgprint_usage ()
42a4f78defSmrg{
43a4f78defSmrg  cat <<END
44a4f78defSmrgUsage:
45a4f78defSmrg  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
46a4f78defSmrg              [--expect-failure={yes|no}] [--color-tests={yes|no}]
47a4f78defSmrg              [--enable-hard-errors={yes|no}] [--]
48a4f78defSmrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49a4f78defSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
50a4f78defSmrgEND
51a4f78defSmrg}
52a4f78defSmrg
53a4f78defSmrgtest_name= # Used for reporting.
54a4f78defSmrglog_file=  # Where to save the output of the test script.
55a4f78defSmrgtrs_file=  # Where to save the metadata of the test run.
56a4f78defSmrgexpect_failure=no
57a4f78defSmrgcolor_tests=no
58a4f78defSmrgenable_hard_errors=yes
59a4f78defSmrgwhile test $# -gt 0; do
60a4f78defSmrg  case $1 in
61a4f78defSmrg  --help) print_usage; exit $?;;
62a4f78defSmrg  --version) echo "test-driver $scriptversion"; exit $?;;
63a4f78defSmrg  --test-name) test_name=$2; shift;;
64a4f78defSmrg  --log-file) log_file=$2; shift;;
65a4f78defSmrg  --trs-file) trs_file=$2; shift;;
66a4f78defSmrg  --color-tests) color_tests=$2; shift;;
67a4f78defSmrg  --expect-failure) expect_failure=$2; shift;;
68a4f78defSmrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
69a4f78defSmrg  --) shift; break;;
70a4f78defSmrg  -*) usage_error "invalid option: '$1'";;
71a4f78defSmrg   *) break;;
72a4f78defSmrg  esac
73a4f78defSmrg  shift
74a4f78defSmrgdone
75a4f78defSmrg
76a4f78defSmrgmissing_opts=
77a4f78defSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
78a4f78defSmrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
79a4f78defSmrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
80a4f78defSmrgif test x"$missing_opts" != x; then
81a4f78defSmrg  usage_error "the following mandatory options are missing:$missing_opts"
82a4f78defSmrgfi
83a4f78defSmrg
84a4f78defSmrgif test $# -eq 0; then
85a4f78defSmrg  usage_error "missing argument"
86a4f78defSmrgfi
87a4f78defSmrg
88a4f78defSmrgif test $color_tests = yes; then
89a4f78defSmrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
90a4f78defSmrg  red='[0;31m' # Red.
91a4f78defSmrg  grn='[0;32m' # Green.
92a4f78defSmrg  lgn='[1;32m' # Light green.
93a4f78defSmrg  blu='[1;34m' # Blue.
94a4f78defSmrg  mgn='[0;35m' # Magenta.
95a4f78defSmrg  std='[m'     # No color.
96a4f78defSmrgelse
97a4f78defSmrg  red= grn= lgn= blu= mgn= std=
98a4f78defSmrgfi
99a4f78defSmrg
100a4f78defSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
101a4f78defSmrgtrap "st=129; $do_exit" 1
102a4f78defSmrgtrap "st=130; $do_exit" 2
103a4f78defSmrgtrap "st=141; $do_exit" 13
104a4f78defSmrgtrap "st=143; $do_exit" 15
105a4f78defSmrg
106a4f78defSmrg# Test script is run here.
107a4f78defSmrg"$@" >$log_file 2>&1
108a4f78defSmrgestatus=$?
109a4f78defSmrg
110a4f78defSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then
111a4f78defSmrg  tweaked_estatus=1
112a4f78defSmrgelse
113a4f78defSmrg  tweaked_estatus=$estatus
114a4f78defSmrgfi
115a4f78defSmrg
116a4f78defSmrgcase $tweaked_estatus:$expect_failure in
117a4f78defSmrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
118a4f78defSmrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
119a4f78defSmrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
120a4f78defSmrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
121a4f78defSmrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
122a4f78defSmrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
123a4f78defSmrgesac
124a4f78defSmrg
125a4f78defSmrg# Report the test outcome and exit status in the logs, so that one can
126a4f78defSmrg# know whether the test passed or failed simply by looking at the '.log'
127a4f78defSmrg# file, without the need of also peaking into the corresponding '.trs'
128a4f78defSmrg# file (automake bug#11814).
129a4f78defSmrgecho "$res $test_name (exit status: $estatus)" >>$log_file
130a4f78defSmrg
131a4f78defSmrg# Report outcome to console.
132a4f78defSmrgecho "${col}${res}${std}: $test_name"
133a4f78defSmrg
134a4f78defSmrg# Register the test result, and other relevant metadata.
135a4f78defSmrgecho ":test-result: $res" > $trs_file
136a4f78defSmrgecho ":global-test-result: $res" >> $trs_file
137a4f78defSmrgecho ":recheck: $recheck" >> $trs_file
138a4f78defSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file
139a4f78defSmrg
140a4f78defSmrg# Local Variables:
141a4f78defSmrg# mode: shell-script
142a4f78defSmrg# sh-indentation: 2
143fb570538Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
144a4f78defSmrg# time-stamp-start: "scriptversion="
145a4f78defSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
146fb570538Smrg# time-stamp-time-zone: "UTC0"
147a4f78defSmrg# time-stamp-end: "; # UTC"
148a4f78defSmrg# End:
149