-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[Code Coverage] Add a tool to check test coverage of a patch #71841
base: main
Are you sure you want to change the base?
Conversation
Moved the code review from Phabricator (https://reviews.llvm.org/D158864) since quite a long we had deprecated Phabricator. |
ddfe0aa
to
724183f
Compare
724183f
to
d454aa5
Compare
Hi All, I have run the tool on GitHub CI for patch - #72273. There are twenty-eight lines not covered by any test case - This is a patch with .ll test case and opt binary. Tomorrow I will run it for a patch with .c & .cpp test case and clang binary and share the result. |
Hi, I have run it for patch - #71894 which is for the clang binary and .c test cases. There are twenty lines not covered by any test case - Here I have to change the way to run the tool - To |
06e5472
to
acadd0e
Compare
I have tested it on an llc binary and .mir test case patch - #72388. It works and shows three lines are not covered for two source files on standard output and there is a log file as artifect which has detailed log of coverage data - https://github.com/xgupta/llvm-project/suites/18461817041/artifacts/1070751301. https://github.com/xgupta/llvm-project/actions/runs/6977269225/job/18986837631#step:5:2602 Also run with ld.lld binary and .s test case for patch - #71248 |
6ba6bfa
to
e3d3e4d
Compare
I realize that it is not working for unit tests. So I wrote a separate function to run them but unlike unit tests of clang, llvm unit tests are not showing up with But I think it should be fine to review and commit this version and then proceed for unit tests coverage in the next step.
|
This script create a patch from the HEAD commit, extract modified or added source files, test case files and source code lines, add coverage instrumentation for the affected source files, runs Lit tests, and records which test cases cause each counter to be executed. Then report the number of test cases executing the counter and the number of test cases executing the counter that are also changed in some way by the patch. Thus providing developer the information of inadequately tested source lines.
91ca211
to
9a86a6e
Compare
Actually, the above issue is because of -DLLVM_BUILD_TESTS=ON flag, using that in cmake, gives the list of all unit tests. I have llvm unit tests patch - #71952 I have clang unit test patch - #71672 |
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.
I don't know much about coverage, but I don't see any reason not to add this.
Actually, added a few reviewers who are contributing to LLVM Python code, just to make sure it is following the correct coding practices. I haven't worked on Python before this. |
I know we are not doing this right now, but I wonder if we should have tests for python scripts as well so that we can run it with our supported python version and see if it works, because it can be hard to spot in a review. I will make a sweep on the code later today. |
I am very much in favor of starting to add tests for these utilities. I wouldn't block this patch on having tests, but it's definitely a good practice in general. It's on my todo list to get tests up and running for |
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.
Quite a few nits, lots of other comments on my initial pass.
This looks like it could be pretty useful. Thanks for putting this together! I'm envisioning this as an on demand job that can be run on a PR with a rich representation reported in a comment (something to be added later) could be a pretty good litmus check for a lot of things.
One question: It seems like this doesn't currently cover cases where only source files or only test files are touched. Just looking at test files might be difficult as there's no way to know what to report. But, looking at just source files I think would be doable (would just require running the whole test suite, not sure how expensive this is) and would be really useful for refactorings and probably other cases.
This Python script creates a patch from the HEAD commit, extracts modified or added source files, test case files, and source code lines, adds coverage instrumentation for the affected source files, runs Lit tests, and records which test cases cause each counter to be executed. Then report the number of test cases executing the counter and the number of test cases executing the counter that are also changed in some way by the patch. Thus providing the developer the information of inadequately tested source lines.