diff mbox

Make dg-extract-results.sh explicitly treat .{sum,log} files as text

Message ID 87egrz46f0.fsf@redhat.com
State New
Headers show

Commit Message

Sergio Durigan Junior Dec. 16, 2014, 9:43 p.m. UTC
On Tuesday, December 16 2014, Mike Stump wrote:

> So, either, the tool should not generate 0 in the output, which, is rather anti-social, or one should strip the funny characters in a more portable fashion.
>
> tr and cat -v come to mind; both should be pretty portable.
>
>> OK to apply?
>
> Try cat | cat -v in there instead.

Thanks, Mike.  WDYT of the attached patch?  It tries to use "grep
--text" if that is available, and falls back to using "cat -v"
otherwise.  Unfortunately, it is necessary to provide the filenames to
grep here:

  CNT=`$GREP '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`

so I couldn't use "cat -v $SUM_FILES" directly.

Thanks,

Comments

Mike Stump Dec. 17, 2014, 12:18 a.m. UTC | #1
On Dec 16, 2014, at 1:43 PM, Sergio Durigan Junior <sergiodj@redhat.com> wrote:
> On Tuesday, December 16 2014, Mike Stump wrote:
> 
>> So, either, the tool should not generate 0 in the output, which, is rather anti-social, or one should strip the funny characters in a more portable fashion.
>> 
>> tr and cat -v come to mind; both should be pretty portable.
>> 
>>> OK to apply?
>> 
>> Try cat | cat -v in there instead.
> 
> Thanks, Mike.  WDYT of the attached patch?

Well, I’d still say that ‘\0’ in the output of tools is antisocial and that is the real bug that needs to be fixed.

That aside, it is reasonable to protect testing from poorly behaving tools…  if you really want to.

Ok.
Sergio Durigan Junior Dec. 17, 2014, 12:49 a.m. UTC | #2
On Tuesday, December 16 2014, Mike Stump wrote:

> Well, I’d still say that ‘\0’ in the output of tools is antisocial and that is the real bug that needs to be fixed.

I agree with you, and I am working on a patch to fix GDB, too.

> That aside, it is reasonable to protect testing from poorly behaving tools…  if you really want to.

That is also my rationale for keep wanting to commit this patch.

> Ok.

Thank you.  Despite having had patches accepted for GCC before, I am
still not in the Commit After Approval list (shame!).  Can you commit
this one for me, please?

Thanks,
Mike Stump Dec. 17, 2014, 10:37 p.m. UTC | #3
On Dec 16, 2014, at 4:49 PM, Sergio Durigan Junior <sergiodj@redhat.com> wrote:
> 
>> Ok.
> 
> Can you commit this one for me, please?

Committed revision 218843.

If anyone discovers any nasties, pre-approved to pull the patch out or resolve the issue in the obvious way.  I’d hate to impact the folks with this change.
diff mbox

Patch

diff --git a/contrib/dg-extract-results.sh b/contrib/dg-extract-results.sh
index a83c8e8..0ddf25b 100755
--- a/contrib/dg-extract-results.sh
+++ b/contrib/dg-extract-results.sh
@@ -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
 
@@ -435,6 +450,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