blob: 472551049bfcf19462318578e3980a260b90ff2a [file] [log] [blame]
Christophe Lyonbff39612015-11-18 16:29:11 +01001#!/bin/bash
2
3mydir="`dirname $0`"
4status=0
5
Laurent Alfonsidf859d32022-11-21 14:59:49 +01006while true
7do
8 case "x$1" in
9 "x-pass-thresh")
10 pass_thresh=$2
11 shift 2
12 ;;
13 "x-compr")
14 compr=$2
15 shift 2
16 ;;
17 *)
18 break
19 ;;
20 esac
21done
Christophe Lyonca9d8302017-05-22 12:04:00 +000022
Christophe Lyona8d87b82018-04-27 14:41:22 +010023if [ $# -lt 2 ]
Christophe Lyonbff39612015-11-18 16:29:11 +010024then
Laurent Alfonsidf859d32022-11-21 14:59:49 +010025 echo "Usage: $0 [-pass-thresh pass-ratio-threshold] [-compr compression-scheme] ref_logs new_logs [target ...]"
Christophe Lyona8d87b82018-04-27 14:41:22 +010026 echo " If no target name is provided, detect which targets have been built and compare their results"
Christophe Lyonbff39612015-11-18 16:29:11 +010027 exit 1
28fi
29
30ref_logs=$1
31new_logs=$2
Christophe Lyona8d87b82018-04-27 14:41:22 +010032shift 2
Christophe Lyonbff39612015-11-18 16:29:11 +010033
34tmptargets=/tmp/targets.$$
35trap "rm -f ${tmptargets}" 0 1 2 3 5 9 13 15
36
37rm -f ${tmptargets}
38
Christophe Lyonbff39612015-11-18 16:29:11 +010039function html_report_print_row
40{
41 local target=${1?}
Christophe Lyon473c8162016-01-13 14:40:27 +010042 local status=${2?}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +010043 local message=${3?}
Christophe Lyon803277b2017-10-16 21:39:59 +000044 local log_url=1-diff-${target}.txt
Christophe Lyonbff39612015-11-18 16:29:11 +010045 cat <<EOF
46 <tr>
47 <td>${target}</td>
Christophe Lyon473c8162016-01-13 14:40:27 +010048 <td class="$status"><a href="$log_url"><b>${message}</b></a></td>
Christophe Lyonbff39612015-11-18 16:29:11 +010049 </tr>
50EOF
51}
52
Christophe Lyon473c8162016-01-13 14:40:27 +010053# Should be called for all HTML documents (e.g. report, log, ...)
54function html_doc_print_header
55{
56 cat <<EOF
57<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
58 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
59<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
60<head>
61 <title>Report</title>
62 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
63 <link rel="stylesheet" type="text/css" href="report.css" />
64</head>
65<body>
66EOF
67}
68
Christophe Lyonbff39612015-11-18 16:29:11 +010069function html_report_print_header
70{
71 cat <<EOF
72<h1>Results comparison ${ref_logs} vs ${new_logs}</h1>
73<table border="1">
74 <tr>
75 <td><b>Target</b></td>
76 <td><b>Status</b></td>
77 </tr>
78EOF
79}
80
Christophe Lyon473c8162016-01-13 14:40:27 +010081# Should be called for all HTML documents (e.g. report, log, ...)
82function html_doc_print_footer
83{
84 cat <<EOF
85</body>
86</html>
87EOF
88}
89
Christophe Lyonbff39612015-11-18 16:29:11 +010090function html_report_print_footer
91{
92 cat <<EOF
93</table>
94EOF
95}
96
Christophe Lyonbff39612015-11-18 16:29:11 +010097# For the time being, we expect different jobs to store their results
98# in similar directories.
99
100# Build list of all build-targets validated for ${ref_logs}
101for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d`
102do
103 basename ${dir} >> ${tmptargets}
104done
105
106# Build list of all build-targets validated for ${new_logs}
107for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d`
108do
109 basename ${dir} >> ${tmptargets}
110done
111
Christophe Lyona8d87b82018-04-27 14:41:22 +0100112buildtargets=
Christophe Lyon1bead622018-05-16 22:51:59 +0000113# If the user provided no target name, use what we detected
114if [ $# -ne 0 ]; then
115 # Otherwise, use what the user provided, which may be incomplete
116 # and not include builder_type for instance
117 rm -f ${tmptargets}
118 for mytarget in "$@"
119 do
120 for dir in `ls -d ${ref_logs}/*${mytarget} ${new_logs}/*${mytarget}`
121 do
122 basename ${dir} >> ${tmptargets}
123 done
124 done
125fi
126if [ -s ${tmptargets} ]; then
127 buildtargets=`sort -u ${tmptargets}`
Christophe Lyonbff39612015-11-18 16:29:11 +0100128fi
129rm -f ${tmptargets}
130
Christophe Lyon803277b2017-10-16 21:39:59 +0000131HTML_REPORT=${mydir}/0-report.html
Christophe Lyonbff39612015-11-18 16:29:11 +0100132rm -f ${HTML_REPORT} ${HTML_REPORT}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100133
Christophe Lyon473c8162016-01-13 14:40:27 +0100134html_doc_print_header > ${HTML_REPORT}.part
135html_report_print_header >> ${HTML_REPORT}.part
Christophe Lyonbff39612015-11-18 16:29:11 +0100136
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100137# Gather all diffs, to concatenate them to the main report
138difflog=${mydir}/alldiffs.txt
139rm -f ${difflog}
140touch ${difflog}
141
Christophe Lyonbff39612015-11-18 16:29:11 +0100142for buildtarget in ${buildtargets}
143do
144 ref="${ref_logs}/${buildtarget}"
145 build="${new_logs}/${buildtarget}"
146 echo "REF = "${ref}
147 echo "BUILD = "${build}
148 failed=false
Christophe Lyona8755e82015-11-20 00:40:34 +0100149 improved=false
Christophe Lyon803277b2017-10-16 21:39:59 +0000150 mylog=${mydir}/1-diff-${buildtarget}.txt
Christophe Lyonbff39612015-11-18 16:29:11 +0100151 target=`echo ${buildtarget} | cut -d. -f2`
152 printf "\t# ============================================================== #\n" > ${mylog}
153 printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog}
154 printf "\t# ============================================================== #\n\n" >> ${mylog}
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100155
Christophe Lyon473c8162016-01-13 14:40:27 +0100156 class=no-change
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100157 color=lightgreen
158 message=PASSED
Christophe Lyone0075272016-02-04 11:09:58 +0100159 ret=0
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100160
Christophe Lyone0075272016-02-04 11:09:58 +0100161 if [ -d "${build}" -a -d "${ref}" ]
162 then
163 printf "# Running on `hostname` in `pwd`\n" >> ${mylog}
164 ${mydir}/compare_tests -target ${target} \
Christophe Lyon20e676d2017-06-02 07:21:38 +0000165 ${pass_thresh:+-pass-thresh ${pass_thresh}} \
Laurent Alfonsidf859d32022-11-21 14:59:49 +0100166 ${compr:+-compr ${compr}} \
Christophe Lyone0075272016-02-04 11:09:58 +0100167 ${ref} ${build} >> ${mylog}
168 ret=$?
169 fi
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100170 if [ ! -d "${ref}" ]; then
171 printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100172 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100173 fi
174 if [ ! -d "${build}" ]; then
175 printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog}
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100176 ret=5
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100177 fi
Christophe Lyona8755e82015-11-20 00:40:34 +0100178 case $ret in
179 0) # No change
180 ;;
181 1) # Improvement
Christophe Lyon473c8162016-01-13 14:40:27 +0100182 class=improvement
183 color=green
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100184 message=BETTER
Christophe Lyona8755e82015-11-20 00:40:34 +0100185 ;;
186 2) # Regression
Christophe Lyon473c8162016-01-13 14:40:27 +0100187 class=regression
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100188 color=red
189 message=FAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100190 failed=true
Christophe Lyona8755e82015-11-20 00:40:34 +0100191 ;;
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100192 3) # No common logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100193 class=no-common-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100194 color=red
195 message=NO-COMMON-LOGS
196 failed=true
197 ;;
198 4) # Extra logs
Christophe Lyon473c8162016-01-13 14:40:27 +0100199 class=extra-logs
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100200 color=red
201 message=EXTRA-LOGS
202 failed=true
203 ;;
204 5) # Build failed
Christophe Lyon473c8162016-01-13 14:40:27 +0100205 class=build-failed
Christophe Lyon8fbc2a92015-12-02 17:46:22 +0100206 color=darkred
207 message=BUILDFAILED
Christophe Lyonae7e47a2016-01-07 18:29:50 +0100208 failed=true
Christophe Lyonf02cb6b2016-01-12 14:32:24 +0100209 ;;
Christophe Lyona8755e82015-11-20 00:40:34 +0100210 esac
Christophe Lyonbff39612015-11-18 16:29:11 +0100211
212 ${failed} && status=1
Christophe Lyon473c8162016-01-13 14:40:27 +0100213 html_report_print_row "${buildtarget}" "$class" "$message" >> $HTML_REPORT.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100214
215 cat ${mylog} >> ${difflog}
Christophe Lyonbff39612015-11-18 16:29:11 +0100216done
217
Christophe Lyonbff39612015-11-18 16:29:11 +0100218html_report_print_footer >> ${HTML_REPORT}.part
Christophe Lyonabeb4f92016-01-12 14:42:02 +0100219
220echo "<pre>" >> ${HTML_REPORT}.part
221cat ${difflog} >> ${HTML_REPORT}.part
222rm -f ${difflog}
223echo "</pre>" >> ${HTML_REPORT}.part
224
Christophe Lyon473c8162016-01-13 14:40:27 +0100225html_doc_print_footer >> ${HTML_REPORT}.part
Christophe Lyon473c8162016-01-13 14:40:27 +0100226
Christophe Lyonbff39612015-11-18 16:29:11 +0100227mv ${HTML_REPORT}.part ${HTML_REPORT}
Christophe Lyonbff39612015-11-18 16:29:11 +0100228
229exit ${status}