Debian Codegraph @

bin/tests/system/custom-test-driver

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