blob: 1499376f5a3d79d33bec0834333a8b65178863fc [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
Christophe Lyone0075272016-02-04 11:09:58 +0100126 ret=0
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100127
Christophe Lyone0075272016-02-04 11:09:58 +0100128 if [ -d "${build}" -a -d "${ref}" ]
129 then
130 printf "# Running on `hostname` in `pwd`\n" >> ${mylog}
131 ${mydir}/compare_tests -target ${target} \
132 ${ref} ${build} >> ${mylog}
133 ret=$?
134 fi
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100135 if [ ! -d "${ref}" ]; then
136 printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100137 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100138 fi
139 if [ ! -d "${build}" ]; then
140 printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100141 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100142 fi
Christophe Lyona8755e82015-11-20 00:40:34 +0100143 case $ret in
144 0) # No change
145 ;;
146 1) # Improvement
Christophe Lyon473c8162016-01-13 14:40:27 +0100147 class=improvement
148 color=green
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100149 message=BETTER
Christophe Lyona8755e82015-11-20 00:40:34 +0100150 ;;
151 2) # Regression
Christophe Lyon473c8162016-01-13 14:40:27 +0100152 class=regression
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100153 color=red
154 message=FAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100155 failed=true
Christophe Lyona8755e82015-11-20 00:40:34 +0100156 ;;
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100157 3) # No common logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100158 class=no-common-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100159 color=red
160 message=NO-COMMON-LOGS
161 failed=true
162 ;;
163 4) # Extra logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100164 class=extra-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100165 color=red
166 message=EXTRA-LOGS
167 failed=true
168 ;;
169 5) # Build failed
Christophe Lyon473c8162016-01-13 14:40:27 +0100170 class=build-failed
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100171 color=darkred
172 message=BUILDFAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100173 failed=true
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100174 ;;
Christophe Lyona8755e82015-11-20 00:40:34 +0100175 esac
Christophe Lyonbff39612015-11-18 16:29:11 +0100176
177 ${failed} && status=1
Christophe Lyon473c8162016-01-13 14:40:27 +0100178 html_report_print_row "${buildtarget}" "$class" "$message" >> $HTML_REPORT.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100179
180 cat ${mylog} >> ${difflog}
Christophe Lyonbff39612015-11-18 16:29:11 +0100181done
182
Christophe Lyonbff39612015-11-18 16:29:11 +0100183html_report_print_footer >> ${HTML_REPORT}.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100184
185echo "<pre>" >> ${HTML_REPORT}.part
186cat ${difflog} >> ${HTML_REPORT}.part
187rm -f ${difflog}
188echo "</pre>" >> ${HTML_REPORT}.part
189
Christophe Lyon473c8162016-01-13 14:40:27 +0100190html_doc_print_footer >> ${HTML_REPORT}.part
Christophe Lyon473c8162016-01-13 14:40:27 +0100191
Christophe Lyonbff39612015-11-18 16:29:11 +0100192mv ${HTML_REPORT}.part ${HTML_REPORT}
Christophe Lyonbff39612015-11-18 16:29:11 +0100193
194exit ${status}