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