]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - contrib/dg-extract-results.sh
Update copyright years.
[thirdparty/gcc.git] / contrib / dg-extract-results.sh
index a83c8e8d67841f5dcbac4dd66f35d2ec2b28e3b8..00ef80046f74e8ad6c67137d83cd85db10cefc31 100755 (executable)
@@ -6,7 +6,7 @@
 # The resulting file can be used with test result comparison scripts for
 # results from tests that were run in parallel.  See usage() below.
 
-# Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation
+# Copyright (C) 2008-2024 Free Software Foundation, Inc.
 # Contributed by Janis Johnson <janis187@us.ibm.com>
 #
 # This file is part of GCC.
@@ -32,7 +32,7 @@ PROGNAME=dg-extract-results.sh
 PYTHON_VER=`echo "$0" | sed 's/sh$/py/'`
 if test "$PYTHON_VER" != "$0" &&
    test -f "$PYTHON_VER" &&
-   python -c 'import sys; sys.exit (0 if sys.version_info >= (2, 6) else 1)' \
+   python -c 'import sys, getopt, re, io, datetime, operator; sys.exit (0 if sys.version_info >= (2, 6) else 1)' \
      > /dev/null 2> /dev/null; then
   exec python $PYTHON_VER "$@"
 fi
@@ -127,13 +127,28 @@ do
 done
 test $ERROR -eq 0 || exit 1
 
+# Test if grep supports the '--text' option
+
+GREP=grep
+
+if echo -e '\x00foo\x00' | $GREP --text foo > /dev/null 2>&1 ; then
+  GREP="grep --text"
+else
+  # Our grep does not recognize the '--text' option.  We have to
+  # treat our files in order to remove any non-printable character.
+  for file in $SUM_FILES ; do
+    mv $file ${file}.orig
+    cat -v ${file}.orig > $file
+  done
+fi
+
 if [ -z "$TOOL" ]; then
   # If no tool was specified, all specified summary files must be for
   # the same tool.
 
-  CNT=`grep '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
+  CNT=`$GREP '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
   if [ $CNT -eq 1 ]; then
-    TOOL=`grep '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
+    TOOL=`$GREP '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
   else
     msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
     msg ""
@@ -144,7 +159,7 @@ else
   # Ignore the specified summary files that are not for this tool.  This
   # should keep the relevant files in the same order.
 
-  SUM_FILES=`grep -l "=== $TOOL" $SUM_FILES`
+  SUM_FILES=`$GREP -l "=== $TOOL" $SUM_FILES`
   if test -z "$SUM_FILES" ; then
     msg "${PROGNAME}: none of the specified files are results for $TOOL"
     exit 1
@@ -233,7 +248,7 @@ else
   VARIANTS=""
   for VAR in $VARS
   do
-    grep "Running target $VAR" $SUM_FILES > /dev/null && VARIANTS="$VARIANTS $VAR"
+    $GREP "Running target $VAR" $SUM_FILES > /dev/null && VARIANTS="$VARIANTS $VAR"
   done
 fi
 
@@ -256,7 +271,7 @@ cat $SUM_FILES \
 
 # Write the begining of the combined summary file.
 
-head -n 2 $FIRST_SUM
+head -n 3 $FIRST_SUM
 echo
 echo "         === $TOOL tests ==="
 echo
@@ -283,6 +298,8 @@ BEGIN {
   cnt=0
   print_using=0
   need_close=0
+  has_timeout=0
+  timeout_cnt=0
 }
 /^EXPFILE: / {
   expfiles[expfileno] = \$2
@@ -309,23 +326,51 @@ BEGIN {
   }
 }
 /^\t\t=== .* ===$/ { curvar = ""; next }
