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 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)
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
33 Usage: $PROGNAME [-t tool] [-l variant-list] [-L] sum-file ...
35 tool The tool (e.g. g++, libffi) for which to create a
36 new test summary file. If not specified then all
37 specified sum files must be for the same tool.
38 variant-list One or more test variant names. If the list is
39 not specified then one is constructed from all
40 variants in the files for <tool>.
41 sum-file A test summary file with the format of those
42 created by runtest from DejaGnu.
43 If -L is used, merge *.log files instead of *.sum. In this
44 mode the exact order of lines may not be preserved, just different
45 Running *.exp chunks should be in correct order.
49 # Write a message to the standard error.
55 # Parse the command-line options.
61 while getopts "l:t:L" ARG
; do
63 l
) VARIANTS
="${VARIANTS} ${OPTARG}";;
64 t
) test -z "$TOOL" ||
(msg
"${PROGNAME}: only one tool can be specified"; exit 1);
70 shift `expr ${OPTIND} - 1`
72 if test $# -lt 1 ; then
81 trap 'EXIT_STATUS=$?; rm -rf $TMP && exit $EXIT_STATUS' 0
82 # Create a (secure) tmp directory for tmp files.
84 TMP
=`(umask 077 && mktemp -d -q "${TMPDIR}/dg-combine-results-$$-XXXXXX") 2>/dev/null` &&
85 test -n "$TMP" && test -d "$TMP"
88 TMP
=${TMPDIR}/dg-combine-results-$$
-$RANDOM
89 (umask 077 && mkdir
$TMP)
92 msg
"${PROGNAME}: cannot create a temporary directory"
98 if test -z "$AWK" ; then
99 for AWK
in gawk nawk
awk
101 if type $AWK 2>&1 |
grep 'not found' > /dev
/null
2>&1 ; then
109 # Verify that the specified summary files exist.
112 for FILE
in $SUM_FILES
114 if ! test -f $FILE ; then
115 msg
"${PROGNAME}: file $FILE does not exist."
119 test $ERROR -eq 0 ||
exit 1
121 if [ -z "$TOOL" ]; then
122 # If no tool was specified, all specified summary files must be for
125 CNT
=`grep '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
126 if [ $CNT -eq 1 ]; then
127 TOOL
=`grep '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
129 msg
"${PROGNAME}: sum files are for multiple tools, specify a tool"
135 # Ignore the specified summary files that are not for this tool. This
136 # should keep the relevant files in the same order.
138 SUM_FILES
=`grep -l "=== $TOOL" $SUM_FILES`
139 if test -z "$SUM_FILES" ; then
140 msg
"${PROGNAME}: none of the specified files are results for $TOOL"
145 if [ "$TOOL" = acats
]; then
146 # Acats *.sum or *.log files aren't dejagnu generated, and they have
147 # somewhat different format.
148 ACATS_AWK
=${TMP}/acats.
awk
149 cat <<EOF > $ACATS_AWK
151 print_prologue=1; chapter=""; insummary=0
152 passcnt=0; failcnt=0; unsupcnt=0; failures=""
154 /=== acats configuration ===/ {
156 if (print_prologue) print
159 /=== acats tests ===/ {
160 if (print_prologue) print
164 /^Running chapter / {
166 print > "${TMP}/chapter-"chapter
169 /=== acats Summary ===/ {
174 /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
175 /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
176 /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
177 /^\*\*\* FAILURES: / {
178 if (insummary == 1) {
179 if (failures) sub(/^\*\*\* FAILURES:/,"")
180 failures=failures""\$0
184 if (print_prologue) { print; next }
185 if (chapter) print > "${TMP}/chapter-"chapter
188 system ("cat ${TMP}/chapter-*")
189 print " === acats Summary ==="
190 print "# of expected passes " passcnt
191 print "# of unexpected failures " failcnt
192 if (unsupcnt) print "# of unsupported tests " unsupcnt
193 if (failures) print failures
197 $AWK -f $ACATS_AWK $SUM_FILES
201 # If no variants were specified, find all variants in the remaining
202 # summary files. Otherwise, ignore specified variants that aren't in
203 # any of those summary files.
205 if test -z "$VARIANTS" ; then
206 VAR_AWK
=${TMP}/variants.
awk
208 /^Schedule of variations:/ { in_vars=1; next }
210 /^Running target/ { exit }
211 { if (in_vars==1) print \$1; else next }
215 for FILE
in $SUM_FILES; do
216 $AWK -f $VAR_AWK $FILE >> ${TMP}/varlist
218 VARIANTS
="`sort -u ${TMP}/varlist`"
224 grep -q "Running target $VAR" $SUM_FILES && VARIANTS
="$VARIANTS $VAR"
228 # Find out if we have more than one variant, or any at all.
233 VARIANT_COUNT
=`expr $VARIANT_COUNT + 1`
236 if test $VARIANT_COUNT -eq 0 ; then
237 msg
"${PROGNAME}: no file for $TOOL has results for the specified variants"
242 |
$AWK '/^Running/ { if ($2 != "target" && $3 == "...") print "EXPFILE: "$2 } ' \
243 |
sort -u > ${TMP}/expfiles
245 # Write the begining of the combined summary file.
249 echo " === $TOOL tests ==="
251 echo "Schedule of variations:"
258 # For each test variant for the tool, copy test reports from each of the
259 # summary files. Set up two awk scripts from within the loop to
260 # initialize VAR and TOOL with the script, rather than assuming that the
261 # available version of awk can pass variables from the command line.
265 GUTS_AWK
=${TMP}/guts.
awk
266 cat << EOF > $GUTS_AWK
275 expfiles[expfileno] = \$2
276 expfilesr[\$2] = expfileno
277 expfileno = expfileno + 1
281 if (variant == curvar && firstvar == 1) { print; print_using=1; firstvar = 0 }
285 if (variant == curvar && print_using) { print; next }
289 if (variant == curvar) {
290 curfile="${TMP}/list"expfilesr[\$2]
291 expfileseen[\$2]=expfileseen[\$2] + 1
296 /\===/ { curvar = ""; next }
297 /^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/ {
299 # Ugly hack for gfortran.dg/dg.exp
300 if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
303 /^$/ { if ("$MODE" == "sum") next }
304 { if (variant == curvar && curfile) {
305 if ("$MODE" == "sum") {
306 printf "%s %08d|", testname, cnt > curfile
309 filewritten[curfile]=1
316 while (n < expfileno) {
317 if (expfileseen[expfiles[n]]) {
318 print "Running "expfiles[n]" ..."
319 if (filewritten["${TMP}/list"n]) {
320 if (expfileseen[expfiles[n]] == 1)
324 if ("$MODE" == "sum")
325 system (cmd" ${TMP}/list"n" | sed -n 's/^[^ ]* [^ |]*|//p'")
327 system ("cat ${TMP}/list"n)
335 SUMS_AWK
=${TMP}/sums.
awk
337 cat << EOF > $SUMS_AWK
341 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; unsupcnt=0; unrescnt=0;
342 curvar=""; insummary=0
344 /^Running target / { curvar = \$3; next }
345 /^# of / { if (variant == curvar) insummary = 1 }
346 /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
347 /^# of unexpected successes/ { if (insummary == 1) xpasscnt += \$5; next; }
348 /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
349 /^# of expected failures/ { if (insummary == 1) xfailcnt += \$5; next; }
350 /^# of untested testcases/ { if (insummary == 1) untstcnt += \$5; next; }
351 /^# of unresolved testcases/ { if (insummary == 1) unrescnt += \$5; next; }
352 /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
353 /^$/ { if (insummary == 1)
354 { insummary = 0; curvar = "" }
359 printf ("\t\t=== %s Summary for %s ===\n\n", tool, variant)
360 if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
361 if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
362 if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
363 if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
364 if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
365 if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
366 if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
370 PVAR
=`echo $VAR | sed 's,/,.,g'`
371 TMPFILE
=${TMP}/var-
$PVAR
374 cat ${TMP}/expfiles
$SUM_FILES |
$AWK -f $GUTS_AWK
375 cat $SUM_FILES |
$AWK -f $SUMS_AWK > $TMPFILE
376 # If there are multiple variants, output the counts for this one;
377 # otherwise there will just be the final counts at the end.
378 test $VARIANT_COUNT -eq 1 ||
cat $TMPFILE
381 # Set up an awk script to get the combined summary counts for the tool.
383 TOTAL_AWK
=${TMP}/total.
awk
384 cat << EOF > $TOTAL_AWK
387 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; unsupcnt=0; unrescnt=0
389 /^# of expected passes/ { passcnt += \$5 }
390 /^# of unexpected failures/ { failcnt += \$5 }
391 /^# of unexpected successes/ { xpasscnt += \$5 }
392 /^# of expected failures/ { xfailcnt += \$5 }
393 /^# of untested testcases/ { untstcnt += \$5 }
394 /^# of unresolved testcases/ { unrescnt += \$5 }
395 /^# of unsupported tests/ { unsupcnt += \$5 }
397 printf ("\n\t\t=== %s Summary ===\n\n", tool)
398 if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
399 if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
400 if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
401 if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
402 if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
403 if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
404 if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
408 # Find the total summaries for the tool and add to the end of the output.
409 cat ${TMP}/var-
* |
$AWK -f $TOTAL_AWK
411 # This is ugly, but if there's version output from the compiler under test
412 # at the end of the file, we want it. The other thing that might be there
413 # is the final summary counts.
414 tail -n 2 $FIRST_SUM |
grep -q '^#' ||
tail -n 2 $FIRST_SUM