Skip to content

[llvm-cov] Export decision coverage to output json #144335

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

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iterator>
Expand Down Expand Up @@ -494,6 +495,17 @@ struct MCDCRecord {
return TV[TestVectorIndex].first[PosToID[Condition]];
}

/// Return the number of True and False decisions for all executed test
/// vectors.
std::pair<unsigned, unsigned> getDecisions() const {
const unsigned TrueDecisions =
std::count_if(TV.begin(), TV.end(), [](const auto &TestVec) {
return TestVec.second == CondState::MCDC_True;
});

return {TrueDecisions, TV.size() - TrueDecisions};
}

/// Return the Result evaluation for an executed test vector.
/// See MCDCRecordProcessor::RecordTestVector().
CondState getTVResult(unsigned TestVectorIndex) {
Expand Down
6 changes: 4 additions & 2 deletions llvm/tools/llvm-cov/CoverageExporterJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include <utility>

/// The semantic version combined as a string.
#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.1"
#define LLVM_COVERAGE_EXPORT_JSON_STR "3.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for updating this. We have not been good about moving the version forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually very important to me, as I check this value to see whether the subsequent processing is still correct.


/// Unique type identifier for JSON coverage export.
#define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export"
Expand Down Expand Up @@ -110,8 +110,10 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {

json::Array renderMCDCRecord(const coverage::MCDCRecord &Record) {
const llvm::coverage::CounterMappingRegion &CMR = Record.getDecisionRegion();
const auto [TrueDecisions, FalseDecisions] = Record.getDecisions();
return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd,
CMR.ColumnEnd, CMR.ExpandedFileID, int64_t(CMR.Kind),
CMR.ColumnEnd, TrueDecisions, FalseDecisions,
CMR.ExpandedFileID, int64_t(CMR.Kind),
gatherConditions(Record)});
}

Expand Down
Loading