-/^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL):/ {
+/^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|WARNING|ERROR|UNSUPPORTED|UNTESTED|KFAIL|KPASS|PATH|DUPLICATE):/ {
   testname=\$2
   # Ugly hack for gfortran.dg/dg.exp
   if ("$TOOL" == "gfortran" && testname ~ /^gfortran.dg\/g77\//)
     testname="h"testname
+  if ("$MODE" == "sum") {
+    if (\$0 ~ /^WARNING: program timed out/) {
+      has_timeout=1
+      timeout_cnt=cnt+1
+    } else {
+      # Prepare timeout replacement message in case it's needed
+      timeout_msg=\$0
+      sub(\$1, "WARNING:", timeout_msg)
+    }
+  }
 }
 /^$/ { if ("$MODE" == "sum") next }
 { if (variant == curvar && curfile) {
     if ("$MODE" == "sum") {
-      printf "%s %08d|", testname, cnt >> curfile
-      cnt = cnt + 1
+      # Do not print anything if the current line is a timeout
+      if (has_timeout == 0) {
+       # If the previous line was a timeout,
+       # insert the full current message without keyword
+       if (timeout_cnt != 0) {
+         printf "%s %08d|%s program timed out.\n", testname, timeout_cnt-1, timeout_msg >> curfile
+         timeout_cnt = 0
+         cnt = cnt + 1
+       }
+       printf "%s %08d|", testname, cnt >> curfile
+       cnt = cnt + 1
+       filewritten[curfile]=1
+       need_close=1
+       print >> curfile
+      }
+      has_timeout=0
+    } else {
+      filewritten[curfile]=1
+      need_close=1
+      print >> curfile
     }
-    filewritten[curfile]=1
-    need_close=1
-    print >> curfile
-  } else
+  } else {
+    has_timeout=0
+    timeout_cnt=0
     next
+  }
 }
 END {
   n=1
@@ -354,10 +399,12 @@ EOF
 BEGIN {
   variant="$VAR"
   tool="$TOOL"
-  passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0;
+  passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kpasscnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0; dgerrorcnt=0;
+  pathcnt=0; dupcnt=0
   curvar=""; insummary=0
 }
 /^Running target /             { curvar = \$3; next }
+/^ERROR: \(DejaGnu\)/          { if (variant == curvar) dgerrorcnt += 1 }
 /^# of /                       { if (variant == curvar) insummary = 1 }
 /^# of expected passes/                { if (insummary == 1) passcnt += \$5; next; }
 /^# of unexpected successes/   { if (insummary == 1) xpasscnt += \$5; next; }
@@ -368,6 +415,8 @@ BEGIN {
 /^# of untested testcases/     { if (insummary == 1) untstcnt += \$5; next; }
 /^# of unresolved testcases/   { if (insummary == 1) unrescnt += \$5; next; }
 /^# of unsupported tests/      { if (insummary == 1) unsupcnt += \$5; next; }
+/^# of paths in test names/    { if (insummary == 1) pathcnt += \$7; next; }
+/^# of duplicate test names/   { if (insummary == 1) dupcnt += \$6; next; }
 /^$/                           { if (insummary == 1)
                                    { insummary = 0; curvar = "" }
                                  next
@@ -375,6 +424,7 @@ BEGIN {
 { next }
 END {
   printf ("\t\t=== %s Summary for %s ===\n\n", tool, variant)
+  if (dgerrorcnt != 0) printf ("# of DejaGnu errors\t\t%d\n", dgerrorcnt)
   if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
   if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
   if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
@@ -384,6 +434,8 @@ END {
   if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
   if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
   if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
+  if (pathcnt != 0) printf ("# of paths in test names\t%d\n", pathcnt)
+  if (dupcnt != 0) printf ("# of duplicate test names\t%d\n", dupcnt)
 }
 EOF
 
@@ -404,8 +456,10 @@ TOTAL_AWK=${TMP}/total.awk
 cat << EOF > $TOTAL_AWK
 BEGIN {
   tool="$TOOL"
-  passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0
+  passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; kfailcnt=0; unsupcnt=0; unrescnt=0; dgerrorcnt=0
+  pathcnt=0; dupcnt=0
 }
+/^# of DejaGnu errors/         { dgerrorcnt += \$5 }
 /^# of expected passes/                { passcnt += \$5 }
 /^# of unexpected failures/    { failcnt += \$5 }
 /^# of unexpected successes/   { xpasscnt += \$5 }
@@ -415,8 +469,11 @@ BEGIN {
 /^# of untested testcases/     { untstcnt += \$5 }
 /^# of unresolved testcases/   { unrescnt += \$5 }
 /^# of unsupported tests/      { unsupcnt += \$5 }
+/^# of paths in test names/    { pathcnt += \$7 }
+/^# of duplicate test names/   { dupcnt += \$6 }
 END {
   printf ("\n\t\t=== %s Summary ===\n\n", tool)
+  if (dgerrorcnt != 0) printf ("# of DejaGnu errors\t\t%d\n", dgerrorcnt)
   if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
   if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
   if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
@@ -426,6 +483,8 @@ END {
   if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
   if (unrescnt != 0) printf ("# of unresolved testcases\t%d\n", unrescnt)
   if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
+  if (pathcnt != 0) printf ("# of paths in test names\t%d\n", pathcnt)
+  if (dupcnt != 0) printf ("# of duplicate test names\t%d\n", dupcnt)
 }
 EOF
 
@@ -435,6 +494,6 @@ cat ${TMP}/var-* | $AWK -f $TOTAL_AWK
 # This is ugly, but if there's version output from the compiler under test
 # at the end of the file, we want it.  The other thing that might be there
 # is the final summary counts.
-tail -2 $FIRST_SUM | grep '^#' > /dev/null || tail -2 $FIRST_SUM
+tail -2 $FIRST_SUM | $GREP '^#' > /dev/null || tail -2 $FIRST_SUM
 
 exit 0