Browse code

tests: fork default automake test-driver

For some of the test we don't like the default log behavior
and there seems no easy way to change that except to fork
the driver. The license seems unproblematic since we're
GPL anyway.

v2:
- Do not use forked-test-driver for UTs. Default behavior
is fine for those.

Change-Id: I67d461afbcc9c06b1fc5ab4477141d7b8bd9ba8e
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Message-Id: <20240125110036.16070-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28132.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

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