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

Verification coverage report #4625

Merged
merged 23 commits into from
Oct 12, 2023

Conversation

atomb
Copy link
Member

@atomb atomb commented Oct 6, 2023

Description

Adds support for producing reports describing verification coverage in the same format used for the expected test coverage reports that can be produced from dafny generate-tests. Verification and test coverage reports can be merged using dafny merge-coverage-reports.

How has this been tested?

Includes a test of expected output in Test/logger/ProofDependencyLogging.dfy_verification.html.expect.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@atomb atomb requested a review from Dargones October 10, 2023 23:50
Comment on lines 119 to 128
var source = new StreamReader(program.GetStartOfFirstFileToken().ActualFilename).ReadToEnd();
var lines = source.Split("\n");
var pos = 0;
var line = 0;
var linePositions = new int[lines.Length];
while (pos < source.Length) {
linePositions[line] = pos;
pos += lines[line].Length + 1;
line++;
}
Copy link
Collaborator

@Dargones Dargones Oct 11, 2023

Choose a reason for hiding this comment

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

A test coverage report might include several files, but the linePositions array only works if there is only one file. I think something like this should work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, of course. I was mistakenly carrying over my mental model from another location that was file-specific. Thanks for fixing it!

Comment on lines +272 to +274
for (var pos = span.Span.StartToken.pos; pos <= span.Span.EndToken.pos; pos++) {
characterLabels[pos] = CoverageLabelExtension.Combine(characterLabels[pos], span.Label);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have just realized that this loop replaces about 30 lines of some binary search recursion madness I wrote...

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally started thinking about interval trees when I realized that I needed to deal with arbitrary types and degrees of overlap. And then I realized that just tracking the labels on a per-character basis was simpler and probably even more efficient.

@@ -239,16 +265,30 @@ public class CoverageReporter {
private string HtmlReportForFile(CoverageReport report, string pathToSourceFile, string baseDirectory, string linksToOtherReports) {
var source = new StreamReader(pathToSourceFile).ReadToEnd();
var lines = source.Split("\n");
IToken lastToken = new Token(0, 0);
var characterLabels = new CoverageLabel[source.Length];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it worth explicitly initializing values with None so that the order of labels in the CoverageLabel enum doesn't affect the behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good catch. I'll change that.

@atomb atomb marked this pull request as ready for review October 11, 2023 21:53
@atomb atomb requested a review from Dargones October 11, 2023 22:35
@atomb atomb self-assigned this Oct 11, 2023
Dargones
Dargones previously approved these changes Oct 12, 2023
Copy link
Collaborator

@Dargones Dargones left a comment

Choose a reason for hiding this comment

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

Have tested locally, everything works on my end (and I will work on a separate PR with tests for test generation coverage)

@Dargones Dargones self-requested a review October 12, 2023 17:28
Dargones
Dargones previously approved these changes Oct 12, 2023
@atomb atomb merged commit e85ad5c into dafny-lang:master Oct 12, 2023
18 checks passed
@atomb atomb deleted the verification-coverage-report branch October 12, 2023 21:13
robin-aws pushed a commit to robin-aws/dafny that referenced this pull request Oct 13, 2023
# Description

Adds support for producing reports describing verification coverage in
the same format used for the expected test coverage reports that can be
produced from `dafny generate-tests`. Verification and test coverage
reports can be merged using `dafny merge-coverage-reports`.

# How has this been tested?

Includes a test of expected output in
`Test/logger/ProofDependencyLogging.dfy_verification.html.expect`.

By submitting this pull request, I confirm that my contribution is made
under the terms of the MIT license.

---------

Co-authored-by: Aleksandr Fedchin <[email protected]>
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.

None yet

2 participants