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 | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 38 | local color=${2?} |
| 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> |
| 44 | <td style="background-color:$color"><a href="$log_url"><b>${message}</b></a></td> |
| 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 | |
| 61 | function html_report_print_header |
| 62 | { |
| 63 | cat <<EOF |
| 64 | <h1>Results comparison ${ref_logs} vs ${new_logs}</h1> |
| 65 | <table border="1"> |
| 66 | <tr> |
| 67 | <td><b>Target</b></td> |
| 68 | <td><b>Status</b></td> |
| 69 | </tr> |
| 70 | EOF |
| 71 | } |
| 72 | |
| 73 | function xml_report_print_footer |
| 74 | { |
| 75 | cat <<EOF |
| 76 | </table></section> |
| 77 | EOF |
| 78 | } |
| 79 | |
| 80 | function html_report_print_footer |
| 81 | { |
| 82 | cat <<EOF |
| 83 | </table> |
| 84 | EOF |
| 85 | } |
| 86 | |
| 87 | function xml_log_print_field |
| 88 | { |
| 89 | local target=${1?} |
| 90 | local log=${2?} |
| 91 | cat <<EOF |
| 92 | <field name="${target}"> |
| 93 | <![CDATA[ |
| 94 | EOF |
| 95 | cat $log |
| 96 | cat <<EOF |
| 97 | ]]></field> |
| 98 | EOF |
| 99 | } |
| 100 | |
| 101 | function html_log_print_field |
| 102 | { |
| 103 | local target=${1?} |
| 104 | local log=${2?} |
| 105 | cat <<EOF |
| 106 | <p>${target}</p> |
| 107 | EOF |
| 108 | cat $log |
| 109 | cat <<EOF |
| 110 | EOF |
| 111 | } |
| 112 | |
| 113 | function xml_log_print_header |
| 114 | { |
| 115 | cat <<EOF |
| 116 | <section name="Logs"> |
| 117 | EOF |
| 118 | } |
| 119 | |
| 120 | function html_log_print_header |
| 121 | { |
| 122 | cat <<EOF |
| 123 | <h1>Logs</h1> |
| 124 | EOF |
| 125 | } |
| 126 | |
| 127 | function xml_log_print_footer |
| 128 | { |
| 129 | cat <<EOF |
| 130 | </section> |
| 131 | EOF |
| 132 | } |
| 133 | |
| 134 | function html_log_print_footer |
| 135 | { |
| 136 | cat <<EOF |
| 137 | EOF |
| 138 | } |
| 139 | |
| 140 | # For the time being, we expect different jobs to store their results |
| 141 | # in similar directories. |
| 142 | |
| 143 | # Build list of all build-targets validated for ${ref_logs} |
| 144 | for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d` |
| 145 | do |
| 146 | basename ${dir} >> ${tmptargets} |
| 147 | done |
| 148 | |
| 149 | # Build list of all build-targets validated for ${new_logs} |
| 150 | for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d` |
| 151 | do |
| 152 | basename ${dir} >> ${tmptargets} |
| 153 | done |
| 154 | |
| 155 | if [ -s ${tmptargets} ]; then |
| 156 | buildtargets=`sort -u ${tmptargets}` |
| 157 | fi |
| 158 | rm -f ${tmptargets} |
| 159 | |
| 160 | XML_REPORT=${mydir}/report0.xml |
| 161 | HTML_REPORT=${mydir}/report0.html |
| 162 | rm -f ${XML_REPORT} ${XML_REPORT}.part |
| 163 | rm -f ${HTML_REPORT} ${HTML_REPORT}.part |
| 164 | XML_LOG=${mydir}/report1.xml |
| 165 | HTML_LOG=${mydir}/report1.html |
| 166 | rm -f ${XML_LOG} ${XML_LOG}.part |
| 167 | rm -f ${HTML_LOG} ${HTML_LOG}.part |
| 168 | |
| 169 | xml_report_print_header > ${XML_REPORT}.part |
| 170 | html_report_print_header > ${HTML_REPORT}.part |
| 171 | xml_log_print_header > ${XML_LOG}.part |
| 172 | html_log_print_header > ${HTML_LOG}.part |
| 173 | |
| 174 | for buildtarget in ${buildtargets} |
| 175 | do |
| 176 | ref="${ref_logs}/${buildtarget}" |
| 177 | build="${new_logs}/${buildtarget}" |
| 178 | echo "REF = "${ref} |
| 179 | echo "BUILD = "${build} |
| 180 | failed=false |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 181 | improved=false |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 182 | mylog=${mydir}/diff-${buildtarget}.txt |
| 183 | target=`echo ${buildtarget} | cut -d. -f2` |
| 184 | printf "\t# ============================================================== #\n" > ${mylog} |
| 185 | printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog} |
| 186 | printf "\t# ============================================================== #\n\n" >> ${mylog} |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 187 | |
| 188 | color=lightgreen |
| 189 | message=PASSED |
| 190 | |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 191 | [ -d "${build}" -a -d "${ref}" ] && ${mydir}/compare_tests -target ${target} \ |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 192 | ${ref} ${build} >> ${mylog} |
| 193 | ret=$? |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 194 | if [ ! -d "${ref}" ]; then |
| 195 | printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog} |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame^] | 196 | ret=5 |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 197 | fi |
| 198 | if [ ! -d "${build}" ]; then |
| 199 | printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog} |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame^] | 200 | ret=5 |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 201 | fi |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 202 | case $ret in |
| 203 | 0) # No change |
| 204 | ;; |
| 205 | 1) # Improvement |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 206 | color=green |
| 207 | message=BETTER |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 208 | ;; |
| 209 | 2) # Regression |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 210 | color=red |
| 211 | message=FAILED |
Christophe Lyon | ae7e47a | 2016-01-07 18:29:50 +0100 | [diff] [blame] | 212 | failed=true |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 213 | ;; |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame^] | 214 | 3) # No common logs |
| 215 | color=red |
| 216 | message=NO-COMMON-LOGS |
| 217 | failed=true |
| 218 | ;; |
| 219 | 4) # Extra logs |
| 220 | color=red |
| 221 | message=EXTRA-LOGS |
| 222 | failed=true |
| 223 | ;; |
| 224 | 5) # Build failed |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 225 | color=darkred |
| 226 | message=BUILDFAILED |
Christophe Lyon | ae7e47a | 2016-01-07 18:29:50 +0100 | [diff] [blame] | 227 | failed=true |
Christophe Lyon | f02cb6b | 2016-01-12 14:32:24 +0100 | [diff] [blame^] | 228 | ;; |
Christophe Lyon | a8755e8 | 2015-11-20 00:40:34 +0100 | [diff] [blame] | 229 | esac |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 230 | |
| 231 | ${failed} && status=1 |
Christophe Lyon | 8fbc2a9 | 2015-12-02 17:46:22 +0100 | [diff] [blame] | 232 | xml_report_print_row "${buildtarget}" "$color" "$message" >> $XML_REPORT.part |
| 233 | html_report_print_row "${buildtarget}" "$color" "$message" >> $HTML_REPORT.part |
Christophe Lyon | bff3961 | 2015-11-18 16:29:11 +0100 | [diff] [blame] | 234 | xml_log_print_field "${buildtarget}" ${mylog} >> $XML_LOG.part |
| 235 | html_log_print_field "${buildtarget}" ${mylog} >> $HTML_LOG.part |
| 236 | done |
| 237 | |
| 238 | xml_report_print_footer >> ${XML_REPORT}.part |
| 239 | html_report_print_footer >> ${HTML_REPORT}.part |
| 240 | xml_log_print_footer >> ${XML_LOG}.part |
| 241 | html_log_print_footer >> ${HTML_LOG}.part |
| 242 | mv ${XML_REPORT}.part ${XML_REPORT} |
| 243 | mv ${HTML_REPORT}.part ${HTML_REPORT} |
| 244 | mv ${XML_LOG}.part ${XML_LOG} |
| 245 | mv ${HTML_LOG}.part ${HTML_LOG} |
| 246 | |
| 247 | exit ${status} |