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