xref: /iperf/config/test-driver (revision aa8a3f4f)
1487ee810SBruce A. Mah#! /bin/sh
2487ee810SBruce A. Mah# test-driver - basic testsuite driver script.
3487ee810SBruce A. Mah
4*aa8a3f4fSBruce A. Mahscriptversion=2018-03-07.03; # UTC
5487ee810SBruce A. Mah
6*aa8a3f4fSBruce A. Mah# Copyright (C) 2011-2021 Free Software Foundation, Inc.
7487ee810SBruce A. Mah#
8487ee810SBruce A. Mah# This program is free software; you can redistribute it and/or modify
9487ee810SBruce A. Mah# it under the terms of the GNU General Public License as published by
10487ee810SBruce A. Mah# the Free Software Foundation; either version 2, or (at your option)
11487ee810SBruce A. Mah# any later version.
12487ee810SBruce A. Mah#
13487ee810SBruce A. Mah# This program is distributed in the hope that it will be useful,
14487ee810SBruce A. Mah# but WITHOUT ANY WARRANTY; without even the implied warranty of
15487ee810SBruce A. Mah# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16487ee810SBruce A. Mah# GNU General Public License for more details.
17487ee810SBruce A. Mah#
18487ee810SBruce A. Mah# You should have received a copy of the GNU General Public License
19*aa8a3f4fSBruce A. Mah# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20487ee810SBruce A. Mah
21487ee810SBruce A. Mah# As a special exception to the GNU General Public License, if you
22487ee810SBruce A. Mah# distribute this file as part of a program that contains a
23487ee810SBruce A. Mah# configuration script generated by Autoconf, you may include it under
24487ee810SBruce A. Mah# the same distribution terms that you use for the rest of that program.
25487ee810SBruce A. Mah
26487ee810SBruce A. Mah# This file is maintained in Automake, please report
27487ee810SBruce A. Mah# bugs to <[email protected]> or send patches to
28487ee810SBruce A. Mah# <[email protected]>.
29487ee810SBruce A. Mah
30487ee810SBruce A. Mah# Make unconditional expansion of undefined variables an error.  This
31487ee810SBruce A. Mah# helps a lot in preventing typo-related bugs.
32487ee810SBruce A. Mahset -u
33487ee810SBruce A. Mah
34487ee810SBruce A. Mahusage_error ()
35487ee810SBruce A. Mah{
36487ee810SBruce A. Mah  echo "$0: $*" >&2
37487ee810SBruce A. Mah  print_usage >&2
38487ee810SBruce A. Mah  exit 2
39487ee810SBruce A. Mah}
40487ee810SBruce A. Mah
41487ee810SBruce A. Mahprint_usage ()
42487ee810SBruce A. Mah{
43487ee810SBruce A. Mah  cat <<END
44487ee810SBruce A. MahUsage:
45*aa8a3f4fSBruce A. Mah  test-driver --test-name NAME --log-file PATH --trs-file PATH
46*aa8a3f4fSBruce A. Mah              [--expect-failure {yes|no}] [--color-tests {yes|no}]
47*aa8a3f4fSBruce A. Mah              [--enable-hard-errors {yes|no}] [--]
48487ee810SBruce A. Mah              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49*aa8a3f4fSBruce A. Mah
50487ee810SBruce A. MahThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
51*aa8a3f4fSBruce A. MahSee the GNU Automake documentation for information.
52487ee810SBruce A. MahEND
53487ee810SBruce A. Mah}
54487ee810SBruce A. Mah
55487ee810SBruce A. Mahtest_name= # Used for reporting.
56487ee810SBruce A. Mahlog_file=  # Where to save the output of the test script.
57487ee810SBruce A. Mahtrs_file=  # Where to save the metadata of the test run.
58487ee810SBruce A. Mahexpect_failure=no
59487ee810SBruce A. Mahcolor_tests=no
60487ee810SBruce A. Mahenable_hard_errors=yes
61487ee810SBruce A. Mahwhile test $# -gt 0; do
62487ee810SBruce A. Mah  case $1 in
63487ee810SBruce A. Mah  --help) print_usage; exit $?;;
64487ee810SBruce A. Mah  --version) echo "test-driver $scriptversion"; exit $?;;
65487ee810SBruce A. Mah  --test-name) test_name=$2; shift;;
66487ee810SBruce A. Mah  --log-file) log_file=$2; shift;;
67487ee810SBruce A. Mah  --trs-file) trs_file=$2; shift;;
68487ee810SBruce A. Mah  --color-tests) color_tests=$2; shift;;
69487ee810SBruce A. Mah  --expect-failure) expect_failure=$2; shift;;
70487ee810SBruce A. Mah  --enable-hard-errors) enable_hard_errors=$2; shift;;
71487ee810SBruce A. Mah  --) shift; break;;
72487ee810SBruce A. Mah  -*) usage_error "invalid option: '$1'";;
73487ee810SBruce A. Mah   *) break;;
74487ee810SBruce A. Mah  esac
75487ee810SBruce A. Mah  shift
76487ee810SBruce A. Mahdone
77487ee810SBruce A. Mah
78487ee810SBruce A. Mahmissing_opts=
79487ee810SBruce A. Mahtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
80487ee810SBruce A. Mahtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
81487ee810SBruce A. Mahtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
82487ee810SBruce A. Mahif test x"$missing_opts" != x; then
83487ee810SBruce A. Mah  usage_error "the following mandatory options are missing:$missing_opts"
84487ee810SBruce A. Mahfi
85487ee810SBruce A. Mah
86487ee810SBruce A. Mahif test $# -eq 0; then
87487ee810SBruce A. Mah  usage_error "missing argument"
88487ee810SBruce A. Mahfi
89487ee810SBruce A. Mah
90487ee810SBruce A. Mahif test $color_tests = yes; then
91487ee810SBruce A. Mah  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
92487ee810SBruce A. Mah  red='' # Red.
93487ee810SBruce A. Mah  grn='' # Green.
94487ee810SBruce A. Mah  lgn='' # Light green.
95487ee810SBruce A. Mah  blu='' # Blue.
96487ee810SBruce A. Mah  mgn='' # Magenta.
97487ee810SBruce A. Mah  std=''     # No color.
98487ee810SBruce A. Mahelse
99487ee810SBruce A. Mah  red= grn= lgn= blu= mgn= std=
100487ee810SBruce A. Mahfi
101487ee810SBruce A. Mah
102487ee810SBruce A. Mahdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
103487ee810SBruce A. Mahtrap "st=129; $do_exit" 1
104487ee810SBruce A. Mahtrap "st=130; $do_exit" 2
105487ee810SBruce A. Mahtrap "st=141; $do_exit" 13
106487ee810SBruce A. Mahtrap "st=143; $do_exit" 15
107487ee810SBruce A. Mah
108*aa8a3f4fSBruce A. Mah# Test script is run here. We create the file first, then append to it,
109*aa8a3f4fSBruce A. Mah# to ameliorate tests themselves also writing to the log file. Our tests
110*aa8a3f4fSBruce A. Mah# don't, but others can (automake bug#35762).
111*aa8a3f4fSBruce A. Mah: >"$log_file"
112*aa8a3f4fSBruce A. Mah"$@" >>"$log_file" 2>&1
113487ee810SBruce A. Mahestatus=$?
114*aa8a3f4fSBruce A. Mah
115487ee810SBruce A. Mahif test $enable_hard_errors = no && test $estatus -eq 99; then
116*aa8a3f4fSBruce A. Mah  tweaked_estatus=1
117*aa8a3f4fSBruce A. Mahelse
118*aa8a3f4fSBruce A. Mah  tweaked_estatus=$estatus
119487ee810SBruce A. Mahfi
120487ee810SBruce A. Mah
121*aa8a3f4fSBruce A. Mahcase $tweaked_estatus:$expect_failure in
122487ee810SBruce A. Mah  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
123487ee810SBruce A. Mah  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
124487ee810SBruce A. Mah  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
125487ee810SBruce A. Mah  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
126487ee810SBruce A. Mah  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
127487ee810SBruce A. Mah  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
128487ee810SBruce A. Mahesac
129487ee810SBruce A. Mah
130*aa8a3f4fSBruce A. Mah# Report the test outcome and exit status in the logs, so that one can
131*aa8a3f4fSBruce A. Mah# know whether the test passed or failed simply by looking at the '.log'
132*aa8a3f4fSBruce A. Mah# file, without the need of also peaking into the corresponding '.trs'
133*aa8a3f4fSBruce A. Mah# file (automake bug#11814).
134*aa8a3f4fSBruce A. Mahecho "$res $test_name (exit status: $estatus)" >>"$log_file"
135*aa8a3f4fSBruce A. Mah
136487ee810SBruce A. Mah# Report outcome to console.
137487ee810SBruce A. Mahecho "${col}${res}${std}: $test_name"
138487ee810SBruce A. Mah
139487ee810SBruce A. Mah# Register the test result, and other relevant metadata.
140487ee810SBruce A. Mahecho ":test-result: $res" > $trs_file
141487ee810SBruce A. Mahecho ":global-test-result: $res" >> $trs_file
142487ee810SBruce A. Mahecho ":recheck: $recheck" >> $trs_file
143487ee810SBruce A. Mahecho ":copy-in-global-log: $gcopy" >> $trs_file
144487ee810SBruce A. Mah
145487ee810SBruce A. Mah# Local Variables:
146487ee810SBruce A. Mah# mode: shell-script
147487ee810SBruce A. Mah# sh-indentation: 2
148*aa8a3f4fSBruce A. Mah# eval: (add-hook 'before-save-hook 'time-stamp)
149487ee810SBruce A. Mah# time-stamp-start: "scriptversion="
150487ee810SBruce A. Mah# time-stamp-format: "%:y-%02m-%02d.%02H"
151*aa8a3f4fSBruce A. Mah# time-stamp-time-zone: "UTC0"
152487ee810SBruce A. Mah# time-stamp-end: "; # UTC"
153487ee810SBruce A. Mah# End:
154