Fix bootstrap/PR63632
[official-gcc.git] / contrib / dg-extract-results.sh
bloba83c8e8d67841f5dcbac4dd66f35d2ec2b28e3b8
1 #! /bin/sh
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.
9 # Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation
10 # Contributed by Janis Johnson <janis187@us.ibm.com>
12 # This file is part of GCC.
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.
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.
24 # You should have received a copy of the GNU General Public License
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.
29 PROGNAME=dg-extract-results.sh
31 # Try to use the python version if possible, since it tends to be faster.
32 PYTHON_VER=`echo "$0" | sed 's/sh$/py/'`
33 if test "$PYTHON_VER" != "$0" &&
34 test -f "$PYTHON_VER" &&
35 python -c 'import sys; sys.exit (0 if sys.version_info >= (2, 6) else 1)' \
36 > /dev/null 2> /dev/null; then
37 exec python $PYTHON_VER "$@"
40 usage() {
41 cat <<EOF >&2
42 Usage: $PROGNAME [-t tool] [-l variant-list] [-L] sum-file ...
44 tool The tool (e.g. g++, libffi) for which to create a
45 new test summary file. If not specified then all
46 specified sum files must be for the same tool.
47 variant-list One or more test variant names. If the list is
48 not specified then one is constructed from all
49 variants in the files for <tool>.
50 sum-file A test summary file with the format of those
51 created by runtest from DejaGnu.
52 If -L is used, merge *.log files instead of *.sum. In this
53 mode the exact order of lines may not be preserved, just different
54 Running *.exp chunks should be in correct order.
55 EOF
58 # Write a message to the standard error.
60 msg() {
61 echo "$@" >&2
64 # Parse the command-line options.
66 VARIANTS=""
67 TOOL=""
68 MODE="sum"
70 while getopts "l:t:L" ARG; do
71 case $ARG in
72 l) VARIANTS="${VARIANTS} ${OPTARG}";;
73 t) test -z "$TOOL" || (msg "${PROGNAME}: only one tool can be specified"; exit 1);
74 TOOL="${OPTARG}";;
75 L) MODE="log";;
76 \?) usage; exit 0;;
77 esac
78 done
79 shift `expr ${OPTIND} - 1`
81 if test $# -lt 1 ; then
82 usage
83 exit 1
86 TMPDIR=${TMPDIR-/tmp}
87 SUM_FILES="$@"
88 FIRST_SUM=$1
89 TMP=
90 trap 'EXIT_STATUS=$?; rm -rf $TMP && exit $EXIT_STATUS' 0
91 # Create a (secure) tmp directory for tmp files.
93 TMP=`(umask 077 && mktemp -d -q "${TMPDIR}/dg-combine-results-$$-XXXXXX") 2>/dev/null` &&
94 test -n "$TMP" && test -d "$TMP"
95 } ||
97 TMP=${TMPDIR}/dg-combine-results-$$-$RANDOM
98 (umask 077 && mkdir $TMP)
99 } ||
101 msg "${PROGNAME}: cannot create a temporary directory"
102 { (exit 1); exit 1; }
105 # Find a good awk.
107 if test -z "$AWK" ; then
108 for AWK in gawk nawk awk
110 if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
112 else
113 break
115 done
118 # Verify that the specified summary files exist.
120 ERROR=0
121 for FILE in $SUM_FILES
123 if ! test -f $FILE ; then
124 msg "${PROGNAME}: file $FILE does not exist."
125 ERROR=1
127 done
128 test $ERROR -eq 0 || exit 1
130 if [ -z "$TOOL" ]; then
131 # If no tool was specified, all specified summary files must be for
132 # the same tool.
134 CNT=`grep '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
135 if [ $CNT -eq 1 ]; then
136 TOOL=`grep '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
137 else
138 msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
139 msg ""
140 usage
141 exit 1
143 else
144 # Ignore the specified summary files that are not for this tool. This
145 # should keep the relevant files in the same order.
147 SUM_FILES=`grep -l "=== $TOOL" $SUM_FILES`
148 if test -z "$SUM_FILES" ; then
149 msg "${PROGNAME}: none of the specified files are results for $TOOL"
150 exit 1
154 if [ "$TOOL" = acats ]; then
155 # Acats *.sum or *.log files aren't dejagnu generated, and they have
156 # somewhat different format.
157 ACATS_AWK=${TMP}/acats.awk
158 cat <<EOF > $ACATS_AWK
159 BEGIN {
160 print_prologue=1; curfile=""; insummary=0
161 passcnt=0; failcnt=0; unsupcnt=0; failures=""
163 /^[ \t]*=== acats configuration ===/ {
164 insummary=0
165 if (print_prologue) print
166 next
168 /^[ \t]*=== acats tests ===/ {
169 if (print_prologue) print
170 print_prologue=0
171 next
173 /^Running chapter / {
174 if (curfile) close (curfile)
175 curfile="${TMP}/chapter-"\$3
176 print >> curfile
177 next
179 /^[ \t]*=== acats Summary ===/ {
180 if (curfile) close (curfile)
181 curfile=""
182 insummary=1
183 next
185 /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
186 /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
187 /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
188 /^\*\*\* FAILURES: / {
189 if (insummary == 1) {
190 if (failures) sub(/^\*\*\* FAILURES:/,"")
191 failures=failures""\$0
195 if (print_prologue) { print; next }
196 if (curfile) print >> curfile
198 END {
199 system ("cat ${TMP}/chapter-*")
200 print " === acats Summary ==="
201 print "# of expected passes " passcnt
202 print "# of unexpected failures " failcnt
203 if (unsupcnt) print "# of unsupported tests " unsupcnt
204 if (failures) print failures
208 rm -f ${TMP}/chapter-*
209 $AWK -f $ACATS_AWK $SUM_FILES
210 exit 0
213 # If no variants were specified, find all variants in the remaining
214 # summary files. Otherwise, ignore specified variants that aren't in
215 # any of those summary files.
217 if test -z "$VARIANTS" ; then
218 VAR_AWK=${TMP}/variants.awk
219 cat <<EOF > $VAR_AWK
220 /^Schedule of variations:/ { in_vars=1; next }
221 /^$/ { in_vars=0 }
222 /^Running target/ { exit }
223 { if (in_vars==1) print \$1; else next }
226 touch ${TMP}/varlist
227 for FILE in $SUM_FILES; do
228 $AWK -f $VAR_AWK $FILE >> ${TMP}/varlist
229 done
230 VARIANTS="`sort -u ${TMP}/varlist`"
231 else
232 VARS="$VARIANTS"
233 VARIANTS=""
234 for VAR in $VARS
236 grep "Running target $VAR" $SUM_FILES > /dev/null && VARIANTS="$VARIANTS $VAR"
237 done
240 # Find out if we have more than one variant, or any at all.
242 VARIANT_COUNT=0
243 for VAR in $VARIANTS
245 VARIANT_COUNT=`expr $VARIANT_COUNT + 1`
246 done
248 if test $VARIANT_COUNT -eq 0 ; then
249 msg "${PROGNAME}: no file for $TOOL has results for the specified variants"
250 exit 1
253 cat $SUM_FILES \
254 | $AWK '/^Running/ { if ($2 != "target" && $3 == "...") print "EXPFILE: "$2 } ' \
255 | sort -u > ${TMP}/expfiles
257 # Write the begining of the combined summary file.
259 head -n 2 $FIRST_SUM
260 echo
261 echo " === $TOOL tests ==="
262 echo
263 echo "Schedule of variations:"
264 for VAR in $VARIANTS
266 echo " $VAR"
267 done
268 echo
270 # For each test variant for the tool, copy test reports from each of the
271 # summary files. Set up two awk scripts from within the loop to
272 # initialize VAR and TOOL with the script, rather than assuming that the
273 # available version of awk can pass variables from the command line.
275 for VAR in $VARIANTS
277 GUTS_AWK=${TMP}/guts.awk
278 cat << EOF > $GUTS_AWK
279 BEGIN {
280 variant="$VAR"
281 firstvar=1
282 expfileno=1
283 cnt=0
284 print_using=0
285 need_close=0
287 /^EXPFILE: / {
288 expfiles[expfileno] = \$2
289 expfilesr[\$2] = expfileno
290 expfileno = expfileno + 1
292 /^Running target / {
293 curvar = \$3
294 if (variant == curvar && firstvar == 1) { print; print_using=1; firstvar = 0 }
295 next
297 /^Using / {
298 if (variant == curvar && print_using) { print; next }
300 /^Running .*\\.exp \\.\\.\\./ {
301 print_using=0
302 if (variant == curvar) {
303 if (need_close) close(curfile)
304 curfile="${TMP}/list"expfilesr[\$2]
305 expfileseen[\$2]=expfileseen[\$2] + 1
306 need_close=0
307 testname="00"
308 next
311 /^\t\t=== .* ===$/ { curvar = ""; next }
312 /^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/ {
313 testname=\$2
314 # Ugly hack for gfortran.dg/dg.exp
315 if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
316 testname="h"testname
318 /^$/ { if ("$MODE" == "sum") next }
319 { if (variant == curvar && curfile) {
320 if ("$MODE" == "sum") {
321 printf "%s %08d|", testname, cnt >> curfile
322 cnt = cnt + 1
324 filewritten[curfile]=1
325 need_close=1
326 print >> curfile
327 } else
328 next
330 END {
332 while (n < expfileno) {
333 if (expfileseen[expfiles[n]]) {
334 print "Running "expfiles[n]" ..."
335 if (filewritten["${TMP}/list"n]) {
336 if (expfileseen[expfiles[n]] == 1)
337 cmd="cat"
338 else
339 cmd="LC_ALL=C sort"
340 if ("$MODE" == "sum")
341 system (cmd" ${TMP}/list"n" | sed -n 's/^[^ ]* [^ |]*|//p'")
342 else
343 system ("cat ${TMP}/list"n)
346 n = n + 1
351 SUMS_AWK=${TMP}/sums.awk
352 rm -f $SUMS_AWK
353 cat << EOF > $SUMS_AWK
354 BEGIN {
355 variant="$VAR"
356 tool="$TOOL"
357 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0;
358 curvar=""; insummary=0
360 /^Running target / { curvar = \$3; next }
361 /^# of / { if (variant == curvar) insummary = 1 }
362 /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
363 /^# of unexpected successes/ { if (insummary == 1) xpasscnt += \$5; next; }
364 /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
365 /^# of expected failures/ { if (insummary == 1) xfailcnt += \$5; next; }
366 /^# of unknown successes/ { if (insummary == 1) kpasscnt += \$5; next; }
367 /^# of known failures/ { if (insummary == 1) kfailcnt += \$5; next; }
368 /^# of untested testcases/ { if (insummary == 1) untstcnt += \$5; next; }
369 /^# of unresolved testcases/ { if (insummary == 1) unrescnt += \$5; next; }
370 /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
371 /^$/ { if (insummary == 1)
372 { insummary = 0; curvar = "" }
373 next
375 { next }
376 END {
377 printf ("\t\t=== %s Summary for %s ===\n\n", tool, variant)
378 if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
379 if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
380 if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
381 if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
382 if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt)
383 if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt)
384 if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
385 if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
386 if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
390 PVAR=`echo $VAR | sed 's,/,.,g'`
391 TMPFILE=${TMP}/var-$PVAR
392 rm -f $TMPFILE
393 rm -f ${TMP}/list*
394 cat ${TMP}/expfiles $SUM_FILES | $AWK -f $GUTS_AWK
395 cat $SUM_FILES | $AWK -f $SUMS_AWK > $TMPFILE
396 # If there are multiple variants, output the counts for this one;
397 # otherwise there will just be the final counts at the end.
398 test $VARIANT_COUNT -eq 1 || cat $TMPFILE
399 done
401 # Set up an awk script to get the combined summary counts for the tool.
403 TOTAL_AWK=${TMP}/total.awk
404 cat << EOF > $TOTAL_AWK
405 BEGIN {
406 tool="$TOOL"
407 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0
409 /^# of expected passes/ { passcnt += \$5 }
410 /^# of unexpected failures/ { failcnt += \$5 }
411 /^# of unexpected successes/ { xpasscnt += \$5 }
412 /^# of expected failures/ { xfailcnt += \$5 }
413 /^# of unknown successes/ { kpasscnt += \$5 }
414 /^# of known failures/ { kfailcnt += \$5 }
415 /^# of untested testcases/ { untstcnt += \$5 }
416 /^# of unresolved testcases/ { unrescnt += \$5 }
417 /^# of unsupported tests/ { unsupcnt += \$5 }
418 END {
419 printf ("\n\t\t=== %s Summary ===\n\n", tool)
420 if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
421 if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
422 if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
423 if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
424 if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt)
425 if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt)
426 if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
427 if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
428 if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
432 # Find the total summaries for the tool and add to the end of the output.
433 cat ${TMP}/var-* | $AWK -f $TOTAL_AWK
435 # This is ugly, but if there's version output from the compiler under test
436 # at the end of the file, we want it. The other thing that might be there
437 # is the final summary counts.
438 tail -2 $FIRST_SUM | grep '^#' > /dev/null || tail -2 $FIRST_SUM
440 exit 0