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]

[gcov] tweak formatting


Hi,
my recent gcov changes broke some test cases. This fixes them,
and adds a new one. 

tested on i686-pc-linux-gnu, installed as obvious

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2002-08-05  Nathan Sidwell  <nathan@codesourcery.com>

	* gcov.c (output_data): Round to % to nearest, tweak formatting.

Index: gcov.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcov.c,v
retrieving revision 1.44
diff -c -3 -p -r1.44 gcov.c
*** gcov.c	4 Aug 2002 17:06:10 -0000	1.44
--- gcov.c	5 Aug 2002 22:03:17 -0000
*************** format_hwint (top, bottom, dp)
*** 1134,1143 ****
        for (ix = dp; ix--; )
  	limit *= 10;
        
!       percent = (unsigned) (ratio * limit);
!       if (!percent && top)
  	percent = 1;
!       else if (percent == limit && top != bottom)
  	percent = limit - 1;
        ix = sprintf (buffer, "%.*u%%", dp + 1, percent);
        if (dp)
--- 1134,1143 ----
        for (ix = dp; ix--; )
  	limit *= 10;
        
!       percent = (unsigned) (ratio * limit + (float)0.5);
!       if (percent <= 0 && top)
  	percent = 1;
!       else if (percent >= limit && top != bottom)
  	percent = limit - 1;
        ix = sprintf (buffer, "%.*u%%", dp + 1, percent);
        if (dp)
