njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 1 | #! @PERL@ |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 2 | ##--------------------------------------------------------------------## |
| 3 | ##--- Valgrind regression testing script vg_regtest ---## |
| 4 | ##--------------------------------------------------------------------## |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 5 | |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 6 | # This file is part of Valgrind, an extensible x86 protected-mode |
| 7 | # emulator for monitoring program execution on x86-Unixes. |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 8 | # |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 9 | # Copyright (C) 2003 Nicholas Nethercote |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 10 | # njn25@cam.ac.uk |
| 11 | # |
| 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 | #---------------------------------------------------------------------------- |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 30 | # usage: vg_regtest [options] <dirs | files> |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 31 | # |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 32 | # Options: |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 33 | # --all: run tests in all subdirs |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 34 | # --valgrind: valgrind to use. Default is one built from this source tree. |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 35 | # |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 36 | # The easiest way is to run all tests in valgrind/ with (assuming you installed |
| 37 | # in $PREFIX): |
| 38 | # |
| 39 | # $PREFIX/bin/vg_regtest --all |
| 40 | # |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 41 | # You can specify individual files to test, or whole directories, or both. |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 42 | # Directories are traversed recursively, except for ones named, for example, |
| 43 | # CVS/ or docs/. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 44 | # |
| 45 | # Each test is defined in a file <test>.vgtest, containing one or more of the |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 46 | # following lines, in any order: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 47 | # - prog: <prog to run> (compulsory) |
| 48 | # - args: <args for prog> (default: none) |
| 49 | # - vgopts: <Valgrind options> (default: none) |
| 50 | # - stdout_filter: <filter to run stdout through> (default: none) |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 51 | # - stderr_filter: <filter to run stderr through> (default: ./filter_stderr) |
nethercote | b1affa8 | 2004-01-19 19:14:18 +0000 | [diff] [blame^] | 52 | # - cpu_test: <cpu feature required for test> (default: none) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 53 | # |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 54 | # Note that filters are necessary for stderr results to filter out things that |
| 55 | # always change, eg. process id numbers. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 56 | # |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 57 | # Expected stdout (filtered) is kept in <test>.stdout.exp. It can be missing |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 58 | # if it would be empty. Expected stderr (filtered) is kept in |
| 59 | # <test>.stderr.exp. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 60 | # |
| 61 | # If results don't match, the output can be found in <test>.std<strm>.out, |
| 62 | # and the diff between expected and actual in <test>.std<strm>.diff. |
| 63 | # |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 64 | # Notes on adding regression tests for a new tool are in |
| 65 | # coregrind/docs/coregrind_tools.html. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 66 | #---------------------------------------------------------------------------- |
| 67 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 68 | use warnings; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 69 | use strict; |
| 70 | |
| 71 | #---------------------------------------------------------------------------- |
| 72 | # Global vars |
| 73 | #---------------------------------------------------------------------------- |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 74 | my $usage="vg_regtest [--all, --valgrind]\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 75 | |
| 76 | my $tmp="vg_regtest.tmp.$$"; |
| 77 | |
| 78 | # Test variables |
| 79 | my $vgopts; # valgrind options |
| 80 | my $prog; # test prog |
| 81 | my $args; # test prog args |
| 82 | my $stdout_filter; # filter program to run stdout results file through |
| 83 | my $stderr_filter; # filter program to run stderr results file through |
nethercote | b1affa8 | 2004-01-19 19:14:18 +0000 | [diff] [blame^] | 84 | my $cpu_test; # cpu feature to check for before running test |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 85 | |
| 86 | my @failures; # List of failed tests |
| 87 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 88 | my $num_tests_done = 0; |
| 89 | my %num_failures = (stderr => 0, stdout => 0); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 90 | |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 91 | # Default valgrind to use is this build tree's (uninstalled) one |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 92 | my $prefix="@prefix@"; |
| 93 | my $exec_prefix="@exec_prefix@"; |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 94 | my $valgrind = "./coregrind/valgrind"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 95 | |
| 96 | chomp(my $tests_dir = `pwd`); |
| 97 | |
| 98 | # default filter is the one named "filter_stderr" in the test's directory |
| 99 | my $default_stderr_filter = "filter_stderr"; |
| 100 | |
| 101 | |
| 102 | #---------------------------------------------------------------------------- |
| 103 | # Process command line, setup |
| 104 | #---------------------------------------------------------------------------- |
| 105 | |
| 106 | # If $prog is a relative path, it prepends $dir to it. Useful for two reasons: |
| 107 | # |
| 108 | # 1. Can prepend "." onto programs to avoid trouble with users who don't have |
| 109 | # "." in their path (by making $dir = ".") |
| 110 | # 2. Can prepend the current dir to make the command absolute to avoid |
| 111 | # subsequent trouble when we change directories. |
| 112 | # |
| 113 | # Also checks the program exists and is executable. |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 114 | sub validate_program ($$$) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 115 | { |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 116 | my ($dir, $prog, $must_be_executable) = @_; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 117 | |
| 118 | # If absolute path, leave it alone. If relative, make it |
| 119 | # absolute -- by prepending current dir -- so we can change |
| 120 | # dirs and still use it. |
| 121 | $prog = "$dir/$prog" if ($prog !~ /^\//); |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 122 | (-f $prog) or die "vg_regtest: `$prog' not found or not a file ($dir)\n"; |
| 123 | if ($must_be_executable) { |
| 124 | (-x $prog) or die "vg_regtest: `$prog' not executable ($dir)\n"; |
| 125 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 126 | |
| 127 | return $prog; |
| 128 | } |
| 129 | |
| 130 | sub process_command_line() |
| 131 | { |
| 132 | my $alldirs = 0; |
| 133 | my @fs; |
| 134 | |
| 135 | for my $arg (@ARGV) { |
| 136 | if ($arg =~ /^-/) { |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 137 | if ($arg =~ /^--all$/) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 138 | $alldirs = 1; |
| 139 | } elsif ($arg =~ /^--valgrind=(.*)$/) { |
| 140 | $valgrind = $1; |
| 141 | } else { |
| 142 | die $usage; |
| 143 | } |
| 144 | } else { |
| 145 | push(@fs, $arg); |
| 146 | } |
| 147 | } |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 148 | $valgrind = validate_program($tests_dir, $valgrind, 0); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 149 | |
| 150 | if ($alldirs) { |
| 151 | @fs = (); |
| 152 | foreach my $f (glob "*") { |
| 153 | push(@fs, $f) if (-d $f); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | (0 != @fs) or die "No test files or directories specified\n"; |
| 158 | |
| 159 | return @fs; |
| 160 | } |
| 161 | |
| 162 | #---------------------------------------------------------------------------- |
| 163 | # Read a .vgtest file |
| 164 | #---------------------------------------------------------------------------- |
| 165 | sub read_vgtest_file($) |
| 166 | { |
| 167 | my ($f) = @_; |
| 168 | |
| 169 | # Defaults. |
nethercote | b1affa8 | 2004-01-19 19:14:18 +0000 | [diff] [blame^] | 170 | ($vgopts, $prog, $args, $stdout_filter, $stderr_filter, $cpu_test) = |
| 171 | ("", undef, "", undef, undef, undef); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 172 | |
| 173 | # Every test directory must have a "filter_stderr" |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 174 | $stderr_filter = validate_program(".", $default_stderr_filter, 1); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 175 | |
| 176 | open(INPUTFILE, "< $f") || die "File $f not openable\n"; |
| 177 | |
| 178 | while (my $line = <INPUTFILE>) { |
| 179 | if ($line =~ /^\s*vgopts:\s*(.*)$/) { |
| 180 | $vgopts = $1; |
| 181 | } elsif ($line =~ /^\s*prog:\s*(.*)$/) { |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 182 | $prog = validate_program(".", $1, 1); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 183 | } elsif ($line =~ /^\s*args:\s*(.*)$/) { |
| 184 | $args = $1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 185 | } elsif ($line =~ /^\s*stdout_filter:\s*(.*)$/) { |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 186 | $stdout_filter = validate_program(".", $1, 1); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 187 | } elsif ($line =~ /^\s*stderr_filter:\s*(.*)$/) { |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 188 | $stderr_filter = validate_program(".", $1, 1); |
nethercote | b1affa8 | 2004-01-19 19:14:18 +0000 | [diff] [blame^] | 189 | } elsif ($line =~ /^\s*cpu_test:\s*(.*)$/) { |
| 190 | $cpu_test = $1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 191 | } else { |
| 192 | die "Bad line in $f: $line\n"; |
| 193 | } |
| 194 | } |
| 195 | close(INPUTFILE); |
| 196 | |
| 197 | if (!defined $prog) { |
| 198 | die "no `prog:' line in `$f'\n"; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | #---------------------------------------------------------------------------- |
| 203 | # Do one test |
| 204 | #---------------------------------------------------------------------------- |
| 205 | # Since most of the program time is spent in system() calls, need this to |
| 206 | # propagate a Ctrl-C enabling us to quit. |
| 207 | sub mysystem($) |
| 208 | { |
| 209 | (system($_[0]) != 2) or exit 1; # 2 is SIGINT |
| 210 | } |
| 211 | |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 212 | # from a directory name like "/foo/cachesim/tests/" determine the tool name |
| 213 | sub determine_tool() |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 214 | { |
| 215 | my $dir = `pwd`; |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 216 | $dir =~ /.*\/([^\/]+)\/tests.*/; # foo/tool_name/tests/foo |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 217 | return $1; |
| 218 | } |
| 219 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 220 | sub do_one_test($$) |
| 221 | { |
| 222 | my ($dir, $vgtest) = @_; |
| 223 | $vgtest =~ /^(.*)\.vgtest/; |
| 224 | my $name = $1; |
| 225 | my $fullname = "$dir/$name"; |
| 226 | |
| 227 | read_vgtest_file($vgtest); |
| 228 | |
nethercote | b1affa8 | 2004-01-19 19:14:18 +0000 | [diff] [blame^] | 229 | if (defined $cpu_test) { |
| 230 | return unless system("../../tests/cputest $cpu_test") == 0; |
| 231 | } |
| 232 | |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 233 | printf("%-16s valgrind $vgopts $prog $args\n", "$name:"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 234 | |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 235 | # Pass the appropriate --tool option for the directory (can be overridden |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 236 | # by an "args:" or "args.dev:" line, though). |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 237 | my $tool=determine_tool(); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 238 | mysystem("VALGRINDLIB=$tests_dir/.in_place $valgrind --tool=$tool $vgopts $prog $args > $name.stdout.out 2> $name.stderr.out"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 239 | |
| 240 | if (defined $stdout_filter) { |
| 241 | mysystem("$stdout_filter < $name.stdout.out > $tmp"); |
| 242 | rename($tmp, "$name.stdout.out"); |
| 243 | } |
| 244 | |
| 245 | mysystem("$stderr_filter < $name.stderr.out > $tmp"); |
| 246 | rename($tmp, "$name.stderr.out"); |
| 247 | |
| 248 | # If stdout expected empty, .exp file might be missing so diff with |
| 249 | # /dev/null |
| 250 | my $stdout_exp = ( -r "$name.stdout.exp" |
| 251 | ? "$name.stdout.exp" |
| 252 | : "/dev/null" ); |
| 253 | |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 254 | my $stderr_exp = "$name.stderr.exp"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 255 | (-r $stderr_exp) or die "Could not read `$stderr_exp'\n"; |
| 256 | |
| 257 | mysystem("diff -C0 $stdout_exp $name.stdout.out > $name.stdout.diff"); |
| 258 | mysystem("diff -C0 $stderr_exp $name.stderr.out > $name.stderr.diff"); |
| 259 | |
| 260 | for my $ext ("stdout", "stderr") { |
| 261 | if (-s "$name.$ext.diff") { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 262 | print "*** $name failed ($ext) ***\n"; |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 263 | push(@failures, sprintf("%-40s ($ext)", "$fullname")); |
| 264 | $num_failures{$ext}++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 265 | } else { |
| 266 | unlink("$name.$ext.out", "$name.$ext.diff"); |
| 267 | } |
| 268 | } |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 269 | $num_tests_done++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | #---------------------------------------------------------------------------- |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 273 | # Test one directory (and any subdirs) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 274 | #---------------------------------------------------------------------------- |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 275 | sub test_one_dir($$); # forward declaration |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 276 | |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 277 | sub test_one_dir($$) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 278 | { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 279 | my ($dir, $prev_dirs) = @_; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 280 | $dir =~ s/\/$//; # trim a trailing '/' |
| 281 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 282 | # ignore dirs into which we should not recurse |
mueller | 92f0b80 | 2003-11-19 00:55:32 +0000 | [diff] [blame] | 283 | if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; } |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 284 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 285 | chdir($dir) or die "Could not change into $dir\n"; |
| 286 | |
njn | 584eaac | 2002-10-04 15:30:48 +0000 | [diff] [blame] | 287 | # Nb: Don't prepend a '/' to the base directory |
| 288 | my $full_dir = $prev_dirs . ($prev_dirs eq "" ? "" : "/") . $dir; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 289 | my $dashes = "-" x (50 - length $full_dir); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 290 | |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 291 | my @fs = glob "*"; |
| 292 | my @vgtests = grep { $_ =~ /\.vgtest$/ } @fs; |
| 293 | my $found_tests = (0 != (grep { $_ =~ /\.vgtest$/ } @fs)); |
| 294 | |
| 295 | if ($found_tests) { |
| 296 | print "-- Running tests in $full_dir $dashes\n"; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 297 | } |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 298 | foreach my $f (@fs) { |
| 299 | if (-d $f) { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 300 | test_one_dir($f, $full_dir); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 301 | } elsif ($f =~ /\.vgtest$/) { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 302 | do_one_test($full_dir, $f); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 303 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 304 | } |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 305 | if ($found_tests) { |
| 306 | print "-- Finished tests in $full_dir $dashes\n"; |
| 307 | } |
| 308 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 309 | chdir(".."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | #---------------------------------------------------------------------------- |
| 313 | # Summarise results |
| 314 | #---------------------------------------------------------------------------- |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 315 | sub plural($) |
| 316 | { |
| 317 | return ( $_[0] == 1 ? "" : "s" ); |
| 318 | } |
| 319 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 320 | sub summarise_results |
| 321 | { |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 322 | my $x = ( $num_tests_done == 1 ? "test" : "tests" ); |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 323 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 324 | printf("\n== %d test%s, %d stderr failure%s, %d stdout failure%s =================\n", |
| 325 | $num_tests_done, plural($num_tests_done), |
| 326 | $num_failures{"stderr"}, plural($num_failures{"stderr"}), |
| 327 | $num_failures{"stdout"}, plural($num_failures{"stdout"})); |
| 328 | |
| 329 | foreach my $failure (@failures) { |
| 330 | print "$failure\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 331 | } |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 332 | print "\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | #---------------------------------------------------------------------------- |
| 336 | # main(), sort of |
| 337 | #---------------------------------------------------------------------------- |
| 338 | |
daywalker | bb93698 | 2003-04-23 16:52:06 +0000 | [diff] [blame] | 339 | # nuke VALGRIND_OPTS |
| 340 | $ENV{"VALGRIND_OPTS"} = ""; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 341 | |
| 342 | my @fs = process_command_line(); |
| 343 | foreach my $f (@fs) { |
| 344 | if (-d $f) { |
njn | 584eaac | 2002-10-04 15:30:48 +0000 | [diff] [blame] | 345 | test_one_dir($f, ""); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 346 | } else { |
| 347 | # Allow the .vgtest suffix to be given or omitted |
| 348 | if ($f =~ /.vgtest$/ && -r $f) { |
| 349 | # do nothing |
| 350 | } elsif (-r "$f.vgtest") { |
| 351 | $f = "$f.vgtest"; |
| 352 | } else { |
| 353 | die "`$f' neither a directory nor a readable test file/name\n" |
| 354 | } |
| 355 | my $dir = `dirname $f`; chomp $dir; |
| 356 | my $file = `basename $f`; chomp $file; |
| 357 | chdir($dir) or die "Could not change into $dir\n"; |
| 358 | do_one_test($dir, $file); |
| 359 | chdir($tests_dir); |
| 360 | } |
| 361 | } |
| 362 | summarise_results(); |
| 363 | |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 364 | ##--------------------------------------------------------------------## |
| 365 | ##--- end vg_regtest ---## |
| 366 | ##--------------------------------------------------------------------## |