blob: 37f7df02901e1f2f5cef4ff37842f9604376d430 [file] [log] [blame]
njn9fb16f52003-04-23 17:47:13 +00001#! @PERL@
njna217f3d2002-09-27 08:26:27 +00002##--------------------------------------------------------------------##
3##--- Valgrind regression testing script vg_regtest ---##
4##--------------------------------------------------------------------##
njnc2e7f482002-09-27 08:44:17 +00005
njnb9c427c2004-12-01 14:14:42 +00006# This file is part of Valgrind, a dynamic binary instrumentation
7# framework.
njnc2e7f482002-09-27 08:44:17 +00008#
njn0e1b5142003-04-15 14:58:06 +00009# Copyright (C) 2003 Nicholas Nethercote
njn2bc10122005-05-08 02:10:27 +000010# njn@valgrind.org
njnc2e7f482002-09-27 08:44:17 +000011#
12# This program is free software; you can redistribute it and/or
13# modify it under the terms of the GNU General Public License as
14# published by the Free Software Foundation; either version 2 of the
15# License, or (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful, but
18# WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20# General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25# 02111-1307, USA.
26#
27# The GNU General Public License is contained in the file COPYING.
28
29#----------------------------------------------------------------------------
njna217f3d2002-09-27 08:26:27 +000030# usage: vg_regtest [options] <dirs | files>
njn25e49d8e72002-09-23 09:36:25 +000031#
njna217f3d2002-09-27 08:26:27 +000032# Options:
njna217f3d2002-09-27 08:26:27 +000033# --all: run tests in all subdirs
njn3ed89602006-10-23 18:38:35 +000034# --valgrind: valgrind launcher to use. Default is ./coregrind/valgrind.
35# (This option should probably only be used in conjunction with
36# --valgrind-lib.)
37# --valgrind-lib: valgrind libraries to use. Default is $tests_dir/.in_place.
38# (This option should probably only be used in conjunction with
39# --valgrind.)
njna217f3d2002-09-27 08:26:27 +000040#
njn4ba5a792002-09-30 10:23:54 +000041# The easiest way is to run all tests in valgrind/ with (assuming you installed
42# in $PREFIX):
43#
44# $PREFIX/bin/vg_regtest --all
45#
njna217f3d2002-09-27 08:26:27 +000046# You can specify individual files to test, or whole directories, or both.
jsgf855d93d2003-10-13 22:26:55 +000047# Directories are traversed recursively, except for ones named, for example,
48# CVS/ or docs/.
njn25e49d8e72002-09-23 09:36:25 +000049#
50# Each test is defined in a file <test>.vgtest, containing one or more of the
njna217f3d2002-09-27 08:26:27 +000051# following lines, in any order:
njn25e49d8e72002-09-23 09:36:25 +000052# - prog: <prog to run> (compulsory)
53# - args: <args for prog> (default: none)
54# - vgopts: <Valgrind options> (default: none)
55# - stdout_filter: <filter to run stdout through> (default: none)
njna217f3d2002-09-27 08:26:27 +000056# - stderr_filter: <filter to run stderr through> (default: ./filter_stderr)
nethercotec5e1d802004-11-18 12:48:17 +000057# - prereq: <prerequisite command> (default: none)
njn734b8052007-11-01 04:40:37 +000058# - post: <post-test check command> (default: none)
59# - cleanup: <post-test cleanup cmd> (default: none)
njn25e49d8e72002-09-23 09:36:25 +000060#
njna217f3d2002-09-27 08:26:27 +000061# Note that filters are necessary for stderr results to filter out things that
62# always change, eg. process id numbers.
njn25e49d8e72002-09-23 09:36:25 +000063#
njn78660312005-06-29 04:02:24 +000064# Expected stdout (filtered) is kept in <test>.stdout.exp[0-9]* (can be more
nethercote4592db62004-02-29 01:31:09 +000065# than one expected output). It can be missing if it would be empty. Expected
sewardj79e88da2007-11-09 23:29:46 +000066# stderr (filtered) is kept in <test>.stderr.exp*. There must be at least
67# one stderr.exp* file.
njn25e49d8e72002-09-23 09:36:25 +000068#
nethercotec5e1d802004-11-18 12:48:17 +000069# The prerequisite command, if present, must return 0 otherwise the test is
njn0001fc32006-04-03 14:25:23 +000070# skipped. The post-test command, if present, must return 0 and its stdout
njn734b8052007-11-01 04:40:37 +000071# must match the expected stdout which is kept in <test>.post.exp[0-9]*.
nethercotec5e1d802004-11-18 12:48:17 +000072#
njn25e49d8e72002-09-23 09:36:25 +000073# If results don't match, the output can be found in <test>.std<strm>.out,
njn78660312005-06-29 04:02:24 +000074# and the diff between expected and actual in <test>.std<strm>.diff[0-9]*.
njn25e49d8e72002-09-23 09:36:25 +000075#
sewardj91368992006-05-26 00:13:21 +000076# Sometimes it is useful to run all the tests at a high sanity check
77# level or with arbitrary other flags. To make this simple, extra
78# options, applied to all tests run, are read from $EXTRA_REGTEST_OPTS,
79# and handed to valgrind prior to any other flags specified by the
80# .vgtest file.
81#
njn7358d522006-11-26 22:49:58 +000082# Some more notes on adding regression tests for a new tool are in
83# docs/xml/manual-writing-tools.xml.
njn25e49d8e72002-09-23 09:36:25 +000084#----------------------------------------------------------------------------
85
njn9fb16f52003-04-23 17:47:13 +000086use warnings;
njn25e49d8e72002-09-23 09:36:25 +000087use strict;
88
89#----------------------------------------------------------------------------
90# Global vars
91#----------------------------------------------------------------------------
njn3ed89602006-10-23 18:38:35 +000092my $usage="vg_regtest [--all, --valgrind, --valgrind-lib]\n";
njn25e49d8e72002-09-23 09:36:25 +000093
94my $tmp="vg_regtest.tmp.$$";
95
96# Test variables
97my $vgopts; # valgrind options
98my $prog; # test prog
99my $args; # test prog args
100my $stdout_filter; # filter program to run stdout results file through
101my $stderr_filter; # filter program to run stderr results file through
nethercotec5e1d802004-11-18 12:48:17 +0000102my $prereq; # prerequisite test to satisfy before running test
njn734b8052007-11-01 04:40:37 +0000103my $post; # check command after running test
nethercote64bc5af2004-11-18 11:57:00 +0000104my $cleanup; # cleanup command to run
njn25e49d8e72002-09-23 09:36:25 +0000105
106my @failures; # List of failed tests
107
njn9fb16f52003-04-23 17:47:13 +0000108my $num_tests_done = 0;
njn734b8052007-11-01 04:40:37 +0000109my %num_failures = (stderr => 0, stdout => 0, post => 0);
njn25e49d8e72002-09-23 09:36:25 +0000110
njn71fe3e62003-04-23 21:48:20 +0000111# Default valgrind to use is this build tree's (uninstalled) one
njn71fe3e62003-04-23 21:48:20 +0000112my $valgrind = "./coregrind/valgrind";
njn25e49d8e72002-09-23 09:36:25 +0000113
114chomp(my $tests_dir = `pwd`);
115
njn3ed89602006-10-23 18:38:35 +0000116my $valgrind_lib = "$tests_dir/.in_place";
117
njn25e49d8e72002-09-23 09:36:25 +0000118# default filter is the one named "filter_stderr" in the test's directory
119my $default_stderr_filter = "filter_stderr";
120
121
122#----------------------------------------------------------------------------
123# Process command line, setup
124#----------------------------------------------------------------------------
125
126# If $prog is a relative path, it prepends $dir to it. Useful for two reasons:
127#
128# 1. Can prepend "." onto programs to avoid trouble with users who don't have
129# "." in their path (by making $dir = ".")
130# 2. Can prepend the current dir to make the command absolute to avoid
131# subsequent trouble when we change directories.
132#
133# Also checks the program exists and is executable.
nethercotef4928da2004-06-15 10:54:40 +0000134sub validate_program ($$$$)
njn25e49d8e72002-09-23 09:36:25 +0000135{
nethercotef4928da2004-06-15 10:54:40 +0000136 my ($dir, $prog, $must_exist, $must_be_executable) = @_;
njn25e49d8e72002-09-23 09:36:25 +0000137
138 # If absolute path, leave it alone. If relative, make it
139 # absolute -- by prepending current dir -- so we can change
140 # dirs and still use it.
141 $prog = "$dir/$prog" if ($prog !~ /^\//);
nethercotef4928da2004-06-15 10:54:40 +0000142 if ($must_exist) {
143 (-f $prog) or die "vg_regtest: `$prog' not found or not a file ($dir)\n";
144 }
njn71fe3e62003-04-23 21:48:20 +0000145 if ($must_be_executable) {
nethercotef4928da2004-06-15 10:54:40 +0000146 (-x $prog) or die "vg_regtest: `$prog' not executable ($dir)\n";
njn71fe3e62003-04-23 21:48:20 +0000147 }
njn25e49d8e72002-09-23 09:36:25 +0000148
149 return $prog;
150}
151
152sub process_command_line()
153{
154 my $alldirs = 0;
155 my @fs;
156
157 for my $arg (@ARGV) {
158 if ($arg =~ /^-/) {
njnd8ced862003-04-08 00:47:05 +0000159 if ($arg =~ /^--all$/) {
njn25e49d8e72002-09-23 09:36:25 +0000160 $alldirs = 1;
161 } elsif ($arg =~ /^--valgrind=(.*)$/) {
162 $valgrind = $1;
njn3ed89602006-10-23 18:38:35 +0000163 } elsif ($arg =~ /^--valgrind-lib=(.*)$/) {
164 $valgrind_lib = $1;
njn25e49d8e72002-09-23 09:36:25 +0000165 } else {
166 die $usage;
167 }
168 } else {
169 push(@fs, $arg);
170 }
171 }
nethercotef4928da2004-06-15 10:54:40 +0000172 $valgrind = validate_program($tests_dir, $valgrind, 1, 0);
njn25e49d8e72002-09-23 09:36:25 +0000173
174 if ($alldirs) {
175 @fs = ();
176 foreach my $f (glob "*") {
177 push(@fs, $f) if (-d $f);
178 }
179 }
180
181 (0 != @fs) or die "No test files or directories specified\n";
182
183 return @fs;
184}
185
186#----------------------------------------------------------------------------
187# Read a .vgtest file
188#----------------------------------------------------------------------------
189sub read_vgtest_file($)
190{
191 my ($f) = @_;
192
193 # Defaults.
njn0001fc32006-04-03 14:25:23 +0000194 ($vgopts, $prog, $args) = ("", undef, "");
195 ($stdout_filter, $stderr_filter) = (undef, undef);
njn734b8052007-11-01 04:40:37 +0000196 ($prereq, $post, $cleanup) = (undef, undef, undef);
njn25e49d8e72002-09-23 09:36:25 +0000197
198 # Every test directory must have a "filter_stderr"
nethercotef4928da2004-06-15 10:54:40 +0000199 $stderr_filter = validate_program(".", $default_stderr_filter, 1, 1);
njn25e49d8e72002-09-23 09:36:25 +0000200
201 open(INPUTFILE, "< $f") || die "File $f not openable\n";
202
203 while (my $line = <INPUTFILE>) {
sewardjb5f6f512005-03-10 23:59:00 +0000204 if ($line =~ /^\s*#/ || $line =~ /^\s*$/) {
205 next;
206 } elsif ($line =~ /^\s*vgopts:\s*(.*)$/) {
njn25e49d8e72002-09-23 09:36:25 +0000207 $vgopts = $1;
208 } elsif ($line =~ /^\s*prog:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000209 $prog = validate_program(".", $1, 0, 0);
njn25e49d8e72002-09-23 09:36:25 +0000210 } elsif ($line =~ /^\s*args:\s*(.*)$/) {
211 $args = $1;
njn25e49d8e72002-09-23 09:36:25 +0000212 } elsif ($line =~ /^\s*stdout_filter:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000213 $stdout_filter = validate_program(".", $1, 1, 1);
njn25e49d8e72002-09-23 09:36:25 +0000214 } elsif ($line =~ /^\s*stderr_filter:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000215 $stderr_filter = validate_program(".", $1, 1, 1);
nethercotec5e1d802004-11-18 12:48:17 +0000216 } elsif ($line =~ /^\s*prereq:\s*(.*)$/) {
217 $prereq = $1;
njn734b8052007-11-01 04:40:37 +0000218 } elsif ($line =~ /^\s*post:\s*(.*)$/) {
219 $post = $1;
nethercote64bc5af2004-11-18 11:57:00 +0000220 } elsif ($line =~ /^\s*cleanup:\s*(.*)$/) {
221 $cleanup = $1;
njn25e49d8e72002-09-23 09:36:25 +0000222 } else {
223 die "Bad line in $f: $line\n";
224 }
225 }
226 close(INPUTFILE);
227
228 if (!defined $prog) {
nethercotef4928da2004-06-15 10:54:40 +0000229 $prog = ""; # allow no prog for testing error and --help cases
njn25e49d8e72002-09-23 09:36:25 +0000230 }
231}
232
233#----------------------------------------------------------------------------
234# Do one test
235#----------------------------------------------------------------------------
236# Since most of the program time is spent in system() calls, need this to
237# propagate a Ctrl-C enabling us to quit.
238sub mysystem($)
239{
njn734b8052007-11-01 04:40:37 +0000240 my $exit_code = system($_[0]);
241 ($exit_code == 2) and exit 1; # 2 is SIGINT
242 return $exit_code;
njn25e49d8e72002-09-23 09:36:25 +0000243}
244
nethercote137bc552003-11-14 17:47:54 +0000245# from a directory name like "/foo/cachesim/tests/" determine the tool name
246sub determine_tool()
njn25cac76cb2002-09-23 11:21:57 +0000247{
248 my $dir = `pwd`;
nethercote137bc552003-11-14 17:47:54 +0000249 $dir =~ /.*\/([^\/]+)\/tests.*/; # foo/tool_name/tests/foo
njn25cac76cb2002-09-23 11:21:57 +0000250 return $1;
251}
252
nethercote4592db62004-02-29 01:31:09 +0000253# Compare output against expected output; it should match at least one of
254# them.
255sub do_diffs($$$$)
256{
257 my ($fullname, $name, $mid, $f_exps) = @_;
258
259 for my $f_exp (@$f_exps) {
260 (-r $f_exp) or die "Could not read `$f_exp'\n";
261
262 my $n = "";
njn78660312005-06-29 04:02:24 +0000263 if ($f_exp =~ /.*\.exp(\d*)/) {
nethercote4592db62004-02-29 01:31:09 +0000264 $n = $1;
265 } else {
266 $n = "";
267 ($f_exp eq "/dev/null") or die "Unexpected .exp file: $f_exp\n";
268 }
269
sewardj2659b162006-10-17 02:24:51 +0000270 #print("diff $f_exp $name.$mid.out > $name.$mid.diff$n\n");
271 mysystem("diff $f_exp $name.$mid.out > $name.$mid.diff$n");
nethercote4592db62004-02-29 01:31:09 +0000272
273 if (not -s "$name.$mid.diff$n") {
274 # A match; remove .out and any previously created .diff files.
275 unlink("$name.$mid.out");
276 unlink(<$name.$mid.diff*>);
277 return;
278 }
279 }
280 # If we reach here, none of the .exp files matched.
281 print "*** $name failed ($mid) ***\n";
282 push(@failures, sprintf("%-40s ($mid)", "$fullname"));
283 $num_failures{$mid}++;
284}
285
njn25e49d8e72002-09-23 09:36:25 +0000286sub do_one_test($$)
287{
288 my ($dir, $vgtest) = @_;
289 $vgtest =~ /^(.*)\.vgtest/;
290 my $name = $1;
291 my $fullname = "$dir/$name";
292
sewardj91368992006-05-26 00:13:21 +0000293 # Pull any extra options (for example, --sanity-level=4)
294 # from $EXTRA_REGTEST_OPTS.
295 my $maybe_extraopts = $ENV{"EXTRA_REGTEST_OPTS"};
296 my $extraopts = $maybe_extraopts ? $maybe_extraopts : "";
297
njn25e49d8e72002-09-23 09:36:25 +0000298 read_vgtest_file($vgtest);
299
nethercotec5e1d802004-11-18 12:48:17 +0000300 if (defined $prereq) {
301 if (system("$prereq") != 0) {
302 printf("%-16s (skipping, prereq failed: $prereq)\n", "$name:");
nethercote781bed42004-10-19 16:56:41 +0000303 return;
304 }
nethercoteb1affa82004-01-19 19:14:18 +0000305 }
306
sewardj91368992006-05-26 00:13:21 +0000307 printf("%-16s valgrind $extraopts $vgopts $prog $args\n", "$name:");
njn25e49d8e72002-09-23 09:36:25 +0000308
nethercote137bc552003-11-14 17:47:54 +0000309 # Pass the appropriate --tool option for the directory (can be overridden
njnefc94ad2005-11-12 16:08:09 +0000310 # by an "args:" line, though). Set both VALGRIND_LIB and
311 # VALGRIND_LIB_INNER in case this Valgrind was configured with
312 # --enable-inner.
nethercote137bc552003-11-14 17:47:54 +0000313 my $tool=determine_tool();
njn3ed89602006-10-23 18:38:35 +0000314 mysystem("VALGRIND_LIB=$valgrind_lib VALGRIND_LIB_INNER=$valgrind_lib "
njnefc94ad2005-11-12 16:08:09 +0000315 . "$valgrind --command-line-only=yes --memcheck:leak-check=no "
sewardj91368992006-05-26 00:13:21 +0000316 . "--tool=$tool $extraopts $vgopts "
njnefc94ad2005-11-12 16:08:09 +0000317 . "$prog $args > $name.stdout.out 2> $name.stderr.out");
njn25e49d8e72002-09-23 09:36:25 +0000318
njn0001fc32006-04-03 14:25:23 +0000319 # Filter stdout
njn25e49d8e72002-09-23 09:36:25 +0000320 if (defined $stdout_filter) {
321 mysystem("$stdout_filter < $name.stdout.out > $tmp");
322 rename($tmp, "$name.stdout.out");
323 }
nethercote4592db62004-02-29 01:31:09 +0000324 # Find all the .stdout.exp files. If none, use /dev/null.
325 my @stdout_exps = <$name.stdout.exp*>;
326 @stdout_exps = ( "/dev/null" ) if (0 == scalar @stdout_exps);
njn0001fc32006-04-03 14:25:23 +0000327 do_diffs($fullname, $name, "stdout", \@stdout_exps);
njn25e49d8e72002-09-23 09:36:25 +0000328
njn0001fc32006-04-03 14:25:23 +0000329 # Filter stderr
330 mysystem("$stderr_filter < $name.stderr.out > $tmp");
331 rename($tmp, "$name.stderr.out");
sewardj79e88da2007-11-09 23:29:46 +0000332 # Find all the .stderr.exp files. At least one must exist.
nethercote4592db62004-02-29 01:31:09 +0000333 my @stderr_exps = <$name.stderr.exp*>;
sewardj79e88da2007-11-09 23:29:46 +0000334 (0 != scalar @stderr_exps) or die "Could not find `$name.stderr.exp*'\n";
nethercote4592db62004-02-29 01:31:09 +0000335 do_diffs($fullname, $name, "stderr", \@stderr_exps);
njn0001fc32006-04-03 14:25:23 +0000336
337 # Maybe do post-test check
njn734b8052007-11-01 04:40:37 +0000338 if (defined $post) {
339 if (mysystem("$post > $name.post.out") != 0) {
340 print("post check failed: $post\n");
341 $num_failures{"post"}++;
njn0001fc32006-04-03 14:25:23 +0000342 } else {
njn734b8052007-11-01 04:40:37 +0000343 # Find all the .post.exp files. If none, use /dev/null.
344 my @post_exps = <$name.post.exp*>;
345 @post_exps = ( "/dev/null" ) if (0 == scalar @post_exps);
346 do_diffs($fullname, $name, "post", \@post_exps);
njn0001fc32006-04-03 14:25:23 +0000347 }
348 }
nethercotec1f8ad92004-04-17 17:25:08 +0000349
nethercote64bc5af2004-11-18 11:57:00 +0000350 if (defined $cleanup) {
351 (system("$cleanup") == 0) or
352 print("(cleanup operation failed: $cleanup)\n");
nethercotec1f8ad92004-04-17 17:25:08 +0000353 }
354
njn9fb16f52003-04-23 17:47:13 +0000355 $num_tests_done++;
njn25e49d8e72002-09-23 09:36:25 +0000356}
357
358#----------------------------------------------------------------------------
njn25cac76cb2002-09-23 11:21:57 +0000359# Test one directory (and any subdirs)
njn25e49d8e72002-09-23 09:36:25 +0000360#----------------------------------------------------------------------------
njndb3c4692002-10-04 10:03:34 +0000361sub test_one_dir($$); # forward declaration
njn25cac76cb2002-09-23 11:21:57 +0000362
njndb3c4692002-10-04 10:03:34 +0000363sub test_one_dir($$)
njn25e49d8e72002-09-23 09:36:25 +0000364{
njndb3c4692002-10-04 10:03:34 +0000365 my ($dir, $prev_dirs) = @_;
njn25e49d8e72002-09-23 09:36:25 +0000366 $dir =~ s/\/$//; # trim a trailing '/'
367
nethercote362c0d22004-11-18 18:21:56 +0000368 # Ignore dirs into which we should not recurse.
mueller92f0b802003-11-19 00:55:32 +0000369 if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; }
njn25cac76cb2002-09-23 11:21:57 +0000370
njn52783ca2005-12-08 22:39:04 +0000371 (-x "$tests_dir/tests/cputest") or die
372 "vg_regtest: 'cputest' is missing. Did you forget to 'make check'?\n";
373
nethercote362c0d22004-11-18 18:21:56 +0000374 # Ignore any dir whose name matches that of an architecture which is not
375 # the architecture we are running on (eg. when running on x86, ignore ppc/
376 # directories).
377 # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256...
378 if (256 == system("$tests_dir/tests/cputest $dir")) { return; }
379
njn25e49d8e72002-09-23 09:36:25 +0000380 chdir($dir) or die "Could not change into $dir\n";
381
njn584eaac2002-10-04 15:30:48 +0000382 # Nb: Don't prepend a '/' to the base directory
383 my $full_dir = $prev_dirs . ($prev_dirs eq "" ? "" : "/") . $dir;
njndb3c4692002-10-04 10:03:34 +0000384 my $dashes = "-" x (50 - length $full_dir);
njn25cac76cb2002-09-23 11:21:57 +0000385
njndb3c4692002-10-04 10:03:34 +0000386 my @fs = glob "*";
njndb3c4692002-10-04 10:03:34 +0000387 my $found_tests = (0 != (grep { $_ =~ /\.vgtest$/ } @fs));
388
389 if ($found_tests) {
390 print "-- Running tests in $full_dir $dashes\n";
njndb3c4692002-10-04 10:03:34 +0000391 }
njn25cac76cb2002-09-23 11:21:57 +0000392 foreach my $f (@fs) {
393 if (-d $f) {
njndb3c4692002-10-04 10:03:34 +0000394 test_one_dir($f, $full_dir);
njn25cac76cb2002-09-23 11:21:57 +0000395 } elsif ($f =~ /\.vgtest$/) {
njndb3c4692002-10-04 10:03:34 +0000396 do_one_test($full_dir, $f);
njn25cac76cb2002-09-23 11:21:57 +0000397 }
njn25e49d8e72002-09-23 09:36:25 +0000398 }
njndb3c4692002-10-04 10:03:34 +0000399 if ($found_tests) {
400 print "-- Finished tests in $full_dir $dashes\n";
401 }
402
njn25e49d8e72002-09-23 09:36:25 +0000403 chdir("..");
njn25e49d8e72002-09-23 09:36:25 +0000404}
405
406#----------------------------------------------------------------------------
407# Summarise results
408#----------------------------------------------------------------------------
njn9fb16f52003-04-23 17:47:13 +0000409sub plural($)
410{
411 return ( $_[0] == 1 ? "" : "s" );
412}
413
njn25e49d8e72002-09-23 09:36:25 +0000414sub summarise_results
415{
njnd8ced862003-04-08 00:47:05 +0000416 my $x = ( $num_tests_done == 1 ? "test" : "tests" );
njnd8ced862003-04-08 00:47:05 +0000417
njn0001fc32006-04-03 14:25:23 +0000418 printf("\n== %d test%s, %d stderr failure%s, %d stdout failure%s, "
njn734b8052007-11-01 04:40:37 +0000419 . "%d post failure%s ==\n",
njn9fb16f52003-04-23 17:47:13 +0000420 $num_tests_done, plural($num_tests_done),
njn0001fc32006-04-03 14:25:23 +0000421 $num_failures{"stderr"}, plural($num_failures{"stderr"}),
422 $num_failures{"stdout"}, plural($num_failures{"stdout"}),
njn734b8052007-11-01 04:40:37 +0000423 $num_failures{"post"}, plural($num_failures{"post"}));
njn9fb16f52003-04-23 17:47:13 +0000424
425 foreach my $failure (@failures) {
426 print "$failure\n";
njn25e49d8e72002-09-23 09:36:25 +0000427 }
njn9fb16f52003-04-23 17:47:13 +0000428 print "\n";
njn25e49d8e72002-09-23 09:36:25 +0000429}
430
431#----------------------------------------------------------------------------
432# main(), sort of
433#----------------------------------------------------------------------------
sewardj91368992006-05-26 00:13:21 +0000434sub warn_about_EXTRA_REGTEST_OPTS()
435{
436 print "WARNING: \$EXTRA_REGTEST_OPTS is set. You probably don't want\n";
437 print "to run the regression tests with it set, unless you are doing some\n";
438 print "strange experiment, and/or you really know what you are doing.\n";
439 print "\n";
440}
njn25e49d8e72002-09-23 09:36:25 +0000441
daywalkerbb936982003-04-23 16:52:06 +0000442# nuke VALGRIND_OPTS
443$ENV{"VALGRIND_OPTS"} = "";
njn25e49d8e72002-09-23 09:36:25 +0000444
sewardj91368992006-05-26 00:13:21 +0000445if ($ENV{"EXTRA_REGTEST_OPTS"}) {
446 print "\n";
447 warn_about_EXTRA_REGTEST_OPTS();
448}
449
njn25e49d8e72002-09-23 09:36:25 +0000450my @fs = process_command_line();
451foreach my $f (@fs) {
452 if (-d $f) {
njn584eaac2002-10-04 15:30:48 +0000453 test_one_dir($f, "");
njn25e49d8e72002-09-23 09:36:25 +0000454 } else {
455 # Allow the .vgtest suffix to be given or omitted
456 if ($f =~ /.vgtest$/ && -r $f) {
457 # do nothing
458 } elsif (-r "$f.vgtest") {
459 $f = "$f.vgtest";
460 } else {
461 die "`$f' neither a directory nor a readable test file/name\n"
462 }
463 my $dir = `dirname $f`; chomp $dir;
464 my $file = `basename $f`; chomp $file;
465 chdir($dir) or die "Could not change into $dir\n";
466 do_one_test($dir, $file);
467 chdir($tests_dir);
468 }
469}
470summarise_results();
471
sewardj91368992006-05-26 00:13:21 +0000472if ($ENV{"EXTRA_REGTEST_OPTS"}) {
473 warn_about_EXTRA_REGTEST_OPTS();
474}
475
njn0001fc32006-04-03 14:25:23 +0000476if (0 == $num_failures{"stdout"} &&
477 0 == $num_failures{"stderr"} &&
njn734b8052007-11-01 04:40:37 +0000478 0 == $num_failures{"post"}) {
nethercoteab422192004-03-01 08:27:37 +0000479 exit 0;
480} else {
481 exit 1;
482}
483
njnc2e7f482002-09-27 08:44:17 +0000484##--------------------------------------------------------------------##
485##--- end vg_regtest ---##
486##--------------------------------------------------------------------##