-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Implement initial LCOV reporter (no function names support) #11883
Conversation
❌ @Jarred-Sumner, your commit has failing tests :( 💻 1 failing tests Darwin x64 baseline
🐧💪 1 failing tests Linux AARCH64
🪟💻 1 failing tests Windows x64 baseline
🪟💻 2 failing tests Windows x64
|
I am happy to finish this PR if I get advised what is missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall this looks good. some notes attached.
in addition
- kind of sad that lines with comments are marked as not hit. though i dont think that is an issue in your implementation, but the coverage stuff overall.
- should we get
--coverage-reporter=
command line arguments? - for tests, I think it would be reasonable to snapshot test the samples. look for usages of
tempDirWithFiles
to setup directory trees to test.
src/cli/test_command.zig
Outdated
|
||
while (iter.next()) |entry| { | ||
const value: bun.sourcemap.ByteRangeMapping = entry.*; | ||
byte_ranges.appendAssumeCapacity(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cant this just be written as appendAssumeCapacity(value.*)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't compile on my end:
src/cli/test_command.zig:292:51: error: cannot dereference non-pointer type 'src.sourcemap.CodeCoverage.ByteRangeMapping'
byte_ranges.appendAssumeCapacity(value.*);
~~~~~^~
src/sourcemap/CodeCoverage.zig:307:30: note: struct declared here
pub const ByteRangeMapping = struct {
^~~~~~
referenced by:
exec: src/cli/test_command.zig:920:37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait sorry, i meant entry.*
the point being these two lines can be one line (i dont think the type annotation is of much value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it worked 54d12d3
(Sorry, I am a super newbie to Ziglang)
@paperdave Thanks for your review. I think all comments are addressed |
@exoego see the two bullet points in the main 'requested changes' comment. to repeat:
but otherwise we're good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im going to add a commit that renames --coverage-reports-dir to just --coverage-dir but yeah this is good.
it could use more tests, but i want to get this in for todays release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, nevermind, coverage.test.ts is failing
Hmm, do you have an advice to fix coverage.test.ts? |
…make it one pass, use more Windows-friendly APIs for creating the directory
src/sourcemap/CodeCoverage.zig
Outdated
while (iter.next()) |line| { | ||
// DA: line number, hit count | ||
// FIXME: Remove the magic number that is used to convert the hit count to the correct value | ||
try writer.print("DA:{d},{d}\n", .{ line + 1, report.lines_hits.ptr[line] - 2863311530 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@exoego the reason this magic number made it seemingly work: undefined memory. In safety-checked builds of Zig (debug, ReleaseSafe), 0xa
is the default-initialized value for memory.
This magic number was turning 0xa
into 0. In a release build, this is undefined behavior and will produce a result which will either crash the program, infinite loop, or something unexpected. This is why it did not work in CI.
line_hits = try LinesHits.initCapacity(allocator, line_count); | ||
line_hits.len = line_count; | ||
const line_hits_slice = line_hits.slice(); | ||
@memset(line_hits_slice, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@exoego note how we now zero-initialize the line_hits
array to ensure that we can access values which have never been written to without worrying about undefined behavior.
@@ -415,7 +477,7 @@ pub const ByteRangeMapping = struct { | |||
executable_lines.set(line); | |||
if (has_executed) { | |||
lines_which_have_executed.set(line); | |||
lines_hits.ptr[line] += 1; | |||
line_hits_slice[line] += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@exoego writing to a many-item pointer ([*]MyType
) directly is very much a footgun. You want to use a slice (ptr[0..len]
), which has bounds checks.
Thanks!! |
Co-authored-by: Jarred Sumner <[email protected]> Co-authored-by: dave caruso <[email protected]>
Co-authored-by: Jarred Sumner <[email protected]> Co-authored-by: dave caruso <[email protected]>
const tmpname = std.fmt.bufPrintZ(&shortname_buf, ".lcov.info.{s}.tmp", .{bun.fmt.fmtSliceHexLower(&base64_bytes)}) catch unreachable; | ||
const path = bun.path.joinAbsStringBufZ(relative_dir, &lcov_name_buf, &.{ opts.reports_directory, tmpname }, .auto); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this PR do?
Closes #4015
This adds new config to bunfig which allows users to use
lcov
coverage reporter and also disableconsole
reporter.AFAIK, function names in LCOV is optional, and tools like CodeCov accept LCOV file without function names.
So I think LCOV without function names is still valuable to users.
How did you verify your code works?
I run the locally-built
bun-debug
overhttps://github.com/honojs/hono
and obtained LCOV file like below:Then I uploaded the generated LCOV to CodeCov and confirmed files are succesfully processed by CodeCov:
Sorry, I couldn't figure out how to write test for this.
Happy to add test if guidance provided 🙇
bun-debug test test-file-name.test
)module_loader.zig
to include the new module