]> git.evergreen-ils.org Git - working/random.git/blob - qa/test_output_webifier.pl
adjust expected errors for Evergreen pre-req fetching
[working/random.git] / qa / test_output_webifier.pl
1 #!/usr/bin/perl
2
3 # This script assumes git checkouts at ~/git/Evergreen and ~/git/OpenSRF that
4 # correspond to branches used to produce the test output being parsed.
5
6 my $state = 'skipping';
7 my $error_count = 0;
8 my $subpage_count = 0;
9 my $subpage = '';
10 my $opensrf_tip = '';
11 my $evergreen_tip = '';
12 my @all_lines = ();
13
14 open  MAIN_PAGE, ">test.html";
15 print MAIN_PAGE html_header('Test Output Summary');
16 print MAIN_PAGE qq^[<a href="cronoutput.txt">test.sh output</a>]\n^;
17 print MAIN_PAGE qq^[<a href="$ARGV[0]">installer_installer.sh output</a>]\n^;
18 print MAIN_PAGE qq^[<a href="archive/">Previous Runs</a>]\n^;
19 print MAIN_PAGE qq^[<a href="http://git.evergreen-ils.org/?p=working/random.git;a=shortlog;h=refs/heads/collab/phasefx/wheezy_installer">Git</a>]\n^;
20 print MAIN_PAGE "<h1>Test Output Summary</h1>\n";
21 print MAIN_PAGE 'HTML generated on ' . `date` . "\n";
22 print MAIN_PAGE "<ul>\n";
23
24 open PASS_FAIL, ">pass_fail.txt";
25
26 while (my $line = <>) {
27     push @all_lines, $line;
28     if ($line =~ /Tip of OpenSRF: (.*)/) {
29         $opensrf_tip = $1;
30     }
31     if ($line =~ /Tip of Evergreen: (.*)/) {
32         $evergreen_tip = $1;
33     }
34     if ($line =~ /_\.-~= (.*)$/) {
35         $prev_subpage = $subpage;
36         $subpage = $1;
37         $state = 'outputting';
38         print_pass_or_fail($prev_subpage);
39         $error_count = 0;
40         $subpage_count++;
41         print MAIN_PAGE qq^\n<li><a href="test.$subpage_count.html">$subpage</a>^;
42         open  SUB_PAGE, ">test.$subpage_count.html";
43         print SUB_PAGE html_header($subpage);
44         print SUB_PAGE "<h1>$subpage</h1>\n<pre>";
45     }
46     if ($state eq 'outputting') {
47         my $class = 'output ';
48         if ($line =~ /^ok/
49             || $line =~ /\. ok/
50             || $line =~ /^PASS/
51             || $line =~ /\* OK/
52             || $line =~ /\* Jabber successfully connected/
53             || $line =~ /\* Database has the expected server encoding /
54         ) {
55             $class .= 'ok ';
56         }
57         $class .= 'error ' if ($line =~ /^err/i); 
58         if (($line =~ /^not ok/ && !($line =~ /TODO/))
59             || $line =~ /\. not ok/
60             || $line =~ /\* ERROR/
61             || $line =~ /\* WARNING/
62             || $line =~ /\[ERR/
63             || $line =~ /ERROR:/
64         ) {
65             $class .= 'notok ';
66             $error_count++;
67         }
68         if ($line =~ /^not ok/ && $line =~ /TODO/) {
69             $class .= 'todo ';
70         }
71         $class .= 'result ' if ($line =~ /^Result:/); 
72         $class .= 'pass ' if ($line =~ /^Result: PASS/); 
73         if ($line =~ /^Result: FAIL/) {
74             $class .= 'fail ';
75             $error_count++;
76         }
77         if ($line =~ /^Return Value = (.+)$/) {
78             if ($1 ne '0') {
79                 $class .= 'fail ';
80                 $error_count++;
81             }
82         }
83         if ($line =~ /^#/
84             || $line =~ /Checks:/
85             || $line =~ /_\.-~=/
86             || $line =~ /=~-\._/
87             || $line =~ / tests /
88             || $line =~ /Failed /
89             || $line =~ /Passed /
90             || $line =~ /Files=/
91         ) {
92             $class .= 'comment ';
93         }
94         if ($subpage eq 'Gathering system information'
95             || $subpage eq 'Gathering log summary'
96         ) {
97             $class = '';
98         }
99         chomp $line;
100         my $html_line = "<span class='$class'>$line</span>";
101         print SUB_PAGE "$html_line\n";
102     }
103     if ($line =~ /=~-\._/) {
104         print SUB_PAGE "</pre>\n" . html_footer();
105         close SUB_PAGE;
106         $state = 'skipping';
107     }
108 }
109 print_pass_or_fail();
110 print MAIN_PAGE "</ul>\n";
111 print MAIN_PAGE "<h2>Timing</h2>\n<pre>";
112 my $sys_time = pop @all_lines;
113 my $user_time = pop @all_lines;
114 my $real_time = pop @all_lines;
115 print MAIN_PAGE "$real_time$user_time$sys_time";
116 print MAIN_PAGE "</pre>\n";
117 print MAIN_PAGE branch_tips() . "\n";
118 print MAIN_PAGE html_footer();
119 close MAIN_PAGE;
120 close PASS_FAIL;
121 update_rss();
122
123 sub html_header {
124     my $title = shift;
125     return qq^
126 <html>
127     <head>
128         <meta charset="utf-8">
129         <title>$title</title>
130         <link rel="stylesheet" type="text/css" href="test_output.css">
131         <link rel="alternate" title="Test RSS" href="http://testing.evergreen-ils.org/~live/test_rss.xml" type="application/rss+xml">
132     </head>
133     <body>
134     ^;
135 }
136
137 sub html_footer {
138     return q^
139     </body>
140 </html>^;
141 }
142
143 sub print_pass_or_fail {
144     my $subpage = shift;
145     my $exception = {}; # keyed on subpage, value = # of expected errors
146     $exception{'Installing Evergreen pre-requisites'} = 1; # Class-DBI-Frozen test failure
147     if (! defined $exception{$subpage}) {
148         $exception{$subpage} = 0;
149     }
150     #print "subpage = <$subpage> error_count = $error_count\n";
151     if ($error_count && $error_count != $exception{$subpage} ) {
152         print MAIN_PAGE ' - <span class="fail">Failed</span>';
153         if ($exception{$subpage} > 0) {
154             print MAIN_PAGE " - Expected $exception{$subpage} errors but encountered $error_count."
155         }
156         print PASS_FAIL "Failed\n";
157     } else {
158         if ($subpage_count) {
159             print MAIN_PAGE ' - <span class="pass">Passed</span>';
160             print PASS_FAIL "Passed\n";
161         }
162     }
163 }
164
165 sub branch_tips {
166     my $html = "<h2>Current OpenSRF tip:</h2>\n<pre>$opensrf_tip</pre>\n";
167     $html .= "<h2>Current Evergreen tip:</h2>\n<pre>$evergreen_tip</pre>\n";
168     my $opensrf_tip_hash = '';
169     if ($opensrf_tip =~ /^(\S+)\s/) {
170         $opensrf_tip_hash = $1;
171     }
172     my $evergreen_tip_hash = '';
173     if ($evergreen_tip =~ /^(\S+)\s/) {
174         $evergreen_tip_hash = $1;
175     }
176     `touch prev_evergreen_tip.hash`;
177     `touch prev_opensrf_tip.hash`;
178     my $prev_opensrf_tip_hash = `cat prev_opensrf_tip.hash`;
179     chop $prev_opensrf_tip_hash;
180     my $prev_evergreen_tip_hash = `cat prev_evergreen_tip.hash`;
181     chop $prev_evergreen_tip_hash;
182     $html .= "<h2>OpenSRF commits since last build:</h2>\n<pre>";
183     $html .= `cd ~/git/OpenSRF/ ; git fetch 2> /dev/null ; git pull 2> /dev/null ; git log --format=oneline $prev_opensrf_tip_hash..$opensrf_tip_hash`;
184     $html .= "</pre><h2>Evergreen commits since last build:</h2>\n<pre>";
185     $html .= `cd ~/git/Evergreen/ ; git fetch 2> /dev/null ; git pull 2> /dev/null ; git log --format=oneline $prev_evergreen_tip_hash..$evergreen_tip_hash`;
186     `echo $opensrf_tip_hash > prev_opensrf_tip.hash`;
187     `echo $evergreen_tip_hash > prev_evergreen_tip.hash`;
188     $html .= "</pre>\n";
189     return $html;
190 }
191
192 sub update_rss {
193     `touch pass_fail.txt.prev`;
194     if (`diff pass_fail.txt pass_fail.txt.prev`) {
195         $fail = `grep Failed pass_fail.txt`;
196         open RSS_FILE, ">test_rss.xml";
197         print RSS_FILE q^<?xml version="1.0"?>
198 <rss version="2.0">
199     <channel>
200         <title>Test Output Summary</title>
201         <link>http://testing.evergreen-ils.org/~live/test.html</link>
202         <description>Live Test Suite</description>
203         <item>^ . (
204             $fail
205             ? q^<title>Test Failure - http://testing.evergreen-ils.org/~live/test.html</title>
206                 <link>http://testing.evergreen-ils.org/~live/test.html</link>
207                 <description>One or more tests failed</description>
208                 ^
209             : q^<title>Test Success - http://testing.evergreen-ils.org/~live/test.html</title>
210                 <link>http://testing.evergreen-ils.org/~live/test.html</link>
211                 <description>All tests passed</description>
212                 ^
213         ) . q^</item>
214     </channel>
215 </rss>
216 ^;
217         close RSS_FILE;
218     }
219     `mv pass_fail.txt pass_fail.txt.prev`;
220 }