Skip to content

Fixes coverage map updates and bit counting logic - #309

Merged
ThomasTNO merged 4 commits into
TNO-S3:mainfrom
Rou404:fix-lcov-coverage-ratio
May 18, 2026
Merged

ThomasTNO merged 4 commits into
TNO-S3:mainfrom
Rou404:fix-lcov-coverage-ratio

Conversation

@Rou404

@Rou404 Rou404 commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

There are three changes with this pull request

The most obvious one is changing how the total is calculated in max_coverage_ratio

   fn max_coverage_ratio(&mut self) -> (u64, u64) {
        let count = self
            .cov_map_total
            .iter()
            .fold(0u64, |sum, val| sum + u64::from(val.count_ones()));
        let total = self.first_unused_idx as u64;
        // update the max coverage ratio
        self.max_ratio.0 = std::cmp::max(self.max_ratio.0, count);
        self.max_ratio.1 = std::cmp::max(self.max_ratio.1, total);
        self.max_ratio
    }

before this was done by multiplying the total by 8, which is a mistake because each mapped line uses one byte as a boolean slot, not eight independent coverage bits.

Before

 let total = self.first_unused_idx as u64 * 8;

Second change is removing the unnecessary assignment of the cov_bit to the total map

   cmp::Ordering::Less => {
        self.cov_map[bit_idx] = val;
        self.cov_map_total[bit_idx] = val;
    }

This is unnecessary since the total coverage map is merged with the cov_map a few lines under, and is not required in between steps.

The third and the debatable change is lcov_client.rs:254:

Mapping every LineData, including count == 0, changes the denominator from β€œlines ever covered” to β€œcoverable/instrumented lines observed in LCOV”. That is probably the more precise coverage ratio, but it can lower reported ratios compared with the old implementation. If that is intended, this version is better.

Fixes #103

Removes redundant coverage map assignment.
Changed the denominator from β€œlines ever covered” to β€œcoverable/instrumented lines observed in LCOV”.
Adjusts total bit calculation to prevent overcounting (unnecessary multiplication by 8 to covert to bit level).
@Rou404 Rou404 changed the title Fixes coverage map updates and bit counting logic [] Fixes coverage map updates and bit counting logic May 13, 2026
Comment thread src/coverage_clients/lcov_client.rs Resolved
@Rou404
Rou404 marked this pull request as ready for review May 13, 2026 16:22

@Jelle-Nauta Jelle-Nauta left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with all three points and their fixes, pretty bad that apparently we wildly misreported coverage before. It would be good to have some tests for this (though that is beyond the scope of this PR).

@koltiradw

Copy link
Copy Markdown

I also noticed a strange calculation of the initial coverage -

(hit * 100 + total / 2) / total

@ThomasTNO

ThomasTNO commented May 18, 2026 •

Copy link
Copy Markdown
Member

I also noticed a strange calculation of the initial coverage -

(hit * 100 + total / 2) / total

@grebnetiew, we introduced this in #145. Seems like I committed this and you reviewed. I have no clue why this is such a strange formula. Guess some copy-paste mistake, or am I missing something here?

@ThomasTNO

Copy link
Copy Markdown
Member

I also noticed a strange calculation of the initial coverage -

(hit * 100 + total / 2) / total

@grebnetiew, we introduced this in #145. Seems like I committed this and you reviewed. I have no clue why this is such a strange formula. Guess some copy-paste mistake, or am I missing something here?

This has to do with integer rounding, readability is a bit of a mess..

@ThomasTNO
ThomasTNO enabled auto-merge (squash) May 18, 2026 08:29
@ThomasTNO
ThomasTNO disabled auto-merge May 18, 2026 08:32
@ThomasTNO
ThomasTNO merged commit f424ad9 into TNO-S3:main May 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Line coverage in Python does not seem to work on multithreaded programs

4 participants