Commit | Line | Data |
---|---|---|
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 | ||
32d0add0 | 9 | # Copyright (C) 2008-2015 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 | |
7785b880 | 25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6bc80edc TT |
26 | |
27 | PROGNAME=dg-extract-results.sh | |
28 | ||
395cf596 SDJ |
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 "$@" | |
36 | fi | |
37 | ||
6bc80edc TT |
38 | usage() { |
39 | cat <<EOF >&2 | |
40 | Usage: $PROGNAME [-t tool] [-l variant-list] [-L] sum-file ... | |
41 | ||
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. | |
53 | EOF | |
54 | } | |
55 | ||
56 | # Write a message to the standard error. | |
57 | ||
58 | msg() { | |
59 | echo "$@" >&2 | |
60 | } | |
61 | ||
62 | # Parse the command-line options. | |
63 | ||
64 | VARIANTS="" | |
65 | TOOL="" | |
66 | MODE="sum" | |
67 | ||
68 | while getopts "l:t:L" ARG; do | |
69 | case $ARG in | |
70 | l) VARIANTS="${VARIANTS} ${OPTARG}";; | |
71 | t) test -z "$TOOL" || (msg "${PROGNAME}: only one tool can be specified"; exit 1); | |
72 | TOOL="${OPTARG}";; | |
73 | L) MODE="log";; | |
74 | \?) usage; exit 0;; | |
75 | esac | |
76 | done | |
77 | shift `expr ${OPTIND} - 1` | |
78 | ||
79 | if test $# -lt 1 ; then | |
80 | usage | |
81 | exit 1 | |
82 | fi | |
83 | ||
84 | TMPDIR=${TMPDIR-/tmp} | |
85 | SUM_FILES="$@" | |
86 | FIRST_SUM=$1 | |
87 | TMP= | |
88 | trap 'EXIT_STATUS=$?; rm -rf $TMP && exit $EXIT_STATUS' 0 | |
89 | # Create a (secure) tmp directory for tmp files. | |
90 | { | |
91 | TMP=`(umask 077 && mktemp -d -q "${TMPDIR}/dg-combine-results-$$-XXXXXX") 2>/dev/null` && | |
92 | test -n "$TMP" && test -d "$TMP" | |
93 | } || | |
94 | { | |
95 | TMP=${TMPDIR}/dg-combine-results-$$-$RANDOM | |
96 | (umask 077 && mkdir $TMP) | |
97 | } || | |
98 | { | |
99 | msg "${PROGNAME}: cannot create a temporary directory" | |
100 | { (exit 1); exit 1; } | |
101 | } | |
102 | ||
103 | # Find a good awk. | |
104 | ||
105 | if test -z "$AWK" ; then | |
106 | for AWK in gawk nawk awk | |
107 | do | |
108 | if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then | |
109 | : | |
110 | else | |
111 | break | |
112 | fi | |
113 | done | |
114 | fi | |
115 | ||
116 | # Verify that the specified summary files exist. | |
117 | ||
118 | ERROR=0 | |
119 | for FILE in $SUM_FILES | |
120 | do | |
121 | if ! test -f $FILE ; then | |
122 | msg "${PROGNAME}: file $FILE does not exist." | |
123 | ERROR=1 | |
124 | fi | |
125 | done | |
126 | test $ERROR -eq 0 || exit 1 | |
127 | ||
128 | if [ -z "$TOOL" ]; then | |
129 | # If no tool was specified, all specified summary files must be for | |
130 | # the same tool. | |
131 | ||
132 | CNT=`grep '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l` | |
133 | if [ $CNT -eq 1 ]; then | |
134 | TOOL=`grep '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'` | |
135 | else | |
136 | msg "${PROGNAME}: sum files are for multiple tools, specify a tool" | |
137 | msg "" | |
138 | usage | |
139 | exit 1 | |
140 | fi | |
141 | else | |
142 | # Ignore the specified summary files that are not for this tool. This | |
143 | # should keep the relevant files in the same order. | |
144 | ||
145 | SUM_FILES=`grep -l "=== $TOOL" $SUM_FILES` | |
146 | if test -z "$SUM_FILES" ; then | |
147 | msg "${PROGNAME}: none of the specified files are results for $TOOL" | |
148 | exit 1 | |
149 | fi | |
150 | fi | |
151 | ||
152 | if [ "$TOOL" = acats ]; then | |
153 | # Acats *.sum or *.log files aren't dejagnu generated, and they have | |
154 | # somewhat different format. | |
155 | ACATS_AWK=${TMP}/acats.awk | |
156 | cat <<EOF > $ACATS_AWK | |
157 | BEGIN { | |
158 | print_prologue=1; curfile=""; insummary=0 | |
159 | passcnt=0; failcnt=0; unsupcnt=0; failures="" | |
160 | } | |
161 | /^[ \t]*=== acats configuration ===/ { | |
162 | insummary=0 | |
163 | if (print_prologue) print | |
164 | next | |
165 | } | |
166 | /^[ \t]*=== acats tests ===/ { | |
167 | if (print_prologue) print | |
168 | print_prologue=0 | |
169 | next | |
170 | } | |
171 | /^Running chapter / { | |
172 | if (curfile) close (curfile) | |
173 | curfile="${TMP}/chapter-"\$3 | |
174 | print >> curfile | |
175 | next | |
176 | } | |
177 | /^[ \t]*=== acats Summary ===/ { | |
178 | if (curfile) close (curfile) | |
179 | curfile="" | |
180 | insummary=1 | |
181 | next | |
182 | } | |
183 | /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; } | |
184 | /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; } | |
185 | /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; } | |
186 | /^\*\*\* FAILURES: / { | |
187 | if (insummary == 1) { | |
188 | if (failures) sub(/^\*\*\* FAILURES:/,"") | |
189 | failures=failures""\$0 | |
190 | } | |
191 | } | |
192 | { | |
193 | if (print_prologue) { print; next } | |
194 | if (curfile) print >> curfile | |
195 | } | |
196 | END { | |
197 | system ("cat ${TMP}/chapter-*") | |
198 | print " === acats Summary ===" | |
199 | print "# of expected passes " passcnt | |
200 | print "# of unexpected failures " failcnt | |
201 | if (unsupcnt) print "# of unsupported tests " unsupcnt | |
202 | if (failures) print failures | |
203 | } | |
204 | EOF | |
205 | ||
206 | rm -f ${TMP}/chapter-* | |
207 | $AWK -f $ACATS_AWK $SUM_FILES | |
208 | exit 0 | |
209 | fi | |
210 | ||
211 | # If no variants were specified, find all variants in the remaining | |
212 | # summary files. Otherwise, ignore specified variants that aren't in | |
213 | # any of those summary files. | |
214 | ||
215 | if test -z "$VARIANTS" ; then | |
216 | VAR_AWK=${TMP}/variants.awk | |
217 | cat <<EOF > $VAR_AWK | |
218 | /^Schedule of variations:/ { in_vars=1; next } | |
219 | /^$/ { in_vars=0 } | |
220 | /^Running target/ { exit } | |
221 | { if (in_vars==1) print \$1; else next } | |
222 | EOF | |
223 | ||
224 | touch ${TMP}/varlist | |
225 | for FILE in $SUM_FILES; do | |
226 | $AWK -f $VAR_AWK $FILE >> ${TMP}/varlist | |
227 | done | |
228 | VARIANTS="`sort -u ${TMP}/varlist`" | |
229 | else | |
230 | VARS="$VARIANTS" | |
231 | VARIANTS="" | |
232 | for VAR in $VARS | |
233 | do | |
96343774 | 234 | grep "Running target $VAR" $SUM_FILES > /dev/null && VARIANTS="$VARIANTS $VAR" |
6bc80edc TT |
235 | done |
236 | fi | |
237 | ||
238 | # Find out if we have more than one variant, or any at all. | |
239 | ||
240 | VARIANT_COUNT=0 | |
241 | for VAR in $VARIANTS | |
242 | do | |
243 | VARIANT_COUNT=`expr $VARIANT_COUNT + 1` | |
244 | done | |
245 | ||
246 | if test $VARIANT_COUNT -eq 0 ; then | |
247 | msg "${PROGNAME}: no file for $TOOL has results for the specified variants" | |
248 | exit 1 | |
249 | fi | |
250 | ||
251 | cat $SUM_FILES \ | |
252 | | $AWK '/^Running/ { if ($2 != "target" && $3 == "...") print "EXPFILE: "$2 } ' \ | |
253 | | sort -u > ${TMP}/expfiles | |
254 | ||
255 | # Write the begining of the combined summary file. | |
256 | ||
257 | head -n 2 $FIRST_SUM | |
258 | echo | |
259 | echo " === $TOOL tests ===" | |
260 | echo | |
261 | echo "Schedule of variations:" | |
262 | for VAR in $VARIANTS | |
263 | do | |
264 | echo " $VAR" | |
265 | done | |
266 | echo | |
267 | ||
268 | # For each test variant for the tool, copy test reports from each of the | |
269 | # summary files. Set up two awk scripts from within the loop to | |
270 | # initialize VAR and TOOL with the script, rather than assuming that the | |
271 | # available version of awk can pass variables from the command line. | |
272 | ||
273 | for VAR in $VARIANTS | |
274 | do | |
275 | GUTS_AWK=${TMP}/guts.awk | |
276 | cat << EOF > $GUTS_AWK | |
277 | BEGIN { | |
278 | variant="$VAR" | |
279 | firstvar=1 | |
280 | expfileno=1 | |
281 | cnt=0 | |
282 | print_using=0 | |
283 | need_close=0 | |
284 | } | |
285 | /^EXPFILE: / { | |
286 | expfiles[expfileno] = \$2 | |
287 | expfilesr[\$2] = expfileno | |
288 | expfileno = expfileno + 1 | |
289 | } | |
290 | /^Running target / { | |
291 | curvar = \$3 | |
292 | if (variant == curvar && firstvar == 1) { print; print_using=1; firstvar = 0 } | |
293 | next | |
294 | } | |
295 | /^Using / { | |
296 | if (variant == curvar && print_using) { print; next } | |
297 | } | |
96343774 | 298 | /^Running .*\\.exp \\.\\.\\./ { |
6bc80edc TT |
299 | print_using=0 |
300 | if (variant == curvar) { | |
301 | if (need_close) close(curfile) | |
302 | curfile="${TMP}/list"expfilesr[\$2] | |
303 | expfileseen[\$2]=expfileseen[\$2] + 1 | |
304 | need_close=0 | |
305 | testname="00" | |
306 | next | |
307 | } | |
308 | } | |
c847d045 | 309 | /^\t\t=== .* ===$/ { curvar = ""; next } |
6bc80edc TT |
310 | /^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/ { |
311 | testname=\$2 | |
312 | # Ugly hack for gfortran.dg/dg.exp | |
313 | if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//) | |
314 | testname="h"testname | |
315 | } | |
316 | /^$/ { if ("$MODE" == "sum") next } | |
317 | { if (variant == curvar && curfile) { | |
318 | if ("$MODE" == "sum") { | |
319 | printf "%s %08d|", testname, cnt >> curfile | |
320 | cnt = cnt + 1 | |
321 | } | |
322 | filewritten[curfile]=1 | |
323 | need_close=1 | |
324 | print >> curfile | |
325 | } else | |
326 | next | |
327 | } | |
328 | END { | |
329 | n=1 | |
330 | while (n < expfileno) { | |
331 | if (expfileseen[expfiles[n]]) { | |
332 | print "Running "expfiles[n]" ..." | |
333 | if (filewritten["${TMP}/list"n]) { | |
334 | if (expfileseen[expfiles[n]] == 1) | |
335 | cmd="cat" | |
336 | else | |
337 | cmd="LC_ALL=C sort" | |
338 | if ("$MODE" == "sum") | |
339 | system (cmd" ${TMP}/list"n" | sed -n 's/^[^ ]* [^ |]*|//p'") | |
340 | else | |
341 | system ("cat ${TMP}/list"n) | |
342 | } | |
343 | } | |
344 | n = n + 1 | |
345 | } | |
346 | } | |
347 | EOF | |
348 | ||
349 | SUMS_AWK=${TMP}/sums.awk | |
350 | rm -f $SUMS_AWK | |
351 | cat << EOF > $SUMS_AWK | |
352 | BEGIN { | |
353 | variant="$VAR" | |
354 | tool="$TOOL" | |
96343774 | 355 | passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0; |
6bc80edc TT |
356 | curvar=""; insummary=0 |
357 | } | |
358 | /^Running target / { curvar = \$3; next } | |
359 | /^# of / { if (variant == curvar) insummary = 1 } | |
360 | /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; } | |
361 | /^# of unexpected successes/ { if (insummary == 1) xpasscnt += \$5; next; } | |
362 | /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; } | |
363 | /^# of expected failures/ { if (insummary == 1) xfailcnt += \$5; next; } | |
96343774 | 364 | /^# of unknown successes/ { if (insummary == 1) kpasscnt += \$5; next; } |
8fabffee | 365 | /^# of known failures/ { if (insummary == 1) kfailcnt += \$5; next; } |
6bc80edc TT |
366 | /^# of untested testcases/ { if (insummary == 1) untstcnt += \$5; next; } |
367 | /^# of unresolved testcases/ { if (insummary == 1) unrescnt += \$5; next; } | |
368 | /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; } | |
369 | /^$/ { if (insummary == 1) | |
370 | { insummary = 0; curvar = "" } | |
371 | next | |
372 | } | |
373 | { next } | |
374 | END { | |
375 | printf ("\t\t=== %s Summary for %s ===\n\n", tool, variant) | |
376 | if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt) | |
6bc80edc | 377 | if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt) |
c847d045 | 378 | if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt) |
6bc80edc | 379 | if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt) |
96343774 | 380 | if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt) |
8fabffee | 381 | if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt) |
6bc80edc TT |
382 | if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt) |
383 | if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt) | |
384 | if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt) | |
385 | } | |
386 | EOF | |
387 | ||
388 | PVAR=`echo $VAR | sed 's,/,.,g'` | |
389 | TMPFILE=${TMP}/var-$PVAR | |
390 | rm -f $TMPFILE | |
391 | rm -f ${TMP}/list* | |
392 | cat ${TMP}/expfiles $SUM_FILES | $AWK -f $GUTS_AWK | |
393 | cat $SUM_FILES | $AWK -f $SUMS_AWK > $TMPFILE | |
394 | # If there are multiple variants, output the counts for this one; | |
395 | # otherwise there will just be the final counts at the end. | |
396 | test $VARIANT_COUNT -eq 1 || cat $TMPFILE | |
397 | done | |
398 | ||
399 | # Set up an awk script to get the combined summary counts for the tool. | |
400 | ||
401 | TOTAL_AWK=${TMP}/total.awk | |
402 | cat << EOF > $TOTAL_AWK | |
403 | BEGIN { | |
404 | tool="$TOOL" | |
8fabffee | 405 | passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0 |
6bc80edc TT |
406 | } |
407 | /^# of expected passes/ { passcnt += \$5 } | |
408 | /^# of unexpected failures/ { failcnt += \$5 } | |
409 | /^# of unexpected successes/ { xpasscnt += \$5 } | |
410 | /^# of expected failures/ { xfailcnt += \$5 } | |
96343774 | 411 | /^# of unknown successes/ { kpasscnt += \$5 } |
8fabffee | 412 | /^# of known failures/ { kfailcnt += \$5 } |
6bc80edc TT |
413 | /^# of untested testcases/ { untstcnt += \$5 } |
414 | /^# of unresolved testcases/ { unrescnt += \$5 } | |
415 | /^# of unsupported tests/ { unsupcnt += \$5 } | |
416 | END { | |
417 | printf ("\n\t\t=== %s Summary ===\n\n", tool) | |
418 | if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt) | |
419 | if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt) | |
420 | if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt) | |
421 | if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt) | |
96343774 | 422 | if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt) |
8fabffee | 423 | if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt) |
6bc80edc TT |
424 | if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt) |
425 | if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt) | |
426 | if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt) | |
427 | } | |
428 | EOF | |
429 | ||
430 | # Find the total summaries for the tool and add to the end of the output. | |
431 | cat ${TMP}/var-* | $AWK -f $TOTAL_AWK | |
432 | ||
433 | # This is ugly, but if there's version output from the compiler under test | |
434 | # at the end of the file, we want it. The other thing that might be there | |
435 | # is the final summary counts. | |
96343774 | 436 | tail -2 $FIRST_SUM | grep '^#' > /dev/null || tail -2 $FIRST_SUM |
6bc80edc TT |
437 | |
438 | exit 0 |