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