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 | # |
sewardj | b3a1e4b | 2015-08-21 11:32:26 +0000 | [diff] [blame] | 9 | # Copyright (C) 2003-2015 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.) |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 40 | # --keep-unfiltered: keep a copy of the unfiltered output/error output |
| 41 | # of each test by adding an extension .unfiltered.out |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 42 | # |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 43 | # --outer-valgrind: run this valgrind under the given outer valgrind. |
| 44 | # This valgrind must be configured with --enable-inner. |
| 45 | # --outer-tool: tool to use by the outer valgrind (default memcheck). |
| 46 | # --outer-args: use this as outer tool args. |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 47 | # --loop-till-fail: loops on the test(s) till one fail, then exit |
| 48 | # This is useful to obtain detailed trace or --keep-unfiltered |
| 49 | # output of a non deterministic test failure |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 50 | # |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 51 | # The easiest way is to run all tests in valgrind/ with (assuming you installed |
| 52 | # in $PREFIX): |
| 53 | # |
| 54 | # $PREFIX/bin/vg_regtest --all |
| 55 | # |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 56 | # You can specify individual files to test, or whole directories, or both. |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 57 | # Directories are traversed recursively, except for ones named, for example, |
| 58 | # CVS/ or docs/. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 59 | # |
| 60 | # 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] | 61 | # following lines, in any order: |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 62 | # - prog: <prog to run> |
| 63 | # - prog-asis: <prog to run> |
| 64 | # - env: <environment variable for prog> (default: none) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 65 | # - args: <args for prog> (default: none) |
njn | f6b0076 | 2009-04-17 04:26:41 +0000 | [diff] [blame] | 66 | # - vgopts: <Valgrind options> (default: none; |
| 67 | # multiple are allowed) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 68 | # - stdout_filter: <filter to run stdout through> (default: none) |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 69 | # - stderr_filter: <filter to run stderr through> (default: ./filter_stderr) |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 70 | # - stdout_filter_args: <args for stdout_filter> (default: basename of .vgtest file) |
| 71 | # - stderr_filter_args: <args for stderr_filter> (default: basename of .vgtest file) |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 72 | # |
| 73 | # - progB: <prog to run in parallel with prog> (default: none) |
florian | 064ed86 | 2015-08-26 20:24:47 +0000 | [diff] [blame] | 74 | # - envB: <environment variable for progB> (default: none) |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 75 | # - argsB: <args for progB> (default: none) |
| 76 | # - stdinB: <input file for progB> (default: none) |
| 77 | # - stdoutB_filter: <filter progB stdout through> (default: none) |
| 78 | # - stderrB_filter: <filter progB stderr through> (default: ./filter_stderr) |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 79 | # - stdoutB_filter_args: <args for stdout_filterB> (default: basename of .vgtest file) |
| 80 | # - stderrB_filter_args: <args for stderr_filterB> (default: basename of .vgtest file) |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 81 | # |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 82 | # - prereq: <prerequisite command> (default: none) |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 83 | # - post: <post-test check command> (default: none) |
| 84 | # - cleanup: <post-test cleanup cmd> (default: none) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 85 | # |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 86 | # One of prog or prog-asis must be specified. |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 87 | # If prog or probB is a relative path, it will be prefix with the test directory. |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 88 | # prog-asis will be taken as is, i.e. not prefixed with the test directory. |
njn | a217f3d | 2002-09-27 08:26:27 +0000 | [diff] [blame] | 89 | # Note that filters are necessary for stderr results to filter out things that |
| 90 | # always change, eg. process id numbers. |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 91 | # Note that if a progB is specified, it is started in background (before prog). |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 92 | # |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 93 | # There can be more than one env: declaration. Here is an example: |
| 94 | # env: PATH=/opt/bin:$PATH |
florian | 064ed86 | 2015-08-26 20:24:47 +0000 | [diff] [blame] | 95 | # Likewise for envB. |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 96 | # |
njn | 1ee25f0 | 2008-02-27 18:10:19 +0000 | [diff] [blame] | 97 | # Expected stdout (filtered) is kept in <test>.stdout.exp* (can be more |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 98 | # 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] | 99 | # stderr (filtered) is kept in <test>.stderr.exp*. There must be at least |
njn | e8ffe52 | 2008-03-02 22:48:14 +0000 | [diff] [blame] | 100 | # one stderr.exp* file. Any .exp* file that ends in '~' or '#' is ignored; |
| 101 | # this is because Emacs creates temporary files of these names. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 102 | # |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 103 | # Expected output for progB is handled similarly, except that |
| 104 | # expected stdout and stderr for progB are in <test>.stdoutB.exp* |
| 105 | # and <test>.stderrB.exp*. |
| 106 | # |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 107 | # 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] | 108 | # and the diff between expected and actual in <test>.std<strm>.diff*. |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 109 | # (for progB, in <test>.std<strm>2.out and <test>.std<strm>2.diff*). |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 110 | # |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 111 | # The prerequisite command, if present, works like this: |
| 112 | # - if it returns 0 the test is run |
| 113 | # - if it returns 1 the test is skipped |
| 114 | # - if it returns anything else the script aborts. |
| 115 | # The idea here is results other than 0 or 1 are likely to be due to |
| 116 | # problems with the commands, and you don't want to conflate them with the 1 |
| 117 | # case, which would happen if you just tested for zero or non-zero. |
| 118 | # |
| 119 | # The post-test command, if present, must return 0 and its stdout must match |
| 120 | # the expected stdout which is kept in <test>.post.exp*. |
| 121 | # |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 122 | # Sometimes it is useful to run all the tests at a high sanity check |
| 123 | # level or with arbitrary other flags. To make this simple, extra |
| 124 | # options, applied to all tests run, are read from $EXTRA_REGTEST_OPTS, |
| 125 | # and handed to valgrind prior to any other flags specified by the |
| 126 | # .vgtest file. |
| 127 | # |
njn | 7358d52 | 2006-11-26 22:49:58 +0000 | [diff] [blame] | 128 | # Some more notes on adding regression tests for a new tool are in |
| 129 | # docs/xml/manual-writing-tools.xml. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 130 | #---------------------------------------------------------------------------- |
| 131 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 132 | use warnings; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 133 | use strict; |
| 134 | |
| 135 | #---------------------------------------------------------------------------- |
| 136 | # Global vars |
| 137 | #---------------------------------------------------------------------------- |
sewardj | a8162b2 | 2007-11-30 21:24:05 +0000 | [diff] [blame] | 138 | my $usage="\n" |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 139 | . "Usage:\n" |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 140 | . " vg_regtest [--all, --valgrind, --valgrind-lib, --keep-unfiltered\n" |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 141 | . " --outer-valgrind, --outer-tool, --outer-args\n" |
| 142 | . " --loop-till-fail]\n" |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 143 | . " Use EXTRA_REGTEST_OPTS to supply extra args for all tests\n" |
| 144 | . "\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 145 | |
| 146 | my $tmp="vg_regtest.tmp.$$"; |
| 147 | |
| 148 | # Test variables |
| 149 | my $vgopts; # valgrind options |
| 150 | my $prog; # test prog |
| 151 | my $args; # test prog args |
| 152 | my $stdout_filter; # filter program to run stdout results file through |
| 153 | my $stderr_filter; # filter program to run stderr results file through |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 154 | my $stdout_filter_args; # arguments passed to stdout_filter |
| 155 | my $stderr_filter_args; # arguments passed to stderr_filter |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 156 | my $progB; # Same but for progB |
| 157 | my $argsB; # |
| 158 | my $stdoutB_filter; # |
| 159 | my $stderrB_filter; # |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 160 | my $stdoutB_filter_args;# arguments passed to stdout_filterB |
| 161 | my $stderrB_filter_args;# arguments passed to stderr_filterB |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 162 | my $stdinB; # Input file for progB |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 163 | my $prereq; # prerequisite test to satisfy before running test |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 164 | my $post; # check command after running test |
nethercote | 64bc5af | 2004-11-18 11:57:00 +0000 | [diff] [blame] | 165 | my $cleanup; # cleanup command to run |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 166 | my @env = (); # environment variable to set prior calling $prog |
florian | 064ed86 | 2015-08-26 20:24:47 +0000 | [diff] [blame] | 167 | my @envB = (); # environment variable to set prior calling $progB |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 168 | |
| 169 | my @failures; # List of failed tests |
| 170 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 171 | my $num_tests_done = 0; |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 172 | my %num_failures = (stderr => 0, stdout => 0, |
| 173 | stderrB => 0, stdoutB => 0, |
| 174 | post => 0); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 175 | |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 176 | # Default valgrind to use is this build tree's (uninstalled) one |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 177 | my $valgrind = "./coregrind/valgrind"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 178 | |
| 179 | chomp(my $tests_dir = `pwd`); |
| 180 | |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 181 | # Outer valgrind to use, and args to use for it. |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 182 | my $outer_valgrind; |
| 183 | my $outer_tool = "memcheck"; |
| 184 | my $outer_args; |
| 185 | |
njn | 3ed8960 | 2006-10-23 18:38:35 +0000 | [diff] [blame] | 186 | my $valgrind_lib = "$tests_dir/.in_place"; |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 187 | my $keepunfiltered = 0; |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 188 | my $looptillfail = 0; |
njn | 3ed8960 | 2006-10-23 18:38:35 +0000 | [diff] [blame] | 189 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 190 | # default filter is the one named "filter_stderr" in the test's directory |
| 191 | my $default_stderr_filter = "filter_stderr"; |
| 192 | |
| 193 | |
| 194 | #---------------------------------------------------------------------------- |
| 195 | # Process command line, setup |
| 196 | #---------------------------------------------------------------------------- |
| 197 | |
| 198 | # If $prog is a relative path, it prepends $dir to it. Useful for two reasons: |
| 199 | # |
| 200 | # 1. Can prepend "." onto programs to avoid trouble with users who don't have |
| 201 | # "." in their path (by making $dir = ".") |
| 202 | # 2. Can prepend the current dir to make the command absolute to avoid |
| 203 | # subsequent trouble when we change directories. |
| 204 | # |
| 205 | # Also checks the program exists and is executable. |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 206 | sub validate_program ($$$$) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 207 | { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 208 | my ($dir, $prog, $must_exist, $must_be_executable) = @_; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 209 | |
| 210 | # If absolute path, leave it alone. If relative, make it |
| 211 | # absolute -- by prepending current dir -- so we can change |
| 212 | # dirs and still use it. |
| 213 | $prog = "$dir/$prog" if ($prog !~ /^\//); |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 214 | if ($must_exist) { |
| 215 | (-f $prog) or die "vg_regtest: `$prog' not found or not a file ($dir)\n"; |
| 216 | } |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 217 | if ($must_be_executable) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 218 | (-x $prog) or die "vg_regtest: `$prog' not executable ($dir)\n"; |
njn | 71fe3e6 | 2003-04-23 21:48:20 +0000 | [diff] [blame] | 219 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 220 | |
| 221 | return $prog; |
| 222 | } |
| 223 | |
| 224 | sub process_command_line() |
| 225 | { |
| 226 | my $alldirs = 0; |
| 227 | my @fs; |
| 228 | |
| 229 | for my $arg (@ARGV) { |
| 230 | if ($arg =~ /^-/) { |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 231 | if ($arg =~ /^--all$/) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 232 | $alldirs = 1; |
| 233 | } elsif ($arg =~ /^--valgrind=(.*)$/) { |
| 234 | $valgrind = $1; |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 235 | } elsif ($arg =~ /^--outer-valgrind=(.*)$/) { |
| 236 | $outer_valgrind = $1; |
| 237 | } elsif ($arg =~ /^--outer-tool=(.*)$/) { |
| 238 | $outer_tool = $1; |
| 239 | } elsif ($arg =~ /^--outer-args=(.*)$/) { |
| 240 | $outer_args = $1; |
njn | 3ed8960 | 2006-10-23 18:38:35 +0000 | [diff] [blame] | 241 | } elsif ($arg =~ /^--valgrind-lib=(.*)$/) { |
| 242 | $valgrind_lib = $1; |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 243 | } elsif ($arg =~ /^--keep-unfiltered$/) { |
| 244 | $keepunfiltered = 1; |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 245 | } elsif ($arg =~ /^--loop-till-fail$/) { |
| 246 | $looptillfail = 1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 247 | } else { |
| 248 | die $usage; |
| 249 | } |
| 250 | } else { |
| 251 | push(@fs, $arg); |
| 252 | } |
| 253 | } |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 254 | $valgrind = validate_program($tests_dir, $valgrind, 1, 0); |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 255 | |
| 256 | if (defined $outer_valgrind) { |
philippe | 14ab1a3 | 2012-04-08 19:52:38 +0000 | [diff] [blame] | 257 | $outer_valgrind = validate_program($tests_dir, $outer_valgrind, 1, 1); |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 258 | if (not defined $outer_args) { |
| 259 | $outer_args = |
philippe | 14ab1a3 | 2012-04-08 19:52:38 +0000 | [diff] [blame] | 260 | " --command-line-only=yes" |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 261 | . " --run-libc-freeres=no --sim-hints=enable-outer" |
philippe | 14ab1a3 | 2012-04-08 19:52:38 +0000 | [diff] [blame] | 262 | . " --smc-check=all-non-file" |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 263 | . " --vgdb=no --trace-children=yes --read-var-info=no" |
philippe | 0a961fc | 2014-06-25 23:27:08 +0000 | [diff] [blame] | 264 | . " --read-inline-info=yes" |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 265 | . " --suppressions=" |
| 266 | . validate_program($tests_dir,"./tests/outer_inner.supp",1,0) |
| 267 | . " --memcheck:leak-check=full --memcheck:show-reachable=no" |
| 268 | . " "; |
| 269 | } |
| 270 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 271 | |
| 272 | if ($alldirs) { |
| 273 | @fs = (); |
| 274 | foreach my $f (glob "*") { |
| 275 | push(@fs, $f) if (-d $f); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | (0 != @fs) or die "No test files or directories specified\n"; |
| 280 | |
| 281 | return @fs; |
| 282 | } |
| 283 | |
| 284 | #---------------------------------------------------------------------------- |
| 285 | # Read a .vgtest file |
| 286 | #---------------------------------------------------------------------------- |
| 287 | sub read_vgtest_file($) |
| 288 | { |
| 289 | my ($f) = @_; |
| 290 | |
| 291 | # Defaults. |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 292 | ($vgopts, $prog, $args) = ("", undef, ""); |
| 293 | ($stdout_filter, $stderr_filter) = (undef, undef); |
| 294 | ($progB, $argsB, $stdinB) = (undef, "", undef); |
| 295 | ($stdoutB_filter, $stderrB_filter) = (undef, undef); |
| 296 | ($prereq, $post, $cleanup) = (undef, undef, undef); |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 297 | ($stdout_filter_args, $stderr_filter_args) = (undef, undef); |
| 298 | ($stdoutB_filter_args, $stderrB_filter_args) = (undef, undef); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 299 | |
| 300 | # Every test directory must have a "filter_stderr" |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 301 | $stderr_filter = validate_program(".", $default_stderr_filter, 1, 1); |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 302 | $stderrB_filter = validate_program(".", $default_stderr_filter, 1, 1); |
| 303 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 304 | |
| 305 | open(INPUTFILE, "< $f") || die "File $f not openable\n"; |
| 306 | |
| 307 | while (my $line = <INPUTFILE>) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 308 | if ($line =~ /^\s*#/ || $line =~ /^\s*$/) { |
| 309 | next; |
| 310 | } elsif ($line =~ /^\s*vgopts:\s*(.*)$/) { |
bart | ef38625 | 2010-08-31 15:15:35 +0000 | [diff] [blame] | 311 | my $addvgopts = $1; |
florian | 7017236 | 2015-09-05 21:19:11 +0000 | [diff] [blame] | 312 | $addvgopts =~ s/\$\{PWD\}/$ENV{PWD}/g; |
bart | ef38625 | 2010-08-31 15:15:35 +0000 | [diff] [blame] | 313 | $vgopts = $vgopts . " " . $addvgopts; # Nb: Make sure there's a space! |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 314 | } elsif ($line =~ /^\s*prog:\s*(.*)$/) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 315 | $prog = validate_program(".", $1, 0, 0); |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 316 | } elsif ($line =~ /^\s*prog-asis:\s*(.*)$/) { |
| 317 | $prog = $1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 318 | } elsif ($line =~ /^\s*args:\s*(.*)$/) { |
| 319 | $args = $1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 320 | } elsif ($line =~ /^\s*stdout_filter:\s*(.*)$/) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 321 | $stdout_filter = validate_program(".", $1, 1, 1); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 322 | } elsif ($line =~ /^\s*stderr_filter:\s*(.*)$/) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 323 | $stderr_filter = validate_program(".", $1, 1, 1); |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 324 | } elsif ($line =~ /^\s*stdout_filter_args:\s*(.*)$/) { |
| 325 | $stdout_filter_args = $1; |
| 326 | } elsif ($line =~ /^\s*stderr_filter_args:\s*(.*)$/) { |
| 327 | $stderr_filter_args = $1; |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 328 | } elsif ($line =~ /^\s*progB:\s*(.*)$/) { |
| 329 | $progB = validate_program(".", $1, 0, 0); |
| 330 | } elsif ($line =~ /^\s*argsB:\s*(.*)$/) { |
| 331 | $argsB = $1; |
| 332 | } elsif ($line =~ /^\s*stdinB:\s*(.*)$/) { |
| 333 | $stdinB = $1; |
| 334 | } elsif ($line =~ /^\s*stdoutB_filter:\s*(.*)$/) { |
| 335 | $stdoutB_filter = validate_program(".", $1, 1, 1); |
| 336 | } elsif ($line =~ /^\s*stderrB_filter:\s*(.*)$/) { |
| 337 | $stderrB_filter = validate_program(".", $1, 1, 1); |
florian | 4b5c3f0 | 2011-10-03 00:19:05 +0000 | [diff] [blame] | 338 | } elsif ($line =~ /^\s*stdoutB_filter_args:\s*(.*)$/) { |
| 339 | $stdoutB_filter_args = $1; |
| 340 | } elsif ($line =~ /^\s*stderrB_filter_args:\s*(.*)$/) { |
| 341 | $stderrB_filter_args = $1; |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 342 | } elsif ($line =~ /^\s*prereq:\s*(.*)$/) { |
| 343 | $prereq = $1; |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 344 | } elsif ($line =~ /^\s*post:\s*(.*)$/) { |
| 345 | $post = $1; |
nethercote | 64bc5af | 2004-11-18 11:57:00 +0000 | [diff] [blame] | 346 | } elsif ($line =~ /^\s*cleanup:\s*(.*)$/) { |
| 347 | $cleanup = $1; |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 348 | } elsif ($line =~ /^\s*env:\s*(.*)$/) { |
| 349 | push @env,$1; |
florian | 064ed86 | 2015-08-26 20:24:47 +0000 | [diff] [blame] | 350 | } elsif ($line =~ /^\s*envB:\s*(.*)$/) { |
| 351 | push @envB,$1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 352 | } else { |
| 353 | die "Bad line in $f: $line\n"; |
| 354 | } |
| 355 | } |
| 356 | close(INPUTFILE); |
| 357 | |
| 358 | if (!defined $prog) { |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 359 | $prog = ""; # allow no prog for testing error and --help cases |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | #---------------------------------------------------------------------------- |
| 364 | # Do one test |
| 365 | #---------------------------------------------------------------------------- |
| 366 | # Since most of the program time is spent in system() calls, need this to |
| 367 | # propagate a Ctrl-C enabling us to quit. |
| 368 | sub mysystem($) |
| 369 | { |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 370 | my $exit_code = system($_[0]); |
| 371 | ($exit_code == 2) and exit 1; # 2 is SIGINT |
| 372 | return $exit_code; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 373 | } |
| 374 | |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 375 | # if $keepunfiltered, copies $1 to $1.unfiltered.out |
| 376 | # renames $0 tp $1 |
| 377 | sub filtered_rename($$) |
| 378 | { |
| 379 | if ($keepunfiltered == 1) { |
| 380 | mysystem("cp $_[1] $_[1].unfiltered.out"); |
| 381 | } |
| 382 | rename ($_[0], $_[1]); |
| 383 | } |
| 384 | |
| 385 | |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 386 | # from a directory name like "/foo/cachesim/tests/" determine the tool name |
| 387 | sub determine_tool() |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 388 | { |
| 389 | my $dir = `pwd`; |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 390 | $dir =~ /.*\/([^\/]+)\/tests.*/; # foo/tool_name/tests/foo |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 391 | return $1; |
| 392 | } |
| 393 | |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 394 | # Compare output against expected output; it should match at least one of |
| 395 | # them. |
| 396 | sub do_diffs($$$$) |
| 397 | { |
| 398 | my ($fullname, $name, $mid, $f_exps) = @_; |
| 399 | |
| 400 | for my $f_exp (@$f_exps) { |
| 401 | (-r $f_exp) or die "Could not read `$f_exp'\n"; |
| 402 | |
njn | e8ffe52 | 2008-03-02 22:48:14 +0000 | [diff] [blame] | 403 | # Emacs produces temporary files that end in '~' and '#'. We ignore |
| 404 | # these. |
| 405 | if ($f_exp !~ /[~#]$/) { |
| 406 | # $n is the (optional) suffix after the ".exp"; we tack it onto |
| 407 | # the ".diff" file. |
| 408 | my $n = ""; |
| 409 | if ($f_exp =~ /.*\.exp(.*)$/) { |
| 410 | $n = $1; |
| 411 | } else { |
| 412 | $n = ""; |
| 413 | ($f_exp eq "/dev/null") or die "Unexpected .exp file: $f_exp\n"; |
| 414 | } |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 415 | |
njn | 0d2e58f | 2009-02-25 04:57:56 +0000 | [diff] [blame] | 416 | mysystem("@DIFF@ $f_exp $name.$mid.out > $name.$mid.diff$n"); |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 417 | |
njn | e8ffe52 | 2008-03-02 22:48:14 +0000 | [diff] [blame] | 418 | if (not -s "$name.$mid.diff$n") { |
| 419 | # A match; remove .out and any previously created .diff files. |
| 420 | unlink("$name.$mid.out"); |
| 421 | unlink(<$name.$mid.diff*>); |
| 422 | return; |
| 423 | } |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | # If we reach here, none of the .exp files matched. |
| 427 | print "*** $name failed ($mid) ***\n"; |
| 428 | push(@failures, sprintf("%-40s ($mid)", "$fullname")); |
| 429 | $num_failures{$mid}++; |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 430 | if ($looptillfail == 1) { |
| 431 | print "Failure encountered, stopping to loop\n"; |
| 432 | exit 1 |
| 433 | } |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 434 | } |
| 435 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 436 | sub do_one_test($$) |
| 437 | { |
| 438 | my ($dir, $vgtest) = @_; |
| 439 | $vgtest =~ /^(.*)\.vgtest/; |
| 440 | my $name = $1; |
| 441 | my $fullname = "$dir/$name"; |
| 442 | |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 443 | # Pull any extra options (for example, --sanity-level=4) |
| 444 | # from $EXTRA_REGTEST_OPTS. |
| 445 | my $maybe_extraopts = $ENV{"EXTRA_REGTEST_OPTS"}; |
| 446 | my $extraopts = $maybe_extraopts ? $maybe_extraopts : ""; |
| 447 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 448 | read_vgtest_file($vgtest); |
| 449 | |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 450 | if (defined $prereq) { |
bart | 3a89e00 | 2015-07-23 02:46:44 +0000 | [diff] [blame] | 451 | my $prereq_res = system("/bin/sh", "-c", $prereq); |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 452 | if (0 == $prereq_res) { |
| 453 | # Do nothing (ie. continue with the test) |
| 454 | } elsif (256 == $prereq_res) { |
| 455 | # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256... |
| 456 | # Prereq failed, skip. |
nethercote | c5e1d80 | 2004-11-18 12:48:17 +0000 | [diff] [blame] | 457 | printf("%-16s (skipping, prereq failed: $prereq)\n", "$name:"); |
nethercote | 781bed4 | 2004-10-19 16:56:41 +0000 | [diff] [blame] | 458 | return; |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 459 | } else { |
| 460 | # Bad prereq; abort. |
| 461 | $prereq_res /= 256; |
| 462 | die "prereq returned $prereq_res: $prereq\n"; |
nethercote | 781bed4 | 2004-10-19 16:56:41 +0000 | [diff] [blame] | 463 | } |
nethercote | b1affa8 | 2004-01-19 19:14:18 +0000 | [diff] [blame] | 464 | } |
| 465 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 466 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 467 | if (defined $progB) { |
florian | 064ed86 | 2015-08-26 20:24:47 +0000 | [diff] [blame] | 468 | # Collect environment variables, if any. |
| 469 | my $envBvars = ""; |
| 470 | foreach my $e (@envB) { |
| 471 | $envBvars = "$envBvars $e"; |
| 472 | } |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 473 | # If there is a progB, let's start it in background: |
| 474 | printf("%-16s valgrind $extraopts $vgopts $prog $args (progB: $progB $argsB)\n", |
| 475 | "$name:"); |
| 476 | # progB.done used to detect child has finished. See below. |
| 477 | # Note: redirection of stdout and stderr is before $progB to allow argsB |
| 478 | # to e.g. redirect stdoutB to stderrB |
| 479 | if (defined $stdinB) { |
| 480 | mysystem("(rm -f progB.done;" |
florian | 064ed86 | 2015-08-26 20:24:47 +0000 | [diff] [blame] | 481 | . " < $stdinB > $name.stdoutB.out 2> $name.stderrB.out" |
| 482 | . " $envBvars $progB $argsB;" |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 483 | . "touch progB.done) &"); |
| 484 | } else { |
| 485 | mysystem("(rm -f progB.done;" |
florian | 064ed86 | 2015-08-26 20:24:47 +0000 | [diff] [blame] | 486 | . " > $name.stdoutB.out 2> $name.stderrB.out" |
| 487 | . "$envBvars $progB $argsB;" |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 488 | . "touch progB.done) &"); |
| 489 | } |
| 490 | } else { |
| 491 | printf("%-16s valgrind $extraopts $vgopts $prog $args\n", "$name:"); |
| 492 | } |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 493 | |
| 494 | # Collect environment variables, if any. |
| 495 | my $envvars = ""; |
| 496 | foreach my $e (@env) { |
| 497 | $envvars = "$envvars $e"; |
| 498 | } |
| 499 | |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 500 | # Pass the appropriate --tool option for the directory (can be overridden |
philippe | 14ab1a3 | 2012-04-08 19:52:38 +0000 | [diff] [blame] | 501 | # by an "args:" line, though). |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 502 | my $tool=determine_tool(); |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 503 | if (defined $outer_valgrind ) { |
philippe | 14ab1a3 | 2012-04-08 19:52:38 +0000 | [diff] [blame] | 504 | # in an outer-inner setup, only set VALGRIND_LIB_INNER |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 505 | mysystem( "$envvars VALGRIND_LIB_INNER=$valgrind_lib " |
philippe | 14ab1a3 | 2012-04-08 19:52:38 +0000 | [diff] [blame] | 506 | . "$outer_valgrind " |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 507 | . "--tool=" . $outer_tool . " " |
| 508 | . "$outer_args " |
| 509 | . "--log-file=" . "$name.outer.log " |
| 510 | . "$valgrind --command-line-only=yes --memcheck:leak-check=no " |
| 511 | . "--sim-hints=no-inner-prefix " |
| 512 | . "--tool=$tool $extraopts $vgopts " |
| 513 | . "$prog $args > $name.stdout.out 2> $name.stderr.out"); |
| 514 | } else { |
philippe | 14ab1a3 | 2012-04-08 19:52:38 +0000 | [diff] [blame] | 515 | # Set both VALGRIND_LIB and VALGRIND_LIB_INNER in case this Valgrind |
| 516 | # was configured with --enable-inner. |
florian | 8d22844 | 2015-04-02 22:02:24 +0000 | [diff] [blame] | 517 | mysystem( "$envvars VALGRIND_LIB=$valgrind_lib VALGRIND_LIB_INNER=$valgrind_lib " |
philippe | 72faf10 | 2012-03-11 22:24:03 +0000 | [diff] [blame] | 518 | . "$valgrind --command-line-only=yes --memcheck:leak-check=no " |
| 519 | . "--tool=$tool $extraopts $vgopts " |
| 520 | . "$prog $args > $name.stdout.out 2> $name.stderr.out"); |
| 521 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 522 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 523 | # Filter stdout |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 524 | if (defined $stdout_filter) { |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 525 | $stdout_filter_args = $name if (! defined $stdout_filter_args); |
| 526 | mysystem("$stdout_filter $stdout_filter_args < $name.stdout.out > $tmp"); |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 527 | filtered_rename($tmp, "$name.stdout.out"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 528 | } |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 529 | # Find all the .stdout.exp files. If none, use /dev/null. |
| 530 | my @stdout_exps = <$name.stdout.exp*>; |
| 531 | @stdout_exps = ( "/dev/null" ) if (0 == scalar @stdout_exps); |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 532 | do_diffs($fullname, $name, "stdout", \@stdout_exps); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 533 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 534 | # Filter stderr |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 535 | $stderr_filter_args = $name if (! defined $stderr_filter_args); |
| 536 | mysystem("$stderr_filter $stderr_filter_args < $name.stderr.out > $tmp"); |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 537 | filtered_rename($tmp, "$name.stderr.out"); |
sewardj | 79e88da | 2007-11-09 23:29:46 +0000 | [diff] [blame] | 538 | # Find all the .stderr.exp files. At least one must exist. |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 539 | my @stderr_exps = <$name.stderr.exp*>; |
sewardj | 79e88da | 2007-11-09 23:29:46 +0000 | [diff] [blame] | 540 | (0 != scalar @stderr_exps) or die "Could not find `$name.stderr.exp*'\n"; |
nethercote | 4592db6 | 2004-02-29 01:31:09 +0000 | [diff] [blame] | 541 | do_diffs($fullname, $name, "stderr", \@stderr_exps); |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 542 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 543 | if (defined $progB) { |
| 544 | # wait for the child to be finished |
| 545 | # tried things such as: |
| 546 | # wait; |
| 547 | # $SIG{CHLD} = sub { wait }; |
| 548 | # but nothing worked: |
| 549 | # e.g. running mssnapshot.vgtest in a loop failed from time to time |
| 550 | # due to some missing output (not yet written?). |
| 551 | # So, we search progB.done during max 100 times 100 millisecond. |
| 552 | my $count; |
| 553 | for ($count = 1; $count <= 100; $count++) { |
| 554 | (-f "progB.done") or select(undef, undef, undef, 0.100); |
| 555 | } |
| 556 | # Filter stdout |
| 557 | if (defined $stdoutB_filter) { |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 558 | $stdoutB_filter_args = $name if (! defined $stdoutB_filter_args); |
| 559 | mysystem("$stdoutB_filter $stdoutB_filter_args < $name.stdoutB.out > $tmp"); |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 560 | filtered_rename($tmp, "$name.stdoutB.out"); |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 561 | } |
| 562 | # Find all the .stdoutB.exp files. If none, use /dev/null. |
| 563 | my @stdoutB_exps = <$name.stdoutB.exp*>; |
| 564 | @stdoutB_exps = ( "/dev/null" ) if (0 == scalar @stdoutB_exps); |
| 565 | do_diffs($fullname, $name, "stdoutB", \@stdoutB_exps); |
| 566 | |
| 567 | # Filter stderr |
florian | 31014da | 2011-09-26 00:29:44 +0000 | [diff] [blame] | 568 | $stderrB_filter_args = $name if (! defined $stderrB_filter_args); |
| 569 | mysystem("$stderrB_filter $stderrB_filter_args < $name.stderrB.out > $tmp"); |
sewardj | eefeeb7 | 2011-05-10 11:01:07 +0000 | [diff] [blame] | 570 | filtered_rename($tmp, "$name.stderrB.out"); |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 571 | # Find all the .stderrB.exp files. At least one must exist. |
| 572 | my @stderrB_exps = <$name.stderrB.exp*>; |
| 573 | (0 != scalar @stderrB_exps) or die "Could not find `$name.stderrB.exp*'\n"; |
| 574 | do_diffs($fullname, $name, "stderrB", \@stderrB_exps); |
| 575 | } |
| 576 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 577 | # Maybe do post-test check |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 578 | if (defined $post) { |
| 579 | if (mysystem("$post > $name.post.out") != 0) { |
| 580 | print("post check failed: $post\n"); |
| 581 | $num_failures{"post"}++; |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 582 | } else { |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 583 | # Find all the .post.exp files. If none, use /dev/null. |
| 584 | my @post_exps = <$name.post.exp*>; |
| 585 | @post_exps = ( "/dev/null" ) if (0 == scalar @post_exps); |
| 586 | do_diffs($fullname, $name, "post", \@post_exps); |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 587 | } |
| 588 | } |
nethercote | c1f8ad9 | 2004-04-17 17:25:08 +0000 | [diff] [blame] | 589 | |
nethercote | 64bc5af | 2004-11-18 11:57:00 +0000 | [diff] [blame] | 590 | if (defined $cleanup) { |
| 591 | (system("$cleanup") == 0) or |
| 592 | print("(cleanup operation failed: $cleanup)\n"); |
nethercote | c1f8ad9 | 2004-04-17 17:25:08 +0000 | [diff] [blame] | 593 | } |
| 594 | |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 595 | $num_tests_done++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | #---------------------------------------------------------------------------- |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 599 | # Test one directory (and any subdirs) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 600 | #---------------------------------------------------------------------------- |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 601 | sub test_one_dir($$); # forward declaration |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 602 | |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 603 | sub test_one_dir($$) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 604 | { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 605 | my ($dir, $prev_dirs) = @_; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 606 | $dir =~ s/\/$//; # trim a trailing '/' |
| 607 | |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 608 | # Ignore dirs into which we should not recurse. |
mueller | 92f0b80 | 2003-11-19 00:55:32 +0000 | [diff] [blame] | 609 | if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; } |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 610 | |
njn | 107bc57 | 2009-02-16 00:42:10 +0000 | [diff] [blame] | 611 | (-x "$tests_dir/tests/arch_test") or die |
| 612 | "vg_regtest: 'arch_test' is missing. Did you forget to 'make check'?\n"; |
njn | 52783ca | 2005-12-08 22:39:04 +0000 | [diff] [blame] | 613 | |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 614 | # Ignore any dir whose name matches that of an architecture which is not |
njn | 107bc57 | 2009-02-16 00:42:10 +0000 | [diff] [blame] | 615 | # the architecture we are running on. Eg. when running on x86, ignore |
| 616 | # ppc/ directories ('arch_test' returns 1 for this case). Likewise for |
| 617 | # the OS and platform. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 618 | # 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] | 619 | if (256 == system("$tests_dir/tests/arch_test $dir")) { return; } |
| 620 | if (256 == system("$tests_dir/tests/os_test $dir")) { return; } |
njn | 107bc57 | 2009-02-16 00:42:10 +0000 | [diff] [blame] | 621 | if ($dir =~ /(\w+)-(\w+)/ && |
| 622 | 256 == system("sh $tests_dir/tests/platform_test $1 $2")) { return; } |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 623 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 624 | chdir($dir) or die "Could not change into $dir\n"; |
| 625 | |
njn | 584eaac | 2002-10-04 15:30:48 +0000 | [diff] [blame] | 626 | # Nb: Don't prepend a '/' to the base directory |
| 627 | my $full_dir = $prev_dirs . ($prev_dirs eq "" ? "" : "/") . $dir; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 628 | my $dashes = "-" x (50 - length $full_dir); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 629 | |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 630 | my @fs = glob "*"; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 631 | my $found_tests = (0 != (grep { $_ =~ /\.vgtest$/ } @fs)); |
| 632 | |
| 633 | if ($found_tests) { |
| 634 | print "-- Running tests in $full_dir $dashes\n"; |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 635 | } |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 636 | foreach my $f (@fs) { |
| 637 | if (-d $f) { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 638 | test_one_dir($f, $full_dir); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 639 | } elsif ($f =~ /\.vgtest$/) { |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 640 | do_one_test($full_dir, $f); |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 641 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 642 | } |
njn | db3c469 | 2002-10-04 10:03:34 +0000 | [diff] [blame] | 643 | if ($found_tests) { |
| 644 | print "-- Finished tests in $full_dir $dashes\n"; |
| 645 | } |
| 646 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 647 | chdir(".."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | #---------------------------------------------------------------------------- |
| 651 | # Summarise results |
| 652 | #---------------------------------------------------------------------------- |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 653 | sub plural($) |
| 654 | { |
| 655 | return ( $_[0] == 1 ? "" : "s" ); |
| 656 | } |
| 657 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 658 | sub summarise_results |
| 659 | { |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 660 | my $x = ( $num_tests_done == 1 ? "test" : "tests" ); |
njn | d8ced86 | 2003-04-08 00:47:05 +0000 | [diff] [blame] | 661 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 662 | printf("\n== %d test%s, %d stderr failure%s, %d stdout failure%s, " |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 663 | . "%d stderrB failure%s, %d stdoutB failure%s, " |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 664 | . "%d post failure%s ==\n", |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 665 | $num_tests_done, plural($num_tests_done), |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 666 | $num_failures{"stderr"}, plural($num_failures{"stderr"}), |
| 667 | $num_failures{"stdout"}, plural($num_failures{"stdout"}), |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 668 | $num_failures{"stderrB"}, plural($num_failures{"stderrB"}), |
| 669 | $num_failures{"stdoutB"}, plural($num_failures{"stdoutB"}), |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 670 | $num_failures{"post"}, plural($num_failures{"post"})); |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 671 | |
| 672 | foreach my $failure (@failures) { |
| 673 | print "$failure\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 674 | } |
njn | 9fb16f5 | 2003-04-23 17:47:13 +0000 | [diff] [blame] | 675 | print "\n"; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | #---------------------------------------------------------------------------- |
| 679 | # main(), sort of |
| 680 | #---------------------------------------------------------------------------- |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 681 | sub warn_about_EXTRA_REGTEST_OPTS() |
| 682 | { |
| 683 | print "WARNING: \$EXTRA_REGTEST_OPTS is set. You probably don't want\n"; |
| 684 | print "to run the regression tests with it set, unless you are doing some\n"; |
| 685 | print "strange experiment, and/or you really know what you are doing.\n"; |
| 686 | print "\n"; |
| 687 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 688 | |
daywalker | bb93698 | 2003-04-23 16:52:06 +0000 | [diff] [blame] | 689 | # nuke VALGRIND_OPTS |
| 690 | $ENV{"VALGRIND_OPTS"} = ""; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 691 | |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 692 | if ($ENV{"EXTRA_REGTEST_OPTS"}) { |
| 693 | print "\n"; |
| 694 | warn_about_EXTRA_REGTEST_OPTS(); |
| 695 | } |
| 696 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 697 | my @fs = process_command_line(); |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 698 | while (1) { # we will exit after one loop, unless looptillfail |
| 699 | foreach my $f (@fs) { |
| 700 | if (-d $f) { |
| 701 | test_one_dir($f, ""); |
| 702 | } else { |
| 703 | # Allow the .vgtest suffix to be given or omitted |
| 704 | if ($f =~ /.vgtest$/ && -r $f) { |
| 705 | # do nothing |
| 706 | } elsif (-r "$f.vgtest") { |
| 707 | $f = "$f.vgtest"; |
| 708 | } else { |
| 709 | die "`$f' neither a directory nor a readable test file/name\n" |
| 710 | } |
| 711 | my $dir = `dirname $f`; chomp $dir; |
| 712 | my $file = `basename $f`; chomp $file; |
| 713 | chdir($dir) or die "Could not change into $dir\n"; |
| 714 | do_one_test($dir, $file); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 715 | } |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 716 | chdir($tests_dir); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 717 | } |
philippe | 69e8f17 | 2015-03-14 18:29:35 +0000 | [diff] [blame] | 718 | if ($looptillfail == 0) { |
| 719 | last; |
| 720 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 721 | } |
| 722 | summarise_results(); |
| 723 | |
sewardj | 9136899 | 2006-05-26 00:13:21 +0000 | [diff] [blame] | 724 | if ($ENV{"EXTRA_REGTEST_OPTS"}) { |
| 725 | warn_about_EXTRA_REGTEST_OPTS(); |
| 726 | } |
| 727 | |
njn | 0001fc3 | 2006-04-03 14:25:23 +0000 | [diff] [blame] | 728 | if (0 == $num_failures{"stdout"} && |
| 729 | 0 == $num_failures{"stderr"} && |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 730 | 0 == $num_failures{"stdoutB"} && |
| 731 | 0 == $num_failures{"stderrB"} && |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 732 | 0 == $num_failures{"post"}) { |
nethercote | ab42219 | 2004-03-01 08:27:37 +0000 | [diff] [blame] | 733 | exit 0; |
| 734 | } else { |
| 735 | exit 1; |
| 736 | } |
| 737 | |
njn | c2e7f48 | 2002-09-27 08:44:17 +0000 | [diff] [blame] | 738 | ##--------------------------------------------------------------------## |
| 739 | ##--- end vg_regtest ---## |
| 740 | ##--------------------------------------------------------------------## |