1 # Perl module for parsing and generating the Subunit protocol
2 # Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 @EXPORT_OK = qw(parse_results);
30 use Time::HiRes qw(time);
33 sub parse_results($$$)
35 my ($msg_ops, $statistics, $fh) = @_;
36 my $expected_fail = 0;
40 if (/^test: (.+)\n/) {
41 $msg_ops->control_msg($_);
42 $msg_ops->start_test($1);
43 push (@$open_tests, $1);
44 } elsif (/^time: (\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)\n/) {
45 $msg_ops->report_time(mktime($6, $5, $4, $3, $2-1, $1-1900));
46 } elsif (/^(success|successful|failure|fail|skip|knownfail|error|xfail|skip-testsuite|testsuite-failure|testsuite-xfail|testsuite-success|testsuite-error): (.*?)( \[)?([ \t]*)( multipart)?\n/) {
47 $msg_ops->control_msg($_);
53 # reason may be specified in next lines
56 $msg_ops->control_msg($_);
57 if ($_ eq "]\n") { $terminated = 1; last; } else { $reason .= $_; }
60 unless ($terminated) {
61 $statistics->{TESTS_ERROR}++;
62 $msg_ops->end_test($testname, "error", 1,
63 "reason ($result) interrupted\n");
67 if ($result eq "success" or $result eq "successful") {
68 pop(@$open_tests); #FIXME: Check that popped value == $testname
69 $statistics->{TESTS_EXPECTED_OK}++;
70 $msg_ops->end_test($testname, "success", 0, $reason);
71 } elsif ($result eq "xfail" or $result eq "knownfail") {
72 pop(@$open_tests); #FIXME: Check that popped value == $testname
73 $statistics->{TESTS_EXPECTED_FAIL}++;
74 $msg_ops->end_test($testname, "xfail", 0, $reason);
76 } elsif ($result eq "failure" or $result eq "fail") {
77 pop(@$open_tests); #FIXME: Check that popped value == $testname
78 $statistics->{TESTS_UNEXPECTED_FAIL}++;
79 $msg_ops->end_test($testname, "failure", 1, $reason);
80 } elsif ($result eq "skip") {
81 $statistics->{TESTS_SKIP}++;
82 # Allow tests to be skipped without prior announcement of test
83 my $last = pop(@$open_tests);
84 if (defined($last) and $last ne $testname) {
85 push (@$open_tests, $testname);
87 $msg_ops->end_test($testname, "skip", 0, $reason);
88 } elsif ($result eq "error") {
89 $statistics->{TESTS_ERROR}++;
90 pop(@$open_tests); #FIXME: Check that popped value == $testname
91 $msg_ops->end_test($testname, "error", 1, $reason);
92 } elsif ($result eq "skip-testsuite") {
93 $msg_ops->skip_testsuite($testname);
94 } elsif ($result eq "testsuite-success") {
95 $msg_ops->end_testsuite($testname, "success", $reason);
96 } elsif ($result eq "testsuite-failure") {
97 $msg_ops->end_testsuite($testname, "failure", $reason);
98 } elsif ($result eq "testsuite-xfail") {
99 $msg_ops->end_testsuite($testname, "xfail", $reason);
100 } elsif ($result eq "testsuite-error") {
101 $msg_ops->end_testsuite($testname, "error", $reason);
103 } elsif (/^testsuite: (.*)\n/) {
104 $msg_ops->start_testsuite($1);
106 $msg_ops->output_msg($_);
110 while ($#$open_tests+1 > 0) {
111 $msg_ops->end_test(pop(@$open_tests), "error", 1,
112 "was started but never finished!\n");
113 $statistics->{TESTS_ERROR}++;
116 # if the Filter module is in use, it will have the right counts
117 if (defined($msg_ops->{total_error})) {
118 $statistics->{TESTS_ERROR} = $msg_ops->{total_error};
119 $statistics->{TESTS_UNEXPECTED_FAIL} = $msg_ops->{total_fail};
120 $statistics->{TESTS_EXPECTED_FAIL} = $msg_ops->{total_xfail};
123 return 1 if $statistics->{TESTS_ERROR} > 0;
124 return 1 if $statistics->{TESTS_UNEXPECTED_FAIL} > 0;
132 print "test: $testname\n";
141 print "$result: $name [\n";
143 if (substr($reason, -1, 1) ne "\n") { print "\n"; }
146 print "$result: $name\n";
154 end_test($name, "skip", $reason);
161 end_test($name, "fail", $reason);
164 sub success_test($;$)
168 end_test($name, "success", $reason);
175 end_test($name, "xfail", $reason);
181 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
182 printf "time: %04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec;
187 print "progress: pop\n";
192 print "progress: push\n";
197 my ($count, $whence) = @_;
199 unless(defined($whence)) {
203 print "progress: $whence$count\n";
206 # The following are Samba extensions:
208 sub start_testsuite($)
211 print "testsuite: $name\n";
214 sub skip_testsuite($;$)
216 my ($name, $reason) = @_;
218 print "skip-testsuite: $name [\n$reason\n]\n";
220 print "skip-testsuite: $name\n";
224 sub end_testsuite($$;$)
230 print "testsuite-$result: $name [\n";
234 print "testsuite-$result: $name\n";