~ihanick/percona-server/5.1.59-innodb_log_archiving

« back to all changes in this revision

Viewing changes to patches/subunit.patch

  • Committer: Stewart Smith
  • Date: 2011-10-06 06:45:16 UTC
  • Revision ID: stewart@flamingspork.com-20111006064516-rrjg17x7wwn9vr6w
add subunit support to mtr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=== added file 'mysql-test/lib/Subunit.pm'
 
2
--- /dev/null
 
3
+++ b/mysql-test/lib/Subunit.pm
 
4
@@ -0,0 +1,94 @@
 
5
+# Perl module for parsing and generating the Subunit protocol
 
6
+# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
 
7
+#
 
8
+#  Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
 
9
+#  license at the users choice. A copy of both licenses are available in the
 
10
+#  project source as Apache-2.0 and BSD. You may not use this file except in
 
11
+#  compliance with one of these two licences.
 
12
+#
 
13
+#  Unless required by applicable law or agreed to in writing, software
 
14
+#  distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
 
15
+#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 
16
+#  license you chose for the specific language governing permissions and
 
17
+#  limitations under that license.
 
18
+
 
19
+package Subunit;
 
20
+use POSIX;
 
21
+
 
22
+use vars qw ( $VERSION );
 
23
+
 
24
+$VERSION = '0.0.2';
 
25
+
 
26
+use strict;
 
27
+my $SUBUNIT_OUT= 'test_results.subunit';
 
28
+# reset the file
 
29
+open(SUBUNITOUT, ">$SUBUNIT_OUT");
 
30
+close(SUBUNITOUT);
 
31
+
 
32
+sub subunit_start_test($)
 
33
+{
 
34
+       my ($testname) = @_;
 
35
+        open(SUBUNITOUT, ">>$SUBUNIT_OUT");
 
36
+       print SUBUNITOUT "test: $testname\n";
 
37
+        close(SUBUNITOUT);
 
38
+        return;
 
39
+}
 
40
+
 
41
+sub subunit_end_test($$;$)
 
42
+{
 
43
+       my $name = shift;
 
44
+       my $result = shift;
 
45
+       my $reason = shift;
 
46
+        open(SUBUNITOUT, ">>$SUBUNIT_OUT");
 
47
+       if ($reason) {
 
48
+               print SUBUNITOUT "$result: $name [\n";
 
49
+               print SUBUNITOUT "$reason\n";
 
50
+               print SUBUNITOUT "]\n";
 
51
+       } else {
 
52
+               print SUBUNITOUT "$result: $name\n";
 
53
+       }
 
54
+        close(SUBUNITOUT);
 
55
+        return;
 
56
+}
 
57
+
 
58
+sub subunit_skip_test($;$)
 
59
+{
 
60
+       my $name = shift;
 
61
+       my $reason = shift;
 
62
+       subunit_end_test($name, "skip", $reason);
 
63
+}
 
64
+
 
65
+sub subunit_fail_test($;$)
 
66
+{
 
67
+       my $name = shift;
 
68
+       my $reason = shift;
 
69
+       subunit_end_test($name, "fail", $reason);
 
70
+}
 
71
+
 
72
+sub subunit_pass_test($;$)
 
73
+{
 
74
+       my $name = shift;
 
75
+       my $reason = shift;
 
76
+       subunit_end_test($name, "success", $reason);
 
77
+}
 
78
+
 
79
+sub subunit_xfail_test($;$)
 
80
+{
 
81
+       my $name = shift;
 
82
+       my $reason = shift;
 
83
+       subunit_end_test($name, "xfail", $reason);
 
84
+}
 
85
+
 
86
+sub report_time($)
 
87
+{
 
88
+       my ($time) = @_;
 
89
+       my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
 
90
+        open(SUBUNITOUT, ">>$SUBUNIT_OUT");
 
91
+       printf SUBUNITOUT "time: %04d-%02d-%02d %02d:%02d:%02dZ\n", $year+1900, $mon, $mday, $hour, $min, $sec;
 
92
+        close(SUBUNITOUT);
 
93
+        return;
 
94
+}
 
95
+
 
96
+
 
97
+
 
98
+1;
 
99
--- a/mysql-test/lib/mtr_report.pm
 
100
+++ b/mysql-test/lib/mtr_report.pm
 
101
@@ -27,9 +27,11 @@
 
102
                mtr_warning mtr_error mtr_debug mtr_verbose
 
