OSDN Git Service

* trans-types.c (gfc_sym_type, gfc_return_by_reference): For
[pf3gnuchains/gcc-fork.git] / contrib / dg-extract-results.sh
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
9 # Copyright (C) 2008 Free Software Foundation
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
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.
28
29 PROGNAME=dg-extract-results.sh
30
31 usage() {
32   cat <<EOF >&2
33 Usage: $PROGNAME [-t tool] [-l variant-list] [-L] sum-file ...
34
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.
46 EOF
47 }
48
49 # Write a message to the standard error.
50
51 msg() {
52   echo "$@" >&2
53 }
54
55 # Parse the command-line options.
56
57 VARIANTS=""
58 TOOL=""
59 MODE="sum"
60
61 while getopts "l:t:L" ARG; do
62   case $ARG in
63   l)  VARIANTS="${VARIANTS} ${OPTARG}";;
64   t)  test -z "$TOOL" || (msg "${PROGNAME}: only one tool can be specified"; exit 1);
65       TOOL="${OPTARG}";;
66   L)  MODE="log";;
67   \?) usage; exit 0;;
68   esac
69 done
70 shift `expr ${OPTIND} - 1`
71
72 if test $# -lt 1 ; then
73   usage
74   exit 1
75 fi
76
77 TMPDIR=${TMPDIR-/tmp}
78 SUM_FILES="$@"
79 FIRST_SUM=$1
80 TMP=
81 trap 'EXIT_STATUS=$?; rm -rf $TMP && exit $EXIT_STATUS' 0
82 # Create a (secure) tmp directory for tmp files.
83 {
84   TMP=`(umask 077 && mktemp -d -q "${TMPDIR}/dg-combine-results-$$-XXXXXX") 2>/dev/null` &&
85   test -n "$TMP" && test -d "$TMP"
86 } ||
87 {
88   TMP=${TMPDIR}/dg-combine-results-$$-$RANDOM
89   (umask 077 && mkdir $TMP)
90 } ||
91 {
92   msg "${PROGNAME}: cannot create a temporary directory"
93   { (exit 1); exit 1; }
94 }
95
96 # Find a good awk.
97
98 if test -z "$AWK" ; then
99   for AWK in gawk nawk awk
100   do
101     if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
102       :
103     else
104       break
105     fi
106   done
107 fi
108
109 # Verify that the specified summary files exist.
110
111 ERROR=0
112 for FILE in $SUM_FILES
113 do
114   if ! test -f $FILE ; then
115     msg "${PROGNAME}: file $FILE does not exist."
116     ERROR=1
117   fi
118 done
119 test $ERROR -eq 0 || exit 1
120
121 if [ -z "$TOOL" ]; then
122   # If no tool was specified, all specified summary files must be for
123   # the same tool.
124
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 }'`
128   else
129     msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
130     msg ""
131     usage
132     exit 1
133   fi
134 else
135   # Ignore the specified summary files that are not for this tool.  This
136   # should keep the relevant files in the same order.
137
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"
141     exit 1
142   fi
143 fi
144
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
150 BEGIN {
151   print_prologue=1; chapter=""; insummary=0
152   passcnt=0; failcnt=0; unsupcnt=0; failures=""
153 }
154 /=== acats configuration ===/ {
155   insummary=0
156   if (print_prologue) print
157   next
158 }
159 /=== acats tests ===/ {
160   if (print_prologue) print
161   print_prologue=0
162   next
163 }
164 /^Running chapter / {
165   chapter=\$3
166   print > "${TMP}/chapter-"chapter
167   next
168 }
169 /=== acats Summary ===/ {
170   chapter=""
171   insummary=1
172   next
173 }
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
181   }
182 }
183 {
184   if (print_prologue) { print; next }
185   if (chapter) print > "${TMP}/chapter-"chapter
186 }
187 END {
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
194 }
195 EOF
196
197   $AWK -f $ACATS_AWK $SUM_FILES
198   exit 0
199 fi
200
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.
204
205 if test -z "$VARIANTS" ; then
206   VAR_AWK=${TMP}/variants.awk
207   cat <<EOF > $VAR_AWK
208 /^Schedule of variations:/      { in_vars=1; next }
209 /^$/                            { in_vars=0 }
210 /^Running target/               { exit }
211 { if (in_vars==1) print \$1; else next }
212 EOF
213
214   touch ${TMP}/varlist
215   for FILE in $SUM_FILES; do
216     $AWK -f $VAR_AWK $FILE >> ${TMP}/varlist
217   done
218   VARIANTS="`sort -u ${TMP}/varlist`"
219 else
220   VARS="$VARIANTS"
221   VARIANTS=""
222   for VAR in $VARS
223   do
224     grep -q "Running target $VAR" $SUM_FILES && VARIANTS="$VARIANTS $VAR"
225   done
226 fi
227
228 # Find out if we have more than one variant, or any at all.
229
230 VARIANT_COUNT=0
231 for VAR in $VARIANTS
232 do
233   VARIANT_COUNT=`expr $VARIANT_COUNT + 1`
234 done
235
236 if test $VARIANT_COUNT -eq 0 ; then
237   msg "${PROGNAME}: no file for $TOOL has results for the specified variants"
238   exit 1
239 fi
240
241 cat $SUM_FILES \
242   | $AWK '/^Running/ { if ($2 != "target" && $3 == "...") print "EXPFILE: "$2 } ' \
243   | sort -u > ${TMP}/expfiles
244
245 # Write the begining of the combined summary file.
246
247 head -n 2 $FIRST_SUM
248 echo
249 echo "          === $TOOL tests ==="
250 echo
251 echo "Schedule of variations:"
252 for VAR in $VARIANTS
253 do
254   echo "    $VAR"
255 done
256 echo
257
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.
262
263 for VAR in $VARIANTS
264 do
265   GUTS_AWK=${TMP}/guts.awk
266   cat << EOF > $GUTS_AWK
267 BEGIN {
268   variant="$VAR"
269   firstvar=1
270   expfileno=1
271   cnt=0
272   print_using=0
273 }
274 /^EXPFILE: / {
275   expfiles[expfileno] = \$2
276   expfilesr[\$2] = expfileno
277   expfileno = expfileno + 1
278 }
279 /^Running target / {
280   curvar = \$3
281   if (variant == curvar && firstvar == 1) { print; print_using=1; firstvar = 0 }
282   next
283 }
284 /^Using / {
285   if (variant == curvar && print_using) { print; next }
286 }
287 /^Running / {
288   print_using=0
289   if (variant == curvar) {
290     curfile="${TMP}/list"expfilesr[\$2]
291     expfileseen[\$2]=expfileseen[\$2] + 1
292     testname="00"
293     next
294   }
295 }
296 /\===/ { curvar = ""; next }
297 /^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/ {
298   testname=\$2
299   # Ugly hack for gfortran.dg/dg.exp
300   if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
301     testname="h"testname
302 }
303 /^$/ { if ("$MODE" == "sum") next }
304 { if (variant == curvar && curfile) {
305     if ("$MODE" == "sum") {
306       printf "%s %08d|", testname, cnt > curfile
307       cnt = cnt + 1
308     }
309     filewritten[curfile]=1
310     print > curfile
311   } else
312     next
313 }
314 END {
315   n=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)
321           cmd="cat"
322         else
323           cmd="LC_ALL=C sort"
324         if ("$MODE" == "sum")
325           system (cmd" ${TMP}/list"n" | sed -n 's/^[^ ]* [^ |]*|//p'")
326         else
327           system ("cat ${TMP}/list"n)
328       }
329     }
330     n = n + 1
331   }
332 }
333 EOF
334
335   SUMS_AWK=${TMP}/sums.awk
336   rm -f $SUMS_AWK
337   cat << EOF > $SUMS_AWK
338 BEGIN {
339   variant="$VAR"
340   tool="$TOOL"
341   passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; unsupcnt=0; unrescnt=0;
342   curvar=""; insummary=0
343 }
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 = "" }
355                                   next
356                                 }
357 { next }
358 END {
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)
367 }
368 EOF
369
370   PVAR=`echo $VAR | sed 's,/,.,g'`
371   TMPFILE=${TMP}/var-$PVAR
372   rm -f $TMPFILE
373   rm -f ${TMP}/list*
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
379 done
380
381 # Set up an awk script to get the combined summary counts for the tool.
382
383 TOTAL_AWK=${TMP}/total.awk
384 cat << EOF > $TOTAL_AWK
385 BEGIN {
386   tool="$TOOL"
387   passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; unsupcnt=0; unrescnt=0
388 }
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 }
396 END {
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)
405 }
406 EOF
407
408 # Find the total summaries for the tool and add to the end of the output.
409 cat ${TMP}/var-* | $AWK -f $TOTAL_AWK
410
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
415
416 exit 0