| #!/bin/bash |
| |
| mydir="`dirname $0`" |
| status=0 |
| |
| if [ $# != 2 ] |
| then |
| echo "Usage: $0 ref_logs new_logs" |
| exit 1 |
| fi |
| |
| ref_logs=$1 |
| new_logs=$2 |
| |
| tmptargets=/tmp/targets.$$ |
| trap "rm -f ${tmptargets}" 0 1 2 3 5 9 13 15 |
| |
| rm -f ${tmptargets} |
| |
| function html_report_print_row |
| { |
| local target=${1?} |
| local status=${2?} |
| local message=${3?} |
| local log_url=diff-${target}.txt |
| cat <<EOF |
| <tr> |
| <td>${target}</td> |
| <td class="$status"><a href="$log_url"><b>${message}</b></a></td> |
| </tr> |
| EOF |
| } |
| |
| # Should be called for all HTML documents (e.g. report, log, ...) |
| function html_doc_print_header |
| { |
| cat <<EOF |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
| <head> |
| <title>Report</title> |
| <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> |
| <link rel="stylesheet" type="text/css" href="report.css" /> |
| </head> |
| <body> |
| EOF |
| } |
| |
| function html_report_print_header |
| { |
| cat <<EOF |
| <h1>Results comparison ${ref_logs} vs ${new_logs}</h1> |
| <table border="1"> |
| <tr> |
| <td><b>Target</b></td> |
| <td><b>Status</b></td> |
| </tr> |
| EOF |
| } |
| |
| # Should be called for all HTML documents (e.g. report, log, ...) |
| function html_doc_print_footer |
| { |
| cat <<EOF |
| </body> |
| </html> |
| EOF |
| } |
| |
| function html_report_print_footer |
| { |
| cat <<EOF |
| </table> |
| EOF |
| } |
| |
| # For the time being, we expect different jobs to store their results |
| # in similar directories. |
| |
| # Build list of all build-targets validated for ${ref_logs} |
| for dir in `find ${ref_logs}/ -mindepth 1 -maxdepth 1 -type d` |
| do |
| basename ${dir} >> ${tmptargets} |
| done |
| |
| # Build list of all build-targets validated for ${new_logs} |
| for dir in `find ${new_logs}/ -mindepth 1 -maxdepth 1 -type d` |
| do |
| basename ${dir} >> ${tmptargets} |
| done |
| |
| if [ -s ${tmptargets} ]; then |
| buildtargets=`sort -u ${tmptargets}` |
| fi |
| rm -f ${tmptargets} |
| |
| HTML_REPORT=${mydir}/report.html |
| rm -f ${HTML_REPORT} ${HTML_REPORT}.part |
| |
| html_doc_print_header > ${HTML_REPORT}.part |
| html_report_print_header >> ${HTML_REPORT}.part |
| |
| # Gather all diffs, to concatenate them to the main report |
| difflog=${mydir}/alldiffs.txt |
| rm -f ${difflog} |
| touch ${difflog} |
| |
| for buildtarget in ${buildtargets} |
| do |
| ref="${ref_logs}/${buildtarget}" |
| build="${new_logs}/${buildtarget}" |
| echo "REF = "${ref} |
| echo "BUILD = "${build} |
| failed=false |
| improved=false |
| mylog=${mydir}/diff-${buildtarget}.txt |
| target=`echo ${buildtarget} | cut -d. -f2` |
| printf "\t# ============================================================== #\n" > ${mylog} |
| printf "\t#\t\t*** ${buildtarget} ***\n" >> ${mylog} |
| printf "\t# ============================================================== #\n\n" >> ${mylog} |
| |
| class=no-change |
| color=lightgreen |
| message=PASSED |
| ret=0 |
| |
| if [ -d "${build}" -a -d "${ref}" ] |
| then |
| printf "# Running on `hostname` in `pwd`\n" >> ${mylog} |
| ${mydir}/compare_tests -target ${target} \ |
| ${ref} ${build} >> ${mylog} |
| ret=$? |
| fi |
| if [ ! -d "${ref}" ]; then |
| printf "\t# REF RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog} |
| ret=5 |
| fi |
| if [ ! -d "${build}" ]; then |
| printf "\t# BUILD RESULTS NOT PRESENT: BUILD FAILED\n" >> ${mylog} |
| ret=5 |
| fi |
| case $ret in |
| 0) # No change |
| ;; |
| 1) # Improvement |
| class=improvement |
| color=green |
| message=BETTER |
| ;; |
| 2) # Regression |
| class=regression |
| color=red |
| message=FAILED |
| failed=true |
| ;; |
| 3) # No common logs |
| class=no-common-logs |
| color=red |
| message=NO-COMMON-LOGS |
| failed=true |
| ;; |
| 4) # Extra logs |
| class=extra-logs |
| color=red |
| message=EXTRA-LOGS |
| failed=true |
| ;; |
| 5) # Build failed |
| class=build-failed |
| color=darkred |
| message=BUILDFAILED |
| failed=true |
| ;; |
| esac |
| |
| ${failed} && status=1 |
| html_report_print_row "${buildtarget}" "$class" "$message" >> $HTML_REPORT.part |
| |
| cat ${mylog} >> ${difflog} |
| done |
| |
| html_report_print_footer >> ${HTML_REPORT}.part |
| |
| echo "<pre>" >> ${HTML_REPORT}.part |
| cat ${difflog} >> ${HTML_REPORT}.part |
| rm -f ${difflog} |
| echo "</pre>" >> ${HTML_REPORT}.part |
| |
| html_doc_print_footer >> ${HTML_REPORT}.part |
| |
| mv ${HTML_REPORT}.part ${HTML_REPORT} |
| |
| exit ${status} |