blob: 8bcb050de290a8fbdabce1667133c279e6d329fe [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#
70# If results don't match, the output can be found in <test>.std<strm>.out,
njn1ee25f02008-02-27 18:10:19 +000071# and the diff between expected and actual in <test>.std<strm>.diff*.
njn25e49d8e72002-09-23 09:36:25 +000072#
njn61485ab2009-03-04 04:15:16 +000073# The prerequisite command, if present, works like this:
74# - if it returns 0 the test is run
75# - if it returns 1 the test is skipped
76# - if it returns anything else the script aborts.
77# The idea here is results other than 0 or 1 are likely to be due to
78# problems with the commands, and you don't want to conflate them with the 1
79# case, which would happen if you just tested for zero or non-zero.
80#
81# The post-test command, if present, must return 0 and its stdout must match
82# the expected stdout which is kept in <test>.post.exp*.
83#
sewardj91368992006-05-26 00:13:21 +000084# Sometimes it is useful to run all the tests at a high sanity check
85# level or with arbitrary other flags. To make this simple, extra
86# options, applied to all tests run, are read from $EXTRA_REGTEST_OPTS,
87# and handed to valgrind prior to any other flags specified by the
88# .vgtest file.
89#
njn7358d522006-11-26 22:49:58 +000090# Some more notes on adding regression tests for a new tool are in
91# docs/xml/manual-writing-tools.xml.
njn25e49d8e72002-09-23 09:36:25 +000092#----------------------------------------------------------------------------
93
njn9fb16f52003-04-23 17:47:13 +000094use warnings;
njn25e49d8e72002-09-23 09:36:25 +000095use strict;
96
97#----------------------------------------------------------------------------
98# Global vars
99#----------------------------------------------------------------------------
sewardja8162b22007-11-30 21:24:05 +0000100my $usage="\n"
101 . "Usage:\n"
102 . " vg_regtest [--all, --valgrind, --valgrind-lib]\n"
103 . " Use EXTRA_REGTEST_OPTS to supply extra args for all tests\n"
104 . "\n";
njn25e49d8e72002-09-23 09:36:25 +0000105
106my $tmp="vg_regtest.tmp.$$";
107
108# Test variables
109my $vgopts; # valgrind options
110my $prog; # test prog
111my $args; # test prog args
112my $stdout_filter; # filter program to run stdout results file through
113my $stderr_filter; # filter program to run stderr results file through
nethercotec5e1d802004-11-18 12:48:17 +0000114my $prereq; # prerequisite test to satisfy before running test
njn734b8052007-11-01 04:40:37 +0000115my $post; # check command after running test
nethercote64bc5af2004-11-18 11:57:00 +0000116my $cleanup; # cleanup command to run
njn25e49d8e72002-09-23 09:36:25 +0000117
118my @failures; # List of failed tests
119
njn9fb16f52003-04-23 17:47:13 +0000120my $num_tests_done = 0;
njn734b8052007-11-01 04:40:37 +0000121my %num_failures = (stderr => 0, stdout => 0, post => 0);
njn25e49d8e72002-09-23 09:36:25 +0000122
njn71fe3e62003-04-23 21:48:20 +0000123# Default valgrind to use is this build tree's (uninstalled) one
njn71fe3e62003-04-23 21:48:20 +0000124my $valgrind = "./coregrind/valgrind";
njn25e49d8e72002-09-23 09:36:25 +0000125
126chomp(my $tests_dir = `pwd`);
127
njn3ed89602006-10-23 18:38:35 +0000128my $valgrind_lib = "$tests_dir/.in_place";
129
njn25e49d8e72002-09-23 09:36:25 +0000130# default filter is the one named "filter_stderr" in the test's directory
131my $default_stderr_filter = "filter_stderr";
132
133
134#----------------------------------------------------------------------------
135# Process command line, setup
136#----------------------------------------------------------------------------
137
138# If $prog is a relative path, it prepends $dir to it. Useful for two reasons:
139#
140# 1. Can prepend "." onto programs to avoid trouble with users who don't have
141# "." in their path (by making $dir = ".")
142# 2. Can prepend the current dir to make the command absolute to avoid
143# subsequent trouble when we change directories.
144#
145# Also checks the program exists and is executable.
nethercotef4928da2004-06-15 10:54:40 +0000146sub validate_program ($$$$)
njn25e49d8e72002-09-23 09:36:25 +0000147{
nethercotef4928da2004-06-15 10:54:40 +0000148 my ($dir, $prog, $must_exist, $must_be_executable) = @_;
njn25e49d8e72002-09-23 09:36:25 +0000149
150 # If absolute path, leave it alone. If relative, make it
151 # absolute -- by prepending current dir -- so we can change
152 # dirs and still use it.
153 $prog = "$dir/$prog" if ($prog !~ /^\//);
nethercotef4928da2004-06-15 10:54:40 +0000154 if ($must_exist) {
155 (-f $prog) or die "vg_regtest: `$prog' not found or not a file ($dir)\n";
156 }
njn71fe3e62003-04-23 21:48:20 +0000157 if ($must_be_executable) {
nethercotef4928da2004-06-15 10:54:40 +0000158 (-x $prog) or die "vg_regtest: `$prog' not executable ($dir)\n";
njn71fe3e62003-04-23 21:48:20 +0000159 }
njn25e49d8e72002-09-23 09:36:25 +0000160
161 return $prog;
162}
163
164sub process_command_line()
165{
166 my $alldirs = 0;
167 my @fs;
168
169 for my $arg (@ARGV) {
170 if ($arg =~ /^-/) {
njnd8ced862003-04-08 00:47:05 +0000171 if ($arg =~ /^--all$/) {
njn25e49d8e72002-09-23 09:36:25 +0000172 $alldirs = 1;
173 } elsif ($arg =~ /^--valgrind=(.*)$/) {
174 $valgrind = $1;
njn3ed89602006-10-23 18:38:35 +0000175 } elsif ($arg =~ /^--valgrind-lib=(.*)$/) {
176 $valgrind_lib = $1;
njn25e49d8e72002-09-23 09:36:25 +0000177 } else {
178 die $usage;
179 }
180 } else {
181 push(@fs, $arg);
182 }
183 }
nethercotef4928da2004-06-15 10:54:40 +0000184 $valgrind = validate_program($tests_dir, $valgrind, 1, 0);
njn25e49d8e72002-09-23 09:36:25 +0000185
186 if ($alldirs) {
187 @fs = ();
188 foreach my $f (glob "*") {
189 push(@fs, $f) if (-d $f);
190 }
191 }
192
193 (0 != @fs) or die "No test files or directories specified\n";
194
195 return @fs;
196}
197
198#----------------------------------------------------------------------------
199# Read a .vgtest file
200#----------------------------------------------------------------------------
201sub read_vgtest_file($)
202{
203 my ($f) = @_;
204
205 # Defaults.
njn0001fc32006-04-03 14:25:23 +0000206 ($vgopts, $prog, $args) = ("", undef, "");
207 ($stdout_filter, $stderr_filter) = (undef, undef);
njn734b8052007-11-01 04:40:37 +0000208 ($prereq, $post, $cleanup) = (undef, undef, undef);
njn25e49d8e72002-09-23 09:36:25 +0000209
210 # Every test directory must have a "filter_stderr"
nethercotef4928da2004-06-15 10:54:40 +0000211 $stderr_filter = validate_program(".", $default_stderr_filter, 1, 1);
njn25e49d8e72002-09-23 09:36:25 +0000212
213 open(INPUTFILE, "< $f") || die "File $f not openable\n";
214
215 while (my $line = <INPUTFILE>) {
sewardjb5f6f512005-03-10 23:59:00 +0000216 if ($line =~ /^\s*#/ || $line =~ /^\s*$/) {
217 next;
218 } elsif ($line =~ /^\s*vgopts:\s*(.*)$/) {
njn25e49d8e72002-09-23 09:36:25 +0000219 $vgopts = $1;
220 } elsif ($line =~ /^\s*prog:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000221 $prog = validate_program(".", $1, 0, 0);
njn25e49d8e72002-09-23 09:36:25 +0000222 } elsif ($line =~ /^\s*args:\s*(.*)$/) {
223 $args = $1;
njn25e49d8e72002-09-23 09:36:25 +0000224 } elsif ($line =~ /^\s*stdout_filter:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000225 $stdout_filter = validate_program(".", $1, 1, 1);
njn25e49d8e72002-09-23 09:36:25 +0000226 } elsif ($line =~ /^\s*stderr_filter:\s*(.*)$/) {
nethercotef4928da2004-06-15 10:54:40 +0000227 $stderr_filter = validate_program(".", $1, 1, 1);
nethercotec5e1d802004-11-18 12:48:17 +0000228 } elsif ($line =~ /^\s*prereq:\s*(.*)$/) {
229 $prereq = $1;
njn734b8052007-11-01 04:40:37 +0000230 } elsif ($line =~ /^\s*post:\s*(.*)$/) {
231 $post = $1;
nethercote64bc5af2004-11-18 11:57:00 +0000232 } elsif ($line =~ /^\s*cleanup:\s*(.*)$/) {
233 $cleanup = $1;
njn25e49d8e72002-09-23 09:36:25 +0000234 } else {
235 die "Bad line in $f: $line\n";
236 }
237 }
238 close(INPUTFILE);
239
240 if (!defined $prog) {
nethercotef4928da2004-06-15 10:54:40 +0000241 $prog = ""; # allow no prog for testing error and --help cases
njn25e49d8e72002-09-23 09:36:25 +0000242 }
243}
244
245#----------------------------------------------------------------------------
246# Do one test
247#----------------------------------------------------------------------------
248# Since most of the program time is spent in system() calls, need this to
249# propagate a Ctrl-C enabling us to quit.
250sub mysystem($)
251{
njn734b8052007-11-01 04:40:37 +0000252 my $exit_code = system($_[0]);
253 ($exit_code == 2) and exit 1; # 2 is SIGINT
254 return $exit_code;
njn25e49d8e72002-09-23 09:36:25 +0000255}
256
nethercote137bc552003-11-14 17:47:54 +0000257# from a directory name like "/foo/cachesim/tests/" determine the tool name
258sub determine_tool()
njn25cac76cb2002-09-23 11:21:57 +0000259{
260 my $dir = `pwd`;
nethercote137bc552003-11-14 17:47:54 +0000261 $dir =~ /.*\/([^\/]+)\/tests.*/; # foo/tool_name/tests/foo
njn25cac76cb2002-09-23 11:21:57 +0000262 return $1;
263}
264
nethercote4592db62004-02-29 01:31:09 +0000265# Compare output against expected output; it should match at least one of
266# them.
267sub do_diffs($$$$)
268{
269 my ($fullname, $name, $mid, $f_exps) = @_;
270
271 for my $f_exp (@$f_exps) {
272 (-r $f_exp) or die "Could not read `$f_exp'\n";
273
njne8ffe522008-03-02 22:48:14 +0000274 # Emacs produces temporary files that end in '~' and '#'. We ignore
275 # these.
276 if ($f_exp !~ /[~#]$/) {
277 # $n is the (optional) suffix after the ".exp"; we tack it onto
278 # the ".diff" file.
279 my $n = "";
280 if ($f_exp =~ /.*\.exp(.*)$/) {
281 $n = $1;
282 } else {
283 $n = "";
284 ($f_exp eq "/dev/null") or die "Unexpected .exp file: $f_exp\n";
285 }
nethercote4592db62004-02-29 01:31:09 +0000286
njn0d2e58f2009-02-25 04:57:56 +0000287 mysystem("@DIFF@ $f_exp $name.$mid.out > $name.$mid.diff$n");
nethercote4592db62004-02-29 01:31:09 +0000288
njne8ffe522008-03-02 22:48:14 +0000289 if (not -s "$name.$mid.diff$n") {
290 # A match; remove .out and any previously created .diff files.
291 unlink("$name.$mid.out");
292 unlink(<$name.$mid.diff*>);
293 return;
294 }
nethercote4592db62004-02-29 01:31:09 +0000295 }
296 }
297 # If we reach here, none of the .exp files matched.
298 print "*** $name failed ($mid) ***\n";
299 push(@failures, sprintf("%-40s ($mid)", "$fullname"));
300 $num_failures{$mid}++;
301}
302
njn25e49d8e72002-09-23 09:36:25 +0000303sub do_one_test($$)
304{
305 my ($dir, $vgtest) = @_;
306 $vgtest =~ /^(.*)\.vgtest/;
307 my $name = $1;
308 my $fullname = "$dir/$name";
309
sewardj91368992006-05-26 00:13:21 +0000310 # Pull any extra options (for example, --sanity-level=4)
311 # from $EXTRA_REGTEST_OPTS.
312 my $maybe_extraopts = $ENV{"EXTRA_REGTEST_OPTS"};
313 my $extraopts = $maybe_extraopts ? $maybe_extraopts : "";
314
njn25e49d8e72002-09-23 09:36:25 +0000315 read_vgtest_file($vgtest);
316
nethercotec5e1d802004-11-18 12:48:17 +0000317 if (defined $prereq) {
njn61485ab2009-03-04 04:15:16 +0000318 my $prereq_res = system("$prereq");
319 if (0 == $prereq_res) {
320 # Do nothing (ie. continue with the test)
321 } elsif (256 == $prereq_res) {
322 # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256...
323 # Prereq failed, skip.
nethercotec5e1d802004-11-18 12:48:17 +0000324 printf("%-16s (skipping, prereq failed: $prereq)\n", "$name:");
nethercote781bed42004-10-19 16:56:41 +0000325 return;
njn61485ab2009-03-04 04:15:16 +0000326 } else {
327 # Bad prereq; abort.
328 $prereq_res /= 256;
329 die "prereq returned $prereq_res: $prereq\n";
nethercote781bed42004-10-19 16:56:41 +0000330 }
nethercoteb1affa82004-01-19 19:14:18 +0000331 }
332
sewardj91368992006-05-26 00:13:21 +0000333 printf("%-16s valgrind $extraopts $vgopts $prog $args\n", "$name:");
njn25e49d8e72002-09-23 09:36:25 +0000334
nethercote137bc552003-11-14 17:47:54 +0000335 # Pass the appropriate --tool option for the directory (can be overridden
njnefc94ad2005-11-12 16:08:09 +0000336 # by an "args:" line, though). Set both VALGRIND_LIB and
337 # VALGRIND_LIB_INNER in case this Valgrind was configured with
338 # --enable-inner.
nethercote137bc552003-11-14 17:47:54 +0000339 my $tool=determine_tool();
njn3ed89602006-10-23 18:38:35 +0000340 mysystem("VALGRIND_LIB=$valgrind_lib VALGRIND_LIB_INNER=$valgrind_lib "
njnefc94ad2005-11-12 16:08:09 +0000341 . "$valgrind --command-line-only=yes --memcheck:leak-check=no "
sewardj91368992006-05-26 00:13:21 +0000342 . "--tool=$tool $extraopts $vgopts "
njnefc94ad2005-11-12 16:08:09 +0000343 . "$prog $args > $name.stdout.out 2> $name.stderr.out");
njn25e49d8e72002-09-23 09:36:25 +0000344
njn0001fc32006-04-03 14:25:23 +0000345 # Filter stdout
njn25e49d8e72002-09-23 09:36:25 +0000346 if (defined $stdout_filter) {
347 mysystem("$stdout_filter < $name.stdout.out > $tmp");
348 rename($tmp, "$name.stdout.out");
349 }
nethercote4592db62004-02-29 01:31:09 +0000350 # Find all the .stdout.exp files. If none, use /dev/null.
351 my @stdout_exps = <$name.stdout.exp*>;
352 @stdout_exps = ( "/dev/null" ) if (0 == scalar @stdout_exps);
njn0001fc32006-04-03 14:25:23 +0000353 do_diffs($fullname, $name, "stdout", \@stdout_exps);
njn25e49d8e72002-09-23 09:36:25 +0000354
njn0001fc32006-04-03 14:25:23 +0000355 # Filter stderr
356 mysystem("$stderr_filter < $name.stderr.out > $tmp");
357 rename($tmp, "$name.stderr.out");
sewardj79e88da2007-11-09 23:29:46 +0000358 # Find all the .stderr.exp files. At least one must exist.
nethercote4592db62004-02-29 01:31:09 +0000359 my @stderr_exps = <$name.stderr.exp*>;
sewardj79e88da2007-11-09 23:29:46 +0000360 (0 != scalar @stderr_exps) or die "Could not find `$name.stderr.exp*'\n";
nethercote4592db62004-02-29 01:31:09 +0000361 do_diffs($fullname, $name, "stderr", \@stderr_exps);
njn0001fc32006-04-03 14:25:23 +0000362
363 # Maybe do post-test check
njn734b8052007-11-01 04:40:37 +0000364 if (defined $post) {
365 if (mysystem("$post > $name.post.out") != 0) {
366 print("post check failed: $post\n");
367 $num_failures{"post"}++;
njn0001fc32006-04-03 14:25:23 +0000368 } else {
njn734b8052007-11-01 04:40:37 +0000369 # Find all the .post.exp files. If none, use /dev/null.
370 my @post_exps = <$name.post.exp*>;
371 @post_exps = ( "/dev/null" ) if (0 == scalar @post_exps);
372 do_diffs($fullname, $name, "post", \@post_exps);
njn0001fc32006-04-03 14:25:23 +0000373 }
374 }
nethercotec1f8ad92004-04-17 17:25:08 +0000375
nethercote64bc5af2004-11-18 11:57:00 +0000376 if (defined $cleanup) {
377 (system("$cleanup") == 0) or
378 print("(cleanup operation failed: $cleanup)\n");
nethercotec1f8ad92004-04-17 17:25:08 +0000379 }
380
njn9fb16f52003-04-23 17:47:13 +0000381 $num_tests_done++;
njn25e49d8e72002-09-23 09:36:25 +0000382}
383
384#----------------------------------------------------------------------------
njn25cac76cb2002-09-23 11:21:57 +0000385# Test one directory (and any subdirs)
njn25e49d8e72002-09-23 09:36:25 +0000386#----------------------------------------------------------------------------
njndb3c4692002-10-04 10:03:34 +0000387sub test_one_dir($$); # forward declaration
njn25cac76cb2002-09-23 11:21:57 +0000388
njndb3c4692002-10-04 10:03:34 +0000389sub test_one_dir($$)
njn25e49d8e72002-09-23 09:36:25 +0000390{
njndb3c4692002-10-04 10:03:34 +0000391 my ($dir, $prev_dirs) = @_;
njn25e49d8e72002-09-23 09:36:25 +0000392 $dir =~ s/\/$//; # trim a trailing '/'
393
nethercote362c0d22004-11-18 18:21:56 +0000394 # Ignore dirs into which we should not recurse.
mueller92f0b802003-11-19 00:55:32 +0000395 if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; }
njn25cac76cb2002-09-23 11:21:57 +0000396
njn107bc572009-02-16 00:42:10 +0000397 (-x "$tests_dir/tests/arch_test") or die
398 "vg_regtest: 'arch_test' is missing. Did you forget to 'make check'?\n";
njn52783ca2005-12-08 22:39:04 +0000399
nethercote362c0d22004-11-18 18:21:56 +0000400 # Ignore any dir whose name matches that of an architecture which is not
njn107bc572009-02-16 00:42:10 +0000401 # the architecture we are running on. Eg. when running on x86, ignore
402 # ppc/ directories ('arch_test' returns 1 for this case). Likewise for
403 # the OS and platform.
nethercote362c0d22004-11-18 18:21:56 +0000404 # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256...
njn61485ab2009-03-04 04:15:16 +0000405 if (256 == system("$tests_dir/tests/arch_test $dir")) { return; }
406 if (256 == system("$tests_dir/tests/os_test $dir")) { return; }
njn107bc572009-02-16 00:42:10 +0000407 if ($dir =~ /(\w+)-(\w+)/ &&
408 256 == system("sh $tests_dir/tests/platform_test $1 $2")) { return; }
nethercote362c0d22004-11-18 18:21:56 +0000409
njn25e49d8e72002-09-23 09:36:25 +0000410 chdir($dir) or die "Could not change into $dir\n";
411
njn584eaac2002-10-04 15:30:48 +0000412 # Nb: Don't prepend a '/' to the base directory
413 my $full_dir = $prev_dirs . ($prev_dirs eq "" ? "" : "/") . $dir;
njndb3c4692002-10-04 10:03:34 +0000414 my $dashes = "-" x (50 - length $full_dir);
njn25cac76cb2002-09-23 11:21:57 +0000415
njndb3c4692002-10-04 10:03:34 +0000416 my @fs = glob "*";
njndb3c4692002-10-04 10:03:34 +0000417 my $found_tests = (0 != (grep { $_ =~ /\.vgtest$/ } @fs));
418
419 if ($found_tests) {
420 print "-- Running tests in $full_dir $dashes\n";
njndb3c4692002-10-04 10:03:34 +0000421 }
njn25cac76cb2002-09-23 11:21:57 +0000422 foreach my $f (@fs) {
423 if (-d $f) {
njndb3c4692002-10-04 10:03:34 +0000424 test_one_dir($f, $full_dir);
njn25cac76cb2002-09-23 11:21:57 +0000425 } elsif ($f =~ /\.vgtest$/) {
njndb3c4692002-10-04 10:03:34 +0000426 do_one_test($full_dir, $f);
njn25cac76cb2002-09-23 11:21:57 +0000427 }
njn25e49d8e72002-09-23 09:36:25 +0000428 }
njndb3c4692002-10-04 10:03:34 +0000429 if ($found_tests) {
430 print "-- Finished tests in $full_dir $dashes\n";
431 }
432
njn25e49d8e72002-09-23 09:36:25 +0000433 chdir("..");
njn25e49d8e72002-09-23 09:36:25 +0000434}
435
436#----------------------------------------------------------------------------
437# Summarise results
438#----------------------------------------------------------------------------
njn9fb16f52003-04-23 17:47:13 +0000439sub plural($)
440{
441 return ( $_[0] == 1 ? "" : "s" );
442}
443
njn25e49d8e72002-09-23 09:36:25 +0000444sub summarise_results
445{
njnd8ced862003-04-08 00:47:05 +0000446 my $x = ( $num_tests_done == 1 ? "test" : "tests" );
njnd8ced862003-04-08 00:47:05 +0000447
njn0001fc32006-04-03 14:25:23 +0000448 printf("\n== %d test%s, %d stderr failure%s, %d stdout failure%s, "
njn734b8052007-11-01 04:40:37 +0000449 . "%d post failure%s ==\n",
njn9fb16f52003-04-23 17:47:13 +0000450 $num_tests_done, plural($num_tests_done),
njn0001fc32006-04-03 14:25:23 +0000451 $num_failures{"stderr"}, plural($num_failures{"stderr"}),
452 $num_failures{"stdout"}, plural($num_failures{"stdout"}),
njn734b8052007-11-01 04:40:37 +0000453 $num_failures{"post"}, plural($num_failures{"post"}));
njn9fb16f52003-04-23 17:47:13 +0000454
455 foreach my $failure (@failures) {
456 print "$failure\n";
njn25e49d8e72002-09-23 09:36:25 +0000457 }
njn9fb16f52003-04-23 17:47:13 +0000458 print "\n";
njn25e49d8e72002-09-23 09:36:25 +0000459}
460
461#----------------------------------------------------------------------------
462# main(), sort of
463#----------------------------------------------------------------------------
sewardj91368992006-05-26 00:13:21 +0000464sub warn_about_EXTRA_REGTEST_OPTS()
465{
466 print "WARNING: \$EXTRA_REGTEST_OPTS is set. You probably don't want\n";
467 print "to run the regression tests with it set, unless you are doing some\n";
468 print "strange experiment, and/or you really know what you are doing.\n";
469 print "\n";
470}
njn25e49d8e72002-09-23 09:36:25 +0000471
daywalkerbb936982003-04-23 16:52:06 +0000472# nuke VALGRIND_OPTS
473$ENV{"VALGRIND_OPTS"} = "";
njn25e49d8e72002-09-23 09:36:25 +0000474
sewardj91368992006-05-26 00:13:21 +0000475if ($ENV{"EXTRA_REGTEST_OPTS"}) {
476 print "\n";
477 warn_about_EXTRA_REGTEST_OPTS();
478}
479
njn25e49d8e72002-09-23 09:36:25 +0000480my @fs = process_command_line();
481foreach my $f (@fs) {
482 if (-d $f) {
njn584eaac2002-10-04 15:30:48 +0000483 test_one_dir($f, "");
njn25e49d8e72002-09-23 09:36:25 +0000484 } else {
485 # Allow the .vgtest suffix to be given or omitted
486 if ($f =~ /.vgtest$/ && -r $f) {
487 # do nothing
488 } elsif (-r "$f.vgtest") {
489 $f = "$f.vgtest";
490 } else {
491 die "`$f' neither a directory nor a readable test file/name\n"
492 }
493 my $dir = `dirname $f`; chomp $dir;
494 my $file = `basename $f`; chomp $file;
495 chdir($dir) or die "Could not change into $dir\n";
496 do_one_test($dir, $file);
497 chdir($tests_dir);
498 }
499}
500summarise_results();
501
sewardj91368992006-05-26 00:13:21 +0000502if ($ENV{"EXTRA_REGTEST_OPTS"}) {
503 warn_about_EXTRA_REGTEST_OPTS();
504}
505
njn0001fc32006-04-03 14:25:23 +0000506if (0 == $num_failures{"stdout"} &&
507 0 == $num_failures{"stderr"} &&
njn734b8052007-11-01 04:40:37 +0000508 0 == $num_failures{"post"}) {
nethercoteab422192004-03-01 08:27:37 +0000509 exit 0;
510} else {
511 exit 1;
512}
513
njnc2e7f482002-09-27 08:44:17 +0000514##--------------------------------------------------------------------##
515##--- end vg_regtest ---##
516##--------------------------------------------------------------------##