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