dg-extract-results.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. #! /bin/sh
  2. # For a specified tool and optional list of test variants, extract
  3. # test results from one or more test summary (.sum) files and combine
  4. # the results into a new test summary file, sent to the standard output.
  5. # The resulting file can be used with test result comparison scripts for
  6. # results from tests that were run in parallel. See usage() below.
  7. # Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation
  8. # Contributed by Janis Johnson <janis187@us.ibm.com>
  9. #
  10. # This file is part of GCC.
  11. #
  12. # GCC is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 3, or (at your option)
  15. # any later version.
  16. #
  17. # GCC is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License
  23. # along with GCC; see the file COPYING. If not, write to
  24. # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  25. # Boston, MA 02110-1301, USA.
  26. PROGNAME=dg-extract-results.sh
  27. # Try to use the python version if possible, since it tends to be faster.
  28. PYTHON_VER=`echo "$0" | sed 's/sh$/py/'`
  29. if test "$PYTHON_VER" != "$0" &&
  30. test -f "$PYTHON_VER" &&
  31. python -c 'import sys, getopt, re, io, datetime, operator; sys.exit (0 if sys.version_info >= (2, 6) else 1)' \
  32. > /dev/null 2> /dev/null; then
  33. exec python $PYTHON_VER "$@"
  34. fi
  35. usage() {
  36. cat <<EOF >&2
  37. Usage: $PROGNAME [-t tool] [-l variant-list] [-L] sum-file ...
  38. tool The tool (e.g. g++, libffi) for which to create a
  39. new test summary file. If not specified then all
  40. specified sum files must be for the same tool.
  41. variant-list One or more test variant names. If the list is
  42. not specified then one is constructed from all
  43. variants in the files for <tool>.
  44. sum-file A test summary file with the format of those
  45. created by runtest from DejaGnu.
  46. If -L is used, merge *.log files instead of *.sum. In this
  47. mode the exact order of lines may not be preserved, just different
  48. Running *.exp chunks should be in correct order.
  49. EOF
  50. }
  51. # Write a message to the standard error.
  52. msg() {
  53. echo "$@" >&2
  54. }
  55. # Parse the command-line options.
  56. VARIANTS=""
  57. TOOL=""
  58. MODE="sum"
  59. while getopts "l:t:L" ARG; do
  60. case $ARG in
  61. l) VARIANTS="${VARIANTS} ${OPTARG}";;
  62. t) test -z "$TOOL" || (msg "${PROGNAME}: only one tool can be specified"; exit 1);
  63. TOOL="${OPTARG}";;
  64. L) MODE="log";;
  65. \?) usage; exit 0;;
  66. esac
  67. done
  68. shift `expr ${OPTIND} - 1`
  69. if test $# -lt 1 ; then
  70. usage
  71. exit 1
  72. fi
  73. TMPDIR=${TMPDIR-/tmp}
  74. SUM_FILES="$@"
  75. FIRST_SUM=$1
  76. TMP=
  77. trap 'EXIT_STATUS=$?; rm -rf $TMP && exit $EXIT_STATUS' 0
  78. # Create a (secure) tmp directory for tmp files.
  79. {
  80. TMP=`(umask 077 && mktemp -d -q "${TMPDIR}/dg-combine-results-$$-XXXXXX") 2>/dev/null` &&
  81. test -n "$TMP" && test -d "$TMP"
  82. } ||
  83. {
  84. TMP=${TMPDIR}/dg-combine-results-$$-$RANDOM
  85. (umask 077 && mkdir $TMP)
  86. } ||
  87. {
  88. msg "${PROGNAME}: cannot create a temporary directory"
  89. { (exit 1); exit 1; }
  90. }
  91. # Find a good awk.
  92. if test -z "$AWK" ; then
  93. for AWK in gawk nawk awk
  94. do
  95. if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
  96. :
  97. else
  98. break
  99. fi
  100. done
  101. fi
  102. # Verify that the specified summary files exist.
  103. ERROR=0
  104. for FILE in $SUM_FILES
  105. do
  106. if ! test -f $FILE ; then
  107. msg "${PROGNAME}: file $FILE does not exist."
  108. ERROR=1
  109. fi
  110. done
  111. test $ERROR -eq 0 || exit 1
  112. # Test if grep supports the '--text' option
  113. GREP=grep
  114. if echo -e '\x00foo\x00' | $GREP --text foo > /dev/null 2>&1 ; then
  115. GREP="grep --text"
  116. else
  117. # Our grep does not recognize the '--text' option. We have to
  118. # treat our files in order to remove any non-printable character.
  119. for file in $SUM_FILES ; do
  120. mv $file ${file}.orig
  121. cat -v ${file}.orig > $file
  122. done
  123. fi
  124. if [ -z "$TOOL" ]; then
  125. # If no tool was specified, all specified summary files must be for
  126. # the same tool.
  127. CNT=`$GREP '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
  128. if [ $CNT -eq 1 ]; then
  129. TOOL=`$GREP '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
  130. else
  131. msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
  132. msg ""
  133. usage
  134. exit 1
  135. fi
  136. else
  137. # Ignore the specified summary files that are not for this tool. This
  138. # should keep the relevant files in the same order.
  139. SUM_FILES=`$GREP -l "=== $TOOL" $SUM_FILES`
  140. if test -z "$SUM_FILES" ; then
  141. msg "${PROGNAME}: none of the specified files are results for $TOOL"
  142. exit 1
  143. fi
  144. fi
  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; curfile=""; insummary=0
  152. passcnt=0; failcnt=0; unsupcnt=0; failures=""
  153. }
  154. /^[ \t]*=== acats configuration ===/ {
  155. insummary=0
  156. if (print_prologue) print
  157. next
  158. }
  159. /^[ \t]*=== acats tests ===/ {
  160. if (print_prologue) print
  161. print_prologue=0
  162. next
  163. }
  164. /^Running chapter / {
  165. if (curfile) close (curfile)
  166. curfile="${TMP}/chapter-"\$3
  167. print >> curfile
  168. next
  169. }
  170. /^[ \t]*=== acats Summary ===/ {
  171. if (curfile) close (curfile)
  172. curfile=""
  173. insummary=1
  174. next
  175. }
  176. /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
  177. /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
  178. /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
  179. /^\*\*\* FAILURES: / {
  180. if (insummary == 1) {
  181. if (failures) sub(/^\*\*\* FAILURES:/,"")
  182. failures=failures""\$0
  183. }
  184. }
  185. {
  186. if (print_prologue) { print; next }
  187. if (curfile) print >> curfile
  188. }
  189. END {
  190. system ("cat ${TMP}/chapter-*")
  191. print " === acats Summary ==="
  192. print "# of expected passes " passcnt
  193. print "# of unexpected failures " failcnt
  194. if (unsupcnt) print "# of unsupported tests " unsupcnt
  195. if (failures) print failures
  196. }
  197. EOF
  198. rm -f ${TMP}/chapter-*
  199. $AWK -f $ACATS_AWK $SUM_FILES
  200. exit 0
  201. fi
  202. # If no variants were specified, find all variants in the remaining
  203. # summary files. Otherwise, ignore specified variants that aren't in
  204. # any of those summary files.
  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. touch ${TMP}/varlist
  214. for FILE in $SUM_FILES; do
  215. $AWK -f $VAR_AWK $FILE >> ${TMP}/varlist
  216. done
  217. VARIANTS="`sort -u ${TMP}/varlist`"
  218. else
  219. VARS="$VARIANTS"
  220. VARIANTS=""
  221. for VAR in $VARS
  222. do
  223. $GREP "Running target $VAR" $SUM_FILES > /dev/null && VARIANTS="$VARIANTS $VAR"
  224. done
  225. fi
  226. # Find out if we have more than one variant, or any at all.
  227. VARIANT_COUNT=0
  228. for VAR in $VARIANTS
  229. do
  230. VARIANT_COUNT=`expr $VARIANT_COUNT + 1`
  231. done
  232. if test $VARIANT_COUNT -eq 0 ; then
  233. msg "${PROGNAME}: no file for $TOOL has results for the specified variants"
  234. exit 1
  235. fi
  236. cat $SUM_FILES \
  237. | $AWK '/^Running/ { if ($2 != "target" && $3 == "...") print "EXPFILE: "$2 } ' \
  238. | sort -u > ${TMP}/expfiles
  239. # Write the begining of the combined summary file.
  240. head -n 2 $FIRST_SUM
  241. echo
  242. echo " === $TOOL tests ==="
  243. echo
  244. echo "Schedule of variations:"
  245. for VAR in $VARIANTS
  246. do
  247. echo " $VAR"
  248. done
  249. echo
  250. # For each test variant for the tool, copy test reports from each of the
  251. # summary files. Set up two awk scripts from within the loop to
  252. # initialize VAR and TOOL with the script, rather than assuming that the
  253. # available version of awk can pass variables from the command line.
  254. for VAR in $VARIANTS
  255. do
  256. GUTS_AWK=${TMP}/guts.awk
  257. cat << EOF > $GUTS_AWK
  258. BEGIN {
  259. variant="$VAR"
  260. firstvar=1
  261. expfileno=1
  262. cnt=0
  263. print_using=0
  264. need_close=0
  265. has_timeout=0
  266. timeout_cnt=0
  267. }
  268. /^EXPFILE: / {
  269. expfiles[expfileno] = \$2
  270. expfilesr[\$2] = expfileno
  271. expfileno = expfileno + 1
  272. }
  273. /^Running target / {
  274. curvar = \$3
  275. if (variant == curvar && firstvar == 1) { print; print_using=1; firstvar = 0 }
  276. next
  277. }
  278. /^Using / {
  279. if (variant == curvar && print_using) { print; next }
  280. }
  281. /^Running .*\\.exp \\.\\.\\./ {
  282. print_using=0
  283. if (variant == curvar) {
  284. if (need_close) close(curfile)
  285. curfile="${TMP}/list"expfilesr[\$2]
  286. expfileseen[\$2]=expfileseen[\$2] + 1
  287. need_close=0
  288. testname="00"
  289. next
  290. }
  291. }
  292. /^\t\t=== .* ===$/ { curvar = ""; next }
  293. /^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL|KPASS|PATH|DUPLICATE):/ {
  294. testname=\$2
  295. # Ugly hack for gfortran.dg/dg.exp
  296. if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
  297. testname="h"testname
  298. if ("$MODE" == "sum") {
  299. if (\$0 ~ /^WARNING: program timed out/) {
  300. has_timeout=1
  301. timeout_cnt=cnt+1
  302. } else {
  303. # Prepare timeout replacement message in case it's needed
  304. timeout_msg=\$0
  305. sub(\$1, "WARNING:", timeout_msg)
  306. }
  307. }
  308. }
  309. /^$/ { if ("$MODE" == "sum") next }
  310. { if (variant == curvar && curfile) {
  311. if ("$MODE" == "sum") {
  312. # Do not print anything if the current line is a timeout
  313. if (has_timeout == 0) {
  314. # If the previous line was a timeout,
  315. # insert the full current message without keyword
  316. if (timeout_cnt != 0) {
  317. printf "%s %08d|%s program timed out.\n", testname, timeout_cnt-1, timeout_msg >> curfile
  318. timeout_cnt = 0
  319. cnt = cnt + 1
  320. }
  321. printf "%s %08d|", testname, cnt >> curfile
  322. cnt = cnt + 1
  323. filewritten[curfile]=1
  324. need_close=1
  325. print >> curfile
  326. }
  327. has_timeout=0
  328. } else {
  329. filewritten[curfile]=1
  330. need_close=1
  331. print >> curfile
  332. }
  333. } else {
  334. has_timeout=0
  335. timeout_cnt=0
  336. next
  337. }
  338. }
  339. END {
  340. n=1
  341. while (n < expfileno) {
  342. if (expfileseen[expfiles[n]]) {
  343. print "Running "expfiles[n]" ..."
  344. if (filewritten["${TMP}/list"n]) {
  345. if (expfileseen[expfiles[n]] == 1)
  346. cmd="cat"
  347. else
  348. cmd="LC_ALL=C sort"
  349. if ("$MODE" == "sum")
  350. system (cmd" ${TMP}/list"n" | sed -n 's/^[^ ]* [^ |]*|//p'")
  351. else
  352. system ("cat ${TMP}/list"n)
  353. }
  354. }
  355. n = n + 1
  356. }
  357. }
  358. EOF
  359. SUMS_AWK=${TMP}/sums.awk
  360. rm -f $SUMS_AWK
  361. cat << EOF > $SUMS_AWK
  362. BEGIN {
  363. variant="$VAR"
  364. tool="$TOOL"
  365. passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0; dgerrorcnt=0;
  366. pathcnt=0; dupcnt=0
  367. curvar=""; insummary=0
  368. }
  369. /^Running target / { curvar = \$3; next }
  370. /^ERROR: \(DejaGnu\)/ { if (variant == curvar) dgerrorcnt += 1 }
  371. /^# of / { if (variant == curvar) insummary = 1 }
  372. /^# of expected passes/ { if (insummary == 1) passcnt += \$5; next; }
  373. /^# of unexpected successes/ { if (insummary == 1) xpasscnt += \$5; next; }
  374. /^# of unexpected failures/ { if (insummary == 1) failcnt += \$5; next; }
  375. /^# of expected failures/ { if (insummary == 1) xfailcnt += \$5; next; }
  376. /^# of unknown successes/ { if (insummary == 1) kpasscnt += \$5; next; }
  377. /^# of known failures/ { if (insummary == 1) kfailcnt += \$5; next; }
  378. /^# of untested testcases/ { if (insummary == 1) untstcnt += \$5; next; }
  379. /^# of unresolved testcases/ { if (insummary == 1) unrescnt += \$5; next; }
  380. /^# of unsupported tests/ { if (insummary == 1) unsupcnt += \$5; next; }
  381. /^# of paths in test names/ { if (insummary == 1) pathcnt += \$7; next; }
  382. /^# of duplicate test names/ { if (insummary == 1) dupcnt += \$6; next; }
  383. /^$/ { if (insummary == 1)
  384. { insummary = 0; curvar = "" }
  385. next
  386. }
  387. { next }
  388. END {
  389. printf ("\t\t=== %s Summary for %s ===\n\n", tool, variant)
  390. if (dgerrorcnt != 0) printf ("# of DejaGnu errors\t\t%d\n", dgerrorcnt)
  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)
  400. if (pathcnt != 0) printf ("# of paths in test names\t%d\n", pathcnt)
  401. if (dupcnt != 0) printf ("# of duplicate test names\t%d\n", dupcnt)
  402. }
  403. EOF
  404. PVAR=`echo $VAR | sed 's,/,.,g'`
  405. TMPFILE=${TMP}/var-$PVAR
  406. rm -f $TMPFILE
  407. rm -f ${TMP}/list*
  408. cat ${TMP}/expfiles $SUM_FILES | $AWK -f $GUTS_AWK
  409. cat $SUM_FILES | $AWK -f $SUMS_AWK > $TMPFILE
  410. # If there are multiple variants, output the counts for this one;
  411. # otherwise there will just be the final counts at the end.
  412. test $VARIANT_COUNT -eq 1 || cat $TMPFILE
  413. done
  414. # Set up an awk script to get the combined summary counts for the tool.
  415. TOTAL_AWK=${TMP}/total.awk
  416. cat << EOF > $TOTAL_AWK
  417. BEGIN {
  418. tool="$TOOL"
  419. passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0; dgerrorcnt=0
  420. pathcnt=0; dupcnt=0
  421. }
  422. /^# of DejaGnu errors/ { dgerrorcnt += \$5 }
  423. /^# of expected passes/ { passcnt += \$5 }
  424. /^# of unexpected failures/ { failcnt += \$5 }
  425. /^# of unexpected successes/ { xpasscnt += \$5 }
  426. /^# of expected failures/ { xfailcnt += \$5 }
  427. /^# of unknown successes/ { kpasscnt += \$5 }
  428. /^# of known failures/ { kfailcnt += \$5 }
  429. /^# of untested testcases/ { untstcnt += \$5 }
  430. /^# of unresolved testcases/ { unrescnt += \$5 }
  431. /^# of unsupported tests/ { unsupcnt += \$5 }
  432. /^# of paths in test names/ { pathcnt += \$7 }
  433. /^# of duplicate test names/ { dupcnt += \$6 }
  434. END {
  435. printf ("\n\t\t=== %s Summary ===\n\n", tool)
  436. if (dgerrorcnt != 0) printf ("# of DejaGnu errors\t\t%d\n", dgerrorcnt)
  437. if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
  438. if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
  439. if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
  440. if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
  441. if (kpasscnt != 0) printf ("# of unknown successes\t\t%d\n", kpasscnt)
  442. if (kfailcnt != 0) printf ("# of known failures\t\t%d\n", kfailcnt)
  443. if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
  444. if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
  445. if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
  446. if (pathcnt != 0) printf ("# of paths in test names\t%d\n", pathcnt)
  447. if (dupcnt != 0) printf ("# of duplicate test names\t%d\n", dupcnt)
  448. }
  449. EOF
  450. # Find the total summaries for the tool and add to the end of the output.
  451. cat ${TMP}/var-* | $AWK -f $TOTAL_AWK
  452. # This is ugly, but if there's version output from the compiler under test
  453. # at the end of the file, we want it. The other thing that might be there
  454. # is the final summary counts.
  455. tail -2 $FIRST_SUM | $GREP '^#' > /dev/null || tail -2 $FIRST_SUM
  456. exit 0