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