gcov.c (output_data): Round to % to nearest, tweak formatting.
gcc: * gcov.c (output_data): Round to % to nearest, tweak formatting. testsuite: * lib/gcov.exp: Tweak expected line formats. * gcc.misc-tests/gcov8.c: New test. * gcc.misc-tests/gcov8.x: New flags. From-SVN: r56059
This commit is contained in:
parent
1bed5ee327
commit
d19202bab3
|
@ -1,3 +1,7 @@
|
||||||
|
2002-08-05 Nathan Sidwell <nathan@codesourcery.com>
|
||||||
|
|
||||||
|
* gcov.c (output_data): Round to % to nearest, tweak formatting.
|
||||||
|
|
||||||
2002-08-05 Jakub Jelinek <jakub@redhat.com>
|
2002-08-05 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
* fold-const.c (associate_trees): Only optimize NEGATE_EXPR in one
|
* fold-const.c (associate_trees): Only optimize NEGATE_EXPR in one
|
||||||
|
|
14
gcc/gcov.c
14
gcc/gcov.c
|
@ -1134,10 +1134,10 @@ format_hwint (top, bottom, dp)
|
||||||
for (ix = dp; ix--; )
|
for (ix = dp; ix--; )
|
||||||
limit *= 10;
|
limit *= 10;
|
||||||
|
|
||||||
percent = (unsigned) (ratio * limit);
|
percent = (unsigned) (ratio * limit + (float)0.5);
|
||||||
if (!percent && top)
|
if (percent <= 0 && top)
|
||||||
percent = 1;
|
percent = 1;
|
||||||
else if (percent == limit && top != bottom)
|
else if (percent >= limit && top != bottom)
|
||||||
percent = limit - 1;
|
percent = limit - 1;
|
||||||
ix = sprintf (buffer, "%.*u%%", dp + 1, percent);
|
ix = sprintf (buffer, "%.*u%%", dp + 1, percent);
|
||||||
if (dp)
|
if (dp)
|
||||||
|
@ -1607,10 +1607,10 @@ output_data ()
|
||||||
if (a_ptr->call_insn)
|
if (a_ptr->call_insn)
|
||||||
{
|
{
|
||||||
if (a_ptr->total == 0)
|
if (a_ptr->total == 0)
|
||||||
fnotice (gcov_file, "call %2d: never executed\n", i);
|
fnotice (gcov_file, "call %2d never executed\n", i);
|
||||||
else
|
else
|
||||||
fnotice
|
fnotice
|
||||||
(gcov_file, "call %2d: returns %s\n", i,
|
(gcov_file, "call %2d returns %s\n", i,
|
||||||
format_hwint (a_ptr->total - a_ptr->hits,
|
format_hwint (a_ptr->total - a_ptr->hits,
|
||||||
a_ptr->total,
|
a_ptr->total,
|
||||||
-output_branch_counts));
|
-output_branch_counts));
|
||||||
|
@ -1618,11 +1618,11 @@ output_data ()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (a_ptr->total == 0)
|
if (a_ptr->total == 0)
|
||||||
fnotice (gcov_file, "branch %2d: never executed\n",
|
fnotice (gcov_file, "branch %2d never executed\n",
|
||||||
i);
|
i);
|
||||||
else
|
else
|
||||||
fnotice
|
fnotice
|
||||||
(gcov_file, "branch %2d: taken %s\n", i,
|
(gcov_file, "branch %2d taken %s\n", i,
|
||||||
format_hwint (a_ptr->hits, a_ptr->total,
|
format_hwint (a_ptr->hits, a_ptr->total,
|
||||||
-output_branch_counts));
|
-output_branch_counts));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
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.
|
||||||
|
|
||||||
2002-08-05 Jakub Jelinek <jakub@redhat.com>
|
2002-08-05 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
* consistency.vlad/layout/endian.c: Include string.h.
|
* consistency.vlad/layout/endian.c: Include string.h.
|
||||||
|
|
|
@ -0,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 } } */
|
|
@ -0,0 +1,2 @@
|
||||||
|
set gcov_verify_branches 1
|
||||||
|
return 0
|
|
@ -38,36 +38,21 @@ proc clean-gcov { testcase } {
|
||||||
#
|
#
|
||||||
proc verify-lines { testcase file } {
|
proc verify-lines { testcase file } {
|
||||||
#send_user "verify-lines\n"
|
#send_user "verify-lines\n"
|
||||||
global subdir
|
|
||||||
set failed 0
|
set failed 0
|
||||||
set lmessage ""
|
set fd [open $file r]
|
||||||
set output [grep $file ".*count\\(\[0-9\]+\\)" line]
|
while { [gets $fd line] >= 0 } {
|
||||||
#send_user "output:$output\n"
|
if [regexp "^ *(\[^:]*): *(\[0-9\]+):.*count\\((\[0-9\]+)\\)" \
|
||||||
foreach line $output {
|
"$line" all is n shouldbe] {
|
||||||
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 { $is == "" } {
|
||||||
if { $failed == 0 } {
|
fail "$n:no data available for this line"
|
||||||
set lmessage "$n:no data available for this line"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
} elseif { $is != $shouldbe } {
|
} elseif { $is != $shouldbe } {
|
||||||
if { $failed == 0 } {
|
fail "$n:is $is:should be $shouldbe"
|
||||||
set lmessage "$n:is $is:should be $shouldbe"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if { $failed == 0 } {
|
|
||||||
set lmessage "can't parse $line (in wrong place?)"
|
|
||||||
}
|
|
||||||
incr failed
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [list $failed $lmessage]
|
return $failed
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -90,25 +75,18 @@ proc verify-lines { testcase file } {
|
||||||
#
|
#
|
||||||
proc verify-branches { testcase file } {
|
proc verify-branches { testcase file } {
|
||||||
#send_user "verify-branches\n"
|
#send_user "verify-branches\n"
|
||||||
global bmessage
|
|
||||||
global subdir
|
|
||||||
set failed 0
|
set failed 0
|
||||||
set bmessage ""
|
|
||||||
set shouldbe ""
|
set shouldbe ""
|
||||||
set fd [open $file r]
|
set fd [open $file r]
|
||||||
set n 0
|
set n 0
|
||||||
while { [gets $fd line] >= 0 } {
|
while { [gets $fd line] >= 0 } {
|
||||||
incr n
|
regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n
|
||||||
if [regexp "branch" $line] {
|
if [regexp "branch" $line] {
|
||||||
verbose "Processing branch line $n: $line" 3
|
verbose "Processing branch line $n: $line" 3
|
||||||
if [regexp "branch\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
|
if [regexp "branch\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
|
||||||
# All percentages in the current list should have been seen.
|
# All percentages in the current list should have been seen.
|
||||||
if {[llength $shouldbe] != 0} {
|
if {[llength $shouldbe] != 0} {
|
||||||
if { $failed == 0 } {
|
fail "$n: expected branch percentages not found: $shouldbe"
|
||||||
set bmessage \
|
|
||||||
"$n: expected branch percentages not found: $shouldbe"
|
|
||||||
}
|
|
||||||
#send_user "$n: expected branch percentages not found: $shouldbe\n"
|
|
||||||
incr failed
|
incr failed
|
||||||
set shouldbe ""
|
set shouldbe ""
|
||||||
}
|
}
|
||||||
|
@ -123,21 +101,17 @@ proc verify-branches { testcase file } {
|
||||||
set shouldbe [lreplace $shouldbe $i $i [expr 100 - $num]]
|
set shouldbe [lreplace $shouldbe $i $i [expr 100 - $num]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif [regexp "branch \[0-9\]+ taken = (-\[0-9\]+)%" "$line" \
|
} elseif [regexp "branch +\[0-9\]+ taken (-\[0-9\]+)%" "$line" \
|
||||||
all taken] {
|
all taken] {
|
||||||
# Percentages should never be negative.
|
# Percentages should never be negative.
|
||||||
if { $failed == 0 } {
|
fail "$n: negative percentage: $taken"
|
||||||
set bmessage "$n: negative percentage: $taken"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
} elseif [regexp "branch \[0-9\]+ taken = (\[0-9\]+)%" "$line" \
|
} elseif [regexp "branch +\[0-9\]+ taken (\[0-9\]+)%" "$line" \
|
||||||
all taken] {
|
all taken] {
|
||||||
#send_user "$n: taken = $taken\n"
|
#send_user "$n: taken = $taken\n"
|
||||||
# Percentages should never be greater than 100.
|
# Percentages should never be greater than 100.
|
||||||
if {$taken > 100} {
|
if {$taken > 100} {
|
||||||
if { $failed == 0 } {
|
fail "$n: percentage greater than 100: $taken"
|
||||||
set bmessage "$n: percentage greater than 100: $taken"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
}
|
}
|
||||||
if {$taken > 50} {
|
if {$taken > 50} {
|
||||||
|
@ -152,11 +126,7 @@ proc verify-branches { testcase file } {
|
||||||
} elseif [regexp "branch\\(end\\)" "$line"] {
|
} elseif [regexp "branch\\(end\\)" "$line"] {
|
||||||
# All percentages in the list should have been seen by now.
|
# All percentages in the list should have been seen by now.
|
||||||
if {[llength $shouldbe] != 0} {
|
if {[llength $shouldbe] != 0} {
|
||||||
if { $failed == 0 } {
|
fail "$n: expected branch percentages not found: $shouldbe"
|
||||||
set bmessage \
|
|
||||||
"$n: expected branch percentages not found: $shouldbe"
|
|
||||||
}
|
|
||||||
#send_user "$n: expected branch percentages not found: $shouldbe\n"
|
|
||||||
incr failed
|
incr failed
|
||||||
}
|
}
|
||||||
set shouldbe ""
|
set shouldbe ""
|
||||||
|
@ -165,14 +135,11 @@ proc verify-branches { testcase file } {
|
||||||
}
|
}
|
||||||
# All percentages in the list should have been seen.
|
# All percentages in the list should have been seen.
|
||||||
if {[llength $shouldbe] != 0} {
|
if {[llength $shouldbe] != 0} {
|
||||||
if { $failed == 0 } {
|
fail "$n: expected branch percentages not found: $shouldbe"
|
||||||
set bmessage "$n: expected branch percentages not found: $shouldbe"
|
|
||||||
}
|
|
||||||
#send_user "$n: expected branch percentages not found: $shouldbe\n"
|
|
||||||
incr failed
|
incr failed
|
||||||
}
|
}
|
||||||
close $fd
|
close $fd
|
||||||
return [list $failed $bmessage]
|
return $failed
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -195,37 +162,29 @@ proc verify-branches { testcase file } {
|
||||||
#
|
#
|
||||||
proc verify-calls { testcase file } {
|
proc verify-calls { testcase file } {
|
||||||
#send_user "verify-calls\n"
|
#send_user "verify-calls\n"
|
||||||
global cmessage
|
|
||||||
global subdir
|
|
||||||
set failed 0
|
set failed 0
|
||||||
set cmessage ""
|
|
||||||
set shouldbe ""
|
set shouldbe ""
|
||||||
set fd [open $file r]
|
set fd [open $file r]
|
||||||
set n 0
|
set n 0
|
||||||
while { [gets $fd line] >= 0 } {
|
while { [gets $fd line] >= 0 } {
|
||||||
incr n
|
regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n
|
||||||
if [regexp "returns" $line] {
|
if [regexp "returns" $line] {
|
||||||
verbose "Processing returns line $n: $line" 3
|
verbose "Processing returns line $n: $line" 3
|
||||||
if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
|
if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
|
||||||
# All percentages in the current list should have been seen.
|
# All percentages in the current list should have been seen.
|
||||||
if {[llength $shouldbe] != 0} {
|
if {[llength $shouldbe] != 0} {
|
||||||
if { $failed == 0 } {
|
fail "$n: expected return percentages not found: $shouldbe"
|
||||||
set cmessage \
|
|
||||||
"$n: expected return percentages not found: $shouldbe"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
set shouldbe ""
|
set shouldbe ""
|
||||||
}
|
}
|
||||||
# Record the percentages to check for.
|
# Record the percentages to check for.
|
||||||
set shouldbe $new_shouldbe
|
set shouldbe $new_shouldbe
|
||||||
} elseif [regexp "call \[0-9\]+ returns = (-\[0-9\]+)%" "$line" \
|
} elseif [regexp "call +\[0-9\]+ returns (-\[0-9\]+)%" "$line" \
|
||||||
all returns] {
|
all returns] {
|
||||||
# Percentages should never be negative.
|
# Percentages should never be negative.
|
||||||
if { $failed == 0 } {
|
fail "$n: negative percentage: $returns"
|
||||||
set cmessage "$n: negative percentage: $returns"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
} elseif [regexp "call \[0-9\]+ returns = (\[0-9\]+)%" "$line" \
|
} elseif [regexp "call +\[0-9\]+ returns (\[0-9\]+)%" "$line" \
|
||||||
all returns] {
|
all returns] {
|
||||||
# For branches we check that percentages are not greater than
|
# For branches we check that percentages are not greater than
|
||||||
# 100 but call return percentages can be, as for setjmp(), so
|
# 100 but call return percentages can be, as for setjmp(), so
|
||||||
|
@ -240,10 +199,7 @@ proc verify-calls { testcase file } {
|
||||||
} elseif [regexp "returns\\(end\\)" "$line"] {
|
} elseif [regexp "returns\\(end\\)" "$line"] {
|
||||||
# All percentages in the list should have been seen by now.
|
# All percentages in the list should have been seen by now.
|
||||||
if {[llength $shouldbe] != 0} {
|
if {[llength $shouldbe] != 0} {
|
||||||
if { $failed == 0 } {
|
fail "$n: expected return percentages not found: $shouldbe"
|
||||||
set cmessage \
|
|
||||||
"$n: expected return percentages not found: $shouldbe"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
}
|
}
|
||||||
set shouldbe ""
|
set shouldbe ""
|
||||||
|
@ -252,13 +208,11 @@ proc verify-calls { testcase file } {
|
||||||
}
|
}
|
||||||
# All percentages in the list should have been seen.
|
# All percentages in the list should have been seen.
|
||||||
if {[llength $shouldbe] != 0} {
|
if {[llength $shouldbe] != 0} {
|
||||||
if { $failed == 0 } {
|
fail "$n: expected return percentages not found: $shouldbe"
|
||||||
set cmessage "$n: expected return percentages not found: $shouldbe"
|
|
||||||
}
|
|
||||||
incr failed
|
incr failed
|
||||||
}
|
}
|
||||||
close $fd
|
close $fd
|
||||||
return [list $failed $cmessage]
|
return $failed
|
||||||
}
|
}
|
||||||
|
|
||||||
# Called by dg-final to run gcov and analyze the results.
|
# Called by dg-final to run gcov and analyze the results.
|
||||||
|
@ -314,45 +268,26 @@ proc run-gcov { args } {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that line execution counts are as expected.
|
# Check that line execution counts are as expected.
|
||||||
set loutput [verify-lines $testcase $testcase.gcov]
|
set lfailed [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
|
# If requested via the .x file, check that branch and call information
|
||||||
# is correct.
|
# is correct.
|
||||||
if [info exists gcov_verify_branches] {
|
if [info exists gcov_verify_branches] {
|
||||||
set boutput [verify-branches $testcase $testcase.gcov]
|
set bfailed [verify-branches $testcase $testcase.gcov]
|
||||||
set bfailed [lindex $boutput 0]
|
|
||||||
set bmessage [lindex $boutput 1]
|
|
||||||
} else {
|
} else {
|
||||||
set bfailed 0
|
set bfailed 0
|
||||||
set bmessage ""
|
|
||||||
}
|
}
|
||||||
if [info exists gcov_verify_calls] {
|
if [info exists gcov_verify_calls] {
|
||||||
set coutput [verify-calls $testcase $testcase.gcov]
|
set cfailed [verify-calls $testcase $testcase.gcov]
|
||||||
set cfailed [lindex $coutput 0]
|
|
||||||
set cmessage [lindex $coutput 1]
|
|
||||||
} else {
|
} else {
|
||||||
set cfailed 0
|
set cfailed 0
|
||||||
set cmessage ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Report whether the gcov test passed or failed. If there were
|
# Report whether the gcov test passed or failed. If there were
|
||||||
# multiple failures then the message is a summary.
|
# multiple failures then the message is a summary.
|
||||||
set tfailed [expr $lfailed + $bfailed + $cfailed]
|
set tfailed [expr $lfailed + $bfailed + $cfailed]
|
||||||
if { $tfailed > 0 } {
|
if { $tfailed > 0 } {
|
||||||
if { $tfailed == 1 } {
|
fail "$subdir/$testcase gcov: $lfailed failures in line counts, $bfailed in branch percentages, $cfailed in return percentages"
|
||||||
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 {
|
} else {
|
||||||
pass "$subdir/$testcase gcov"
|
pass "$subdir/$testcase gcov"
|
||||||
clean-gcov $testcase
|
clean-gcov $testcase
|
||||||
|
|
Loading…
Reference in New Issue