Skip to content

Commit cb87084

Browse files
committed
[llvm-cov] Export decision coverage to output json
1 parent 299a55a commit cb87084

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ struct MCDCRecord {
494494
return TV[TestVectorIndex].first[PosToID[Condition]];
495495
}
496496

497+
/// Return the executed test vectors.
498+
const TestVectors &getTV() const { return TV; }
499+
497500
/// Return the Result evaluation for an executed test vector.
498501
/// See MCDCRecordProcessor::RecordTestVector().
499502
CondState getTVResult(unsigned TestVectorIndex) {

llvm/tools/llvm-cov/CoverageExporterJson.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#include <utility>
6363

6464
/// The semantic version combined as a string.
65-
#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.1"
65+
#define LLVM_COVERAGE_EXPORT_JSON_STR "3.0.0"
6666

6767
/// Unique type identifier for JSON coverage export.
6868
#define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export"
@@ -108,10 +108,22 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {
108108
return Conditions;
109109
}
110110

111+
std::pair<unsigned, unsigned> getDecisions(const coverage::MCDCRecord &Record) {
112+
const coverage::MCDCRecord::TestVectors &TestVectors = Record.getTV();
113+
const unsigned TrueConditions =
114+
std::count_if(TestVectors.begin(), TestVectors.end(), [](const auto &TV) {
115+
return TV.second == coverage::MCDCRecord::CondState::MCDC_True;
116+
});
117+
118+
return {TrueConditions, TestVectors.size() - TrueConditions};
119+
}
120+
111121
json::Array renderMCDCRecord(const coverage::MCDCRecord &Record) {
112122
const llvm::coverage::CounterMappingRegion &CMR = Record.getDecisionRegion();
123+
const auto [TrueConditions, FalseConditions] = getDecisions(Record);
113124
return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd,
114-
CMR.ColumnEnd, CMR.ExpandedFileID, int64_t(CMR.Kind),
125+
CMR.ColumnEnd, TrueConditions, FalseConditions,
126+
CMR.ExpandedFileID, int64_t(CMR.Kind),
115127
gatherConditions(Record)});
116128
}
117129

0 commit comments

Comments
 (0)