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