diff options
author | 2023-08-06 06:30:23 -0700 | |
---|---|---|
committer | 2023-08-06 06:30:23 -0700 | |
commit | 14624454196370e08309d4f0b0463b494e4df9ca (patch) | |
tree | 538421bfffc3d804807a4ec70a1323fbcbe3416f /src/bun.js/bindings/CodeCoverage.cpp | |
parent | ecdf2ffa6c615d8a431c2919c0b9bdc4cbe2c4f0 (diff) | |
download | bun-14624454196370e08309d4f0b0463b494e4df9ca.tar.gz bun-14624454196370e08309d4f0b0463b494e4df9ca.tar.zst bun-14624454196370e08309d4f0b0463b494e4df9ca.zip |
Code coverage for `bun test` (#3975)
* WIP code coverage initial commit
* almost works
* one approach
* Code Coverage
* Update WebKit
* it works but is not yet accurate
* skip double ascii check
* wrapper
* it works but i'm not sure what to do about blocks
* hide blocks for now
* Update ZigSourceProvider.cpp
* Create coverage.md
* Update nav.ts
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/CodeCoverage.cpp')
-rw-r--r-- | src/bun.js/bindings/CodeCoverage.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/bun.js/bindings/CodeCoverage.cpp b/src/bun.js/bindings/CodeCoverage.cpp new file mode 100644 index 000000000..1cb3b6ba2 --- /dev/null +++ b/src/bun.js/bindings/CodeCoverage.cpp @@ -0,0 +1,44 @@ +#include "root.h" +#include "ZigSourceProvider.h" +#include <JavaScriptCore/ControlFlowProfiler.h> + +using namespace JSC; + +extern "C" bool CodeCoverage__withBlocksAndFunctions( + JSC::VM* vmPtr, + JSC::SourceID sourceID, + void* ctx, + bool ignoreSourceMap, + void (*blockCallback)(void* ctx, JSC::BasicBlockRange* range, size_t len, size_t functionOffset, bool ignoreSourceMap)) +{ + + VM& vm = *vmPtr; + + auto basicBlocks = vm.controlFlowProfiler()->getBasicBlocksForSourceIDWithoutFunctionRange( + sourceID, vm); + + if (basicBlocks.isEmpty()) { + blockCallback(ctx, nullptr, 0, 0, ignoreSourceMap); + return true; + } + + size_t functionStartOffset = basicBlocks.size(); + + const Vector<std::tuple<bool, unsigned, unsigned>>& functionRanges = vm.functionHasExecutedCache()->getFunctionRanges(sourceID); + + basicBlocks.reserveCapacity(functionRanges.size() + basicBlocks.size()); + + for (const auto& functionRange : functionRanges) { + BasicBlockRange range; + range.m_hasExecuted = std::get<0>(functionRange); + range.m_startOffset = static_cast<int>(std::get<1>(functionRange)); + range.m_endOffset = static_cast<int>(std::get<2>(functionRange)); + range.m_executionCount = range.m_hasExecuted + ? 1 + : 0; // This is a hack. We don't actually count this. + basicBlocks.append(range); + } + + blockCallback(ctx, basicBlocks.data(), basicBlocks.size(), functionStartOffset, ignoreSourceMap); + return true; +} |