Skip to content
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

CI: Get coverage of filecheck tests #256

Merged
merged 2 commits into from Dec 12, 2022
Merged

CI: Get coverage of filecheck tests #256

merged 2 commits into from Dec 12, 2022

Conversation

webmiche
Copy link
Collaborator

@webmiche webmiche commented Dec 7, 2022

This PR leverages the Coverage package to generate the code coverage of our file checks test suite. Currently, there are a couple of choices that are controversial, which I would like to hear your perspectives. I will add comments to the corresponding locations in the file.

@webmiche webmiche added the CI Continuous Integration label Dec 7, 2022
xdsl/tools/xdsl-opt Outdated Show resolved Hide resolved
xdsl/tools/xdsl-opt Outdated Show resolved Hide resolved
xdsl/tools/xdsl-opt Outdated Show resolved Hide resolved
xdsl/tools/xdsl-opt Outdated Show resolved Hide resolved
xdsl/tools/xdsl-opt Outdated Show resolved Hide resolved
@webmiche
Copy link
Collaborator Author

webmiche commented Dec 7, 2022

Notice that this currently does not include the coverage of tests that depend on the MLIR Pyhton bindings as the coverage is uploaded for the Python-based testing only. We might want to consider automatically updating the coverage once the MLIR-based testing has finished.

@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Base: 81.32% // Head: 77.80% // Decreases project coverage by -3.52% ⚠️

Coverage data is based on head (ce5ea46) compared to base (4d93517).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #256      +/-   ##
==========================================
- Coverage   81.32%   77.80%   -3.53%     
==========================================
  Files          31       38       +7     
  Lines        5510     6023     +513     
  Branches      938     1045     +107     
==========================================
+ Hits         4481     4686     +205     
- Misses        786     1082     +296     
- Partials      243      255      +12     
Impacted Files Coverage Δ
xdsl/xdsl_opt_main.py 0.00% <0.00%> (ø)
xdsl/irdl.py 83.67% <0.00%> (ø)
xdsl/dialects/cmath.py 0.00% <0.00%> (ø)
xdsl/mlir_converter.py 66.37% <0.00%> (ø)
xdsl/dialects/affine.py 62.79% <0.00%> (ø)
xdsl/dialects/llvm.py 75.00% <0.00%> (ø)
xdsl/irdl_mlir_printer.py 0.00% <0.00%> (ø)
xdsl/dialects/cf.py 0.00% <0.00%> (ø)
xdsl/dialects/builtin.py 80.44% <0.00%> (+0.24%) ⬆️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

Yes, I like the direction this is getting!

xdsl/tools/xdsl-opt Outdated Show resolved Hide resolved
xdsl/tools/xdsl-opt Outdated Show resolved Hide resolved
tests/filecheck/lit.cfg Outdated Show resolved Hide resolved
@webmiche
Copy link
Collaborator Author

webmiche commented Dec 9, 2022

Okay, I think I have a design that somehwat makes sense now. Considering that lit seems to be weird around the exec_root thing, I decided to dodge it. I have instead defined two user flags for lit:

  • "-DCOVERAGE" makes filecheck tests generate coverage data
  • "-DCOVERAGE_CONFIG" can be passed to specify the coverage config (in our case xdsl/.coveragerc). I then set this using the absolut path from within the CI, therefore sidestepping the execution root issues.

This also means that the coverage files get created next to the filecheck files. Therefore, the coverage combine command got a bit more involved, specifying all subfolders. If anyone sees a nicer way of doing this, tell me pls :)
I have look into the using **, but wasn't able to get something to work that takes arbitrarily deeply nested subdirectories into account.

The aforementioned flags are passed to xdsl-opt in two steps:

  • firstly, xdsl-opt now has two arguments --generate-coverage and --coverage-config[=PATH], which correspond basically one-to-one to the aforementioned two flags.
  • Secondly, I use custom substitutions in lit in order to substitute %cov to either "" (no coverage flag), --generate-coverage (only DCOVERAGE) or --generate-coverage --coverage-config=[PATH] (both flags).

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

Looks really nice now!
I added some comments, to see if we can make this a bit less error-prone for when we will update it, but that's really cool!

lit -v tests/filecheck/ -DCOVERAGE -DCOVERAGE_CONFIG=$(pwd)/.coveragerc
- name: Combine coverage data
run: |
coverage combine --append tests/filecheck/ tests/filecheck/mlir-conversion/ tests/filecheck/mlir-conversion/with-bindings/ tests/filecheck/irdl-printer/ tests/filecheck/parser-printer/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this here where you can't use ** ?
If this is the case, can we write a small script that automates this instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to coverage combine --append $(find tests/filecheck -type d).

tests/filecheck/lit.cfg Outdated Show resolved Hide resolved
@math-fehr math-fehr self-requested a review December 9, 2022 15:47
Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

Looks good to me!
Should we merge this now, or do you still want to add something else to it?

@webmiche
Copy link
Collaborator Author

webmiche commented Dec 9, 2022

I want to make sure that the code coverage is properly uploaded since I'm not 100% sure how this exactly works.

@webmiche
Copy link
Collaborator Author

webmiche commented Dec 9, 2022

Yes, as somewhat expected/feared the .xml file was not found to upload. I will look into this on my way home, hoping I can fix it in time. O/w, we might have to wait until monday to merge this.

If I succeed, I will just merge :)

@webmiche
Copy link
Collaborator Author

webmiche commented Dec 9, 2022

This is extremely weird. If I hard code the path to the file, it works. However, if I try to use the environment variable (so how a sane person would do it), the file is not found. Currently, I am trying to not pass a path and hope it works magically.

If not, I will probably look into this again on Monday and merge it then...

@webmiche
Copy link
Collaborator Author

webmiche commented Dec 9, 2022

Well, it found everything, only the one it should have is missing...

@math-fehr
Copy link
Collaborator

Thanks a lot for all this work. Personally, I don't really know how these things work, but I can take a look if you want!

@webmiche
Copy link
Collaborator Author

webmiche commented Dec 9, 2022

I think I am getting closer. Now, the file is discovered, but it seems that some of the tests are not taken into account. That's why the coverage drops by so much...

@webmiche
Copy link
Collaborator Author

webmiche commented Dec 9, 2022

Noting for my future self: There are two issues atm: Both lit and pytest act like they didn't have the Python Bindings installed. Additionally, the ${GITHUB_WORKSPACE} env variable seems weird, and pytest hsa the wrong root directory.

@webmiche
Copy link
Collaborator Author

webmiche commented Dec 12, 2022

Okay, I think this is about to get finished. I had one run earlier that behaved the way I wanted it too. Notice that we now lose some coverage as I have specified the source directories, so non-executed files are counted as 0% coverage. Furthermore, coverage is now generated on the MLIR CI.

Side thought: We might want to think about what to do with all the __init__ files, as they count towards coverage now, but actually aren't possible to cover 100% within one CI run.

@webmiche webmiche merged commit 98fce5b into main Dec 12, 2022
@webmiche webmiche deleted the filecheck_coverage branch December 14, 2022 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make code coverage CI take filecheck tests into account
3 participants