Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | mydir="`dirname $0`" |
| 4 | status=0 |
| 5 | |
| 6 | if [ $# != 2 ] |
| 7 | then |
| 8 | echo "Usage: $0 ref_logs new_logs" |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
| 12 | ref_logs=$1 |
| 13 | new_logs=$2 |
| 14 | |
| 15 | tmptargets=/tmp/targets.$$ |
| 16 | trap "rm -f ${tmptargets}" 0 1 2 3 5 9 13 15 |
| 17 | |
| 18 | rm -f ${tmptargets} |
| 19 | |
| 20 | function xml_report_print_row |
| 21 | { |
| 22 | local target=${1?} |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 23 | local color=${2?} |
| 24 | local message=${3?} |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 25 | local log_url=BUILD_URL/artifact/artifacts/logs/diff-${target}.txt |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 26 | 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> |
| 32 | EOF |
| 33 | } |
| 34 | |
| 35 | function html_report_print_row |
| 36 | { |
| 37 | local target=${1?} |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 38 | local status=${2?} |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 39 | local message=${3?} |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 40 | local log_url=diff-${target}.txt |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 41 | cat <<EOF |
| 42 | <tr> |
| 43 | <td>${target}</td> |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 44 | <td class="$status"><a href="$log_url"><b>${message}</b></a></td> |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 45 | </tr> |
| 46 | EOF |
| 47 | } |
| 48 | |
| 49 | function 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> |
| 58 | EOF |
| 59 | } |
| 60 | |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 61 | # Should be called for all HTML documents (e.g. report, log, ...) |
| 62 | function html_doc_print_header |
| 63 | { |
| 64 | cat <<EOF |
| 65 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 66 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 67 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
| 68 | <head> |
| 69 | <title>Report</title> |
| 70 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> |
| 71 | <link rel="stylesheet" type="text/css" href="report.css" /> |
| 72 | </head> |
| 73 | <body> |
| 74 | EOF |
| 75 | } |
| 76 | |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 77 | function html_report_print_header |
| 78 | { |
| 79 | cat <<EOF |
| 80 | <h1>Results comparison ${ref_logs} vs ${new_logs}</h1> |
| 81 | <table border="1"> |
| 82 | <tr> |
| 83 | <td><b>Target</b></td> |
| 84 | <td><b>Status</b></td> |
| 85 | </tr> |
| 86 | EOF |
| 87 | } |
| 88 | |
| 89 | function xml_report_print_footer |
| 90 | { |
| 91 | cat <<EOF |
| 92 | </table></section> |
| 93 | EOF |
| 94 | } |
| 95 | |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 96 | # Should be called for all HTML documents (e.g. report, log, ...) |
| 97 | function html_doc_print_footer |
| 98 | { |
| 99 | cat <<EOF |
| 100 | </body> |
| 101 | </html> |
| 102 | EOF |
| 103 | } |
| 104 | |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 105 | function html_report_print_footer |
| 106 | { |
| 107 | cat <<EOF |
| 108 | </table> |
| 109 | EOF |
| 110 | } |
| 111 | |
| 112 | function xml_log_print_field |
| 113 | { |
| 114 | local target=${1?} |
| 115 | local log=${2?} |
| 116 | cat <<EOF |
| 117 | <field name="${target}"> |
| 118 | <![CDATA[ |
| 119 | EOF |
| 120 | cat $log |
| 121 | cat <<EOF |
| 122 | ]]></field> |
| 123 | EOF |
| 124 | } |
| 125 | |
| 126 | function html_log_print_field |
| 127 | { |
| 128 | local target=${1?} |
| 129 | local log=${2?} |
| 130 | cat <<EOF |
| 131 | <p>${target}</p> |
| 132 | EOF |
| 133 | cat $log |
| 134 | cat <<EOF |
| 135 | EOF |
| 136 | } |
| 137 | |
| 138 | function xml_log_print_header |
| 139 | { |
| 140 | cat <<EOF |
| 141 | <section name="Logs"> |
| 142 | EOF |
| 143 | } |
| 144 | |
| 145 | function html_log_print_header |
| 146 | { |
| 147 | cat <<EOF |
| 148 | <h1>Logs</h1> |
| 149 | EOF |
| 150 | } |
| 151 | |
| 152 | function xml_log_print_footer |
| 153 | { |
| 154 | cat <<EOF |
| 155 | </section> |
| 156 | EOF |
| 157 | } |
| 158 | |
| 159 | function html_log_print_footer |
| 160 | { |
| 161 | cat <<EOF |
| 162 | EOF |
| 163 | } |
| 164 | |
| 165 | # For the time being, we expect different jobs to store their results |
| 166 | # in similar directories. |
| 167 | |
| 168 | # Build list of all build-targets validated for ${ref_logs} |
| 169 | for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d` |
| 170 | do |
| 171 | basename ${dir} >> ${tmptargets} |
| 172 | done |
| 173 | |
| 174 | # Build list of all build-targets validated for ${new_logs} |
| 175 | for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d` |
| 176 | do |
| 177 | basename ${dir} >> ${tmptargets} |
| 178 | done |
| 179 | |
| 180 | if [ -s ${tmptargets} ]; then |
| 181 | buildtargets=`sort -u ${tmptargets}` |
| 182 | fi |
| 183 | rm -f ${tmptargets} |
| 184 | |
| 185 | XML_REPORT=${mydir}/report0.xml |
| 186 | HTML_REPORT=${mydir}/report0.html |
| 187 | rm -f ${XML_REPORT} ${XML_REPORT}.part |
| 188 | rm -f ${HTML_REPORT} ${HTML_REPORT}.part |
| 189 | XML_LOG=${mydir}/report1.xml |
| 190 | HTML_LOG=${mydir}/report1.html |
| 191 | rm -f ${XML_LOG} ${XML_LOG}.part |
| 192 | rm -f ${HTML_LOG} ${HTML_LOG}.part |
| 193 | |
| 194 | xml_report_print_header > ${XML_REPORT}.part |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 195 | html_doc_print_header > ${HTML_REPORT}.part |
| 196 | html_report_print_header >> ${HTML_REPORT}.part |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 197 | xml_log_print_header > ${XML_LOG}.part |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 198 | html_doc_print_header > ${HTML_LOG}.part |
| 199 | html_log_print_header >> ${HTML_LOG}.part |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 200 | |
Christophe Lyon | abeb4f9 | 2016-01-12 14:42:02 +0100 | [diff] [blame] | 201 | # Gather all diffs, to concatenate them to the main report |
| 202 | difflog=${mydir}/alldiffs.txt |
| 203 | rm -f ${difflog} |
| 204 | touch ${difflog} |
| 205 | |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 206 | for buildtarget in ${buildtargets} |
| 207 | do |
| 208 | ref="${ref_logs}/${buildtarget}" |
| 209 | build="${new_logs}/${buildtarget}" |
| 210 | echo "REF = "${ref} |
| 211 | echo "BUILD = "${build} |
| 212 | failed=false |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 213 | improved=false |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 214 | mylog=${mydir}/diff-${buildtarget}.txt |
| 215 | target=`echo ${buildtarget} | cut -d. -f2` |
| 216 | printf "\t# ============================================================== #\n" > ${mylog} |
| 217 | printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog} |
| 218 | printf "\t# ============================================================== #\n\n" >> ${mylog} |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 219 | |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 220 | class=no-change |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 221 | color=lightgreen |
| 222 | message=PASSED |
| 223 | |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 224 | [ -d "${build}" -a -d "${ref}" ] && ${mydir}/compare_tests -target ${target} \ |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 225 | ${ref} ${build} >> ${mylog} |
| 226 | ret=$? |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 227 | if [ ! -d "${ref}" ]; then |
| 228 | printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog} |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame] | 229 | ret=5 |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 230 | fi |
| 231 | if [ ! -d "${build}" ]; then |
| 232 | printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog} |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame] | 233 | ret=5 |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 234 | fi |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 235 | case $ret in |
| 236 | 0) # No change |
| 237 | ;; |
| 238 | 1) # Improvement |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 239 | class=improvement |
| 240 | color=green |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 241 | message=BETTER |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 242 | ;; |
| 243 | 2) # Regression |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 244 | class=regression |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 245 | color=red |
| 246 | message=FAILED |
Christophe Lyon | ae7e47a | 2016-01-07 18:29:50 +0100 | [diff] [blame] | 247 | failed=true |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 248 | ;; |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame] | 249 | 3) # No common logs |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 250 | class=no-common-logs |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame] | 251 | color=red |
| 252 | message=NO-COMMON-LOGS |
| 253 | failed=true |
| 254 | ;; |
| 255 | 4) # Extra logs |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 256 | class=extra-logs |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame] | 257 | color=red |
| 258 | message=EXTRA-LOGS |
| 259 | failed=true |
| 260 | ;; |
| 261 | 5) # Build failed |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 262 | class=build-failed |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 263 | color=darkred |
| 264 | message=BUILDFAILED |
Christophe Lyon | ae7e47a | 2016-01-07 18:29:50 +0100 | [diff] [blame] | 265 | failed=true |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame] | 266 | ;; |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 267 | esac |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 268 | |
| 269 | ${failed} && status=1 |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 270 | xml_report_print_row "${buildtarget}" "$color" "$message" >> $XML_REPORT.part |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 271 | html_report_print_row "${buildtarget}" "$class" "$message" >> $HTML_REPORT.part |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 272 | xml_log_print_field "${buildtarget}" ${mylog} >> $XML_LOG.part |
| 273 | html_log_print_field "${buildtarget}" ${mylog} >> $HTML_LOG.part |
Christophe Lyon | abeb4f9 | 2016-01-12 14:42:02 +0100 | [diff] [blame] | 274 | |
| 275 | cat ${mylog} >> ${difflog} |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 276 | done |
| 277 | |
| 278 | xml_report_print_footer >> ${XML_REPORT}.part |
| 279 | html_report_print_footer >> ${HTML_REPORT}.part |
| 280 | xml_log_print_footer >> ${XML_LOG}.part |
| 281 | html_log_print_footer >> ${HTML_LOG}.part |
Christophe Lyon | abeb4f9 | 2016-01-12 14:42:02 +0100 | [diff] [blame] | 282 | |
| 283 | echo "<pre>" >> ${HTML_REPORT}.part |
| 284 | cat ${difflog} >> ${HTML_REPORT}.part |
| 285 | rm -f ${difflog} |
| 286 | echo "</pre>" >> ${HTML_REPORT}.part |
| 287 | |
Christophe Lyon | 473c816 | 2016-01-13 14:40:27 +0100 | [diff] [blame^] | 288 | html_doc_print_footer >> ${HTML_REPORT}.part |
| 289 | html_doc_print_footer >> ${HTML_LOG}.part |
| 290 | |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 291 | mv ${XML_REPORT}.part ${XML_REPORT} |
| 292 | mv ${HTML_REPORT}.part ${HTML_REPORT} |
| 293 | mv ${XML_LOG}.part ${XML_LOG} |
| 294 | mv ${HTML_LOG}.part ${HTML_LOG} |
| 295 | |
| 296 | exit ${status} |