Add support for branch information.
From-SVN: r45055
This commit is contained in:
parent
d573392193
commit
de3e861eb0
@ -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 @@ proc clean-gcov { testcase } {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user