-
Notifications
You must be signed in to change notification settings - Fork 14k
[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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-pgo Author: None (uthmanna) ChangesThis commit adds decision coverage to the JSON output of llvm-cov, as discussed here: Missing Decision Coverage (DC) in output json with @evodius96 Full diff: https://github.com/llvm/llvm-project/pull/144335.diff 2 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index d1230b0ba7c58..c9854e08a38e8 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -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) {
diff --git a/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
index 4088c1b053aa8..cae7b86bc6b0c 100644
--- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp
+++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
@@ -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"
/// Unique type identifier for JSON coverage export.
#define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export"
@@ -108,10 +108,22 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {
return Conditions;
}
+std::pair<unsigned, unsigned> getDecisions(const coverage::MCDCRecord &Record) {
+ 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)});
}
|
@@ -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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -108,10 +108,22 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) { | |||
return Conditions; | |||
} | |||
|
|||
std::pair<unsigned, unsigned> getDecisions(const coverage::MCDCRecord &Record) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Do you have access to merge it? If not, I can attempt to merge it on your behalf.
@evodius96 It doesn't look like it, or I can't find it. Feel free to merge them. Thank you! |
This commit adds decision coverage to the JSON output of llvm-cov, as discussed here: Missing Decision Coverage (DC) in output json with @evodius96