Skip to content

Commit 866d187

Browse files
jhutzoberpar
authored andcommitted
lcov: Sort branches in unnamed blocks first
When processing branch coverage data, consider branches in "unnamed" blocks to come before other blocks on the same line, so that they appear in the correct order in HTML output. This is accomplished by using block number -1 for unnamed blocks, instead of 9999 as was previously done. In branch data vectors, this is reprsented by the value $BR_VEC_MAX, which is defined to be the largest value representable in the field width used. This same value is also used in .info files, for backward-compatibility with regular expressions used to parse these files. As a result, .info files generated by versions of lcov with this change can be read by older versions, though branch results will still appear out of order. Signed-off-by: Jeffrey Hutzelman <[email protected]>
1 parent 17c0ede commit 866d187

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

bin/genhtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use Digest::MD5 qw(md5_base64);
7373

7474
# Global constants
7575
our $title = "LCOV - code coverage report";
76-
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.79 $)';
76+
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.80 $)';
7777
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
7878
our $tool_name = basename($0);
7979

@@ -146,6 +146,7 @@ our $BR_BRANCH = 1;
146146
our $BR_TAKEN = 2;
147147
our $BR_VEC_ENTRIES = 3;
148148
our $BR_VEC_WIDTH = 32;
149+
our $BR_VEC_MAX = vec(pack('b*', 1 x $BR_VEC_WIDTH), 0, $BR_VEC_WIDTH);
149150

150151
# Additional offsets used when converting branch coverage data to HTML
151152
our $BR_LEN = 3;
@@ -5041,6 +5042,7 @@ sub br_ivec_get($$)
50415042

50425043
# Retrieve data from vector
50435044
$block = vec($vec, $offset + $BR_BLOCK, $BR_VEC_WIDTH);
5045+
$block = -1 if ($block == $BR_VEC_MAX);
50445046
$branch = vec($vec, $offset + $BR_BRANCH, $BR_VEC_WIDTH);
50455047
$taken = vec($vec, $offset + $BR_TAKEN, $BR_VEC_WIDTH);
50465048

@@ -5066,10 +5068,12 @@ sub br_ivec_push($$$$)
50665068
my $i;
50675069

50685070
$vec = "" if (!defined($vec));
5071+
$block = $BR_VEC_MAX if $block < 0;
50695072

50705073
# Check if branch already exists in vector
50715074
for ($i = 0; $i < $num; $i++) {
50725075
my ($v_block, $v_branch, $v_taken) = br_ivec_get($vec, $i);
5076+
$v_block = $BR_VEC_MAX if $v_block < 0;
50735077

50745078
next if ($v_block != $block || $v_branch != $branch);
50755079

bin/geninfo

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if( $^O eq "msys" )
6161
}
6262

6363
# Constants
64-
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.127 $)';
64+
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.128 $)';
6565
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
6666
our $gcov_tool = "gcov";
6767
our $tool_name = basename($0);
@@ -145,8 +145,9 @@ our $BR_BRANCH = 2;
145145
our $BR_TAKEN = 3;
146146
our $BR_VEC_ENTRIES = 4;
147147
our $BR_VEC_WIDTH = 32;
148+
our $BR_VEC_MAX = vec(pack('b*', 1 x $BR_VEC_WIDTH), 0, $BR_VEC_WIDTH);
148149

149-
our $UNNAMED_BLOCK = 9999;
150+
our $UNNAMED_BLOCK = -1;
150151

151152
# Prototypes
152153
sub print_usage(*);
@@ -1252,6 +1253,7 @@ sub process_dafile($$)
12521253
my ($line, $block, $branch, $taken) =
12531254
br_gvec_get($gcov_branches, $i);
12541255

1256+
$block = $BR_VEC_MAX if ($block < 0);
12551257
print(INFO_HANDLE "BRDA:$line,$block,$branch,$taken\n");
12561258
$br_found++;
12571259
$br_hit++ if ($taken ne '-' && $taken > 0);
@@ -1596,6 +1598,7 @@ sub br_gvec_get($$)
15961598
# Retrieve data from vector
15971599
$line = vec($vec, $offset + $BR_LINE, $BR_VEC_WIDTH);
15981600
$block = vec($vec, $offset + $BR_BLOCK, $BR_VEC_WIDTH);
1601+
$block = -1 if ($block == $BR_VEC_MAX);
15991602
$branch = vec($vec, $offset + $BR_BRANCH, $BR_VEC_WIDTH);
16001603
$taken = vec($vec, $offset + $BR_TAKEN, $BR_VEC_WIDTH);
16011604

@@ -1623,6 +1626,7 @@ sub br_gvec_push($$$$$)
16231626

16241627
$vec = "" if (!defined($vec));
16251628
$offset = br_gvec_len($vec) * $BR_VEC_ENTRIES;
1629+
$block = $BR_VEC_MAX if $block < 0;
16261630

16271631
# Encode taken value into an integer
16281632
if ($taken eq "-") {

bin/lcov

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use Cwd qw /abs_path getcwd/;
7171

7272

7373
# Global constants
74-
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.98 $)';
74+
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.99 $)';
7575
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
7676
our $tool_name = basename($0);
7777

@@ -93,6 +93,7 @@ our $BR_BRANCH = 1;
9393
our $BR_TAKEN = 2;
9494
our $BR_VEC_ENTRIES = 3;
9595
our $BR_VEC_WIDTH = 32;
96+
our $BR_VEC_MAX = vec(pack('b*', 1 x $BR_VEC_WIDTH), 0, $BR_VEC_WIDTH);
9697

9798
# Branch data combination types
9899
our $BR_SUB = 0;
@@ -1472,10 +1473,12 @@ sub br_ivec_push($$$$)
14721473
my $i;
14731474

14741475
$vec = "" if (!defined($vec));
1476+
$block = $BR_VEC_MAX if $block < 0;
14751477

14761478
# Check if branch already exists in vector
14771479
for ($i = 0; $i < $num; $i++) {
14781480
my ($v_block, $v_branch, $v_taken) = br_ivec_get($vec, $i);
1481+
$v_block = $BR_VEC_MAX if $v_block < 0;
14791482

14801483
next if ($v_block != $block || $v_branch != $branch);
14811484

@@ -1512,6 +1515,7 @@ sub br_ivec_get($$)
15121515

15131516
# Retrieve data from vector
15141517
$block = vec($vec, $offset + $BR_BLOCK, $BR_VEC_WIDTH);
1518+
$block = -1 if ($block == $BR_VEC_MAX);
15151519
$branch = vec($vec, $offset + $BR_BRANCH, $BR_VEC_WIDTH);
15161520
$taken = vec($vec, $offset + $BR_TAKEN, $BR_VEC_WIDTH);
15171521

@@ -2632,6 +2636,7 @@ sub write_info_file(*$)
26322636
my ($block, $branch, $taken) =
26332637
br_ivec_get($brdata, $i);
26342638

2639+
$block = $BR_VEC_MAX if ($block < 0);
26352640
print(INFO_HANDLE "BRDA:$line,$block,".
26362641
"$branch,$taken\n");
26372642
$br_found++;

0 commit comments

Comments
 (0)