]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/dg-extract-results.sh
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / dg-extract-results.sh
CommitLineData
6bc80edc
TT
1#! /bin/sh
2
3# For a specified tool and optional list of test variants, extract
4# test results from one or more test summary (.sum) files and combine
5# the results into a new test summary file, sent to the standard output.
6# The resulting file can be used with test result comparison scripts for
7# results from tests that were run in parallel. See usage() below.
8
618f726f 9# Copyright (C) 2008-2016 Free Software Foundation, Inc.
6bc80edc
TT
10# Contributed by Janis Johnson <janis187@us.ibm.com>
11#
12# This file is part of GCC.
13#
14# GCC is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License as published by
16# the Free Software Foundation; either version 3, or (at your option)
17# any later version.
18#
19# GCC is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
7785b880 25# along with this program. If not, see <http://www.gnu.org/licenses/>.
6bc80edc
TT
26
27PROGNAME=dg-extract-results.sh
28
395cf596
SDJ
29# Try to use the python version if possible, since it tends to be faster.
30PYTHON_VER=`echo "$0" | sed 's/sh$/py/'`
31if test "$PYTHON_VER" != "$0" &&
32 test -f "$PYTHON_VER" &&
33 python -c 'import sys; sys.exit (0 if sys.version_info >= (2, 6) else 1)' \
34 > /dev/null 2> /dev/null; then
35 exec python $PYTHON_VER "$@"
36fi
37
6bc80edc
TT
38usage() {
39 cat <<EOF >&2
40Usage: $PROGNAME [-t tool] [-l variant-list] [-L] sum-file ...
41
42 tool The tool (e.g. g++, libffi) for which to create a
43 new test summary file. If not specified then all
44 specified sum files must be for the same tool.
45 variant-list One or more test variant names. If the list is
46 not specified then one is constructed from all
47 variants in the files for <tool>.
48 sum-file A test summary file with the format of those
49 created by runtest from DejaGnu.
50 If -L is used, merge *.log files instead of *.sum. In this
51 mode the exact order of lines may not be preserved, just different
52 Running *.exp chunks should be in correct order.
53EOF
54}
55
56# Write a message to the standard error.
57
58msg() {
59 echo "$@" >&2
60}
61
62# Parse the command-line options.
63
64VARIANTS=""
65TOOL=""
66MODE="sum"
67
68while getopts "l:t:L" ARG; do
69 case $ARG in
70 l) VARIANTS="${VARIANTS} ${OPTARG}";;
71 t) test -z "$TOOL" || (msg "${PROGNAME}: only one tool can be specified"; exit 1);
72 TOOL="${OPTARG}";;
73 L) MODE="log";;
74 \?) usage; exit 0;;
75 esac
76done
77shift `expr ${OPTIND} - 1`
78
79if test $# -lt 1 ; then
80 usage
81 exit 1
82fi
83
84TMPDIR=${TMPDIR-/tmp}
85SUM_FILES="$@"
86FIRST_SUM=$1
87TMP=
88trap 'EXIT_STATUS=$?; rm -rf $TMP && exit $EXIT_STATUS' 0
89# Create a (secure) tmp directory for tmp files.
90{
91 TMP=`(umask 077 && mktemp -d -q "${TMPDIR}/dg-combine-results-$$-XXXXXX") 2>/dev/null` &&
92 test -n "$TMP" && test -d "$TMP"
93} ||
94{
95 TMP=${TMPDIR}/dg-combine-results-$$-$RANDOM
96 (umask 077 && mkdir $TMP)
97} ||
98{
99 msg "${PROGNAME}: cannot create a temporary directory"
100 { (exit 1); exit 1; }
101}
102
103# Find a good awk.
104
105if test -z "$AWK" ; then
106 for AWK in gawk nawk awk
107 do
108 if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
109 :
110 else
111 break
112 fi
113 done
114fi
115
116# Verify that the specified summary files exist.
117
118ERROR=0
119for FILE in $SUM_FILES
120do
121 if ! test -f $FILE ; then
122 msg "${PROGNAME}: file $FILE does not exist."
123 ERROR=1
124 fi
125done
126test $ERROR -eq 0 || exit 1
127
ef878e53
PA
128# Test if grep supports the '--text' option
129
130GREP=grep
131
132if echo -e '\x00foo\x00' | $GREP --text foo > /dev/null 2>&1 ; then
133 GREP="grep --text"
134else
135 # Our grep does not recognize the '--text' option. We have to
136 # treat our files in order to remove any non-printable character.
137 for file in $SUM_FILES ; do
138 mv $file ${file}.orig
139 cat -v ${file}.orig > $file
140 done
141fi
142
6bc80edc
TT
143if [ -z "$TOOL" ]; then
144 # If no tool was specified, all specified summary files must be for
145 # the same tool.
146
ef878e53 147 CNT=`$GREP '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
6bc80edc 148 if [ $CNT -eq 1 ]; then
ef878e53 149 TOOL=`$GREP '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
6bc80edc
TT
150 else
151 msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
152 msg ""
153 usage
154 exit 1
155 fi
156else
157 # Ignore the specified summary files that are not for this tool. This
158 # should keep the relevant files in the same order.
159
ef878e53 160 SUM_FILES=`$GREP -l "=== $TOOL" $SUM_FILES`
6bc80edc
TT
161 if test -z "$SUM_FILES" ; then
162 msg "${PROGNAME}: none of the specified files are results for $TOOL"
163 exit 1
164 fi
165fi
166
167if [ "$TOOL" = acats ]; then
168 # Acats *.sum or *.log files aren't dejagnu generated, and they have
169 # somewhat different format.
170 ACATS_AWK=${TMP}/acats.awk
171 cat <<EOF > $ACATS_AWK
172BEGIN {
173 print_prologue=1; curfile=""; insummary=0
174 passcnt=0; failcnt=0; unsupcnt=0; failures=""
175}
176/^[ \t]*=== acats configuration ===/ {
177 insummary=0
178 if (print_prologue) print
179 next
180}
181/^[ \t]*=== acats tests ===/ {
182 if (print_prologue) print
183 print_prologue=0
184 next
185}
186/^Running chapter / {
187 if (curfile) close (curfile)
188 curfile="${TMP}/chapter-"\$3
189 print >> curfile
190 next
191}
192/^[ \t]*=== acats Summary ===/ {
193 if (curfile) close (curfile)
194 curfile=""
195 insummary=1
196 next
197}
198/^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
199/^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
200/^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
201/^\*\*\* FAILURES: / {
202 if (insummary == 1) {
203 if (failures) sub(/^\*\*\* FAILURES:/,"")
204 failures=failures""\$0
205 }
206}
207{
208 if (print_prologue) { print; next }
209 if (curfile) print >> curfile
210}
211END {
212 system ("cat ${TMP}/chapter-*")
213 print " === acats Summary ==="
214 print "# of expected passes " passcnt
215 print "# of unexpected failures " failcnt
216 if (unsupcnt) print "# of unsupported tests " unsupcnt
217 if (failures) print failures
218}
219EOF
220
221 rm -f ${TMP}/chapter-*
222 $AWK -f $ACATS_AWK $SUM_FILES
223 exit 0
224fi
225
226# If no variants were specified, find all variants in the remaining
227# summary files. Otherwise, ignore specified variants that aren't in
228# any of those summary files.
229
230if test -z "$VARIANTS" ; then
231 VAR_AWK=${TMP}/variants.awk
232 cat <<EOF > $VAR_AWK
233/^Schedule of variations:/ { in_vars=1; next }
234/^$/ { in_vars=0 }
235/^Running target/ { exit }
236{ if (in_vars==1) print \$1; else next }
237EOF
238
239 touch ${TMP}/varlist
240 for FILE in $SUM_FILES; do
241 $AWK -f $VAR_AWK $FILE >> ${TMP}/varlist
242 done
243 VARIANTS="`sort -u ${TMP}/varlist`"
244else
245 VARS="$VARIANTS"
246 VARIANTS=""
247 for VAR in $VARS
248 do
ef878e53 249 $GREP "Running target $VAR" $SUM_FILES > /dev/null && VARIANTS="$VARIANTS $VAR"
6bc80edc
TT
250 done
251fi
252
253# Find out if we have more than one variant, or any at all.
254
255VARIANT_COUNT=0
256for VAR in $VARIANTS
257do
258 VARIANT_COUNT=`expr $VARIANT_COUNT + 1`
259done
260
261if test $VARIANT_COUNT -eq 0 ; then
262 msg "${PROGNAME}: no file for $TOOL has results for the specified variants"
263 exit 1
264fi
265
266cat $SUM_FILES \
267 | $AWK '/^Running/ { if ($2 != "target" && $3 == "...") print "EXPFILE: "$2 } ' \
268 | sort -u > ${TMP}/expfiles
269
270# Write the begining of the combined summary file.
271
272head -n 2 $FIRST_SUM
273echo
274echo " === $TOOL tests ==="
275echo
276echo "Schedule of variations:"
277for VAR in $VARIANTS
278do
279 echo " $VAR"
280done
281echo
282
283# For each test variant for the tool, copy test reports from each of the
284# summary files. Set up two awk scripts from within the loop to
285# initialize VAR and TOOL with the script, rather than assuming that the
286# available version of awk can pass variables from the command line.
287
288for VAR in $VARIANTS
289do
290 GUTS_AWK=${TMP}/guts.awk
291 cat << EOF > $GUTS_AWK
292BEGIN {
293 variant="$VAR"
294 firstvar=1
295 expfileno=1
296 cnt=0
297 print_using=0
298 need_close=0
299}
300/^EXPFILE: / {
301 expfiles[expfileno] = \$2
302 expfilesr[\$2] = expfileno
303 expfileno = expfileno + 1
304}
305/^Running target / {
306 curvar = \$3
307 if (variant == curvar && firstvar == 1) { print; print_using=1; firstvar = 0 }
308 next
309}
310/^Using / {
311 if (variant == curvar && print_using) { print; next }
312}
96343774 313/^Running .*\\.exp \\.\\.\\./ {
6bc80edc
TT
314 print_using=0
315 if (variant == curvar) {
316 if (need_close) close(curfile)
317 curfile="${TMP}/list"expfilesr[\$2]
318 expfileseen[\$2]=expfileseen[\$2] + 1
319 need_close=0
320 testname="00"
321 next
322 }
323}
c847d045 324/^\t\t=== .* ===$/ { curvar = ""; next }
6bc80edc
TT
325/^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/ {
326 testname=\$2
327 # Ugly hack for gfortran.dg/dg.exp
328 if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
329 testname="h"testname
330}
331/^$/ { if ("$MODE" == "sum") next }
332{ if (variant == curvar && curfile) {
333 if ("$MODE" == "sum") {
334 printf "%s %08d|", testname, cnt >> curfile
335 cnt = cnt + 1
336 }
337 filewritten[curfile]=1
338 need_close=1
339 print >> curfile
340 } else
341 next
342}
343END {
344 n=1
345 while (n < expfileno) {
346 if (expfileseen[expfiles[n]]) {
347 print "Running "expfiles[n]" ..."
348 if (filewritten["${TMP}/list"n]) {
349 if (expfileseen[expfiles[n]] == 1)
350 cmd="cat"
351 else
352 cmd="LC_ALL=C sort"
353 if ("$MODE" == "sum")
354 system (cmd" ${TMP}/list"n" | sed -n 's/^[^ ]* [^ |]*|//p'")
355 else
356 system ("cat ${TMP}/list"n)
357 }
358 }
359 n = n + 1
360 }
361}
362EOF
363
364 SUMS_AWK=${TMP}/sums.awk
365 rm -f $SUMS_AWK
366 cat << EOF > $SUMS_AWK
367BEGIN {
368 variant="$VAR"
369 tool="$TOOL"
96343774 370 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0;
6bc80edc
TT
371 curvar=""; insummary=0
372}
373/^Running target / { curvar = \$3; next }
374/^# of / { if (variant == curvar) insummary = 1 }
375/^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
376/^# of unexpected successes/ { if (insummary == 1) xpasscnt += \$5; next; }
377/^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
378/^# of expected failures/ { if (insummary == 1) xfailcnt += \$5; next; }
96343774 379/^# of unknown successes/ { if (insummary == 1) kpasscnt += \$5; next; }
8fabffee 380/^# of known failures/ { if (insummary == 1) kfailcnt += \$5; next; }
6bc80edc
TT
381/^# of untested testcases/ { if (insummary == 1) untstcnt += \$5; next; }
382/^# of unresolved testcases/ { if (insummary == 1) unrescnt += \$5; next; }
383/^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
384/^$/ { if (insummary == 1)
385 { insummary = 0; curvar = "" }
386 next
387 }
388{ next }
389END {
390 printf ("\t\t=== %s Summary for %s ===\n\n", tool, variant)
391 if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
6bc80edc 392 if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
c847d045 393 if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
6bc80edc 394 if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
96343774 395 if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt)
8fabffee 396 if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt)
6bc80edc
TT
397 if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
398 if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
399 if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
400}
401EOF
402
403 PVAR=`echo $VAR | sed 's,/,.,g'`
404 TMPFILE=${TMP}/var-$PVAR
405 rm -f $TMPFILE
406 rm -f ${TMP}/list*
407 cat ${TMP}/expfiles $SUM_FILES | $AWK -f $GUTS_AWK
408 cat $SUM_FILES | $AWK -f $SUMS_AWK > $TMPFILE
409 # If there are multiple variants, output the counts for this one;
410 # otherwise there will just be the final counts at the end.
411 test $VARIANT_COUNT -eq 1 || cat $TMPFILE
412done
413
414# Set up an awk script to get the combined summary counts for the tool.
415
416TOTAL_AWK=${TMP}/total.awk
417cat << EOF > $TOTAL_AWK
418BEGIN {
419 tool="$TOOL"
8fabffee 420 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0
6bc80edc
TT
421}
422/^# of expected passes/ { passcnt += \$5 }
423/^# of unexpected failures/ { failcnt += \$5 }
424/^# of unexpected successes/ { xpasscnt += \$5 }
425/^# of expected failures/ { xfailcnt += \$5 }
96343774 426/^# of unknown successes/ { kpasscnt += \$5 }
8fabffee 427/^# of known failures/ { kfailcnt += \$5 }
6bc80edc
TT
428/^# of untested testcases/ { untstcnt += \$5 }
429/^# of unresolved testcases/ { unrescnt += \$5 }
430/^# of unsupported tests/ { unsupcnt += \$5 }
431END {
432 printf ("\n\t\t=== %s Summary ===\n\n", tool)
433 if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
434 if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
435 if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
436 if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
96343774 437 if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt)
8fabffee 438 if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt)
6bc80edc
TT
439 if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
440 if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
441 if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
442}
443EOF
444
445# Find the total summaries for the tool and add to the end of the output.
446cat ${TMP}/var-* | $AWK -f $TOTAL_AWK
447
448# This is ugly, but if there's version output from the compiler under test
449# at the end of the file, we want it. The other thing that might be there
450# is the final summary counts.
ef878e53 451tail -2 $FIRST_SUM | $GREP '^#' > /dev/null || tail -2 $FIRST_SUM
6bc80edc
TT
452
453exit 0