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 | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 6 | # This file is part of Valgrind, a dynamic binary instrumentation |
| 7 | # framework. |
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 | 2bc1012 | 2005-05-08 02:10:27 +0000 | [diff] [blame] | 10 | # njn@valgrind.org |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 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 | 3ed8960 | 2006-10-23 18:38:35 +0000 | [diff] [blame] | 34 | # --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.) |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 40 | # |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 41 | # 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 | # |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 46 | # You can specify individual files to test, or whole directories, or both. |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 47 | # Directories are traversed recursively, except for ones named, for example, |
| 48 | # CVS/ or docs/. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 49 | # |
| 50 | # 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] | 51 | # following lines, in any order: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 52 | # - 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) |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 56 | # - stderr_filter: <filter to run stderr through> (default: ./filter_stderr) |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 57 | # - prereq: <prerequisite command> (default: none) |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 58 | # - post: <post-test check command> (default: none) |
| 59 | # - cleanup: <post-test cleanup cmd> (default: none) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 60 | # |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 61 | # Note that filters are necessary for stderr results to filter out things that |
| 62 | # always change, eg. process id numbers. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 63 | # |
njn | 1ee25f0 | 2008-02-27 18:10:19 +0000 | [diff] [blame] | 64 | # Expected stdout (filtered) is kept in <test>.stdout.exp* (can be more |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 65 | # than one expected output). It can be missing if it would be empty. Expected |
sewardj | 79e88da | 2007-11-09 23:29:46 +0000 | [diff] [blame] | 66 | # stderr (filtered) is kept in <test>.stderr.exp*. There must be at least |
njn | e8ffe52 | 2008-03-02 22:48:14 +0000 | [diff] [blame] | 67 | # one stderr.exp* file. Any .exp* file that ends in '~' or '#' is ignored; |
| 68 | # this is because Emacs creates temporary files of these names. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 69 | # |
| 70 | # If results don't match, the output can be found in <test>.std<strm>.out, |
njn | 1ee25f0 | 2008-02-27 18:10:19 +0000 | [diff] [blame] | 71 | # and the diff between expected and actual in <test>.std<strm>.diff*. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 72 | # |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 73 | # 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 | # |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 84 | # 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 | # |
njn | 7358d52 | 2006-11-26 22:49:58 +0000 | [diff] [blame] | 90 | # Some more notes on adding regression tests for a new tool are in |
| 91 | # docs/xml/manual-writing-tools.xml. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 92 | #---------------------------------------------------------------------------- |
| 93 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 94 | use warnings; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 95 | use strict; |
| 96 | |
| 97 | #---------------------------------------------------------------------------- |
| 98 | # Global vars |
| 99 | #---------------------------------------------------------------------------- |
sewardj | a8162b2 | 2007-11-30 21:24:05 +0000 | [diff] [blame] | 100 | my $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"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 105 | |
| 106 | my $tmp="vg_regtest.tmp.$$"; |
| 107 | |
| 108 | # Test variables |
| 109 | my $vgopts; # valgrind options |
| 110 | my $prog; # test prog |
| 111 | my $args; # test prog args |
| 112 | my $stdout_filter; # filter program to run stdout results file through |
| 113 | my $stderr_filter; # filter program to run stderr results file through |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 114 | my $prereq; # prerequisite test to satisfy before running test |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 115 | my $post; # check command after running test |
nethercote | 64bc5af | 2004-11-18 11:57:00 +0000 | [diff] [blame] | 116 | my $cleanup; # cleanup command to run |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 117 | |
| 118 | my @failures; # List of failed tests |
| 119 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 120 | my $num_tests_done = 0; |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 121 | my %num_failures = (stderr => 0, stdout => 0, post => 0); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 122 | |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 123 | # Default valgrind to use is this build tree's (uninstalled) one |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 124 | my $valgrind = "./coregrind/valgrind"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 125 | |
| 126 | chomp(my $tests_dir = `pwd`); |
| 127 | |
njn | 3ed8960 | 2006-10-23 18:38:35 +0000 | [diff] [blame] | 128 | my $valgrind_lib = "$tests_dir/.in_place"; |
| 129 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 130 | # default filter is the one named "filter_stderr" in the test's directory |
| 131 | my $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. |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 146 | sub validate_program ($$$$) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 147 | { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 148 | my ($dir, $prog, $must_exist, $must_be_executable) = @_; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 149 | |
| 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 !~ /^\//); |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 154 | if ($must_exist) { |
| 155 | (-f $prog) or die "vg_regtest: `$prog' not found or not a file ($dir)\n"; |
| 156 | } |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 157 | if ($must_be_executable) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 158 | (-x $prog) or die "vg_regtest: `$prog' not executable ($dir)\n"; |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 159 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 160 | |
| 161 | return $prog; |
| 162 | } |
| 163 | |
| 164 | sub process_command_line() |
| 165 | { |
| 166 | my $alldirs = 0; |
| 167 | my @fs; |
| 168 | |
| 169 | for my $arg (@ARGV) { |
| 170 | if ($arg =~ /^-/) { |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 171 | if ($arg =~ /^--all$/) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 172 | $alldirs = 1; |
| 173 | } elsif ($arg =~ /^--valgrind=(.*)$/) { |
| 174 | $valgrind = $1; |
njn | 3ed8960 | 2006-10-23 18:38:35 +0000 | [diff] [blame] | 175 | } elsif ($arg =~ /^--valgrind-lib=(.*)$/) { |
| 176 | $valgrind_lib = $1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 177 | } else { |
| 178 | die $usage; |
| 179 | } |
| 180 | } else { |
| 181 | push(@fs, $arg); |
| 182 | } |
| 183 | } |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 184 | $valgrind = validate_program($tests_dir, $valgrind, 1, 0); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 185 | |
| 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 | #---------------------------------------------------------------------------- |
| 201 | sub read_vgtest_file($) |
| 202 | { |
| 203 | my ($f) = @_; |
| 204 | |
| 205 | # Defaults. |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 206 | ($vgopts, $prog, $args) = ("", undef, ""); |
| 207 | ($stdout_filter, $stderr_filter) = (undef, undef); |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 208 | ($prereq, $post, $cleanup) = (undef, undef, undef); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 209 | |
| 210 | # Every test directory must have a "filter_stderr" |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 211 | $stderr_filter = validate_program(".", $default_stderr_filter, 1, 1); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 212 | |
| 213 | open(INPUTFILE, "< $f") || die "File $f not openable\n"; |
| 214 | |
| 215 | while (my $line = <INPUTFILE>) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 216 | if ($line =~ /^\s*#/ || $line =~ /^\s*$/) { |
| 217 | next; |
| 218 | } elsif ($line =~ /^\s*vgopts:\s*(.*)$/) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 219 | $vgopts = $1; |
| 220 | } elsif ($line =~ /^\s*prog:\s*(.*)$/) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 221 | $prog = validate_program(".", $1, 0, 0); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 222 | } elsif ($line =~ /^\s*args:\s*(.*)$/) { |
| 223 | $args = $1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 224 | } elsif ($line =~ /^\s*stdout_filter:\s*(.*)$/) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 225 | $stdout_filter = validate_program(".", $1, 1, 1); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 226 | } elsif ($line =~ /^\s*stderr_filter:\s*(.*)$/) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 227 | $stderr_filter = validate_program(".", $1, 1, 1); |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 228 | } elsif ($line =~ /^\s*prereq:\s*(.*)$/) { |
| 229 | $prereq = $1; |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 230 | } elsif ($line =~ /^\s*post:\s*(.*)$/) { |
| 231 | $post = $1; |
nethercote | 64bc5af | 2004-11-18 11:57:00 +0000 | [diff] [blame] | 232 | } elsif ($line =~ /^\s*cleanup:\s*(.*)$/) { |
| 233 | $cleanup = $1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 234 | } else { |
| 235 | die "Bad line in $f: $line\n"; |
| 236 | } |
| 237 | } |
| 238 | close(INPUTFILE); |
| 239 | |
| 240 | if (!defined $prog) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 241 | $prog = ""; # allow no prog for testing error and --help cases |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 242 | } |
| 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. |
| 250 | sub mysystem($) |
| 251 | { |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 252 | my $exit_code = system($_[0]); |
| 253 | ($exit_code == 2) and exit 1; # 2 is SIGINT |
| 254 | return $exit_code; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 255 | } |
| 256 | |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 257 | # from a directory name like "/foo/cachesim/tests/" determine the tool name |
| 258 | sub determine_tool() |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 259 | { |
| 260 | my $dir = `pwd`; |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 261 | $dir =~ /.*\/([^\/]+)\/tests.*/; # foo/tool_name/tests/foo |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 262 | return $1; |
| 263 | } |
| 264 | |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 265 | # Compare output against expected output; it should match at least one of |
| 266 | # them. |
| 267 | sub 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 | |
njn | e8ffe52 | 2008-03-02 22:48:14 +0000 | [diff] [blame] | 274 | # 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 | } |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 286 | |
njn | 0d2e58f | 2009-02-25 04:57:56 +0000 | [diff] [blame] | 287 | mysystem("@DIFF@ $f_exp $name.$mid.out > $name.$mid.diff$n"); |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 288 | |
njn | e8ffe52 | 2008-03-02 22:48:14 +0000 | [diff] [blame] | 289 | 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 | } |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 295 | } |
| 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 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 303 | sub do_one_test($$) |
| 304 | { |
| 305 | my ($dir, $vgtest) = @_; |
| 306 | $vgtest =~ /^(.*)\.vgtest/; |
| 307 | my $name = $1; |
| 308 | my $fullname = "$dir/$name"; |
| 309 | |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 310 | # 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 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 315 | read_vgtest_file($vgtest); |
| 316 | |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 317 | if (defined $prereq) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 318 | 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. |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 324 | printf("%-16s (skipping, prereq failed: $prereq)\n", "$name:"); |
nethercote | 781bed4 | 2004-10-19 16:56:41 +0000 | [diff] [blame] | 325 | return; |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 326 | } else { |
| 327 | # Bad prereq; abort. |
| 328 | $prereq_res /= 256; |
| 329 | die "prereq returned $prereq_res: $prereq\n"; |
nethercote | 781bed4 | 2004-10-19 16:56:41 +0000 | [diff] [blame] | 330 | } |
nethercote | b1affa8 | 2004-01-19 19:14:18 +0000 | [diff] [blame] | 331 | } |
| 332 | |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 333 | printf("%-16s valgrind $extraopts $vgopts $prog $args\n", "$name:"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 334 | |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 335 | # Pass the appropriate --tool option for the directory (can be overridden |
njn | efc94ad | 2005-11-12 16:08:09 +0000 | [diff] [blame] | 336 | # by an "args:" line, though). Set both VALGRIND_LIB and |
| 337 | # VALGRIND_LIB_INNER in case this Valgrind was configured with |
| 338 | # --enable-inner. |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 339 | my $tool=determine_tool(); |
njn | 3ed8960 | 2006-10-23 18:38:35 +0000 | [diff] [blame] | 340 | mysystem("VALGRIND_LIB=$valgrind_lib VALGRIND_LIB_INNER=$valgrind_lib " |
njn | efc94ad | 2005-11-12 16:08:09 +0000 | [diff] [blame] | 341 | . "$valgrind --command-line-only=yes --memcheck:leak-check=no " |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 342 | . "--tool=$tool $extraopts $vgopts " |
njn | efc94ad | 2005-11-12 16:08:09 +0000 | [diff] [blame] | 343 | . "$prog $args > $name.stdout.out 2> $name.stderr.out"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 344 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 345 | # Filter stdout |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 346 | if (defined $stdout_filter) { |
| 347 | mysystem("$stdout_filter < $name.stdout.out > $tmp"); |
| 348 | rename($tmp, "$name.stdout.out"); |
| 349 | } |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 350 | # 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); |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 353 | do_diffs($fullname, $name, "stdout", \@stdout_exps); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 354 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 355 | # Filter stderr |
| 356 | mysystem("$stderr_filter < $name.stderr.out > $tmp"); |
| 357 | rename($tmp, "$name.stderr.out"); |
sewardj | 79e88da | 2007-11-09 23:29:46 +0000 | [diff] [blame] | 358 | # Find all the .stderr.exp files. At least one must exist. |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 359 | my @stderr_exps = <$name.stderr.exp*>; |
sewardj | 79e88da | 2007-11-09 23:29:46 +0000 | [diff] [blame] | 360 | (0 != scalar @stderr_exps) or die "Could not find `$name.stderr.exp*'\n"; |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 361 | do_diffs($fullname, $name, "stderr", \@stderr_exps); |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 362 | |
| 363 | # Maybe do post-test check |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 364 | if (defined $post) { |
| 365 | if (mysystem("$post > $name.post.out") != 0) { |
| 366 | print("post check failed: $post\n"); |
| 367 | $num_failures{"post"}++; |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 368 | } else { |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 369 | # 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); |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
nethercote | c1f8ad9 | 2004-04-17 17:25:08 +0000 | [diff] [blame] | 375 | |
nethercote | 64bc5af | 2004-11-18 11:57:00 +0000 | [diff] [blame] | 376 | if (defined $cleanup) { |
| 377 | (system("$cleanup") == 0) or |
| 378 | print("(cleanup operation failed: $cleanup)\n"); |
nethercote | c1f8ad9 | 2004-04-17 17:25:08 +0000 | [diff] [blame] | 379 | } |
| 380 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 381 | $num_tests_done++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | #---------------------------------------------------------------------------- |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 385 | # Test one directory (and any subdirs) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 386 | #---------------------------------------------------------------------------- |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 387 | sub test_one_dir($$); # forward declaration |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 388 | |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 389 | sub test_one_dir($$) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 390 | { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 391 | my ($dir, $prev_dirs) = @_; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 392 | $dir =~ s/\/$//; # trim a trailing '/' |
| 393 | |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 394 | # Ignore dirs into which we should not recurse. |
mueller | 92f0b80 | 2003-11-19 00:55:32 +0000 | [diff] [blame] | 395 | if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; } |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 396 | |
njn | 107bc57 | 2009-02-16 00:42:10 +0000 | [diff] [blame] | 397 | (-x "$tests_dir/tests/arch_test") or die |
| 398 | "vg_regtest: 'arch_test' is missing. Did you forget to 'make check'?\n"; |
njn | 52783ca | 2005-12-08 22:39:04 +0000 | [diff] [blame] | 399 | |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 400 | # Ignore any dir whose name matches that of an architecture which is not |
njn | 107bc57 | 2009-02-16 00:42:10 +0000 | [diff] [blame] | 401 | # 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. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 404 | # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256... |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 405 | if (256 == system("$tests_dir/tests/arch_test $dir")) { return; } |
| 406 | if (256 == system("$tests_dir/tests/os_test $dir")) { return; } |
njn | 107bc57 | 2009-02-16 00:42:10 +0000 | [diff] [blame] | 407 | if ($dir =~ /(\w+)-(\w+)/ && |
| 408 | 256 == system("sh $tests_dir/tests/platform_test $1 $2")) { return; } |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 409 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 410 | chdir($dir) or die "Could not change into $dir\n"; |
| 411 | |
njn | 584eaac | 2002-10-04 15:30:48 +0000 | [diff] [blame] | 412 | # Nb: Don't prepend a '/' to the base directory |
| 413 | my $full_dir = $prev_dirs . ($prev_dirs eq "" ? "" : "/") . $dir; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 414 | my $dashes = "-" x (50 - length $full_dir); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 415 | |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 416 | my @fs = glob "*"; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 417 | my $found_tests = (0 != (grep { $_ =~ /\.vgtest$/ } @fs)); |
| 418 | |
| 419 | if ($found_tests) { |
| 420 | print "-- Running tests in $full_dir $dashes\n"; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 421 | } |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 422 | foreach my $f (@fs) { |
| 423 | if (-d $f) { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 424 | test_one_dir($f, $full_dir); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 425 | } elsif ($f =~ /\.vgtest$/) { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 426 | do_one_test($full_dir, $f); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 427 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 428 | } |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 429 | if ($found_tests) { |
| 430 | print "-- Finished tests in $full_dir $dashes\n"; |
| 431 | } |
| 432 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 433 | chdir(".."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | #---------------------------------------------------------------------------- |
| 437 | # Summarise results |
| 438 | #---------------------------------------------------------------------------- |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 439 | sub plural($) |
| 440 | { |
| 441 | return ( $_[0] == 1 ? "" : "s" ); |
| 442 | } |
| 443 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 444 | sub summarise_results |
| 445 | { |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 446 | my $x = ( $num_tests_done == 1 ? "test" : "tests" ); |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 447 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 448 | printf("\n== %d test%s, %d stderr failure%s, %d stdout failure%s, " |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 449 | . "%d post failure%s ==\n", |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 450 | $num_tests_done, plural($num_tests_done), |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 451 | $num_failures{"stderr"}, plural($num_failures{"stderr"}), |
| 452 | $num_failures{"stdout"}, plural($num_failures{"stdout"}), |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 453 | $num_failures{"post"}, plural($num_failures{"post"})); |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 454 | |
| 455 | foreach my $failure (@failures) { |
| 456 | print "$failure\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 457 | } |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 458 | print "\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | #---------------------------------------------------------------------------- |
| 462 | # main(), sort of |
| 463 | #---------------------------------------------------------------------------- |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 464 | sub 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 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 471 | |
daywalker | bb93698 | 2003-04-23 16:52:06 +0000 | [diff] [blame] | 472 | # nuke VALGRIND_OPTS |
| 473 | $ENV{"VALGRIND_OPTS"} = ""; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 474 | |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 475 | if ($ENV{"EXTRA_REGTEST_OPTS"}) { |
| 476 | print "\n"; |
| 477 | warn_about_EXTRA_REGTEST_OPTS(); |
| 478 | } |
| 479 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 480 | my @fs = process_command_line(); |
| 481 | foreach my $f (@fs) { |
| 482 | if (-d $f) { |
njn | 584eaac | 2002-10-04 15:30:48 +0000 | [diff] [blame] | 483 | test_one_dir($f, ""); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 484 | } 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 | } |
| 500 | summarise_results(); |
| 501 | |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 502 | if ($ENV{"EXTRA_REGTEST_OPTS"}) { |
| 503 | warn_about_EXTRA_REGTEST_OPTS(); |
| 504 | } |
| 505 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 506 | if (0 == $num_failures{"stdout"} && |
| 507 | 0 == $num_failures{"stderr"} && |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 508 | 0 == $num_failures{"post"}) { |
nethercote | ab42219 | 2004-03-01 08:27:37 +0000 | [diff] [blame] | 509 | exit 0; |
| 510 | } else { |
| 511 | exit 1; |
| 512 | } |
| 513 | |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 514 | ##--------------------------------------------------------------------## |
| 515 | ##--- end vg_regtest ---## |
| 516 | ##--------------------------------------------------------------------## |