103
                mtr_verbose_restart mtr_report_test_passed
 
104
                mtr_report_test_skipped mtr_print
 
105
+               mtr_report_test_subunit
 
106
                mtr_report_test);
 
107
 
 
108
 use mtr_match;
 
109
+use Subunit;
 
110
 use My::Platform;
 
111
 use POSIX qw[ _exit ];
 
112
 use IO::Handle qw[ flush ];
 
113
@@ -223,6 +225,68 @@
 
114
   }
 
115
 }
 
116
 
 
117
+sub mtr_report_test_subunit ($) {
 
118
+  my ($tinfo)= @_;
 
119
+  my $subunit_testname= $tinfo->{name};
 
120
+  $subunit_testname.= " '$tinfo->{combination}'"
 
121
+    if defined $tinfo->{combination};
 
122
+
 
123
+
 
124
+  my $comment=  $tinfo->{'comment'};
 
125
+  my $logfile=  $tinfo->{'logfile'};
 
126
+  my $warnings= $tinfo->{'warnings'};
 
127
+  my $result=   $tinfo->{'result'};
 
128
+  my $retry=    $tinfo->{'retries'} ? "retry-" : "";
 
129
+
 
130
+  my $test_name_sub = $tinfo->{name};
 
131
+
 
132
+  if ($result eq 'MTR_RES_FAILED'){
 
133
+
 
134
+    my $timest = format_time();
 
135
+    my $fail = "fail";
 
136
+
 
137
+    if ( $warnings )
 
138
+    {
 
139
+      Subunit::subunit_start_test($subunit_testname);
 
140
+      Subunit::subunit_fail_test($subunit_testname, "Found warnings/errors in server log file!");
 
141
+      return;
 
142
+    }
 
143
+    my $timeout= $tinfo->{'timeout'};
 
144
+    if ( $timeout )
 
145
+    {
 
146
+      Subunit::subunit_start_test($subunit_testname);
 
147
+      Subunit::subunit_fail_test($subunit_testname, "Timeout after $timeout seconds\n\n$tinfo->{'comment'}");
 
148
+      return;
 
149
+    }
 
150
+    Subunit::subunit_start_test($subunit_testname);
 
151
+    Subunit::subunit_fail_test($subunit_testname, "Comment: $comment\n\nLogfile:\n$logfile");
 
152
+  }
 
153
+  elsif ($result eq 'MTR_RES_SKIPPED')
 
154
+  {
 
155
+    if ( $tinfo->{'disable'} )
 
156
+    {
 
157
+      $comment="DISABLED: $comment";
 
158
+    }
 
159
+    # report into to subunit for Jenkins reporting
 
160
+    Subunit::subunit_start_test($subunit_testname);
 
161
+    Subunit::subunit_skip_test($subunit_testname, $comment);
 
162
+  }
 
163
+  elsif ($result eq 'MTR_RES_PASSED')
 
164
+  {
 
165
+    # Show any problems check-testcase found
 
166
+    if ( defined $tinfo->{'check'} )
 
167
+    {
 
168
+      mtr_report($tinfo->{'check'});
 
169
+    }
 
170
+    # report info to subunit for Jenkins reporting
 
171
+    # TODO:  catch 'check-testcase' output??
 
172
+    Subunit::report_time(time() - $tinfo->{timer}/1000);
 
173
+    Subunit::subunit_start_test($subunit_testname);
 
174
+    Subunit::report_time(time());
 
175
+    Subunit::subunit_pass_test($subunit_testname);
 
176
+  }
 
177
+}
 
178
+
 
179
 
 
180
 sub mtr_report_stats ($$;$) {
 
181
   my ($prefix, $tests, $dont_error)= @_;
 
182
--- a/mysql-test/mysql-test-run.pl
 
183
+++ b/mysql-test/mysql-test-run.pl
 
184
@@ -99,6 +99,7 @@
 
185
 use mtr_unique;
 
186
 use IO::Socket::INET;
 
187
 use IO::Select;
 
188
+use Subunit;
 
189
 
 
190
 require "lib/mtr_process.pl";
 
191
 require "lib/mtr_io.pl";
 
192
@@ -529,6 +530,7 @@
 
193
 
 
194
          # Report test status
 
195
          mtr_report_test($result);
 
196
+         mtr_report_test_subunit($result);
 
197
 
 
198
          if ( $result->is_failed() ) {
 
199