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]

[PATCH] extend gcov tests


This patch adds support for checking branch percentages reported by
gcov and adds some new gcov tests.  It also adds a test for a gcov bug
fixed last week that didn't have testing support at that time, and it
fixes an existing test that was leaving generated files around.

Changes to gcov.exp include:

  Procedure run-gcov now takes argument "args", which includes options
  to pass to gcov, not just the name of the source file.

  Multiple failures within a test are now reported once, rather than
  causing the gcov step of the test to fail multiple times.

  If gcov was invoked with -b then gcov output about branches is also
  examined, using two new special comments within the test to specify
  expected percentages.

This is the first time I've used Tcl, so please let me know if there are
obvious things that could be done more efficiently.  I'm planning to do
a C++ version of gcov.exp and I'm working on an expect script for
testing functionality of profile-directed optimizations, so any comments
about my use of Tcl or the other tools would be useful.

I wrote several tests for testing the error detection and reporting in
gcov.exp; is there anything I should do with them?

In gcov-2.c I removed the command to set dg-prms-id because it was
causing that value to be reported in gcc.sum for all of the rest of the
tests in the directory.  If there's a correct way to fix this I'll do
that instead.  The other change to that test makes it invoke gcov and
clean up the generated files.

These tests and the new gcov.exp were tested on ia64-unknown-linux-gnu
and i686-pc-linux-gnu.


2001-07-16  Janis Johnson <janis@us.ibm.com>

	* gcc.misc-tests/gcov.exp: Add support for branch information.
	* gcc.misc-tests/gcov-2.c: Change to invoke gcov and clean up.
	* gcc.misc-tests/gcov-4.c: New test.
	* gcc.misc-tests/gcov-4b.c: New test.
	* gcc.misc-tests/gcov-5b.c: New test.

--- gcc.misc-tests/gcov.exp.orig	Tue Jul  3 13:34:31 2001
+++ gcc.misc-tests/gcov.exp	Mon Jul 16 15:16:40 2001
@@ -1,4 +1,4 @@
-#   Copyright (C) 1997 Free Software Foundation, Inc.
+#   Copyright (C) 1997, 2001 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -36,44 +36,200 @@
     remote_file host delete $base.bb $base.bbg $base.da $basename.gcov
 }
 
-# Called by dg-final to run gcov and analyze the results.
-
-proc run-gcov { testcase } {
-    global GCOV
-
-    verbose "Running $GCOV $testcase" 2
-    set testcase [remote_download host $testcase];
-    set result [remote_exec host $GCOV $testcase];
-    if { [lindex $result 0] != 0 } {
-	fail "gcov failed: [lindex $result 1]"
-	clean-gcov $testcase
-	return
-    }
-
-    remote_upload host $testcase.gcov $testcase.gcov;
-    set output [grep $testcase.gcov ".*count\\(\[0-9\]+\\)" line]
-    #send_user "output:$output\n"
+#
+# verify-lines -- check that line counts are as expected
+#
+# TESTCASE is the name of the test.
+# FILE is the name of the gcov output file.
+#
+proc verify-lines { testcase file } {
+    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 == "" } {
-		fail "$testcase:$n:no data available for this line"
+		if { $failed == 0 } {
+		    set lmessage "$n:no data available for this line"
+		}
 		incr failed
 	    } elseif { $is != $shouldbe } {
-		fail "$testcase:$n:is $is:should be $shouldbe"
+		if { $failed == 0 } {
+		    set lmessage "$n:is $is:should be $shouldbe"
+		}
 		incr failed
 	    }
 	} else {
-	    fail "$testcase: can't parse $line (in wrong place?)"
+	    if { $failed == 0 } {
+	        set lmessage "can't parse $line (in wrong place?)"
+	    }
 	    incr failed
 	}
     }
