blob: eb752ca8a14e85b7f62dee8c7e0f2365d9c9d1b0 [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 Lyon8fbc2a92015-12-02 17:46:22 +010038 local color=${2?}
39 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>
44 <td style="background-color:$color"><a href="$log_url"><b>${message}</b></a></td>
45 </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
61function html_report_print_header
62{
63 cat <<EOF
64<h1>Results comparison ${ref_logs} vs ${new_logs}</h1>
65<table border="1">
66 <tr>
67 <td><b>Target</b></td>
68 <td><b>Status</b></td>
69 </tr>
70EOF
71}
72
73function xml_report_print_footer
74{
75 cat <<EOF
76</table></section>
77EOF
78}
79
80function html_report_print_footer
81{
82 cat <<EOF
83</table>
84EOF
85}
86
87function xml_log_print_field
88{
89 local target=${1?}
90 local log=${2?}
91 cat <<EOF
92 <field name="${target}">
93 <![CDATA[
94EOF
95cat $log
96cat <<EOF
97 ]]></field>
98EOF
99}
100
101function html_log_print_field
102{
103 local target=${1?}
104 local log=${2?}
105 cat <<EOF
106 <p>${target}</p>
107EOF
108cat $log
109cat <<EOF
110EOF
111}
112
113function xml_log_print_header
114{
115 cat <<EOF
116<section name="Logs">
117EOF
118}
119
120function html_log_print_header
121{
122 cat <<EOF
123<h1>Logs</h1>
124EOF
125}
126
127function xml_log_print_footer
128{
129 cat <<EOF
130</section>
131EOF
132}
133
134function html_log_print_footer
135{
136 cat <<EOF
137EOF
138}
139
140# For the time being, we expect different jobs to store their results
141# in similar directories.
142
143# Build list of all build-targets validated for ${ref_logs}
144for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d`
145do
146 basename ${dir} >> ${tmptargets}
147done
148
149# Build list of all build-targets validated for ${new_logs}
150for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d`
151do
152 basename ${dir} >> ${tmptargets}
153done
154
155if [ -s ${tmptargets} ]; then
156 buildtargets=`sort -u ${tmptargets}`
157fi
158rm -f ${tmptargets}
159
160XML_REPORT=${mydir}/report0.xml
161HTML_REPORT=${mydir}/report0.html
162rm -f ${XML_REPORT} ${XML_REPORT}.part
163rm -f ${HTML_REPORT} ${HTML_REPORT}.part
164XML_LOG=${mydir}/report1.xml
165HTML_LOG=${mydir}/report1.html
166rm -f ${XML_LOG} ${XML_LOG}.part
167rm -f ${HTML_LOG} ${HTML_LOG}.part
168
169xml_report_print_header > ${XML_REPORT}.part
170html_report_print_header > ${HTML_REPORT}.part
171xml_log_print_header > ${XML_LOG}.part
172html_log_print_header > ${HTML_LOG}.part
173
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100174# Gather all diffs, to concatenate them to the main report
175difflog=${mydir}/alldiffs.txt
176rm -f ${difflog}
177touch ${difflog}
178
Christophe Lyonbff39612015-11-18 16:29:11 +0100179for buildtarget in ${buildtargets}
180do
181 ref="${ref_logs}/${buildtarget}"
182 build="${new_logs}/${buildtarget}"
183 echo "REF = "${ref}
184 echo "BUILD = "${build}
185 failed=false
Christophe Lyona8755e82015-11-20 00:40:34 +0100186 improved=false
Christophe Lyonbff39612015-11-18 16:29:11 +0100187 mylog=${mydir}/diff-${buildtarget}.txt
188 target=`echo ${buildtarget} | cut -d. -f2`
189 printf "\t# ============================================================== #\n" > ${mylog}
190 printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog}
191 printf "\t# ============================================================== #\n\n" >> ${mylog}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100192
193 color=lightgreen
194 message=PASSED
195
Christophe Lyonbff39612015-11-18 16:29:11 +0100196 [ -d "${build}" -a -d "${ref}" ] && ${mydir}/compare_tests -target ${target} \
Christophe Lyona8755e82015-11-20 00:40:34 +0100197 ${ref} ${build} >> ${mylog}
198 ret=$?
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100199 if [ ! -d "${ref}" ]; then
200 printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
201 ret=3
202 fi
203 if [ ! -d "${build}" ]; then
204 printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
205 ret=3
206 fi
Christophe Lyona8755e82015-11-20 00:40:34 +0100207 case $ret in
208 0) # No change
209 ;;
210 1) # Improvement
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100211 color=green
212 message=BETTER
Christophe Lyona8755e82015-11-20 00:40:34 +0100213 ;;
214 2) # Regression
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100215 color=red
216 message=FAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100217 failed=true
Christophe Lyona8755e82015-11-20 00:40:34 +0100218 ;;
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100219 3) # Build failed
220 color=darkred
221 message=BUILDFAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100222 failed=true
Christophe Lyona8755e82015-11-20 00:40:34 +0100223 esac
Christophe Lyonbff39612015-11-18 16:29:11 +0100224
225 ${failed} && status=1
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100226 xml_report_print_row "${buildtarget}" "$color" "$message" >> $XML_REPORT.part
227 html_report_print_row "${buildtarget}" "$color" "$message" >> $HTML_REPORT.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100228 xml_log_print_field "${buildtarget}" ${mylog} >> $XML_LOG.part
229 html_log_print_field "${buildtarget}" ${mylog} >> $HTML_LOG.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100230
231 cat ${mylog} >> ${difflog}
Christophe Lyonbff39612015-11-18 16:29:11 +0100232done
233
234xml_report_print_footer >> ${XML_REPORT}.part
235html_report_print_footer >> ${HTML_REPORT}.part
236xml_log_print_footer >> ${XML_LOG}.part
237html_log_print_footer >> ${HTML_LOG}.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100238
239echo "<pre>" >> ${HTML_REPORT}.part
240cat ${difflog} >> ${HTML_REPORT}.part
241rm -f ${difflog}
242echo "</pre>" >> ${HTML_REPORT}.part
243
Christophe Lyonbff39612015-11-18 16:29:11 +0100244mv ${XML_REPORT}.part ${XML_REPORT}
245mv ${HTML_REPORT}.part ${HTML_REPORT}
246mv ${XML_LOG}.part ${XML_LOG}
247mv ${HTML_LOG}.part ${HTML_LOG}
248
249exit ${status}