*************** output_data ()
*** 1607,1616 ****
  		      if (a_ptr->call_insn)
  			{
  			  if (a_ptr->total == 0)
! 			    fnotice (gcov_file, "call   %2d: never executed\n", i);
  			  else
  			    fnotice
! 			      (gcov_file, "call   %2d: returns %s\n", i,
  			       format_hwint (a_ptr->total - a_ptr->hits,
  					     a_ptr->total,
  					     -output_branch_counts));
--- 1607,1616 ----
  		      if (a_ptr->call_insn)
  			{
  			  if (a_ptr->total == 0)
! 			    fnotice (gcov_file, "call   %2d never executed\n", i);
  			  else
  			    fnotice
! 			      (gcov_file, "call   %2d returns %s\n", i,
  			       format_hwint (a_ptr->total - a_ptr->hits,
  					     a_ptr->total,
  					     -output_branch_counts));
*************** output_data ()
*** 1618,1628 ****
  		      else
  			{
  			  if (a_ptr->total == 0)
! 			    fnotice (gcov_file, "branch %2d: never executed\n",
  				     i);
  			  else
  			    fnotice
! 			      (gcov_file, "branch %2d: taken %s\n", i,
  			       format_hwint (a_ptr->hits, a_ptr->total,
  					     -output_branch_counts));
  			}
--- 1618,1628 ----
  		      else
  			{
  			  if (a_ptr->total == 0)
! 			    fnotice (gcov_file, "branch %2d never executed\n",
  				     i);
  			  else
  			    fnotice
! 			      (gcov_file, "branch %2d taken %s\n", i,
  			       format_hwint (a_ptr->hits, a_ptr->total,
  					     -output_branch_counts));
  			}
2002-08-05  Nathan Sidwell  <nathan@codesourcery.com>

	* lib/gcov.exp: Tweak expected line formats.
	* gcc.misc-tests/gcov8.c: New test.
	* gcc.misc-tests/gcov8.x: New flags.

Index: testsuite/lib/gcov.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/gcov.exp,v
retrieving revision 1.1
diff -c -3 -p -r1.1 gcov.exp
*** testsuite/lib/gcov.exp	11 Sep 2001 16:41:58 -0000	1.1
--- testsuite/lib/gcov.exp	5 Aug 2002 22:09:46 -0000
*************** proc clean-gcov { testcase } {
*** 38,73 ****
  #
  proc verify-lines { testcase file } {
      #send_user "verify-lines\n"
-     global subdir
      set failed 0
!     set lmessage ""
!     set output [grep $file ".*count\\(\[0-9\]+\\)" line]
!     #send_user "output:$output\n"
!     foreach line $output {
! 	verbose "Processing count line: $line" 3
! 	#send_user "line:$line\n"
! 	if [regexp "(\[0-9\]+) *(\[0-9\]+).*count\\((\[0-9\]+)\\)" \
! 		"$line" all n is shouldbe] {
! 	    #send_user "n $n:is $is:shouldbe $shouldbe\n"
  	    if { $is == "" } {
! 		if { $failed == 0 } {
! 		    set lmessage "$n:no data available for this line"
! 		}
  		incr failed
  	    } elseif { $is != $shouldbe } {
! 		if { $failed == 0 } {
! 		    set lmessage "$n:is $is:should be $shouldbe"
! 		}
  		incr failed
  	    }
- 	} else {
- 	    if { $failed == 0 } {
- 	        set lmessage "can't parse $line (in wrong place?)"
- 	    }
- 	    incr failed
  	}
      }
!     return [list $failed $lmessage]
  }
  
  #
--- 38,58 ----
  #
  proc verify-lines { testcase file } {
      #send_user "verify-lines\n"
      set failed 0
!     set fd [open $file r]
!     while { [gets $fd line] >= 0 } {
! 	if [regexp "^ *(\[^:]*): *(\[0-9\]+):.*count\\((\[0-9\]+)\\)" \
! 		"$line" all is n shouldbe] {
  	    if { $is == "" } {
! 		fail "$n:no data available for this line"
  		incr failed
  	    } elseif { $is != $shouldbe } {
! 		fail "$n:is $is:should be $shouldbe"
  		incr failed
  	    }
  	}
      }
!     return $failed
  }
  
  #
*************** proc verify-lines { testcase file } {
*** 90,114 ****
  #
  proc verify-branches { testcase file } {
      #send_user "verify-branches\n"
-     global bmessage
-     global subdir
      set failed 0
-     set bmessage ""
      set shouldbe ""
      set fd [open $file r]
      set n 0
      while { [gets $fd line] >= 0 } {
! 	incr n
  	if [regexp "branch" $line] {
  	    verbose "Processing branch line $n: $line" 3
  	    if [regexp "branch\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
  		# All percentages in the current list should have been seen.
  		if {[llength $shouldbe] != 0} {
! 		    if { $failed == 0 } {
! 		        set bmessage \
! 			  "$n: expected branch percentages not found: $shouldbe"
! 		    }
! 		    #send_user "$n: expected branch percentages not found: $shouldbe\n"
  		    incr failed
  		    set shouldbe ""
  		}
--- 75,92 ----
  #
  proc verify-branches { testcase file } {
      #send_user "verify-branches\n"
      set failed 0
      set shouldbe ""
      set fd [open $file r]
      set n 0
      while { [gets $fd line] >= 0 } {
! 	regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n
  	if [regexp "branch" $line] {
  	    verbose "Processing branch line $n: $line" 3
  	    if [regexp "branch\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
  		# All percentages in the current list should have been seen.
  		if {[llength $shouldbe] != 0} {
! 		    fail "$n: expected branch percentages not found: $shouldbe"
  		    incr failed
  		    set shouldbe ""
  		}
*************** proc verify-branches { testcase file } {
*** 123,143 ****
  			set shouldbe [lreplace $shouldbe $i $i [expr 100 - $num]]
  		    }
  		}
! 	    } elseif [regexp "branch \[0-9\]+ taken = (-\[0-9\]+)%" "$line" \
  			all taken] {
  		# Percentages should never be negative.
! 		if { $failed == 0 } {
! 		    set bmessage "$n: negative percentage: $taken"
! 		}
  		incr failed
! 	    } elseif [regexp "branch \[0-9\]+ taken = (\[0-9\]+)%" "$line" \
  			all taken] {
  		#send_user "$n: taken = $taken\n"
  		# Percentages should never be greater than 100.
  		if {$taken > 100} {
! 		    if { $failed == 0 } {
! 			set bmessage "$n: percentage greater than 100: $taken"
! 		    }
  		    incr failed
  		}
  		if {$taken > 50} {
--- 101,117 ----
  			set shouldbe [lreplace $shouldbe $i $i [expr 100 - $num]]
  		    }
  		}
! 	    } elseif [regexp "branch +\[0-9\]+ taken (-\[0-9\]+)%" "$line" \
  			all taken] {
  		# Percentages should never be negative.
! 		fail "$n: negative percentage: $taken"
  		incr failed
! 	    } elseif [regexp "branch +\[0-9\]+ taken (\[0-9\]+)%" "$line" \
  			all taken] {
  		#send_user "$n: taken = $taken\n"
  		# Percentages should never be greater than 100.
  		if {$taken > 100} {
! 		    fail "$n: percentage greater than 100: $taken"
  		    incr failed
  		}
  		if {$taken > 50} {
*************** proc verify-branches { testcase file } {
*** 152,162 ****
  	    } elseif [regexp "branch\\(end\\)" "$line"] {
  		# All percentages in the list should have been seen by now.
  		if {[llength $shouldbe] != 0} {
! 		    if { $failed == 0 } {
! 			set bmessage \
! 			  "$n: expected branch percentages not found: $shouldbe"
! 		    }
! 		    #send_user "$n: expected branch percentages not found: $shouldbe\n"
  		    incr failed
  		}
  		set shouldbe ""
--- 126,132 ----
  	    } elseif [regexp "branch\\(end\\)" "$line"] {
  		# All percentages in the list should have been seen by now.
  		if {[llength $shouldbe] != 0} {
! 		    fail "$n: expected branch percentages not found: $shouldbe"
  		    incr failed
  		}
  		set shouldbe ""
*************** proc verify-branches { testcase file } {
*** 165,178 ****
      }
      # All percentages in the list should have been seen.
      if {[llength $shouldbe] != 0} {
! 	if { $failed == 0 } {
! 	    set bmessage "$n: expected branch percentages not found: $shouldbe"
! 	}
! 	#send_user "$n: expected branch percentages not found: $shouldbe\n"
  	incr failed
      }
      close $fd
!     return [list $failed $bmessage]
  }
  
  #
--- 135,145 ----
      }
      # All percentages in the list should have been seen.
      if {[llength $shouldbe] != 0} {
! 	fail "$n: expected branch percentages not found: $shouldbe"
  	incr failed
      }
      close $fd
!     return $failed
  }
  
  #
*************** proc verify-branches { testcase file } {
*** 195,231 ****
  #
  proc verify-calls { testcase file } {
      #send_user "verify-calls\n"
-     global cmessage
-     global subdir
      set failed 0
-     set cmessage ""
      set shouldbe ""
      set fd [open $file r]
      set n 0
      while { [gets $fd line] >= 0 } {
! 	incr n
  	if [regexp "returns" $line] {
  	    verbose "Processing returns line $n: $line" 3
  	    if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
  		# All percentages in the current list should have been seen.
  		if {[llength $shouldbe] != 0} {
! 		    if { $failed == 0 } {
! 		        set cmessage \
! 			  "$n: expected return percentages not found: $shouldbe"
! 		    }
  		    incr failed
  		    set shouldbe ""
  		}
  	        # Record the percentages to check for.
  		set shouldbe $new_shouldbe
! 	    } elseif [regexp "call \[0-9\]+ returns = (-\[0-9\]+)%" "$line" \
  			all returns] {
  		# Percentages should never be negative.
! 		if { $failed == 0 } {
! 		    set cmessage "$n: negative percentage: $returns"
! 		}
  		incr failed
! 	    } elseif [regexp "call \[0-9\]+ returns = (\[0-9\]+)%" "$line" \
  			all returns] {
  		# For branches we check that percentages are not greater than
  		# 100 but call return percentages can be, as for setjmp(), so
--- 162,190 ----
  #
  proc verify-calls { testcase file } {
      #send_user "verify-calls\n"
      set failed 0
      set shouldbe ""
      set fd [open $file r]
      set n 0
      while { [gets $fd line] >= 0 } {
! 	regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n
  	if [regexp "returns" $line] {
  	    verbose "Processing returns line $n: $line" 3
  	    if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
  		# All percentages in the current list should have been seen.
  		if {[llength $shouldbe] != 0} {
! 		    fail "$n: expected return percentages not found: $shouldbe"
  		    incr failed
  		    set shouldbe ""
  		}
  	        # Record the percentages to check for.
  		set shouldbe $new_shouldbe
! 	    } elseif [regexp "call +\[0-9\]+ returns (-\[0-9\]+)%" "$line" \
  			all returns] {
  		# Percentages should never be negative.
! 		fail "$n: negative percentage: $returns"
  		incr failed
! 	    } elseif [regexp "call +\[0-9\]+ returns (\[0-9\]+)%" "$line" \
  			all returns] {
  		# For branches we check that percentages are not greater than
  		# 100 but call return percentages can be, as for setjmp(), so
*************** proc verify-calls { testcase file } {
*** 240,249 ****
  	    } elseif [regexp "returns\\(end\\)" "$line"] {
  		# All percentages in the list should have been seen by now.
  		if {[llength $shouldbe] != 0} {
! 		    if { $failed == 0 } {
! 			set cmessage \
! 			  "$n: expected return percentages not found: $shouldbe"
! 		    }
  		    incr failed
  		}
  		set shouldbe ""
--- 199,205 ----
  	    } elseif [regexp "returns\\(end\\)" "$line"] {
  		# All percentages in the list should have been seen by now.
  		if {[llength $shouldbe] != 0} {
! 		    fail "$n: expected return percentages not found: $shouldbe"
  		    incr failed
  		}
  		set shouldbe ""
*************** proc verify-calls { testcase file } {
*** 252,264 ****
      }
      # All percentages in the list should have been seen.
      if {[llength $shouldbe] != 0} {
! 	if { $failed == 0 } {
! 	    set cmessage "$n: expected return percentages not found: $shouldbe"
! 	}
  	incr failed
      }
      close $fd
!     return [list $failed $cmessage]
  }
  
  # Called by dg-final to run gcov and analyze the results.
--- 208,218 ----
      }
      # All percentages in the list should have been seen.
      if {[llength $shouldbe] != 0} {
! 	fail "$n: expected return percentages not found: $shouldbe"
  	incr failed
      }
      close $fd
!     return $failed
  }
  
  # Called by dg-final to run gcov and analyze the results.
*************** proc run-gcov { args } {
*** 314,358 ****
      }
  
      # Check that line execution counts are as expected.
!     set loutput [verify-lines $testcase $testcase.gcov]
!     set lfailed [lindex $loutput 0]
!     set lmessage [lindex $loutput 1]
  
      # If requested via the .x file, check that branch and call information
      # is correct.
      if [info exists gcov_verify_branches] {
! 	set boutput [verify-branches $testcase $testcase.gcov]
! 	set bfailed [lindex $boutput 0]
! 	set bmessage [lindex $boutput 1]
      } else {
  	set bfailed 0
- 	set bmessage ""
      }
      if [info exists gcov_verify_calls] {
! 	set coutput [verify-calls $testcase $testcase.gcov]
! 	set cfailed [lindex $coutput 0]
! 	set cmessage [lindex $coutput 1]
      } else {
  	set cfailed 0
- 	set cmessage ""
      }
  
      # Report whether the gcov test passed or failed.  If there were
      # multiple failures then the message is a summary.
      set tfailed [expr $lfailed + $bfailed + $cfailed]
      if { $tfailed > 0 } {
! 	if { $tfailed == 1 } {
! 	    set vmessage "$lmessage$bmessage$cmessage"
! 	} elseif { $bfailed == 0 && $cfailed == 0 } {
! 	    set vmessage "$lfailed failures in line counts"
! 	} elseif { $lfailed == 0 && $cfailed == 0 } {
! 	    set vmessage "$bfailed failures in branch percentages"
! 	} elseif { $lfailed == 0 && $bfailed == 0 } {
! 	    set vmessage "$cfailed failures in return percentages"
! 	} else {
! 	    set vmessage "$lfailed failures in line counts, $bfailed in branch percentages, $cfailed in return percentages"
! 	}
! 	fail "$subdir/$testcase gcov: $vmessage"
      } else {
  	pass "$subdir/$testcase gcov"
  	clean-gcov $testcase
--- 268,293 ----
      }
  
      # Check that line execution counts are as expected.
!     set lfailed [verify-lines $testcase $testcase.gcov]
  
      # If requested via the .x file, check that branch and call information
      # is correct.
      if [info exists gcov_verify_branches] {
! 	set bfailed [verify-branches $testcase $testcase.gcov]
      } else {
  	set bfailed 0
      }
      if [info exists gcov_verify_calls] {
! 	set cfailed [verify-calls $testcase $testcase.gcov]
      } else {
  	set cfailed 0
      }
  
      # Report whether the gcov test passed or failed.  If there were
      # multiple failures then the message is a summary.
      set tfailed [expr $lfailed + $bfailed + $cfailed]
      if { $tfailed > 0 } {
! 	fail "$subdir/$testcase gcov: $lfailed failures in line counts, $bfailed in branch percentages, $cfailed in return percentages"
      } else {
  	pass "$subdir/$testcase gcov"
  	clean-gcov $testcase
Index: testsuite/gcc.misc-tests/gcov-8.c
===================================================================
RCS file: testsuite/gcc.misc-tests/gcov-8.c
diff -N testsuite/gcc.misc-tests/gcov-8.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.misc-tests/gcov-8.c	5 Aug 2002 22:09:46 -0000
***************
*** 0 ****
--- 1,47 ----
+ /* Check that gcov correctly rounds nearly zero to non-zero and nearly
+    100 to not-100.
+ 
+    Copyright (C) 2002 Free Software Foundation, Inc.
+    Contributed by Nathan Sidwell <nathan@codesourcery.com>
+ */
+ 
+ /* { dg-options "-fprofile-arcs -ftest-coverage" } */
+ /* { dg-do run { target native } } */
+ 
+ int proxy (int i)
+ {
+   return i;
+ }
+ 
+ int foo (int i)
+ {
+   if (i > 0) /* branch(1) */
+     return proxy (1);
+   else if (i < 0) /* branch(100) */
+     return proxy (-1);
+   else
+     return proxy (0);
+ }
+ 
+ int baz (int i)
+ {
+   if (i == 0) /* branch(99) */
+     return proxy (0);
+   else if (i > 0) /* branch(0)*/
+     return proxy (1);
+   else
+     return proxy (-1);
+ }
+ 
+ int main ()
+ {
+   int t = 0;
+   int ix;
+ 
+   for (ix = 0; ix != 1000; ix++)
+     t += foo (ix) + baz (ix);
+   
+   return t == 0;
+ }
+ 
+ /* { dg-final { run-gcov -b gcov-8.c } } */
Index: testsuite/gcc.misc-tests/gcov-8.x
===================================================================
RCS file: testsuite/gcc.misc-tests/gcov-8.x
diff -N testsuite/gcc.misc-tests/gcov-8.x
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.misc-tests/gcov-8.x	5 Aug 2002 22:09:46 -0000
***************
*** 0 ****
--- 1,2 ----
+ set gcov_verify_branches 1
+ return 0

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