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