Skip to content

Commit ab6beec

Browse files
uthmannauthmanna
andauthored
[llvm-cov] Export decision coverage to output json (#144335)
This commit adds decision coverage counts derived from MC/DC test vector execution to the JSON output of llvm-cov, as discussed here: [Missing Decision Coverage (DC) in output json](https://discourse.llvm.org/t/missing-decision-coverage-dc-in-output-json/86783) with @evodius96 --------- Co-authored-by: uthmanna <[email protected]>
1 parent 8c3fbaf commit ab6beec

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/Support/Endian.h"
3232
#include "llvm/Support/Error.h"
3333
#include "llvm/Support/raw_ostream.h"
34+
#include <algorithm>
3435
#include <cassert>
3536
#include <cstdint>
3637
#include <iterator>
@@ -494,6 +495,17 @@ struct MCDCRecord {
494495
return TV[TestVectorIndex].first[PosToID[Condition]];
495496
}
496497

498+
/// Return the number of True and False decisions for all executed test
499+
/// vectors.
500+
std::pair<unsigned, unsigned> getDecisions() const {
501+
const unsigned TrueDecisions =
502+
std::count_if(TV.begin(), TV.end(), [](const auto &TestVec) {
503+
return TestVec.second == CondState::MCDC_True;
504+
});
505+
506+
return {TrueDecisions, TV.size() - TrueDecisions};
507+
}
508+
497509
/// Return the Result evaluation for an executed test vector.
498510
/// See MCDCRecordProcessor::RecordTestVector().
499511
CondState getTVResult(unsigned TestVectorIndex) {

llvm/tools/llvm-cov/CoverageExporterJson.cpp

Lines changed: 4 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"
@@ -110,8 +110,10 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {
110110

111111
json::Array renderMCDCRecord(const coverage::MCDCRecord &Record) {
112112
const llvm::coverage::CounterMappingRegion &CMR = Record.getDecisionRegion();
113+
const auto [TrueDecisions, FalseDecisions] = Record.getDecisions();
113114
return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd,
114-
CMR.ColumnEnd, CMR.ExpandedFileID, int64_t(CMR.Kind),
115+
CMR.ColumnEnd, TrueDecisions, FalseDecisions,
116+
CMR.ExpandedFileID, int64_t(CMR.Kind),
115117
gatherConditions(Record)});
116118
}
117119

0 commit comments

Comments
 (0)