-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[llvm-cov] Export decision coverage to output json #144335
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! |
@uthmanna Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/18553 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/175/builds/20563 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/185/builds/20421 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/20622 Here is the relevant piece of the build log for the reference
|
This reverts commit ab6beec.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/187/builds/7050 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/27990 Here is the relevant piece of the build log for the reference
|
Hi @uthmanna, I apologize, but I ended up reverting the merge commit due to unresolved test failures. Specifically, |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/17601 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/18084 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/25283 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/21714 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/155/builds/10228 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/18649 Here is the relevant piece of the build log for the reference
|
Reverts #144335 Need to resolve test failures
…" (#144783) Reverts llvm/llvm-project#144335 Need to resolve test failures
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/19461 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/19604 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/21088 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/28783 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/30629 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/35256 Here is the relevant piece of the build log for the reference
|
) Reverts llvm#144335 Need to resolve test failures
@evodius96 Oh, sorry, I overlooked that. Yes, I will adjust/add it. I assume I have to open a whole new PR, right? |
Actually, I do think you need to open a new PR, referencing this one. Sorry about that! I couldn't remember the last time I had to reland a change. |
No problem, it was my mistake. I'll start a new one. |
…#145325) Tests fixed 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
…)" (llvm#145325) Tests fixed 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
…)" (llvm#145325) Tests fixed 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
This commit adds decision coverage to the JSON output of llvm-cov, as discussed here: Missing Decision Coverage (DC) in output json with @evodius96