Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | Modify vg_test wrapper to support PTEST formats |
| 2 | |
| 3 | Change the valgrind regression test script vg_regtest to |
| 4 | support the yocto ptest stdout reporting format. The commit adds |
| 5 | '--yocto-ptest' as an optional argument to vg_regtest, which alters |
| 6 | the output to use the ptest infrastructure reporting format: |
| 7 | "[PASS|SKIP|FAIL]: testname" |
| 8 | instead of valgrind's internal test reporting format. Without the added |
| 9 | option, --yocto-ptest, the valgrind regression test output is unchanged. |
| 10 | |
| 11 | Enforce 30 seconds limit for the test. |
| 12 | This resume execution of the remaining tests when valgrind hangs. |
| 13 | |
| 14 | Upstream-Status: Pending |
| 15 | |
| 16 | Signed-off-by: Dave Lerner <dave.lerner@windriver.com> |
| 17 | Signed-off-by: Tudor Florea <tudor.florea@enea.com> |
| 18 | |
| 19 | diff --git a/tests/vg_regtest.in b/tests/vg_regtest.in |
| 20 | index 224385f..3e0383b 100755 |
| 21 | --- a/tests/vg_regtest.in |
| 22 | +++ b/tests/vg_regtest.in |
| 23 | @@ -39,11 +39,11 @@ |
| 24 | # --valgrind.) |
| 25 | # --keep-unfiltered: keep a copy of the unfiltered output/error output |
| 26 | # of each test by adding an extension .unfiltered.out |
| 27 | -# |
| 28 | # --outer-valgrind: run this valgrind under the given outer valgrind. |
| 29 | # This valgrind must be configured with --enable-inner. |
| 30 | # --outer-tool: tool to use by the outer valgrind (default memcheck). |
| 31 | # --outer-args: use this as outer tool args. |
| 32 | +# --yocto-ptest: output in yocto ptest format |
| 33 | # |
| 34 | # The easiest way is to run all tests in valgrind/ with (assuming you installed |
| 35 | # in $PREFIX): |
| 36 | @@ -126,7 +126,7 @@ use strict; |
| 37 | my $usage="\n" |
| 38 | . "Usage:\n" |
| 39 | . " vg_regtest [--all, --valgrind, --valgrind-lib, --keep-unfiltered\n" |
| 40 | - . " --outer-valgrind, --outer-tool, --outer-args]\n" |
| 41 | + . " --outer-valgrind, --outer-tool, --outer-args, --yocto-ptest]\n" |
| 42 | . " Use EXTRA_REGTEST_OPTS to supply extra args for all tests\n" |
| 43 | . "\n"; |
| 44 | |
| 45 | @@ -170,6 +170,7 @@ my $outer_args; |
| 46 | |
| 47 | my $valgrind_lib = "$tests_dir/.in_place"; |
| 48 | my $keepunfiltered = 0; |
| 49 | +my $yoctoptest = 0; |
| 50 | |
| 51 | # default filter is the one named "filter_stderr" in the test's directory |
| 52 | my $default_stderr_filter = "filter_stderr"; |
| 53 | @@ -226,6 +227,8 @@ sub process_command_line() |
| 54 | $valgrind_lib = $1; |
| 55 | } elsif ($arg =~ /^--keep-unfiltered$/) { |
| 56 | $keepunfiltered = 1; |
| 57 | + } elsif ($arg =~ /^--yocto-ptest$/) { |
| 58 | + $yoctoptest = 1; |
| 59 | } else { |
| 60 | die $usage; |
| 61 | } |
| 62 | @@ -340,13 +343,28 @@ sub read_vgtest_file($) |
| 63 | #---------------------------------------------------------------------------- |
| 64 | # Since most of the program time is spent in system() calls, need this to |
| 65 | # propagate a Ctrl-C enabling us to quit. |
| 66 | -sub mysystem($) |
| 67 | +# Enforce 30 seconds limit for the test. |
| 68 | +# This resume execution of the remaining tests if valgrind hangs. |
| 69 | +sub mysystem($) |
| 70 | { |
| 71 | - my $exit_code = system($_[0]); |
| 72 | - ($exit_code == 2) and exit 1; # 2 is SIGINT |
| 73 | - return $exit_code; |
| 74 | + my $exit_code=0; |
| 75 | + eval { |
| 76 | + local $SIG{'ALRM'} = sub { die "timed out\n" }; |
| 77 | + alarm(30); |
| 78 | + $exit_code = system($_[0]); |
| 79 | + alarm (0); |
| 80 | + ($exit_code == 2) and die "SIGINT\n"; # 2 is SIGINT |
| 81 | + }; |
| 82 | + if ($@) { |
| 83 | + if ($@ eq "timed out\n") { |
| 84 | + print "timed out\n"; |
| 85 | + return 1; |
| 86 | + } |
| 87 | + if ($@ eq "SIGINT\n") { |
| 88 | + exit 1; |
| 89 | + } |
| 90 | + } |
| 91 | } |
| 92 | - |
| 93 | # if $keepunfiltered, copies $1 to $1.unfiltered.out |
| 94 | # renames $0 tp $1 |
| 95 | sub filtered_rename($$) |
| 96 | @@ -394,19 +412,21 @@ sub do_diffs($$$$) |
| 97 | # A match; remove .out and any previously created .diff files. |
| 98 | unlink("$name.$mid.out"); |
| 99 | unlink(<$name.$mid.diff*>); |
| 100 | - return; |
| 101 | + return 0; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | # If we reach here, none of the .exp files matched. |
| 106 | - print "*** $name failed ($mid) ***\n"; |
| 107 | + print "*** $name failed ($mid) ***\n" if ($yoctoptest == 0) ; |
| 108 | push(@failures, sprintf("%-40s ($mid)", "$fullname")); |
| 109 | $num_failures{$mid}++; |
| 110 | + return 1; |
| 111 | } |
| 112 | |
| 113 | sub do_one_test($$) |
| 114 | { |
| 115 | my ($dir, $vgtest) = @_; |
| 116 | + my $diffStatus = 0; |
| 117 | $vgtest =~ /^(.*)\.vgtest/; |
| 118 | my $name = $1; |
| 119 | my $fullname = "$dir/$name"; |
| 120 | @@ -425,7 +445,11 @@ sub do_one_test($$) |
| 121 | } elsif (256 == $prereq_res) { |
| 122 | # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256... |
| 123 | # Prereq failed, skip. |
| 124 | - printf("%-16s (skipping, prereq failed: $prereq)\n", "$name:"); |
| 125 | + if ($yoctoptest == 0) { |
| 126 | + printf("%-16s (skipping, prereq failed: $prereq)\n", "$name:"); |
| 127 | + } else { |
| 128 | + printf("SKIP: $fullname\n"); |
| 129 | + } |
| 130 | return; |
| 131 | } else { |
| 132 | # Bad prereq; abort. |
| 133 | @@ -438,7 +462,7 @@ sub do_one_test($$) |
| 134 | if (defined $progB) { |
| 135 | # If there is a progB, let's start it in background: |
| 136 | printf("%-16s valgrind $extraopts $vgopts $prog $args (progB: $progB $argsB)\n", |
| 137 | - "$name:"); |
| 138 | + "$name:") if ($yoctoptest == 0); |
| 139 | # progB.done used to detect child has finished. See below. |
| 140 | # Note: redirection of stdout and stderr is before $progB to allow argsB |
| 141 | # to e.g. redirect stdoutB to stderrB |
| 142 | @@ -452,7 +476,8 @@ sub do_one_test($$) |
| 143 | . "touch progB.done) &"); |
| 144 | } |
| 145 | } else { |
| 146 | - printf("%-16s valgrind $extraopts $vgopts $prog $args\n", "$name:"); |
| 147 | + printf("%-16s valgrind $extraopts $vgopts $prog $args\n", "$name:") |
| 148 | + if ($yoctoptest == 0); |
| 149 | } |
| 150 | |
| 151 | # Pass the appropriate --tool option for the directory (can be overridden |
| 152 | @@ -487,7 +512,7 @@ sub do_one_test($$) |
| 153 | # Find all the .stdout.exp files. If none, use /dev/null. |
| 154 | my @stdout_exps = <$name.stdout.exp*>; |
| 155 | @stdout_exps = ( "/dev/null" ) if (0 == scalar @stdout_exps); |
| 156 | - do_diffs($fullname, $name, "stdout", \@stdout_exps); |
| 157 | + $diffStatus |= do_diffs($fullname, $name, "stdout", \@stdout_exps); |
| 158 | |
| 159 | # Filter stderr |
| 160 | $stderr_filter_args = $name if (! defined $stderr_filter_args); |
| 161 | @@ -496,7 +521,7 @@ sub do_one_test($$) |
| 162 | # Find all the .stderr.exp files. At least one must exist. |
| 163 | my @stderr_exps = <$name.stderr.exp*>; |
| 164 | (0 != scalar @stderr_exps) or die "Could not find `$name.stderr.exp*'\n"; |
| 165 | - do_diffs($fullname, $name, "stderr", \@stderr_exps); |
| 166 | + $diffStatus |= do_diffs($fullname, $name, "stderr", \@stderr_exps); |
| 167 | |
| 168 | if (defined $progB) { |
| 169 | # wait for the child to be finished |
| 170 | @@ -520,7 +545,7 @@ sub do_one_test($$) |
| 171 | # Find all the .stdoutB.exp files. If none, use /dev/null. |
| 172 | my @stdoutB_exps = <$name.stdoutB.exp*>; |
| 173 | @stdoutB_exps = ( "/dev/null" ) if (0 == scalar @stdoutB_exps); |
| 174 | - do_diffs($fullname, $name, "stdoutB", \@stdoutB_exps); |
| 175 | + $diffStatus |= do_diffs($fullname, $name, "stdoutB", \@stdoutB_exps); |
| 176 | |
| 177 | # Filter stderr |
| 178 | $stderrB_filter_args = $name if (! defined $stderrB_filter_args); |
| 179 | @@ -529,7 +554,7 @@ sub do_one_test($$) |
| 180 | # Find all the .stderrB.exp files. At least one must exist. |
| 181 | my @stderrB_exps = <$name.stderrB.exp*>; |
| 182 | (0 != scalar @stderrB_exps) or die "Could not find `$name.stderrB.exp*'\n"; |
| 183 | - do_diffs($fullname, $name, "stderrB", \@stderrB_exps); |
| 184 | + $diffStatus |= do_diffs($fullname, $name, "stderrB", \@stderrB_exps); |
| 185 | } |
| 186 | |
| 187 | # Maybe do post-test check |
| 188 | @@ -541,7 +566,7 @@ sub do_one_test($$) |
| 189 | # Find all the .post.exp files. If none, use /dev/null. |
| 190 | my @post_exps = <$name.post.exp*>; |
| 191 | @post_exps = ( "/dev/null" ) if (0 == scalar @post_exps); |
| 192 | - do_diffs($fullname, $name, "post", \@post_exps); |
| 193 | + $diffStatus |= do_diffs($fullname, $name, "post", \@post_exps); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | @@ -550,6 +575,13 @@ sub do_one_test($$) |
| 198 | print("(cleanup operation failed: $cleanup)\n"); |
| 199 | } |
| 200 | |
| 201 | + if ($yoctoptest == 1) { |
| 202 | + if ($diffStatus == 0) { |
| 203 | + print("PASS: $fullname\n"); |
| 204 | + } else { |
| 205 | + print("FAIL: $fullname\n"); |
| 206 | + } |
| 207 | + } |
| 208 | $num_tests_done++; |
| 209 | } |
| 210 | |
| 211 | @@ -589,7 +621,7 @@ sub test_one_dir($$) |
| 212 | my $found_tests = (0 != (grep { $_ =~ /\.vgtest$/ } @fs)); |
| 213 | |
| 214 | if ($found_tests) { |
| 215 | - print "-- Running tests in $full_dir $dashes\n"; |
| 216 | + print "-- Running tests in $full_dir $dashes\n" if ($yoctoptest == 0); |
| 217 | } |
| 218 | foreach my $f (@fs) { |
| 219 | if (-d $f) { |
| 220 | @@ -599,7 +631,7 @@ sub test_one_dir($$) |
| 221 | } |
| 222 | } |
| 223 | if ($found_tests) { |
| 224 | - print "-- Finished tests in $full_dir $dashes\n"; |
| 225 | + print "-- Finished tests in $full_dir $dashes\n" if ($yoctoptest == 0); |
| 226 | } |
| 227 | |
| 228 | chdir(".."); |
| 229 | @@ -625,10 +657,12 @@ sub summarise_results |
| 230 | $num_failures{"stdout"}, plural($num_failures{"stdout"}), |
| 231 | $num_failures{"stderrB"}, plural($num_failures{"stderrB"}), |
| 232 | $num_failures{"stdoutB"}, plural($num_failures{"stdoutB"}), |
| 233 | - $num_failures{"post"}, plural($num_failures{"post"})); |
| 234 | + $num_failures{"post"}, plural($num_failures{"post"})) |
| 235 | + if ($yoctoptest == 0); |
| 236 | |
| 237 | foreach my $failure (@failures) { |
| 238 | - print "$failure\n"; |
| 239 | + print "$failure\n" |
| 240 | + if ($yoctoptest == 0); |
| 241 | } |
| 242 | print "\n"; |
| 243 | } |