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