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