]> git.evergreen-ils.org Git - working/random.git/blob - qa/test_output_webifier.pl
Catch "Please install" from settings-tester.pl
[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             || $line =~ /Please install/
65         ) {
66             $class .= 'notok ';
67             $error_count++;
68         }
69         if ($line =~ /^not ok/ && $line =~ /TODO/) {
70             $class .= 'todo ';
71         }
72         $class .= 'result ' if ($line =~ /^Result:/); 
73         $class .= 'pass ' if ($line =~ /^Result: PASS/); 
74         if ($line =~ /^Result: FAIL/) {
75             $class .= 'fail ';
76             $error_count++;
77         }
78         if ($line =~ /^Return Value = (.+)$/) {
79             if ($1 ne '0') {
80                 $class .= 'fail ';
81                 $error_count++;
82             }
83         }
84         if ($line =~ /^#/
85             || $line =~ /Checks:/
86             || $line =~ /_\.-~=/
87             || $line =~ /=~-\._/
88             || $line =~ / tests /
89             || $line =~ /Failed /
90             || $line =~ /Passed /
91             || $line =~ /Files=/
92         ) {
93             $class .= 'comment ';
94         }
95         if ($subpage eq 'Gathering system information'
96             || $subpage eq 'Gathering log summary'
97         ) {
98             $class = '';
99         }
100         chomp $line;
101         my $html_line = "<span class='$class'>$line</span>";
102         print SUB_PAGE "$html_line\n";
103     }
104     if ($line =~ /=~-\._/) {
105         print SUB_PAGE "</pre>\n" . html_footer();
106         close SUB_PAGE;
107         $state = 'skipping';
108     }
109 }
110 print_pass_or_fail();
111 print MAIN_PAGE "</ul>\n";
112 print MAIN_PAGE "<h2>Timing</h2>\n<pre>";
113 my $sys_time = pop @all_lines;
114 my $user_time = pop @all_lines;
115 my $real_time = pop @all_lines;
116 print MAIN_PAGE "$real_time$user_time$sys_time";
117 print MAIN_PAGE "</pre>\n";
118 print MAIN_PAGE branch_tips() . "\n";
119 print MAIN_PAGE html_footer();
120 close MAIN_PAGE;
121 close PASS_FAIL;
122 update_rss();
123
124 sub html_header {
125     my $title = shift;
126     return qq^
127 <html>
128     <head>
129         <meta charset="utf-8">
130         <title>$title</title>
131         <link rel="stylesheet" type="text/css" href="test_output.css">
132         <link rel="alternate" title="Test RSS" href="http://testing.evergreen-ils.org/~live/test_rss.xml" type="application/rss+xml">
133     </head>
134     <body>
135     ^;
136 }
137
138 sub html_footer {
139     return q^
140     </body>
141 </html>^;
142 }
143
144 sub print_pass_or_fail {
145     my $subpage = shift;
146     my $exception = {}; # keyed on subpage, value = # of expected errors
147     $exception{'Installing Evergreen pre-requisites'} = 1; # Class-DBI-Frozen test failure
148     $exception{'Log Output: osrfsys.log'} = 3; # open-ils.cstore ERROR from live_t/08-lp1366964-libdbi-error.t (and related)
149     if (! defined $exception{$subpage}) {
150         $exception{$subpage} = 0;
151     }
152     #print "subpage = <$subpage> error_count = $error_count\n";
153     if ($error_count && $error_count != $exception{$subpage} ) {
154         print MAIN_PAGE ' - <span class="fail">Failed</span>';
155         if ($exception{$subpage} > 0) {
156             print MAIN_PAGE " - Expected $exception{$subpage} errors but encountered $error_count."
157         }
158         print PASS_FAIL "Failed\n";
159     } else {
160         if ($subpage_count) {
161             print MAIN_PAGE ' - <span class="pass">Passed</span>';
162             print PASS_FAIL "Passed\n";
163         }
164     }
165 }
166
167 sub branch_tips {
168     my $html = "<h2>Current OpenSRF tip:</h2>\n<pre>$opensrf_tip</pre>\n";
169     $html .= "<h2>Current Evergreen tip:</h2>\n<pre>$evergreen_tip</pre>\n";
170     my $opensrf_tip_hash = '';
171     if ($opensrf_tip =~ /^(\S+)\s/) {
172         $opensrf_tip_hash = $1;
173     }
174     my $evergreen_tip_hash = '';
175     if ($evergreen_tip =~ /^(\S+)\s/) {
176         $evergreen_tip_hash = $1;
177     }
178     `touch prev_evergreen_tip.hash`;
179     `touch prev_opensrf_tip.hash`;
180     my $prev_opensrf_tip_hash = `cat prev_opensrf_tip.hash`;
181     chop $prev_opensrf_tip_hash;
182     my $prev_evergreen_tip_hash = `cat prev_evergreen_tip.hash`;
183     chop $prev_evergreen_tip_hash;
184     $html .= "<h2>OpenSRF commits since last build:</h2>\n<pre>";
185     $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`;
186     $html .= "</pre><h2>Evergreen commits since last build:</h2>\n<pre>";
187     $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`;
188     `echo $opensrf_tip_hash > prev_opensrf_tip.hash`;
189     `echo $evergreen_tip_hash > prev_evergreen_tip.hash`;
190     $html .= "</pre>\n";
191     return $html;
192 }
193
194 sub update_rss {
195     `touch pass_fail.txt.prev`;
196     if (`diff pass_fail.txt pass_fail.txt.prev`) {
197         $fail = `grep Failed pass_fail.txt`;
198         open RSS_FILE, ">test_rss.xml";
199         print RSS_FILE q^<?xml version="1.0"?>
200 <rss version="2.0">
201     <channel>
202         <title>Test Output Summary</title>
203         <link>http://testing.evergreen-ils.org/~live/test.html</link>
204         <description>Live Test Suite</description>
205         <item>^ . (
206             $fail
207             ? q^<title>Test Failure - http://testing.evergreen-ils.org/~live/test.html</title>
208                 <link>http://testing.evergreen-ils.org/~live/test.html</link>
209                 <description>One or more tests failed</description>
210                 ^
211             : q^<title>Test Success - http://testing.evergreen-ils.org/~live/test.html</title>
212                 <link>http://testing.evergreen-ils.org/~live/test.html</link>
213                 <description>All tests passed</description>
214                 ^
215         ) . q^</item>
216     </channel>
217 </rss>
218 ^;
219         close RSS_FILE;
220     }
221     `mv pass_fail.txt pass_fail.txt.prev`;
222 }