blob: 422671280a04a8a79d3158f8b1f6ededd5030c4e [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
Christophe Lyonbff39612015-11-18 16:29:11 +010020function html_report_print_row
21{
22 local target=${1?}
Christophe Lyon473c8162016-01-13 14:40:27 +010023 local status=${2?}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +010024 local message=${3?}
Christophe Lyonbff39612015-11-18 16:29:11 +010025 local log_url=diff-${target}.txt
Christophe Lyonbff39612015-11-18 16:29:11 +010026 cat <<EOF
27 <tr>
28 <td>${target}</td>
Christophe Lyon473c8162016-01-13 14:40:27 +010029 <td class="$status"><a href="$log_url"><b>${message}</b></a></td>
Christophe Lyonbff39612015-11-18 16:29:11 +010030 </tr>
31EOF
32}
33
Christophe Lyon473c8162016-01-13 14:40:27 +010034# Should be called for all HTML documents (e.g. report, log, ...)
35function html_doc_print_header
36{
37 cat <<EOF
38<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
39 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
40<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
41<head>
42 <title>Report</title>
43 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
44 <link rel="stylesheet" type="text/css" href="report.css" />
45</head>
46<body>
47EOF
48}
49
Christophe Lyonbff39612015-11-18 16:29:11 +010050function html_report_print_header
51{
52 cat <<EOF
53<h1>Results comparison ${ref_logs} vs ${new_logs}</h1>
54<table border="1">
55 <tr>
56 <td><b>Target</b></td>
57 <td><b>Status</b></td>
58 </tr>
59EOF
60}
61
Christophe Lyon473c8162016-01-13 14:40:27 +010062# Should be called for all HTML documents (e.g. report, log, ...)
63function html_doc_print_footer
64{
65 cat <<EOF
66</body>
67</html>
68EOF
69}
70
Christophe Lyonbff39612015-11-18 16:29:11 +010071function html_report_print_footer
72{
73 cat <<EOF
74</table>
75EOF
76}
77
Christophe Lyonbff39612015-11-18 16:29:11 +010078# For the time being, we expect different jobs to store their results
79# in similar directories.
80
81# Build list of all build-targets validated for ${ref_logs}
82for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d`
83do
84 basename ${dir} >> ${tmptargets}
85done
86
87# Build list of all build-targets validated for ${new_logs}
88for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d`
89do
90 basename ${dir} >> ${tmptargets}
91done
92
93if [ -s ${tmptargets} ]; then
94 buildtargets=`sort -u ${tmptargets}`
95fi
96rm -f ${tmptargets}
97
Christophe Lyon51206112016-02-04 11:39:57 +010098HTML_REPORT=${mydir}/report.html
Christophe Lyonbff39612015-11-18 16:29:11 +010099rm -f ${HTML_REPORT} ${HTML_REPORT}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100100
Christophe Lyon473c8162016-01-13 14:40:27 +0100101html_doc_print_header > ${HTML_REPORT}.part
102html_report_print_header >> ${HTML_REPORT}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100103
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100104# Gather all diffs, to concatenate them to the main report
105difflog=${mydir}/alldiffs.txt
106rm -f ${difflog}
107touch ${difflog}
108
Christophe Lyonbff39612015-11-18 16:29:11 +0100109for buildtarget in ${buildtargets}
110do
111 ref="${ref_logs}/${buildtarget}"
112 build="${new_logs}/${buildtarget}"
113 echo "REF = "${ref}
114 echo "BUILD = "${build}
115 failed=false
Christophe Lyona8755e82015-11-20 00:40:34 +0100116 improved=false
Christophe Lyonbff39612015-11-18 16:29:11 +0100117 mylog=${mydir}/diff-${buildtarget}.txt
118 target=`echo ${buildtarget} | cut -d. -f2`
119 printf "\t# ============================================================== #\n" > ${mylog}
120 printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog}
121 printf "\t# ============================================================== #\n\n" >> ${mylog}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100122
Christophe Lyon473c8162016-01-13 14:40:27 +0100123 class=no-change
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100124 color=lightgreen
125 message=PASSED
126
Christophe Lyonbff39612015-11-18 16:29:11 +0100127 [ -d "${build}" -a -d "${ref}" ] && ${mydir}/compare_tests -target ${target} \
Christophe Lyona8755e82015-11-20 00:40:34 +0100128 ${ref} ${build} >> ${mylog}
129 ret=$?
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100130 if [ ! -d "${ref}" ]; then
131 printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100132 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100133 fi
134 if [ ! -d "${build}" ]; then
135 printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100136 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100137 fi
Christophe Lyona8755e82015-11-20 00:40:34 +0100138 case $ret in
139 0) # No change
140 ;;
141 1) # Improvement
Christophe Lyon473c8162016-01-13 14:40:27 +0100142 class=improvement
143 color=green
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100144 message=BETTER
Christophe Lyona8755e82015-11-20 00:40:34 +0100145 ;;
146 2) # Regression
Christophe Lyon473c8162016-01-13 14:40:27 +0100147 class=regression
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100148 color=red
149 message=FAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100150 failed=true
Christophe Lyona8755e82015-11-20 00:40:34 +0100151 ;;
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100152 3) # No common logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100153 class=no-common-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100154 color=red
155 message=NO-COMMON-LOGS
156 failed=true
157 ;;
158 4) # Extra logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100159 class=extra-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100160 color=red
161 message=EXTRA-LOGS
162 failed=true
163 ;;
164 5) # Build failed
Christophe Lyon473c8162016-01-13 14:40:27 +0100165 class=build-failed
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100166 color=darkred
167 message=BUILDFAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100168 failed=true
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100169 ;;
Christophe Lyona8755e82015-11-20 00:40:34 +0100170 esac
Christophe Lyonbff39612015-11-18 16:29:11 +0100171
172 ${failed} && status=1
Christophe Lyon473c8162016-01-13 14:40:27 +0100173 html_report_print_row "${buildtarget}" "$class" "$message" >> $HTML_REPORT.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100174
175 cat ${mylog} >> ${difflog}
Christophe Lyonbff39612015-11-18 16:29:11 +0100176done
177
Christophe Lyonbff39612015-11-18 16:29:11 +0100178html_report_print_footer >> ${HTML_REPORT}.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100179
180echo "<pre>" >> ${HTML_REPORT}.part
181cat ${difflog} >> ${HTML_REPORT}.part
182rm -f ${difflog}
183echo "</pre>" >> ${HTML_REPORT}.part
184
Christophe Lyon473c8162016-01-13 14:40:27 +0100185html_doc_print_footer >> ${HTML_REPORT}.part
Christophe Lyon473c8162016-01-13 14:40:27 +0100186
Christophe Lyonbff39612015-11-18 16:29:11 +0100187mv ${HTML_REPORT}.part ${HTML_REPORT}
Christophe Lyonbff39612015-11-18 16:29:11 +0100188
189exit ${status}