This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[contrib] dg-extract-test-results.sh, to combine or extract .sum files


This proposed addition to contrib/ extracts data for a particular tool
and one or more test variants from one or more test summary (.sum) files
and combines them into a new test summary file.  It's meant to be used
for combining the results of tests that are run separately so those
combined results can be used for comparisons or summaries, but it can
also be used to separate a single set of results for multiple test
variants in order to compare results across those variants.

I've been using this quite a bit with results from my attempts to
paralellize the compiler tests on GNU/Linux.  I've tried to make it
portable  but it's quite possible that it isn't.  I'd appreicate having
other people try it out, perhaps just by running a .sum file through it
to make sure the result is the same as the original file.

2008-10-15  Janis Johnson  <janis187@us.ibm.com>

	* dg-extract-results.sh: New.

Index: contrib/dg-extract-results.sh
===================================================================
--- contrib/dg-extract-results.sh	(revision 0)
+++ contrib/dg-extract-results.sh	(revision 0)
@@ -0,0 +1,279 @@
+#! /bin/sh
+
+# For a specified tool and optional list of test variants, extract
+# test results from one or more test summary (.sum) files and combine
+# the results into a new test summary file, sent to the standard output.
+# 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 Free Software Foundation
+# Contributed by Janis Johnson <janis187@us.ibm.com>
+#
+# This file is part of GCC. 
+# 
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version. 
+# 
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING.  If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+PROGNAME=dg-extract-results.sh
+
+usage() {
+  cat <<EOF >&2
+Usage: $PROGNAME [-t tool] [-l variant-list] sum-file ...
+
+    tool           The tool (e.g. g++, libffi) for which to create a
+                   new test summary file.  If not specified then all
+                   specified sum files must be for the same tool.
+    variant-list   One or more test variant names.  If the list is
+                   not specified then one is constructed from all
+                   variants in the files for <tool>.
+    sum-file       A test summary file with the format of those
+                   created by runtest from DejaGnu.
+EOF
+}
+
+# Write a message to the standard error.
+
+msg() {
+  echo "$@" >&2
+}
+
+# Parse the command-line options.
+
+VARIANTS=""
+TOOL=""
+
+while getopts "l:t:" ARG; do
+  case $ARG in
+  l)  VARIANTS="${VARIANTS} ${OPTARG}";;
+  t)  test -z "$TOOL" || (msg "${PROGNAME}: only one tool can be specified"; exit 1);
+      TOOL="${OPTARG}";;
+  \?) usage; exit 0;;
+  esac
+done
+shift `expr ${OPTIND} - 1`
+
+if test $# -lt 1 ; then
+  usage
+  exit 1
+fi
+
+TMPDIR=${TMPDIR-/tmp}
+SUM_FILES="$@"
+FIRST_SUM=$1
+TMP=${TMPDIR}/dg-combine-results-$$
+
+# Find a good awk.
+
+if test -z "$AWK" ; then
+  for AWK in gawk nawk awk
+  do 
+    if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
+      :
+    else
+      break
+    fi
+  done
+fi
+
+# Verify that the specified summary files exist.
+
+ERROR=0
+for FILE in $SUM_FILES
+do
+  if ! test -f $FILE ; then
+    msg "${PROGNAME}: file $FILE does not exist."
+    ERROR=1
+  fi
+done
+test $ERROR -eq 0 || exit 1
+
+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`
+  if [ $CNT -eq 1 ]; then
+    TOOL=`grep '=== .* tests ===' $FIRST_SUM | awk '{ print $2 }'`
+  else
+    msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
+    msg ""
+    usage
+    exit 1
+  fi
+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`
+  if test -z "$SUM_FILES" ; then
+    msg "${PROGNAME}: none of the specified files are results for $TOOL"
+    exit 1
+  fi
+fi
+
+# If no variants were specified, find all variants in the remaining
+# summary files.  Otherwise, ignore specified variants that aren't in
+# any of those summary files.
+
+if test -z "$VARIANTS" ; then
+  VAR_AWK=${TMP}-variants.awk
+  cat <<EOF > $VAR_AWK
+/^Schedule of variations:/      { in_vars=1; next }
+/^$/                            { in_vars=0 }
+/^Running target/               { exit }
+{ if (in_vars==1) print \$1; else next }
+EOF
+
+  rm -f ${TMP}-list
+  touch ${TMP}-list
+  for FILE in $SUM_FILES; do
+    $AWK -f $VAR_AWK $FILE >> ${TMP}-list
+  done
+  VARIANTS="`sort -u ${TMP}-list`"
+else
+  VARS="$VARIANTS"
+  VARIANTS=""
+  for VAR in $VARS
+  do
+    grep -q "Running target $VAR" $SUM_FILES && VARIANTS="$VARIANTS $VAR"
+  done
+fi
+
+# Find out if we have more than one variant, or any at all.
+
+VARIANT_COUNT=0
+for VAR in $VARIANTS
+do
+  VARIANT_COUNT=`expr $VARIANT_COUNT + 1`
+done
+
+if test $VARIANT_COUNT -eq 0 ; then
+  msg "${PROGNAME}: no file for $TOOL has results for the specified variants"
+  exit 1
+fi
+
+# Write the begining of the combined summary file.
+
+head -n 2 $FIRST_SUM
+echo
+echo "		=== $TOOL tests ==="
+echo
+echo "Schedule of variations:"
+for VAR in $VARIANTS
+do
+  echo "    $VAR"
+done
+echo
+
+# For each test variant for the tool, copy test reports from each of the
+# summary files.  Set up two awk scripts from within the loop to
+# initialize VAR and TOOL with the script, rather than assuming that the
+# available version of awk can pass variables from the command line.
+
+for VAR in $VARIANTS
+do
+  GUTS_AWK=${TMP}-guts.awk
+  cat << EOF > $GUTS_AWK
+BEGIN {
+  variant="$VAR"
+  firstvar=1
+}
+/^Running target /	{ curvar = \$3;
+			  if (variant == curvar && firstvar == 1)
+			    { print; firstvar = 0 }
+			  next
+			}
+/\===/			{ curvar = ""; next }
+{ if (variant == curvar) print; else next }
+EOF
+
+  SUMS_AWK=${TMP}-sums.awk
+  rm -f $SUMS_AWK
+  cat << EOF > $SUMS_AWK
+BEGIN {
+  variant="$VAR"
+  tool="$TOOL"
+  passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; unsupcnt=0
+  curvar=""; insummary=0
+}
+/^Running target /		{ curvar = \$3; next }
+/^# of /			{ if (variant == curvar) insummary = 1 }
+/^# of expected passes/		{ if (insummary == 1) passcnt += \$5; next; }
+/^# of unexpected successes/	{ if (insummary == 1) xpasscnt += \$5; next; }
+/^# of unexpected failures/	{ if (insummary == 1) failcnt += \$5; next; }
+/^# of expected failures/	{ if (insummary == 1) xfailcnt += \$5; next; }
+/^# of untested testcases/	{ if (insummary == 1) untstcnt += \$5; next; }
+/^# of unsupported tests/	{ if (insummary == 1) unsupcnt += \$5; next; }
+/^$/				{ if (insummary == 1)
+				    { insummary = 0; curvar = "" }
+				  next
+				}
+{ next }
+END {
+  printf ("\t\t=== %s Summary for %s ===\n\n", tool, variant)
+  if (passcnt != 0) printf ("# of expected passes\t\t%d\n", passcnt)
+  if (xpasscnt != 0) printf ("# of unexpected successes\t%d\n", xpasscnt)
+  if (failcnt != 0) printf ("# of unexpected failures\t%d\n", failcnt)
+  if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
+  if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
+  if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
+}
+EOF
+
+  PVAR=`echo $VAR | sed 's,/,.,g'`
+  TMPFILE=${TMP}-var-$PVAR
+  rm -f $TMPFILE
+  cat $SUM_FILES | $AWK -f $GUTS_AWK
+  cat $SUM_FILES | $AWK -f $SUMS_AWK > $TMPFILE
+  # If there are multiple variants, output the counts for this one;
+  # otherwise there will just be the final counts at the end.
+  test $VARIANT_COUNT -eq 1 || cat $TMPFILE
+done
+
+# Set up an awk script to get the combined summary counts for the tool.
+
+TOTAL_AWK=${TMP}-total.awk
+cat << EOF > $TOTAL_AWK
+BEGIN {
+  tool="$TOOL"
+  passcnt=0; failcnt=0; untstcnt=0; xpasscnt=0; xfailcnt=0; unsupcnt=0
+}
+/^# of expected passes/		{ passcnt += \$5 }
+/^# of unexpected failures/	{ failcnt += \$5 }
+/^# of unexpected successes/	{ xpasscnt += \$5 }
+/^# of expected failures/	{ xfailcnt += \$5 }
+/^# of untested testcases/	{ untstcnt += \$5 }
+/^# of unsupported tests/	{ unsupcnt += \$5 }
+END {
+  printf ("\n\t\t=== %s Summary ===\n\n", tool)
+  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)
+  if (xfailcnt != 0) printf ("# of expected failures\t\t%d\n", xfailcnt)
+  if (untstcnt != 0) printf ("# of untested testcases\t\t%d\n", untstcnt)
+  if (unsupcnt != 0) printf ("# of unsupported tests\t\t%d\n", unsupcnt)
+}
+EOF
+
+# Find the total summaries for the tool and add to the end of the output.
+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 -n 2 $FIRST_SUM | grep -q '^#' || tail -n 2 $FIRST_SUM
+
+rm -f ${TMP}-*
+exit 0

Property changes on: contrib/dg-extract-results.sh
___________________________________________________________________
Name: svn:executable
   + *




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]