blob: dfeb139fbed1dc9f151de3547c2397a0659ae6ae [file] [log] [blame]
Christophe Lyonbff39612015-11-18 16:29:11 +01001#!/bin/bash
2
3mydir="`dirname $0`"
4status=0
5
6if [ $# != 2 ]
7then
8 echo "Usage: $0 ref_logs new_logs"
9 exit 1
10fi
11
12ref_logs=$1
13new_logs=$2
14
15tmptargets=/tmp/targets.$$
16trap "rm -f ${tmptargets}" 0 1 2 3 5 9 13 15
17
18rm -f ${tmptargets}
19
20function xml_report_print_row
21{
22 local target=${1?}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +010023 local color=${2?}
24 local message=${3?}
Christophe Lyonbff39612015-11-18 16:29:11 +010025 local log_url=BUILD_URL/artifact/artifacts/logs/diff-${target}.txt
Christophe Lyonbff39612015-11-18 16:29:11 +010026 cat <<EOF
27<tr>
28 <td>${target}</td>
29 <td fontattribute="bold" bgcolor="${color}">${message}</td>
30 <td><![CDATA[<a href="$log_url">log for ${target}</a>]]></td>
31</tr>
32EOF
33}
34
35function html_report_print_row
36{
37 local target=${1?}
Christophe Lyon473c8162016-01-13 14:40:27 +010038 local status=${2?}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +010039 local message=${3?}
Christophe Lyonbff39612015-11-18 16:29:11 +010040 local log_url=diff-${target}.txt
Christophe Lyonbff39612015-11-18 16:29:11 +010041 cat <<EOF
42 <tr>
43 <td>${target}</td>
Christophe Lyon473c8162016-01-13 14:40:27 +010044 <td class="$status"><a href="$log_url"><b>${message}</b></a></td>
Christophe Lyonbff39612015-11-18 16:29:11 +010045 </tr>
46EOF
47}
48
49function xml_report_print_header
50{
51 cat <<EOF
52<section name="Results comparison ${ref_logs} vs ${new_logs}"><table>
53 <tr>
54 <td fontattribute="bold" width="120" align="center">Target</td>
55 <td fontattribute="bold" width="120" align="center">Status</td>
56 <td fontattribute="bold" width="120" align="center">Log</td>
57</tr>
58EOF
59}
60
Christophe Lyon473c8162016-01-13 14:40:27 +010061# Should be called for all HTML documents (e.g. report, log, ...)
62function html_doc_print_header
63{
64 cat <<EOF
65<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
66 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
67<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
68<head>
69 <title>Report</title>
70 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
71 <link rel="stylesheet" type="text/css" href="report.css" />
72</head>
73<body>
74EOF
75}
76
Christophe Lyonbff39612015-11-18 16:29:11 +010077function html_report_print_header
78{
79 cat <<EOF
80<h1>Results comparison ${ref_logs} vs ${new_logs}</h1>
81<table border="1">
82 <tr>
83 <td><b>Target</b></td>
84 <td><b>Status</b></td>
85 </tr>
86EOF
87}
88
89function xml_report_print_footer
90{
91 cat <<EOF
92</table></section>
93EOF
94}
95
Christophe Lyon473c8162016-01-13 14:40:27 +010096# Should be called for all HTML documents (e.g. report, log, ...)
97function html_doc_print_footer
98{
99 cat <<EOF
100</body>
101</html>
102EOF
103}
104
Christophe Lyonbff39612015-11-18 16:29:11 +0100105function html_report_print_footer
106{
107 cat <<EOF
108</table>
109EOF
110}
111
112function xml_log_print_field
113{
114 local target=${1?}
115 local log=${2?}
116 cat <<EOF
117 <field name="${target}">
118 <![CDATA[
119EOF
120cat $log
121cat <<EOF
122 ]]></field>
123EOF
124}
125
126function html_log_print_field
127{
128 local target=${1?}
129 local log=${2?}
130 cat <<EOF
131 <p>${target}</p>
132EOF
133cat $log
134cat <<EOF
135EOF
136}
137
138function xml_log_print_header
139{
140 cat <<EOF
141<section name="Logs">
142EOF
143}
144
145function html_log_print_header
146{
147 cat <<EOF
148<h1>Logs</h1>
149EOF
150}
151
152function xml_log_print_footer
153{
154 cat <<EOF
155</section>
156EOF
157}
158
159function html_log_print_footer
160{
161 cat <<EOF
162EOF
163}
164
165# For the time being, we expect different jobs to store their results
166# in similar directories.
167
168# Build list of all build-targets validated for ${ref_logs}
169for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d`
170do
171 basename ${dir} >> ${tmptargets}
172done
173
174# Build list of all build-targets validated for ${new_logs}
175for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d`
176do
177 basename ${dir} >> ${tmptargets}
178done
179
180if [ -s ${tmptargets} ]; then
181 buildtargets=`sort -u ${tmptargets}`
182fi
183rm -f ${tmptargets}
184
185XML_REPORT=${mydir}/report0.xml
186HTML_REPORT=${mydir}/report0.html
187rm -f ${XML_REPORT} ${XML_REPORT}.part
188rm -f ${HTML_REPORT} ${HTML_REPORT}.part
189XML_LOG=${mydir}/report1.xml
190HTML_LOG=${mydir}/report1.html
191rm -f ${XML_LOG} ${XML_LOG}.part
192rm -f ${HTML_LOG} ${HTML_LOG}.part
193
194xml_report_print_header > ${XML_REPORT}.part
Christophe Lyon473c8162016-01-13 14:40:27 +0100195html_doc_print_header > ${HTML_REPORT}.part
196html_report_print_header >> ${HTML_REPORT}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100197xml_log_print_header > ${XML_LOG}.part
Christophe Lyon473c8162016-01-13 14:40:27 +0100198html_doc_print_header > ${HTML_LOG}.part
199html_log_print_header >> ${HTML_LOG}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100200
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100201# Gather all diffs, to concatenate them to the main report
202difflog=${mydir}/alldiffs.txt
203rm -f ${difflog}
204touch ${difflog}
205
Christophe Lyonbff39612015-11-18 16:29:11 +0100206for buildtarget in ${buildtargets}
207do
208 ref="${ref_logs}/${buildtarget}"
209 build="${new_logs}/${buildtarget}"
210 echo "REF = "${ref}
211 echo "BUILD = "${build}
212 failed=false
Christophe Lyona8755e82015-11-20 00:40:34 +0100213 improved=false
Christophe Lyonbff39612015-11-18 16:29:11 +0100214 mylog=${mydir}/diff-${buildtarget}.txt
215 target=`echo ${buildtarget} | cut -d. -f2`
216 printf "\t# ============================================================== #\n" > ${mylog}
217 printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog}
218 printf "\t# ============================================================== #\n\n" >> ${mylog}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100219
Christophe Lyon473c8162016-01-13 14:40:27 +0100220 class=no-change
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100221 color=lightgreen
222 message=PASSED
223
Christophe Lyonbff39612015-11-18 16:29:11 +0100224 [ -d "${build}" -a -d "${ref}" ] && ${mydir}/compare_tests -target ${target} \
Christophe Lyona8755e82015-11-20 00:40:34 +0100225 ${ref} ${build} >> ${mylog}
226 ret=$?
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100227 if [ ! -d "${ref}" ]; then
228 printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100229 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100230 fi
231 if [ ! -d "${build}" ]; then
232 printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100233 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100234 fi
Christophe Lyona8755e82015-11-20 00:40:34 +0100235 case $ret in
236 0) # No change
237 ;;
238 1) # Improvement
Christophe Lyon473c8162016-01-13 14:40:27 +0100239 class=improvement
240 color=green
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100241 message=BETTER
Christophe Lyona8755e82015-11-20 00:40:34 +0100242 ;;
243 2) # Regression
Christophe Lyon473c8162016-01-13 14:40:27 +0100244 class=regression
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100245 color=red
246 message=FAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100247 failed=true
Christophe Lyona8755e82015-11-20 00:40:34 +0100248 ;;
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100249 3) # No common logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100250 class=no-common-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100251 color=red
252 message=NO-COMMON-LOGS
253 failed=true
254 ;;
255 4) # Extra logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100256 class=extra-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100257 color=red
258 message=EXTRA-LOGS
259 failed=true
260 ;;
261 5) # Build failed
Christophe Lyon473c8162016-01-13 14:40:27 +0100262 class=build-failed
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100263 color=darkred
264 message=BUILDFAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100265 failed=true
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100266 ;;
Christophe Lyona8755e82015-11-20 00:40:34 +0100267 esac
Christophe Lyonbff39612015-11-18 16:29:11 +0100268
269 ${failed} && status=1
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100270 xml_report_print_row "${buildtarget}" "$color" "$message" >> $XML_REPORT.part
Christophe Lyon473c8162016-01-13 14:40:27 +0100271 html_report_print_row "${buildtarget}" "$class" "$message" >> $HTML_REPORT.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100272 xml_log_print_field "${buildtarget}" ${mylog} >> $XML_LOG.part
273 html_log_print_field "${buildtarget}" ${mylog} >> $HTML_LOG.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100274
275 cat ${mylog} >> ${difflog}
Christophe Lyonbff39612015-11-18 16:29:11 +0100276done
277
278xml_report_print_footer >> ${XML_REPORT}.part
279html_report_print_footer >> ${HTML_REPORT}.part
280xml_log_print_footer >> ${XML_LOG}.part
281html_log_print_footer >> ${HTML_LOG}.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100282
283echo "<pre>" >> ${HTML_REPORT}.part
284cat ${difflog} >> ${HTML_REPORT}.part
285rm -f ${difflog}
286echo "</pre>" >> ${HTML_REPORT}.part
287
Christophe Lyon473c8162016-01-13 14:40:27 +0100288html_doc_print_footer >> ${HTML_REPORT}.part
289html_doc_print_footer >> ${HTML_LOG}.part
290
Christophe Lyonbff39612015-11-18 16:29:11 +0100291mv ${XML_REPORT}.part ${XML_REPORT}
292mv ${HTML_REPORT}.part ${HTML_REPORT}
293mv ${XML_LOG}.part ${XML_LOG}
294mv ${HTML_LOG}.part ${HTML_LOG}
295
296exit ${status}