aboutsummaryrefslogtreecommitdiff
path: root/scripts/compare_jobs.sh
blob: c82eda3254e5e25e7a7af4101c7d11f7924c5609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/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 xml_report_print_row
{
    local target=${1?}
    local failed=${2?}
    local log_url=BUILD_URL/artifact/artifacts/logs/diff-${target}.txt
    local color='#00FF00'
    $failed && color='#FF0000'
    local message=PASSED
    $failed && message=FAILED
    cat <<EOF
<tr>
  <td>${target}</td>
  <td fontattribute="bold" bgcolor="${color}">${message}</td>
  <td><![CDATA[<a href="$log_url">log for ${target}</a>]]></td>
</tr>
EOF
}

function xml_report_print_header
{
    cat <<EOF
<section name="Results comparison ${ref_logs} vs ${new_logs}"><table>
  <tr>
  <td fontattribute="bold" width="120" align="center">Target</td>
  <td fontattribute="bold" width="120" align="center">Status</td>
  <td fontattribute="bold" width="120" align="center">Log</td>
</tr>
EOF
}

function xml_report_print_footer
{
    cat <<EOF
</table></section>
EOF
}

function xml_log_print_field
{
    local target=${1?}
    local log=${2?}
    cat <<EOF
  <field name="${target}">
    <![CDATA[
EOF
cat $log
cat <<EOF
    ]]></field>
EOF
}

function xml_log_print_header
{
    cat <<EOF
<section name="Logs">
EOF
}

function xml_log_print_footer
{
    cat <<EOF
</section>
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}
# Use grep -v '*' to skip the case where the first regexp does not
# match any directory.
for dir in `echo ${ref_logs}/* | grep -v '*'`
do
    basename ${dir} >> ${tmptargets}
done

# Build list of all build-targets validated for ${new_logs}
for dir in `echo ${new_logs}/* | grep -v '*'`
do
    basename ${dir} >> ${tmptargets}
done

if [ -s ${tmptargets} ]; then
    buildtargets=`sort -u ${tmptargets}`
fi
rm -f ${tmptargets}

XML_REPORT=${mydir}/report0.xml
rm -f ${XML_REPORT} ${XML_REPORT}.part
XML_LOG=${mydir}/report1.xml
rm -f ${XML_LOG} ${XML_LOG}.part

xml_report_print_header > ${XML_REPORT}.part
xml_log_print_header > ${XML_LOG}.part

for buildtarget in ${buildtargets}
do
    ref="${ref_logs}/${buildtarget}"
    build="${new_logs}/${buildtarget}"
    echo "REF = "${ref}
    echo "BUILD = "${build}
    failed=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}
    [ -d "${build}" -a -d "${ref}" ] && ${mydir}/compare_tests -target ${target} \
	${ref} ${build} >> ${mylog} || failed=true

    ${failed} && status=1
    xml_report_print_row "${buildtarget}" "${failed}" >> $XML_REPORT.part
    xml_log_print_field "${buildtarget}" ${mylog} >> $XML_LOG.part
done

xml_report_print_footer >> ${XML_REPORT}.part
xml_log_print_footer >> ${XML_LOG}.part
mv ${XML_REPORT}.part ${XML_REPORT}
mv ${XML_LOG}.part ${XML_LOG}

exit ${status}