blob: bee87fc9c996f5eb82dc245c128268ce18aa44ed [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#
njn1ee25f02008-02-27 18:10:19 +000064# Expected stdout (filtered) is kept in <test>.stdout.exp* (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
njne8ffe522008-03-02 22:48:14 +000067# one stderr.exp* file. Any .exp* file that ends in '~' or '#' is ignored;
68# this is because Emacs creates temporary files of these names.
njn25e49d8e72002-09-23 09:36:25 +000069#
nethercotec5e1d802004-11-18 12:48:17 +000070# The prerequisite command, if present, must return 0 otherwise the test is
njn0001fc32006-04-03 14:25:23 +000071# skipped. The post-test command, if present, must return 0 and its stdout
njn1ee25f02008-02-27 18:10:19 +000072# must match the expected stdout which is kept in <test>.post.exp*.
nethercotec5e1d802004-11-18 12:48:17 +000073#
njn25e49d8e72002-09-23 09:36:25 +000074# If results don't match, the output can be found in <test>.std<strm>.out,
njn1ee25f02008-02-27 18:10:19 +000075# and the diff between expected and actual in <test>.std<strm>.diff*.
njn25e49d8e72002-09-23 09:36:25 +000076#
sewardj91368992006-05-26 00:13:21 +000077# Sometimes it is useful to run all the tests at a high sanity check
78# level or with arbitrary other flags. To make this simple, extra
79# options, applied to all tests run, are read from $EXTRA_REGTEST_OPTS,
80# and handed to valgrind prior to any other flags specified by the
81# .vgtest file.
82#
njn7358d522006-11-26 22:49:58 +000083# Some more notes on adding regression tests for a new tool are in
84# docs/xml/manual-writing-tools.xml.
njn25e49d8e72002-09-23 09:36:25 +000085#----------------------------------------------------------------------------
86
njn9fb16f52003-04-23 17:47:13 +000087use warnings;
njn25e49d8e72002-09-23 09:36:25 +000088use strict;
89
90#----------------------------------------------------------------------------
91# Global vars
92#----------------------------------------------------------------------------
sewardja8162b22007-11-30 21:24:05 +000093my $usage="\n"
94 . "Usage:\n"
95 . " vg_regtest [--all, --valgrind, --valgrind-lib]\n"
96 . " Use EXTRA_REGTEST_OPTS to supply extra args for all tests\n"
97 . "\n";
njn25e49d8e72002-09-23 09:36:25 +000098
99my $tmp="vg_regtest.tmp.$$";
100
101# Test variables
102my $vgopts; # valgrind options
103my $prog; # test prog
104my $args; # test prog args
105my $stdout_filter; # filter program to run stdout results file through
106my $stderr_filter; # filter program to run stderr results file through
nethercotec5e1d802004-11-18 12:48:17 +0000107my $prereq; # prerequisite test to satisfy before running test
njn734b8052007-11-01 04:40:37 +0000108my $post; # check command after running test
nethercote64bc5af2004-11-18 11:57:00 +0000109my $cleanup; # cleanup command to run
njn25e49d8e72002-09-23 09:36:25 +0000110
111my @failures; # List of failed tests
112
njn9fb16f52003-04-23 17:47:13 +0000113my $num_tests_done = 0;
njn734b8052007-11-01 04:40:37 +0000114my %num_failures = (stderr => 0, stdout => 0, post => 0);
njn25e49d8e72002-09-23 09:36:25 +0000115
njn71fe3e62003-04-23 21:48:20 +0000116# Default valgrind to use is this build tree's (uninstalled) one
njn71fe3e62003-04-23 21:48:20 +0000117my $valgrind = "./coregrind/valgrind";
njn25e49d8e72002-09-23 09:36:25 +0000118
119chomp(my $tests_dir = `pwd`);
120
njn3ed89602006-10-23 18:38:35 +0000121my $valgrind_lib = "$tests_dir/.in_place";
122
njn25e49d8e72002-09-23 09:36:25 +0000123# default filter is the one named "filter_stderr" in the test's directory
124my $default_stderr_filter = "filter_stderr";
125
126
127#----------------------------------------------------------------------------
128# Process command line, setup
129#----------------------------------------------------------------------------
130
131# If $prog is a relative path, it prepends $dir to it. Useful for two reasons:
132#
133# 1. Can prepend "." onto programs to avoid trouble with users who don't have
134# "." in their path (by making $dir = ".")
135# 2. Can prepend the current dir to make the command absolute to avoid
136# subsequent trouble when we change directories.
137#
138# Also checks the program exists and is executable.
nethercotef4928da2004-06-15 10:54:40 +0000139sub validate_program ($$$$)
njn25e49d8e72002-09-23 09:36:25 +0000140{
nethercotef4928da2004-06-15 10:54:40 +0000141 my ($dir, $prog, $must_exist, $must_be_executable) = @_;
njn25e49d8e72002-09-23 09:36:25 +0000142
143 # If absolute path, leave it alone. If relative, make it
144 # absolute -- by prepending current dir -- so we can change
145 # dirs and still use it.
146 $prog = "$dir/$prog" if ($prog !~ /^\//);
nethercotef4928da2004-06-15 10:54:40 +0000147 if ($must_exist) {
148 (-f $prog) or die "vg_regtest: `$prog' not found or not a file ($dir)\n";
149 }
njn71fe3e62003-04-23 21:48:20 +0000150 if ($must_be_executable) {
nethercotef4928da2004-06-15 10:54:40 +0000151 (-x $prog) or die "vg_regtest: `$prog' not executable ($dir)\n";
njn71fe3e62003-04-23 21:48:20 +0000152 }
njn25e49d8e72002-09-23 09:36:25 +0000153
154 return $prog;
155}
156
157sub process_command_line()
158{
159 my $alldirs = 0;
160 my @fs;
161
162 for my $arg (@ARGV) {
163 if ($arg =~ /^-/) {
njnd8ced862003-04-08 00:47:05 +0000164 if ($arg =~ /^--all$/) {
njn25e49d8e72002-09-23 09:36:25 +0000165 $alldirs = 1;
166 } elsif ($arg =~ /^--valgrind=(.*)$/) {
167 $valgrind = $1;
njn3ed89602006-10-23 18:38:35 +0000168 } elsif ($arg =~ /^--valgrind-lib=(.*)$/) {
169 $valgrind_lib = $1;
njn25e49d8e72002-09-23 09:36:25 +0000170 } else {
171 die $usage;
172 }
173 } else {
174 push(@fs, $arg);
175 }
176 }
nethercotef4928da2004-06-15 10:54:40 +0000177 $valgrind = validate_program($tests_dir, $valgrind, 1, 0);
njn25e49d8e72002-09-23 09:36:25 +0000178
179 if ($alldirs) {
180 @fs = ();
181 foreach my $f (glob "*") {
182 push(@fs, $f) if (-d $f);
183 }
184 }
185
186 (0 != @fs) or die "No test files or directories specified\n";
187
188 return @fs;
189}
190
191#----------------------------------------------------------------------------
192# Read a .vgtest file
193#----------------------------------------------------------------------------
194sub read_vgtest_file($)
195{
196 my ($f) = @_;
197
198 # Defaults.
njn0001fc32006-04-03 14:25:23 +0000199 ($vgopts, $prog, $args) = ("", undef, "");
200 ($stdout_filter, $stderr_filter) = (undef, undef);
njn734b8052007-11-01 04:40:37 +0000201 ($prereq, $post, $cleanup) = (undef, undef, undef);
njn25e49d8e72002-09-23 09:36:25 +0000202
203 # Every test directory must have a "filter_stderr"
nethercotef4928da2004-06-15 10:54:40 +0000204 $stderr_filter = validate_program(".", $default_stderr_filter, 1, 1);
njn25e49d8e72002-09-23 09:36:25 +0000205
206 open(INPUTFILE, "< $f") || die "File $f not openable\n";
207
208 while (my $line = <INPUTFILE>) {
sewardjb5f6f512005-03-10 23:59:00 +0000209 if ($line =~ /^\s*#/ || $line =~ /^\s*$/) {
210 next;
211 } elsif ($line =~ /^\s*vgopts:\s*(.*)$/) {
njn25e49d8e72002-09-23 09:36:25 +0000212 $vgopts = $1;
213 } elsif ($line =~ /^\s*prog:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000214 $prog = validate_program(".", $1, 0, 0);
njn25e49d8e72002-09-23 09:36:25 +0000215 } elsif ($line =~ /^\s*args:\s*(.*)$/) {
216 $args = $1;
njn25e49d8e72002-09-23 09:36:25 +0000217 } elsif ($line =~ /^\s*stdout_filter:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000218 $stdout_filter = validate_program(".", $1, 1, 1);
njn25e49d8e72002-09-23 09:36:25 +0000219 } elsif ($line =~ /^\s*stderr_filter:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000220 $stderr_filter = validate_program(".", $1, 1, 1);
nethercotec5e1d802004-11-18 12:48:17 +0000221 } elsif ($line =~ /^\s*prereq:\s*(.*)$/) {
222 $prereq = $1;
njn734b8052007-11-01 04:40:37 +0000223 } elsif ($line =~ /^\s*post:\s*(.*)$/) {
224 $post = $1;
nethercote64bc5af2004-11-18 11:57:00 +0000225 } elsif ($line =~ /^\s*cleanup:\s*(.*)$/) {
226 $cleanup = $1;
njn25e49d8e72002-09-23 09:36:25 +0000227 } else {
228 die "Bad line in $f: $line\n";
229 }
230 }
231 close(INPUTFILE);
232
233 if (!defined $prog) {
nethercotef4928da2004-06-15 10:54:40 +0000234 $prog = ""; # allow no prog for testing error and --help cases
njn25e49d8e72002-09-23 09:36:25 +0000235 }
236}
237
238#----------------------------------------------------------------------------
239# Do one test
240#----------------------------------------------------------------------------
241# Since most of the program time is spent in system() calls, need this to
242# propagate a Ctrl-C enabling us to quit.
243sub mysystem($)
244{
njn734b8052007-11-01 04:40:37 +0000245 my $exit_code = system($_[0]);
246 ($exit_code == 2) and exit 1; # 2 is SIGINT
247 return $exit_code;
njn25e49d8e72002-09-23 09:36:25 +0000248}
249
nethercote137bc552003-11-14 17:47:54 +0000250# from a directory name like "/foo/cachesim/tests/" determine the tool name
251sub determine_tool()
njn25cac76cb2002-09-23 11:21:57 +0000252{
253 my $dir = `pwd`;
nethercote137bc552003-11-14 17:47:54 +0000254 $dir =~ /.*\/([^\/]+)\/tests.*/; # foo/tool_name/tests/foo
njn25cac76cb2002-09-23 11:21:57 +0000255 return $1;
256}
257
nethercote4592db62004-02-29 01:31:09 +0000258# Compare output against expected output; it should match at least one of
259# them.
260sub do_diffs($$$$)
261{
262 my ($fullname, $name, $mid, $f_exps) = @_;
263
264 for my $f_exp (@$f_exps) {
265 (-r $f_exp) or die "Could not read `$f_exp'\n";
266
njne8ffe522008-03-02 22:48:14 +0000267 # Emacs produces temporary files that end in '~' and '#'. We ignore
268 # these.
269 if ($f_exp !~ /[~#]$/) {
270 # $n is the (optional) suffix after the ".exp"; we tack it onto
271 # the ".diff" file.
272 my $n = "";
273 if ($f_exp =~ /.*\.exp(.*)$/) {
274 $n = $1;
275 } else {
276 $n = "";
277 ($f_exp eq "/dev/null") or die "Unexpected .exp file: $f_exp\n";
278 }
nethercote4592db62004-02-29 01:31:09 +0000279
njn0d2e58f2009-02-25 04:57:56 +0000280 mysystem("@DIFF@ $f_exp $name.$mid.out > $name.$mid.diff$n");
nethercote4592db62004-02-29 01:31:09 +0000281
njne8ffe522008-03-02 22:48:14 +0000282 if (not -s "$name.$mid.diff$n") {
283 # A match; remove .out and any previously created .diff files.
284 unlink("$name.$mid.out");
285 unlink(<$name.$mid.diff*>);
286 return;
287 }
nethercote4592db62004-02-29 01:31:09 +0000288 }
289 }
290 # If we reach here, none of the .exp files matched.
291 print "*** $name failed ($mid) ***\n";
292 push(@failures, sprintf("%-40s ($mid)", "$fullname"));
293 $num_failures{$mid}++;
294}
295
njn25e49d8e72002-09-23 09:36:25 +0000296sub do_one_test($$)
297{
298 my ($dir, $vgtest) = @_;
299 $vgtest =~ /^(.*)\.vgtest/;
300 my $name = $1;
301 my $fullname = "$dir/$name";
302
sewardj91368992006-05-26 00:13:21 +0000303 # Pull any extra options (for example, --sanity-level=4)
304 # from $EXTRA_REGTEST_OPTS.
305 my $maybe_extraopts = $ENV{"EXTRA_REGTEST_OPTS"};
306 my $extraopts = $maybe_extraopts ? $maybe_extraopts : "";
307
njn25e49d8e72002-09-23 09:36:25 +0000308 read_vgtest_file($vgtest);
309
nethercotec5e1d802004-11-18 12:48:17 +0000310 if (defined $prereq) {
311 if (system("$prereq") != 0) {
312 printf("%-16s (skipping, prereq failed: $prereq)\n", "$name:");
nethercote781bed42004-10-19 16:56:41 +0000313 return;
314 }
nethercoteb1affa82004-01-19 19:14:18 +0000315 }
316
sewardj91368992006-05-26 00:13:21 +0000317 printf("%-16s valgrind $extraopts $vgopts $prog $args\n", "$name:");
njn25e49d8e72002-09-23 09:36:25 +0000318
nethercote137bc552003-11-14 17:47:54 +0000319 # Pass the appropriate --tool option for the directory (can be overridden
njnefc94ad2005-11-12 16:08:09 +0000320 # by an "args:" line, though). Set both VALGRIND_LIB and
321 # VALGRIND_LIB_INNER in case this Valgrind was configured with
322 # --enable-inner.
nethercote137bc552003-11-14 17:47:54 +0000323 my $tool=determine_tool();
njn3ed89602006-10-23 18:38:35 +0000324 mysystem("VALGRIND_LIB=$valgrind_lib VALGRIND_LIB_INNER=$valgrind_lib "
njnefc94ad2005-11-12 16:08:09 +0000325 . "$valgrind --command-line-only=yes --memcheck:leak-check=no "
sewardj91368992006-05-26 00:13:21 +0000326 . "--tool=$tool $extraopts $vgopts "
njnefc94ad2005-11-12 16:08:09 +0000327 . "$prog $args > $name.stdout.out 2> $name.stderr.out");
njn25e49d8e72002-09-23 09:36:25 +0000328
njn0001fc32006-04-03 14:25:23 +0000329 # Filter stdout
njn25e49d8e72002-09-23 09:36:25 +0000330 if (defined $stdout_filter) {
331 mysystem("$stdout_filter < $name.stdout.out > $tmp");
332 rename($tmp, "$name.stdout.out");
333 }
nethercote4592db62004-02-29 01:31:09 +0000334 # Find all the .stdout.exp files. If none, use /dev/null.
335 my @stdout_exps = <$name.stdout.exp*>;
336 @stdout_exps = ( "/dev/null" ) if (0 == scalar @stdout_exps);
njn0001fc32006-04-03 14:25:23 +0000337 do_diffs($fullname, $name, "stdout", \@stdout_exps);
njn25e49d8e72002-09-23 09:36:25 +0000338
njn0001fc32006-04-03 14:25:23 +0000339 # Filter stderr
340 mysystem("$stderr_filter < $name.stderr.out > $tmp");
341 rename($tmp, "$name.stderr.out");
sewardj79e88da2007-11-09 23:29:46 +0000342 # Find all the .stderr.exp files. At least one must exist.
nethercote4592db62004-02-29 01:31:09 +0000343 my @stderr_exps = <$name.stderr.exp*>;
sewardj79e88da2007-11-09 23:29:46 +0000344 (0 != scalar @stderr_exps) or die "Could not find `$name.stderr.exp*'\n";
nethercote4592db62004-02-29 01:31:09 +0000345 do_diffs($fullname, $name, "stderr", \@stderr_exps);
njn0001fc32006-04-03 14:25:23 +0000346
347 # Maybe do post-test check
njn734b8052007-11-01 04:40:37 +0000348 if (defined $post) {
349 if (mysystem("$post > $name.post.out") != 0) {
350 print("post check failed: $post\n");
351 $num_failures{"post"}++;
njn0001fc32006-04-03 14:25:23 +0000352 } else {
njn734b8052007-11-01 04:40:37 +0000353 # Find all the .post.exp files. If none, use /dev/null.
354 my @post_exps = <$name.post.exp*>;
355 @post_exps = ( "/dev/null" ) if (0 == scalar @post_exps);
356 do_diffs($fullname, $name, "post", \@post_exps);
njn0001fc32006-04-03 14:25:23 +0000357 }
358 }
nethercotec1f8ad92004-04-17 17:25:08 +0000359
nethercote64bc5af2004-11-18 11:57:00 +0000360 if (defined $cleanup) {
361 (system("$cleanup") == 0) or
362 print("(cleanup operation failed: $cleanup)\n");
nethercotec1f8ad92004-04-17 17:25:08 +0000363 }
364
njn9fb16f52003-04-23 17:47:13 +0000365 $num_tests_done++;
njn25e49d8e72002-09-23 09:36:25 +0000366}
367
368#----------------------------------------------------------------------------
njn25cac76cb2002-09-23 11:21:57 +0000369# Test one directory (and any subdirs)
njn25e49d8e72002-09-23 09:36:25 +0000370#----------------------------------------------------------------------------
njndb3c4692002-10-04 10:03:34 +0000371sub test_one_dir($$); # forward declaration
njn25cac76cb2002-09-23 11:21:57 +0000372
njndb3c4692002-10-04 10:03:34 +0000373sub test_one_dir($$)
njn25e49d8e72002-09-23 09:36:25 +0000374{
njndb3c4692002-10-04 10:03:34 +0000375 my ($dir, $prev_dirs) = @_;
njn25e49d8e72002-09-23 09:36:25 +0000376 $dir =~ s/\/$//; # trim a trailing '/'
377
nethercote362c0d22004-11-18 18:21:56 +0000378 # Ignore dirs into which we should not recurse.
mueller92f0b802003-11-19 00:55:32 +0000379 if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; }
njn25cac76cb2002-09-23 11:21:57 +0000380
njn107bc572009-02-16 00:42:10 +0000381 (-x "$tests_dir/tests/arch_test") or die
382 "vg_regtest: 'arch_test' is missing. Did you forget to 'make check'?\n";
njn52783ca2005-12-08 22:39:04 +0000383
nethercote362c0d22004-11-18 18:21:56 +0000384 # Ignore any dir whose name matches that of an architecture which is not
njn107bc572009-02-16 00:42:10 +0000385 # the architecture we are running on. Eg. when running on x86, ignore
386 # ppc/ directories ('arch_test' returns 1 for this case). Likewise for
387 # the OS and platform.
nethercote362c0d22004-11-18 18:21:56 +0000388 # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256...
njn107bc572009-02-16 00:42:10 +0000389 if (256 == system( "$tests_dir/tests/arch_test $dir")) { return; }
390 if (256 == system("sh $tests_dir/tests/os_test $dir")) { return; }
391 if ($dir =~ /(\w+)-(\w+)/ &&
392 256 == system("sh $tests_dir/tests/platform_test $1 $2")) { return; }
nethercote362c0d22004-11-18 18:21:56 +0000393
njn25e49d8e72002-09-23 09:36:25 +0000394 chdir($dir) or die "Could not change into $dir\n";
395
njn584eaac2002-10-04 15:30:48 +0000396 # Nb: Don't prepend a '/' to the base directory
397 my $full_dir = $prev_dirs . ($prev_dirs eq "" ? "" : "/") . $dir;
njndb3c4692002-10-04 10:03:34 +0000398 my $dashes = "-" x (50 - length $full_dir);
njn25cac76cb2002-09-23 11:21:57 +0000399
njndb3c4692002-10-04 10:03:34 +0000400 my @fs = glob "*";
njndb3c4692002-10-04 10:03:34 +0000401 my $found_tests = (0 != (grep { $_ =~ /\.vgtest$/ } @fs));
402
403 if ($found_tests) {
404 print "-- Running tests in $full_dir $dashes\n";
njndb3c4692002-10-04 10:03:34 +0000405 }
njn25cac76cb2002-09-23 11:21:57 +0000406 foreach my $f (@fs) {
407 if (-d $f) {
njndb3c4692002-10-04 10:03:34 +0000408 test_one_dir($f, $full_dir);
njn25cac76cb2002-09-23 11:21:57 +0000409 } elsif ($f =~ /\.vgtest$/) {
njndb3c4692002-10-04 10:03:34 +0000410 do_one_test($full_dir, $f);
njn25cac76cb2002-09-23 11:21:57 +0000411 }
njn25e49d8e72002-09-23 09:36:25 +0000412 }
njndb3c4692002-10-04 10:03:34 +0000413 if ($found_tests) {
414 print "-- Finished tests in $full_dir $dashes\n";
415 }
416
njn25e49d8e72002-09-23 09:36:25 +0000417 chdir("..");
njn25e49d8e72002-09-23 09:36:25 +0000418}
419
420#----------------------------------------------------------------------------
421# Summarise results
422#----------------------------------------------------------------------------
njn9fb16f52003-04-23 17:47:13 +0000423sub plural($)
424{
425 return ( $_[0] == 1 ? "" : "s" );
426}
427
njn25e49d8e72002-09-23 09:36:25 +0000428sub summarise_results
429{
njnd8ced862003-04-08 00:47:05 +0000430 my $x = ( $num_tests_done == 1 ? "test" : "tests" );
njnd8ced862003-04-08 00:47:05 +0000431
njn0001fc32006-04-03 14:25:23 +0000432 printf("\n== %d test%s, %d stderr failure%s, %d stdout failure%s, "
njn734b8052007-11-01 04:40:37 +0000433 . "%d post failure%s ==\n",
njn9fb16f52003-04-23 17:47:13 +0000434 $num_tests_done, plural($num_tests_done),
njn0001fc32006-04-03 14:25:23 +0000435 $num_failures{"stderr"}, plural($num_failures{"stderr"}),
436 $num_failures{"stdout"}, plural($num_failures{"stdout"}),
njn734b8052007-11-01 04:40:37 +0000437 $num_failures{"post"}, plural($num_failures{"post"}));
njn9fb16f52003-04-23 17:47:13 +0000438
439 foreach my $failure (@failures) {
440 print "$failure\n";
njn25e49d8e72002-09-23 09:36:25 +0000441 }
njn9fb16f52003-04-23 17:47:13 +0000442 print "\n";
njn25e49d8e72002-09-23 09:36:25 +0000443}
444
445#----------------------------------------------------------------------------
446# main(), sort of
447#----------------------------------------------------------------------------
sewardj91368992006-05-26 00:13:21 +0000448sub warn_about_EXTRA_REGTEST_OPTS()
449{
450 print "WARNING: \$EXTRA_REGTEST_OPTS is set. You probably don't want\n";
451 print "to run the regression tests with it set, unless you are doing some\n";
452 print "strange experiment, and/or you really know what you are doing.\n";
453 print "\n";
454}
njn25e49d8e72002-09-23 09:36:25 +0000455
daywalkerbb936982003-04-23 16:52:06 +0000456# nuke VALGRIND_OPTS
457$ENV{"VALGRIND_OPTS"} = "";
njn25e49d8e72002-09-23 09:36:25 +0000458
sewardj91368992006-05-26 00:13:21 +0000459if ($ENV{"EXTRA_REGTEST_OPTS"}) {
460 print "\n";
461 warn_about_EXTRA_REGTEST_OPTS();
462}
463
njn25e49d8e72002-09-23 09:36:25 +0000464my @fs = process_command_line();
465foreach my $f (@fs) {
466 if (-d $f) {
njn584eaac2002-10-04 15:30:48 +0000467 test_one_dir($f, "");
njn25e49d8e72002-09-23 09:36:25 +0000468 } else {
469 # Allow the .vgtest suffix to be given or omitted
470 if ($f =~ /.vgtest$/ && -r $f) {
471 # do nothing
472 } elsif (-r "$f.vgtest") {
473 $f = "$f.vgtest";
474 } else {
475 die "`$f' neither a directory nor a readable test file/name\n"
476 }
477 my $dir = `dirname $f`; chomp $dir;
478 my $file = `basename $f`; chomp $file;
479 chdir($dir) or die "Could not change into $dir\n";
480 do_one_test($dir, $file);
481 chdir($tests_dir);
482 }
483}
484summarise_results();
485
sewardj91368992006-05-26 00:13:21 +0000486if ($ENV{"EXTRA_REGTEST_OPTS"}) {
487 warn_about_EXTRA_REGTEST_OPTS();
488}
489
njn0001fc32006-04-03 14:25:23 +0000490if (0 == $num_failures{"stdout"} &&
491 0 == $num_failures{"stderr"} &&
njn734b8052007-11-01 04:40:37 +0000492 0 == $num_failures{"post"}) {
nethercoteab422192004-03-01 08:27:37 +0000493 exit 0;
494} else {
495 exit 1;
496}
497
njnc2e7f482002-09-27 08:44:17 +0000498##--------------------------------------------------------------------##
499##--- end vg_regtest ---##
500##--------------------------------------------------------------------##