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-2017 Free Software Foundation, Inc.
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 this program. If not, see <http://www.gnu.org/licenses/>.
27 PROGNAME
=dg-extract-results.sh
29 # Try to use the python version if possible, since it tends to be faster.
30 PYTHON_VER
=`echo "$0" | sed 's/sh$/py/'`
31 if 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 "$@"
40 Usage: $PROGNAME [-t tool] [-l variant-list] [-L] sum-file ...
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.
56 # Write a message to the standard error.
62 # Parse the command-line options.
68 while getopts "l:t:L" ARG
; do
70 l
) VARIANTS
="${VARIANTS} ${OPTARG}";;
71 t
) test -z "$TOOL" ||
(msg
"${PROGNAME}: only one tool can be specified"; exit 1);
77 shift `expr ${OPTIND} - 1`
79 if test $# -lt 1 ; then
88 trap 'EXIT_STATUS=$?; rm -rf $TMP && exit $EXIT_STATUS' 0
89 # Create a (secure) tmp directory for tmp files.
91 TMP
=`(umask 077 && mktemp -d -q "${TMPDIR}/dg-combine-results-$$-XXXXXX") 2>/dev/null` &&
92 test -n "$TMP" && test -d "$TMP"
95 TMP
=${TMPDIR}/dg-combine-results-$$
-$RANDOM
96 (umask 077 && mkdir
$TMP)
99 msg
"${PROGNAME}: cannot create a temporary directory"
100 { (exit 1); exit 1; }
105 if test -z "$AWK" ; then
106 for AWK
in gawk nawk
awk
108 if type $AWK 2>&1 |
grep 'not found' > /dev
/null
2>&1 ; then
116 # Verify that the specified summary files exist.
119 for FILE
in $SUM_FILES
121 if ! test -f $FILE ; then
122 msg
"${PROGNAME}: file $FILE does not exist."
126 test $ERROR -eq 0 ||
exit 1
128 # Test if grep supports the '--text' option
132 if echo -e '\x00foo\x00' |
$GREP --text foo
> /dev
/null
2>&1 ; then
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
143 if [ -z "$TOOL" ]; then
144 # If no tool was specified, all specified summary files must be for
147 CNT
=`$GREP '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
148 if [ $CNT -eq 1 ]; then
149 TOOL
=`$GREP '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
151 msg
"${PROGNAME}: sum files are for multiple tools, specify a tool"
157 # Ignore the specified summary files that are not for this tool. This
158 # should keep the relevant files in the same order.
160 SUM_FILES
=`$GREP -l "=== $TOOL" $SUM_FILES`
161 if test -z "$SUM_FILES" ; then
162 msg
"${PROGNAME}: none of the specified files are results for $TOOL"
167 if [ "$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
173 print_prologue=1; curfile=""; insummary=0
174 passcnt=0; failcnt=0; unsupcnt=0; failures=""
176 /^[ \t]*=== acats configuration ===/ {
178 if (print_prologue) print
181 /^[ \t]*=== acats tests ===/ {
182 if (print_prologue) print
186 /^Running chapter / {
187 if (curfile) close (curfile)
188 curfile="${TMP}/chapter-"\$3
192 /^[ \t]*=== acats Summary ===/ {
193 if (curfile) close (curfile)
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
208 if (print_prologue) { print; next }
209 if (curfile) print >> curfile
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
221 rm -f ${TMP}/chapter-
*
222 $AWK -f $ACATS_AWK $SUM_FILES
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.
230 if test -z "$VARIANTS" ; then
231 VAR_AWK
=${TMP}/variants.
awk
233 /^Schedule of variations:/ { in_vars=1; next }
235 /^Running target/ { exit }
236 { if (in_vars==1) print \$1; else next }
240 for FILE
in $SUM_FILES; do
241 $AWK -f $VAR_AWK $FILE >> ${TMP}/varlist
243 VARIANTS
="`sort -u ${TMP}/varlist`"
249 $GREP "Running target $VAR" $SUM_FILES > /dev
/null
&& VARIANTS
="$VARIANTS $VAR"
253 # Find out if we have more than one variant, or any at all.
258 VARIANT_COUNT
=`expr $VARIANT_COUNT + 1`
261 if test $VARIANT_COUNT -eq 0 ; then
262 msg
"${PROGNAME}: no file for $TOOL has results for the specified variants"
267 |
$AWK '/^Running/ { if ($2 != "target" && $3 == "...") print "EXPFILE: "$2 } ' \
268 |
sort -u > ${TMP}/expfiles
270 # Write the begining of the combined summary file.
274 echo " === $TOOL tests ==="
276 echo "Schedule of variations:"
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.
290 GUTS_AWK
=${TMP}/guts.
awk
291 cat << EOF > $GUTS_AWK
301 expfiles[expfileno] = \$2
302 expfilesr[\$2] = expfileno
303 expfileno = expfileno + 1
307 if (variant == curvar && firstvar == 1) { print; print_using=1; firstvar = 0 }
311 if (variant == curvar && print_using) { print; next }
313 /^Running .*\\.exp \\.\\.\\./ {
315 if (variant == curvar) {
316 if (need_close) close(curfile)
317 curfile="${TMP}/list"expfilesr[\$2]
318 expfileseen[\$2]=expfileseen[\$2] + 1
324 /^\t\t=== .* ===$/ { curvar = ""; next }
325 /^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/ {
327 # Ugly hack for gfortran.dg/dg.exp
328 if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
331 /^$/ { if ("$MODE" == "sum") next }
332 { if (variant == curvar && curfile) {
333 if ("$MODE" == "sum") {
334 printf "%s %08d|", testname, cnt >> curfile
337 filewritten[curfile]=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)
353 if ("$MODE" == "sum")
354 system (cmd" ${TMP}/list"n" | sed -n 's/^[^ ]* [^ |]*|//p'")
356 system ("cat ${TMP}/list"n)
364 SUMS_AWK
=${TMP}/sums.
awk
366 cat << EOF > $SUMS_AWK
370 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0;
371 curvar=""; insummary=0
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; }
379 /^# of unknown successes/ { if (insummary == 1) kpasscnt += \$5; next; }
380 /^# of known failures/ { if (insummary == 1) kfailcnt += \$5; next; }
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 = "" }
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)
392 if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
393 if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
394 if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
395 if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt)
396 if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt)
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)
403 PVAR
=`echo $VAR | sed 's,/,.,g'`
404 TMPFILE
=${TMP}/var-
$PVAR
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
414 # Set up an awk script to get the combined summary counts for the tool.
416 TOTAL_AWK
=${TMP}/total.
awk
417 cat << EOF > $TOTAL_AWK
420 passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0
422 /^# of expected passes/ { passcnt += \$5 }
423 /^# of unexpected failures/ { failcnt += \$5 }
424 /^# of unexpected successes/ { xpasscnt += \$5 }
425 /^# of expected failures/ { xfailcnt += \$5 }
426 /^# of unknown successes/ { kpasscnt += \$5 }
427 /^# of known failures/ { kfailcnt += \$5 }
428 /^# of untested testcases/ { untstcnt += \$5 }
429 /^# of unresolved testcases/ { unrescnt += \$5 }
430 /^# of unsupported tests/ { unsupcnt += \$5 }
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)
437 if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt)
438 if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt)
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)
445 # Find the total summaries for the tool and add to the end of the output.
446 cat ${TMP}/var-
* |
$AWK -f $TOTAL_AWK
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.
451 tail -2 $FIRST_SUM |
$GREP '^#' > /dev
/null ||
tail -2 $FIRST_SUM
This page took 0.039824 seconds and 4 git commands to generate.