blob: 97176cd464d129fd53b34b2a2e5af6dfb82920a1 [file] [log] [blame]
Christophe Lyonbff39612015-11-18 16:29:11 +01001#!/bin/bash
2
3mydir="`dirname $0`"
4status=0
5
Christophe Lyonca9d8302017-05-22 12:04:00 +00006[ x"$1" = x"-pass-thresh" ] && pass_thresh=$2 && shift 2
7
Christophe Lyona8d87b82018-04-27 14:41:22 +01008if [ $# -lt 2 ]
Christophe Lyonbff39612015-11-18 16:29:11 +01009then
Christophe Lyona8d87b82018-04-27 14:41:22 +010010 echo "Usage: $0 [-pass-thresh pass-ratio-threshold] ref_logs new_logs [target ...]"
11 echo " If no target name is provided, detect which targets have been built and compare their results"
Christophe Lyonbff39612015-11-18 16:29:11 +010012 exit 1
13fi
14
15ref_logs=$1
16new_logs=$2
Christophe Lyona8d87b82018-04-27 14:41:22 +010017shift 2
Christophe Lyonbff39612015-11-18 16:29:11 +010018
19tmptargets=/tmp/targets.$$
20trap "rm -f ${tmptargets}" 0 1 2 3 5 9 13 15
21
22rm -f ${tmptargets}
23
Christophe Lyonbff39612015-11-18 16:29:11 +010024function html_report_print_row
25{
26 local target=${1?}
Christophe Lyon473c8162016-01-13 14:40:27 +010027 local status=${2?}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +010028 local message=${3?}
Christophe Lyon803277b2017-10-16 21:39:59 +000029 local log_url=1-diff-${target}.txt
Christophe Lyonbff39612015-11-18 16:29:11 +010030 cat <<EOF
31 <tr>
32 <td>${target}</td>
Christophe Lyon473c8162016-01-13 14:40:27 +010033 <td class="$status"><a href="$log_url"><b>${message}</b></a></td>
Christophe Lyonbff39612015-11-18 16:29:11 +010034 </tr>
35EOF
36}
37
Christophe Lyon473c8162016-01-13 14:40:27 +010038# Should be called for all HTML documents (e.g. report, log, ...)
39function html_doc_print_header
40{
41 cat <<EOF
42<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
43 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
44<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
45<head>
46 <title>Report</title>
47 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
48 <link rel="stylesheet" type="text/css" href="report.css" />
49</head>
50<body>
51EOF
52}
53
Christophe Lyonbff39612015-11-18 16:29:11 +010054function html_report_print_header
55{
56 cat <<EOF
57<h1>Results comparison ${ref_logs} vs ${new_logs}</h1>
58<table border="1">
59 <tr>
60 <td><b>Target</b></td>
61 <td><b>Status</b></td>
62 </tr>
63EOF
64}
65
Christophe Lyon473c8162016-01-13 14:40:27 +010066# Should be called for all HTML documents (e.g. report, log, ...)
67function html_doc_print_footer
68{
69 cat <<EOF
70</body>
71</html>
72EOF
73}
74
Christophe Lyonbff39612015-11-18 16:29:11 +010075function html_report_print_footer
76{
77 cat <<EOF
78</table>
79EOF
80}
81
Christophe Lyonbff39612015-11-18 16:29:11 +010082# For the time being, we expect different jobs to store their results
83# in similar directories.
84
85# Build list of all build-targets validated for ${ref_logs}
86for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d`
87do
88 basename ${dir} >> ${tmptargets}
89done
90
91# Build list of all build-targets validated for ${new_logs}
92for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d`
93do
94 basename ${dir} >> ${tmptargets}
95done
96
Christophe Lyona8d87b82018-04-27 14:41:22 +010097buildtargets=
Christophe Lyon1bead622018-05-16 22:51:59 +000098# If the user provided no target name, use what we detected
99if [ $# -ne 0 ]; then
100 # Otherwise, use what the user provided, which may be incomplete
101 # and not include builder_type for instance
102 rm -f ${tmptargets}
103 for mytarget in "$@"
104 do
105 for dir in `ls -d ${ref_logs}/*${mytarget} ${new_logs}/*${mytarget}`
106 do
107 basename ${dir} >> ${tmptargets}
108 done
109 done
110fi
111if [ -s ${tmptargets} ]; then
112 buildtargets=`sort -u ${tmptargets}`
Christophe Lyonbff39612015-11-18 16:29:11 +0100113fi
114rm -f ${tmptargets}
115
Christophe Lyon803277b2017-10-16 21:39:59 +0000116HTML_REPORT=${mydir}/0-report.html
Christophe Lyonbff39612015-11-18 16:29:11 +0100117rm -f ${HTML_REPORT} ${HTML_REPORT}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100118
Christophe Lyon473c8162016-01-13 14:40:27 +0100119html_doc_print_header > ${HTML_REPORT}.part
120html_report_print_header >> ${HTML_REPORT}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100121
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100122# Gather all diffs, to concatenate them to the main report
123difflog=${mydir}/alldiffs.txt
124rm -f ${difflog}
125touch ${difflog}
126
Christophe Lyonbff39612015-11-18 16:29:11 +0100127for buildtarget in ${buildtargets}
128do
129 ref="${ref_logs}/${buildtarget}"
130 build="${new_logs}/${buildtarget}"
131 echo "REF = "${ref}
132 echo "BUILD = "${build}
133 failed=false
Christophe Lyona8755e82015-11-20 00:40:34 +0100134 improved=false
Christophe Lyon803277b2017-10-16 21:39:59 +0000135 mylog=${mydir}/1-diff-${buildtarget}.txt
Christophe Lyonbff39612015-11-18 16:29:11 +0100136 target=`echo ${buildtarget} | cut -d. -f2`
137 printf "\t# ============================================================== #\n" > ${mylog}
138 printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog}
139 printf "\t# ============================================================== #\n\n" >> ${mylog}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100140
Christophe Lyon473c8162016-01-13 14:40:27 +0100141 class=no-change
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100142 color=lightgreen
143 message=PASSED
Christophe Lyone0075272016-02-04 11:09:58 +0100144 ret=0
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100145
Christophe Lyone0075272016-02-04 11:09:58 +0100146 if [ -d "${build}" -a -d "${ref}" ]
147 then
148 printf "# Running on `hostname` in `pwd`\n" >> ${mylog}
149 ${mydir}/compare_tests -target ${target} \
Christophe Lyon20e676d2017-06-02 07:21:38 +0000150 ${pass_thresh:+-pass-thresh ${pass_thresh}} \
Christophe Lyone0075272016-02-04 11:09:58 +0100151 ${ref} ${build} >> ${mylog}
152 ret=$?
153 fi
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100154 if [ ! -d "${ref}" ]; then
155 printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100156 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100157 fi
158 if [ ! -d "${build}" ]; then
159 printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100160 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100161 fi
Christophe Lyona8755e82015-11-20 00:40:34 +0100162 case $ret in
163 0) # No change
164 ;;
165 1) # Improvement
Christophe Lyon473c8162016-01-13 14:40:27 +0100166 class=improvement
167 color=green
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100168 message=BETTER
Christophe Lyona8755e82015-11-20 00:40:34 +0100169 ;;
170 2) # Regression
Christophe Lyon473c8162016-01-13 14:40:27 +0100171 class=regression
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100172 color=red
173 message=FAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100174 failed=true
Christophe Lyona8755e82015-11-20 00:40:34 +0100175 ;;
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100176 3) # No common logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100177 class=no-common-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100178 color=red
179 message=NO-COMMON-LOGS
180 failed=true
181 ;;
182 4) # Extra logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100183 class=extra-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100184 color=red
185 message=EXTRA-LOGS
186 failed=true
187 ;;
188 5) # Build failed
Christophe Lyon473c8162016-01-13 14:40:27 +0100189 class=build-failed
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100190 color=darkred
191 message=BUILDFAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100192 failed=true
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100193 ;;
Christophe Lyona8755e82015-11-20 00:40:34 +0100194 esac
Christophe Lyonbff39612015-11-18 16:29:11 +0100195
196 ${failed} && status=1
Christophe Lyon473c8162016-01-13 14:40:27 +0100197 html_report_print_row "${buildtarget}" "$class" "$message" >> $HTML_REPORT.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100198
199 cat ${mylog} >> ${difflog}
Christophe Lyonbff39612015-11-18 16:29:11 +0100200done
201
Christophe Lyonbff39612015-11-18 16:29:11 +0100202html_report_print_footer >> ${HTML_REPORT}.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100203
204echo "<pre>" >> ${HTML_REPORT}.part
205cat ${difflog} >> ${HTML_REPORT}.part
206rm -f ${difflog}
207echo "</pre>" >> ${HTML_REPORT}.part
208
Christophe Lyon473c8162016-01-13 14:40:27 +0100209html_doc_print_footer >> ${HTML_REPORT}.part
Christophe Lyon473c8162016-01-13 14:40:27 +0100210
Christophe Lyonbff39612015-11-18 16:29:11 +0100211mv ${HTML_REPORT}.part ${HTML_REPORT}
Christophe Lyonbff39612015-11-18 16:29:11 +0100212
213exit ${status}