summaryrefslogtreecommitdiff
path: root/compare_jobs.sh
blob: 61cf5453dda74f4eff52f56a18f5f5befa39a4d3 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/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 color=${2?}
    local message=${3?}
    local log_url=BUILD_URL/artifact/artifacts/logs/diff-${target}.txt
    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 html_report_print_row
{
    local target=${1?}
    local color=${2?}
    local message=${3?}
    local log_url=diff-${target}.txt
    cat <<EOF
  <tr>
    <td>${target}</td>
    <td style="background-color:$color"><a href="$log_url"><b>${message}</b></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 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
}

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

function html_report_print_footer
{
    cat <<EOF
</table>
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 html_log_print_field
{
    local target=${1?}
    local log=${2?}
    cat <<EOF
  <p>${target}</p>
EOF
cat $log
cat <<EOF
EOF
}

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

function html_log_print_header
{
    cat <<EOF
<h1>Logs</h1>
EOF
}

function xml_log_print_footer
{
    cat <<EOF
</section>
EOF
}

function html_log_print_footer
{
    cat <<EOF
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}

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

xml_report_print_header > ${XML_REPORT}.part
html_report_print_header > ${HTML_REPORT}.part
xml_log_print_header > ${XML_LOG}.part
html_log_print_header > ${HTML_LOG}.part

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}

    color=lightgreen
    message=PASSED

    [ -d "${build}" -a -d "${ref}" ] && ${mydir}/compare_tests -target ${target} \
	${ref} ${build} >> ${mylog}
    ret=$?
    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
	    color=green
	    message=BETTER
	    ;;
	2) # Regression
	    color=red
	    message=FAILED
	    failed=true
	    ;;
	3) # No common logs
	    color=red
	    message=NO-COMMON-LOGS
	    failed=true
	    ;;
	4) # Extra logs
	    color=red
	    message=EXTRA-LOGS
	    failed=true
	    ;;
	5) # Build failed
	    color=darkred
	    message=BUILDFAILED
	    failed=true
	    ;;
    esac

    ${failed} && status=1
    xml_report_print_row "${buildtarget}" "$color" "$message" >> $XML_REPORT.part
    html_report_print_row "${buildtarget}" "$color" "$message"  >> $HTML_REPORT.part
    xml_log_print_field "${buildtarget}" ${mylog} >> $XML_LOG.part
    html_log_print_field "${buildtarget}" ${mylog} >> $HTML_LOG.part
done

xml_report_print_footer >> ${XML_REPORT}.part
html_report_print_footer >> ${HTML_REPORT}.part
xml_log_print_footer >> ${XML_LOG}.part
html_log_print_footer >> ${HTML_LOG}.part
mv ${XML_REPORT}.part ${XML_REPORT}
mv ${HTML_REPORT}.part ${HTML_REPORT}
mv ${XML_LOG}.part ${XML_LOG}
mv ${HTML_LOG}.part ${HTML_LOG}

exit ${status}