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