+    return [list $failed $lmessage]
+}
+
+#
+# verify-branches -- check that branch percentages are as expected
+#
+# TESTCASE is the name of the test.
+# FILE is the name of the gcov output file.
+#
+# Checks are based on comments in the source file.  This means to look for
+# branch percentages 10 or 90, 20 or 80, and # 70 or 30:
+#     /* branch(10, 20, 70) */
+# This means that all specified percentages should have been seen by now:
+#     /* branch(end) */
+# All specified percentages must also be seen by the next branch(n) or
+# by the end of the file.
+#
+# Each check depends on the compiler having generated the expected
+# branch instructions.  Don't check for branches that might be
+# optimized away or replaced with predicated instructions.
+#
+proc verify-branches { testcase file } {
+    global bmessage
+    global subdir
+    set failed 0
+    set bmessage ""
+    set shouldbe ""
+    set fd [open $file r]
+    while { [gets $fd line] >= 0 } {
+	if [regexp "branch" $line] {
+	    verbose "Processing branch line: $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 "expected percentages not found: $shouldbe"
+		    }
+		    incr failed
+		    set shouldbe ""
+		}
+		set shouldbe $new_shouldbe
+	        # Record the percentages to check for. Replace percentage
+		# n > 50 with 100-n, since block ordering affects the
+		# direction of a branch.
+		for {set i 0} {$i < [llength $shouldbe]} {incr i} {
+		    set num [lindex $shouldbe $i]
+		    if {$num > 50} {
+			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 "negative percentage: $taken"
+		}
+		incr failed
+	    } elseif [regexp "branch \[0-9\]+ taken = (\[0-9\]+)%" "$line" all taken] {
+		# Percentages should never be greater than 100.
+		if {$taken > 100} {
+		    if { $failed == 0 } {
+			set bmessage "percentage greater than 100: $taken"
+		    }
+		    incr failed
+		}
+		if {$taken > 50} {
+		    set taken [expr 100 - $taken]
+		}
+		# If this percentage is one to check for then remove it
+		# from the list.  It's normal to ignore some reports.
+		set i [lsearch $shouldbe $taken]
+		if {$i != -1} {
+		    set shouldbe [lreplace $shouldbe $i $i]
+		}
+	    } 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 "expected percentages not found: $shouldbe"
+		    }
+		    incr failed
+		}
+		set shouldbe ""
+	    }
+	}
+    }
+    # All percentages in the list should have been seen.
+    if {[llength $shouldbe] != 0} {
+	if { $failed == 0 } {
+	    set bmessage "expected percentages not found: $shouldbe"
+	}
+	incr failed
+    }
+    close $fd
+    return [list $failed $bmessage]
+}
+
+# Called by dg-final to run gcov and analyze the results.
+#
+# ARGS is the options to pass to gcov followed by the name of the
+# test source file.
+
+proc run-gcov { args } {
+    global GCOV
+    global subdir
+
+    # Extract the test name from the arguments.
+    set testcase [lindex $args end]
+
+    verbose "Running $GCOV $testcase" 2
+    set testcase [remote_download host $testcase];
+    set result [remote_exec host $GCOV $args];
+    if { [lindex $result 0] != 0 } {
+	fail "$subdir/$testcase gcov failed: [lindex $result 1]"
+	clean-gcov $testcase
+	return
+    }
+
+    # Get the gcov output file after making sure it exists.
+    set files [glob -nocomplain $testcase.gcov]
+    if { $files == "" } {
+        fail "$subdir/$testcase gcov failed: $testcase.gcov does not exist"
+        clean-gcov $testcase
+        return;
+    }
+    remote_upload host $testcase.gcov $testcase.gcov;
+
+    # 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 we asked for branch information check that it is correct.
+    if [regexp -- "-b" $args] {
+	set boutput [verify-branches $testcase $testcase.gcov]
+	set bfailed [lindex $boutput 0]
+	set bmessage [lindex $boutput 1]
+    } else {
+	set bfailed 0
+	set bmessage ""
+    }
+
     clean-gcov $testcase
-    if !$failed {
-	pass "gcov $testcase"
+
+    # Report whether the gcov test passed or failed.  If there were
+    # multiple failures then the message is a summary.
+    set tfailed [expr $lfailed + $bfailed]
+    if { $tfailed > 0 } {
+	if { $tfailed == 1 } {
+	    set vmessage "$lmessage$bmessage"
+	} elseif { $bfailed == 0 } {
+	    set vmessage "$lfailed failures in line counts"
+	} elseif { $lfailed == 0 } {
+	    set vmessage "$bfailed failures in branch percentages"
+	} else {
+	    set vmessage "$lfailed failures in line counts, $bfailed in branch percentages"
+	}
+	fail "$subdir/$testcase gcov: $vmessage"
+    } else {
+	pass "$subdir/$testcase gcov"
     }
 }
 
--- gcc.misc-tests/gcov-2.c.orig	Thu Jul  5 12:30:21 2001
+++ gcc.misc-tests/gcov-2.c	Mon Jul 16 15:17:02 2001
@@ -1,6 +1,5 @@
 /* Test Gcov basics.  */
 
-/* { dg-prms-id 8294 } */
 /* { dg-options "-fprofile-arcs -ftest-coverage -g" } */
 /* { dg-do run { target native } } */
 
@@ -20,3 +19,4 @@
 
 int a_variable = 0;
 
+/* { dg-final { run-gcov gcov-2.c } } */
--- gcc.misc-tests/gcov-4.c.orig	Mon Jul 16 15:17:18 2001
+++ gcc.misc-tests/gcov-4.c	Mon Jul 16 15:35:06 2001
@@ -0,0 +1,271 @@
+/* Check that execution counts for various C constructs are reported
+   correctly by gcov. */
+
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+int do_something (int i)
+{
+  return i;
+}
+
+/* Check static inline functions. */
+
+int unref_val;
+
+static inline int
+unreferenced (int i, int j)
+{
+  return i - j;
+}
+
+static inline int
+uncalled (int i, int j)
+{
+  return i * j;
+}
+
+static inline int
+called (int i, int j)
+{
+    return i + j;			/* count(1) */
+}
+
+void
+call_unref ()
+{
+  if (unref_val)			/* count(1) */
+    unref_val = uncalled (1, 2);
+  unref_val = called (unref_val, 4);	/* count(1) */
+}
+
+
+/* Check for loops. */
+
+int for_val1;
+int for_val2;
+int for_temp;
+
+int
+test_for1 (int n)
+{
+  int i;
+  for_temp = 1;				/* count(3) */
+  for (i = 0; i < n; i++)
+    for_temp++;				/* count(9) */
+  return for_temp;			/* count(3) */
+}
+
+int
+test_for2 (int m, int n, int o)
+{
+  int i, j, k;
+  for_temp = 1;				/* count(6) */
+  for (i = 0; i < n; i++)
+    for (j = 0; j < m; j++)
+      for (k = 0; k < o; k++)
+	for_temp++;			/* count(81) */
+  return for_temp;			/* count(6) */
+}
+
+int
+call_for ()
+{
+  for_val1 += test_for1 (0);
+  for_val1 += test_for1 (2);
+  for_val1 += test_for1 (7);
+
+  for_val2 += test_for2 (0, 0, 0);
+  for_val2 += test_for2 (1, 0, 0);
+  for_val2 += test_for2 (1, 3, 0);
+  for_val2 += test_for2 (1, 3, 1);
+  for_val2 += test_for2 (3, 1, 5);
+  for_val2 += test_for2 (3, 7, 3);
+}
+
+/* Check the use of goto. */
+
+int goto_val;
+
+int
+test_goto1 (int f)
+{
+  if (f)				/* count(2) */
+    goto lab1;				/* count(1) */
+  return 1;				/* count(1) */
+lab1:
+  return 2;				/* count(1) */
+}
+
+int
+test_goto2 (int f)
+{
+  int i;
+  for (i = 0; i < 10; i++)		/* count(15) */
+    if (i == f) goto lab2;		/* count(14) */
+  return 4;				/* count(1) */
+lab2:
+  return 8;				/* count(1) */
+}
+
+void
+call_goto ()
+{
+  goto_val += test_goto1 (0);
+  goto_val += test_goto1 (1);
+  goto_val += test_goto2 (3);
+  goto_val += test_goto2 (30);
+}
+
+/* Check nested if-then-else statements. */
+
+int ifelse_val1;
+int ifelse_val2;
+int ifelse_val3;
+
+int
+test_ifelse1 (int i, int j)
+{
+  int result = 0;
+  if (i)				/* count(5) */
+    if (j)				/* count(3) */
+      result = do_something (4);	/* count(3) */
+    else
+      result = do_something (1024);
+  else
+    if (j)				/* count(2) */
+      result = do_something (1);	/* count(1) */
+    else
+      result = do_something (2);	/* count(1) */
+  if (i > j)				/* count(5) */
+    result = do_something (result*2);	/* count(1) */
+  if (i > 10)				/* count(5) */
+    if (j > 10)				/* count(1) */
+      result = do_something (result*4);	/* count(1) */
+  return result;			/* count(5) */
+}
+
+int
+test_ifelse2 (int i)
+{
+  int result = 0;
+  if (!i)				/* count(6) */
+    result = do_something (1);		/* count(1) */
+  if (i == 1)				/* count(6) */
+    result = do_something (1024);
+  if (i == 2)				/* count(6) */
+    result = do_something (2);		/* count(3) */
+  if (i == 3)				/* count(6) */
+    return do_something (8);		/* count(2) */
+  if (i == 4)				/* count(4) */
+    return do_something (2048);
+  return result;			/* count(4) */
+}
+
+int
+test_ifelse3 (int i, int j)
+{
+  int result = 1;
+  if (i > 10 && j > i && j < 20)	/* count(11) */
+    result = do_something (16);		/* count(1) */
+  if (i > 20)				/* count(11) */
+    if (j > i)				/* count(5) */
+      if (j < 30)			/* count(2) */
+	result = do_something (32);	/* count(1) */
+  if (i == 3 || j == 47 || i == j)	/* count(11) */
+    result = do_something (64);		/* count(3) */
+  return result;			/* count(11) */
+}
+
+void
+call_ifelse ()
+{
+  ifelse_val1 += test_ifelse1 (0, 2);
+  ifelse_val1 += test_ifelse1 (0, 0);
+  ifelse_val1 += test_ifelse1 (1, 2);
+  ifelse_val1 += test_ifelse1 (10, 2);
+  ifelse_val1 += test_ifelse1 (11, 11);
+
+  ifelse_val2 += test_ifelse2 (0);
+  ifelse_val2 += test_ifelse2 (2);
+  ifelse_val2 += test_ifelse2 (2);
+  ifelse_val2 += test_ifelse2 (2);
+  ifelse_val2 += test_ifelse2 (3);
+  ifelse_val2 += test_ifelse2 (3);
+
+  ifelse_val3 += test_ifelse3 (11, 19);
+  ifelse_val3 += test_ifelse3 (25, 27);
+  ifelse_val3 += test_ifelse3 (11, 22);
+  ifelse_val3 += test_ifelse3 (11, 10);
+  ifelse_val3 += test_ifelse3 (21, 32);
+  ifelse_val3 += test_ifelse3 (21, 20);
+  ifelse_val3 += test_ifelse3 (1, 2);
+  ifelse_val3 += test_ifelse3 (32, 31);
+  ifelse_val3 += test_ifelse3 (3, 0);
+  ifelse_val3 += test_ifelse3 (0, 47);
+  ifelse_val3 += test_ifelse3 (65, 65);
+}
+
+/* Check switch statements. */
+
+int switch_val, switch_m;
+
+int
+test_switch (int i, int j)
+{
+  int result = 0;			/* count(5) */
+
+  switch (i)				/* count(5) */
+    {
+      case 1:
+        result = do_something (2);	/* count(1) */
+        break;
+      case 2:
+        result = do_something (1024);
+        break;
+      case 3:
+      case 4:
+        if (j == 2)			/* count(3) */
+          return do_something (4);	/* count(1) */
+        result = do_something (8);	/* count(2) */
+        break;
+      default:
+	result = do_something (32);	/* count(1) */
+	switch_m++;			/* count(1) */
+        break;
+    }
+  return result;			/* count(4) */
+}
+
+void
+call_switch ()
+{
+  switch_val += test_switch (1, 0);
+  switch_val += test_switch (3, 0);
+  switch_val += test_switch (3, 2);
+  switch_val += test_switch (4, 0);
+  switch_val += test_switch (16, 0);	
+  switch_val += switch_m;
+}
+
+int
+main()
+{
+  call_for ();
+  call_goto ();
+  call_ifelse ();
+  call_switch ();
+  call_unref ();
+  if ((for_val1 != 12)
+      || (for_val2 != 87)
+      || (goto_val != 15)
+      || (ifelse_val1 != 31)
+      || (ifelse_val2 != 23)
+      || (ifelse_val3 != 246)
+      || (switch_val != 55)
+      || (unref_val != 4))
+    abort ();
+  return 0;
+}
+
+/* { dg-final { run-gcov gcov-4.c } } */
--- gcc.misc-tests/gcov-4b.c.orig	Mon Jul 16 15:17:18 2001
+++ gcc.misc-tests/gcov-4b.c	Mon Jul 16 15:35:06 2001
@@ -0,0 +1,261 @@
+/* Check that execution counts for various C constructs are reported
+   correctly by gcov. */
+
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+int do_something (int i)
+{
+  return i;
+}
+
+/* Check for loops. */
+
+int for_val1;
+int for_val2;
+int for_temp;
+
+int
+test_for1 (int n)
+{
+  int i;
+  for_temp = 1;
+  for (i = 0; i < n; i++)		/* branch(25) */
+    					/* branch(end) */
+    for_temp++;
+  return for_temp;
+}
+
+int
+test_for2 (int m, int n, int o)
+{
+  int i, j, k;
+  for_temp = 1;
+  for (i = 0; i < n; i++)		/* branch(30) */
+    					/* branch(end) */
+    for (j = 0; j < m; j++)		/* branch(32) */
+    					/* branch(end) */
+      for (k = 0; k < o; k++)		/* branch(27) */
+    					/* branch(end) */
+	for_temp++;
+  return for_temp;
+}
+
+int
+call_for ()
+{
+  for_val1 += test_for1 (0);
+  for_val1 += test_for1 (2);
+  for_val1 += test_for1 (7);
+
+  for_val2 += test_for2 (0, 0, 0);
+  for_val2 += test_for2 (1, 0, 0);
+  for_val2 += test_for2 (1, 3, 0);
+  for_val2 += test_for2 (1, 3, 1);
+  for_val2 += test_for2 (3, 1, 5);
+  for_val2 += test_for2 (3, 7, 3);
+}
+
+/* Check the use of goto. */
+
+int goto_val;
+
+int
+test_goto1 (int f)
+{
+  if (f)				/* branch(50) */
+    					/* branch(end) */
+    goto lab1;
+  return 1;
+lab1:
+  return 2;
+}
+
+int
+test_goto2 (int f)
+{
+  int i;
+  for (i = 0; i < 10; i++)		/* branch(7) */
+    					/* branch(end) */
+    if (i == f) goto lab2;
+  return 4;
+lab2:
+  return 8;
+}
+
+void
+call_goto ()
+{
+  goto_val += test_goto1 (0);
+  goto_val += test_goto1 (1);
+  goto_val += test_goto2 (3);
+  goto_val += test_goto2 (30);
+}
+
+/* Check nested if-then-else statements. */
+
+int ifelse_val1;
+int ifelse_val2;
+int ifelse_val3;
+
+int
+test_ifelse1 (int i, int j)
+{
+  int result = 0;
+  if (i)				/* branch(40) */
+    					/* branch(end) */
+    if (j)				/* branch(0) */
+    					/* branch(end) */
+      result = do_something (4);
+    else
+      result = do_something (1024);
+  else
+    if (j)				/* branch(50) */
+    					/* branch(end) */
+      result = do_something (1);
+    else
+      result = do_something (2);
+  if (i > j)				/* branch(80) */
+    					/* branch(end) */
+    result = do_something (result*2);
+  if (i > 10)				/* branch(80) */
+    					/* branch(end) */
+    if (j > 10)				/* branch(100) */
+      result = do_something (result*4);
+  return result;
+}
+
+int
+test_ifelse2 (int i)
+{
+  int result = 0;
+  if (!i)				/* branch(83) */
+    					/* branch(end) */
+    result = do_something (1);
+  if (i == 1)				/* branch(100) */
+    					/* branch(end) */
+    result = do_something (1024);
+  if (i == 2)				/* branch(50) */
+    					/* branch(end) */
+    result = do_something (2);
+  if (i == 3)				/* branch(67) */
+    					/* branch(end) */
+    return do_something (8);
+  if (i == 4)				/* branch(100) */
+    					/* branch(end) */
+    return do_something (2048);
+  return result;
+}
+
+int
+test_ifelse3 (int i, int j)
+{
+  int result = 1;
+  if (i > 10 && j > i && j < 20)	/* branch(27 50 75) */
+    					/* branch(end) */
+    result = do_something (16);
+  if (i > 20)				/* branch(55) */
+    					/* branch(end) */
+    if (j > i)				/* branch(60) */
+    					/* branch(end) */
+      if (j < 30)			/* branch(50) */
+    					/* branch(end) */
+	result = do_something (32);
+  if (i == 3 || j == 47 || i == j)	/* branch(9 10 89) */
+    					/* branch(end) */
+    result = do_something (64);
+  return result;
+}
+
+void
+call_ifelse ()
+{
+  ifelse_val1 += test_ifelse1 (0, 2);
+  ifelse_val1 += test_ifelse1 (0, 0);
+  ifelse_val1 += test_ifelse1 (1, 2);
+  ifelse_val1 += test_ifelse1 (10, 2);
+  ifelse_val1 += test_ifelse1 (11, 11);
+
+  ifelse_val2 += test_ifelse2 (0);
+  ifelse_val2 += test_ifelse2 (2);
+  ifelse_val2 += test_ifelse2 (2);
+  ifelse_val2 += test_ifelse2 (2);
+  ifelse_val2 += test_ifelse2 (3);
+  ifelse_val2 += test_ifelse2 (3);
+
+  ifelse_val3 += test_ifelse3 (11, 19);
+  ifelse_val3 += test_ifelse3 (25, 27);
+  ifelse_val3 += test_ifelse3 (11, 22);
+  ifelse_val3 += test_ifelse3 (11, 10);
+  ifelse_val3 += test_ifelse3 (21, 32);
+  ifelse_val3 += test_ifelse3 (21, 20);
+  ifelse_val3 += test_ifelse3 (1, 2);
+  ifelse_val3 += test_ifelse3 (32, 31);
+  ifelse_val3 += test_ifelse3 (3, 0);
+  ifelse_val3 += test_ifelse3 (0, 47);
+  ifelse_val3 += test_ifelse3 (65, 65);
+}
+
+/* Check switch statements. */
+
+int switch_val, switch_m;
+
+int
+test_switch (int i, int j)
+{
+  int result = 0;
+
+  switch (i)				/* branch(80 25) */
+    					/* branch(end) */
+    {
+      case 1:
+        result = do_something (2);
+        break;
+      case 2:
+        result = do_something (1024);
+        break;
+      case 3:
+      case 4:
+        if (j == 2)			/* branch(67) */
+    					/* branch(end) */
+          return do_something (4);
+        result = do_something (8);
+        break;
+      default:
+	result = do_something (32);
+	switch_m++;
+        break;
+    }
+  return result;
+}
+
+void
+call_switch ()
+{
+  switch_val += test_switch (1, 0);
+  switch_val += test_switch (3, 0);
+  switch_val += test_switch (3, 2);
+  switch_val += test_switch (4, 0);
+  switch_val += test_switch (16, 0);	
+  switch_val += switch_m;
+}
+
+int
+main()
+{
+  call_for ();
+  call_goto ();
+  call_ifelse ();
+  call_switch ();
+  if ((for_val1 != 12)
+      || (for_val2 != 87)
+      || (goto_val != 15)
+      || (ifelse_val1 != 31)
+      || (ifelse_val2 != 23)
+      || (ifelse_val3 != 246)
+      || (switch_val != 55))
+    abort ();
+  return 0;
+}
+
+/* { dg-final { run-gcov -b gcov-4b.c } } */
--- gcc.misc-tests/gcov-5b.c.orig	Mon Jul 16 15:17:18 2001
+++ gcc.misc-tests/gcov-5b.c	Mon Jul 16 15:35:06 2001
@@ -0,0 +1,34 @@
+/* Check that branch percentages are calculated in variables
+   that are large enough to hold the count. */
+
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+#define LIMIT1 7000
+#define LIMIT2 7000
+
+int count;
+
+void incr_count ()
+{
+  count++;
+}
+
+void doit (int i, int j)
+{
+  if (i > j)
+    incr_count ();
+}
+
+int main ()
+{
+  int i, j;
+
+  for (i = 0; i < LIMIT1; i++)
+    for (j = 0; j < LIMIT2; j++)
+      doit (i, j);
+
+  return 0;
+}
+
+/* { dg-final { run-gcov -b gcov-5b.c } } */


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