Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative sequence point coverage when line executions exceed int.MaxValue #1266

Closed
Malivil opened this issue Dec 7, 2021 · 9 comments · Fixed by #1267
Closed

Negative sequence point coverage when line executions exceed int.MaxValue #1266

Malivil opened this issue Dec 7, 2021 · 9 comments · Fixed by #1267
Labels
bug Something isn't working with repro Issue with repro

Comments

@Malivil
Copy link

Malivil commented Dec 7, 2021

Package: coverlet.msbuild
Version: 3.1.0
Format: opencover

In a project where a particular line of code gets called a lot, the sequence point coverage value for that line can become negative if the line is hit more than int.MaxValue times. The value in the XML is negative and shows in the generated report as uncovered.

I created a simple repro of this because I cannot show the actual code that caused the problem (it's from my job).

XML:
image

Report:
image

Repro code: https://github.com/Malivil/Coverlet1266Repro

@daveMueller daveMueller added untriaged To be investigated with repro Issue with repro labels Dec 7, 2021
@daveMueller
Copy link
Collaborator

Thanks for reporting and thanks for the repro. 🙏

@daveMueller
Copy link
Collaborator

Mhh, we could change the tracker to stop tracking hits when int.MaxValue is reached. Something like

public static void RecordHit(int hitLocationIndex)
{
    if(HitsArray[hitLocationIndex] < int.MaxValue)
        Interlocked.Increment(ref HitsArray[hitLocationIndex]);
}

I just tested it with the repro provided by @Malivil and it would work.

image

What do you think, @MarcoRossignoli @petli @tonerdo? Any other ideas for solutions?

@daveMueller daveMueller added bug Something isn't working and removed untriaged To be investigated labels Dec 7, 2021
@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Dec 8, 2021

I prefer to avoid a new branch on the tracker...we're injecting it to probe and we'll slow down more tests, maybe we can try to move to uint32 https://docs.microsoft.com/en-us/dotnet/api/system.threading.interlocked.increment?view=net-6.0#System_Threading_Interlocked_Increment_System_UInt32__ and let it overflow but always >= 0
We need to understand during report generation what's happen if we put a uint istead of int for instance for cobertura+report generator.

@petli
Copy link
Collaborator

petli commented Dec 8, 2021

An alternative is to translate negative numbers to int.MaxValue when collecting the results.

@MarcoRossignoli
Copy link
Collaborator

An alternative is to translate negative numbers to int.MaxValue when collecting the results.

Yep, if we're ok with int.MaxValue, @Malivil from your perspective does it make sense have "correct very huge value" there? I mean are you paying attention to that?

@petli
Copy link
Collaborator

petli commented Dec 8, 2021

I think that if you hit 31 bits you may be likely to hit 32 bits too, and then the only real solution would be to go to long, doubling the memory usage. (But maybe not slow down execution, on 64-bit machines?)

@Malivil
Copy link
Author

Malivil commented Dec 8, 2021

An alternative is to translate negative numbers to int.MaxValue when collecting the results.

Yep, if we're ok with int.MaxValue, @Malivil from your perspective does it make sense have "correct very huge value" there? I mean are you paying attention to that?

We're not paying attention to the number, specifically. As long as it's positive and it makes sense with the surrounding lines we wouldn't even notice. Keeping it at int.MaxValue would work fine from our perspective.

@daveMueller
Copy link
Collaborator

An alternative is to translate negative numbers to int.MaxValue when collecting the results.

Then should we go with this solution? I could prepare a PR in the next days.

@MarcoRossignoli
Copy link
Collaborator

@daveMueller looks like we're all in agreement for the translation, feel free to tackle it if you want! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working with repro Issue with repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants