Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ struct MCDCRecord {
return TV[TestVectorIndex].first[PosToID[Condition]];
}

/// Return the executed test vectors.
const TestVectors &getTV() const { return TV; }

/// Return the Result evaluation for an executed test vector.
/// See MCDCRecordProcessor::RecordTestVector().
CondState getTVResult(unsigned TestVectorIndex) {
Expand Down
16 changes: 14 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 @@ -108,10 +108,22 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {
return Conditions;
}

std::pair<unsigned, unsigned> getDecisions(const coverage::MCDCRecord &Record) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As a design consideration, I'm reluctant to bring knowledge of test vectors into the Exporter and would favor encapsulating the calculation of the number of True and False test vectors within coverage::MCDCRecord. Basically, move getDecisions() into coverage::MCDCRecord. That routine can still return a pair of numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable, I've moved it, hope it's OK.

const coverage::MCDCRecord::TestVectors &TestVectors = Record.getTV();
const unsigned TrueConditions =
std::count_if(TestVectors.begin(), TestVectors.end(), [](const auto &TV) {
return TV.second == coverage::MCDCRecord::CondState::MCDC_True;
});

return {TrueConditions, TestVectors.size() - TrueConditions};
}

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

Expand Down