-
Notifications
You must be signed in to change notification settings - Fork 263
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
add code coverage support for ghdl #627
Conversation
The "36-unit" tests fails, and I don't understand why. The failures occurred due to me putting the check_output function within the |
Hi @ludli505! Incidentally, some weeks ago I tried to extend the existing coverage example, which is currently supported for non-GHDL simulators only. My motivation and work-in-progress have some subtle differences with yours, hence please bear with me:
Overall, I'd be glad if you could have a look at that WIP. Nonetheless, it would be good to split the modifications in this PR into multiple smaller commits that are easier to review. One of the targets (to detect if GHDL's backend supports coverage) is common to both implementations; while moving the results is considered here only. Regarding the issue with modifying the Lines 275 to 325 in a45f4d4
as this seems to be specific to GHDL. Is it expected to be used with other simulators too? |
Thanks for your feedback! I'll look through your WIP later today, and split into multiple commits. I've found two issues with my changes: Problem 1 The alternative is to have gcov merge all the results while running the tests. If the user has specific requirements on which coverage to merge they'd have to make sure to clean any previous test outputs and run the specific tests desired. For me personally it seems better this way than to have the merging be super-slow. Do you agree that I should change it? Problem 2 |
@ludli505 it's really interesting, I use code coverage in GHDL regularly. And we support it in @TerosTechnology https://youtu.be/tgr1KGIitIQ?t=170 I have the same problem that you with the output folders. If I could choose (regardless of performance):
Actually I do --clean when I want to regenerate the code coverage. But it's really slow when I have to compile a lot of libraries... |
|
I've now added |
Simulation now puts the compile-time gcno with the compiled .o-files, and run-time gcda folders within the output folder for each test Each test case produces a separate .gcda file.
examples/vhdl/coverage/run.py
Outdated
LIB.set_compile_option( | ||
"ghdl.a_flags", ["-g", "-O2", "-fprofile-arcs", "-ftest-coverage"] | ||
) | ||
LIB.set_sim_option("ghdl.elab_flags", ["-Wl,-lgcov"]) |
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.
To follow the convention in e.g. modelsim.py:258 this option should be moved to the ghdl interface class and be enabled based on the enable_coverage
sim option.
Maybe ghdl.a_flags
should be handled the same way. For riviera and modelsim the user has to manually set compile option since they have to make a decision on what coverage to enable. For ghdl that choice is not there, so ghdl.a_flags
could be set in the class solely based on enable_coverage
sim option.
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 was my original idea, but I opted not to do it as it seems like the enable_coverage
sim option should not affect compilation.
But it would be more convenient, I'll change it.
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.
The sim option -Wl,-lgcov
, has now been moved into ghdl.py
The compilation function only works on the SourceFile
object, which is neat but means that the enable_coverage
simulation option is not conveniently available. I've added a new enable_coverage
compilation option. This also means that coverage may be enabled only for the desired files. Proof of concept on my tsfpga branch
Co-Authored-By: Lukas Vik <10241915+LukasVik@users.noreply.github.com>
Co-Authored-By: Lukas Vik <10241915+LukasVik@users.noreply.github.com>
I have reviewed it again and think it looks good to merge. It works well, both in the |
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.
Currently example coverage is not added to acceptance tests. Would you mind adding eine@3e16fc5#diff-ec10270706c0b42d3ef658d092217a3a to this PR?
It seems that Problem 1 from #627 (comment) is not an issue anymore, is it? What about Problem 2?
Overall, I think it is good to merge (after these minor issues are fixed). However, I am unsure about how to handle backwards compatibility. @LarsAsplund, @kraigher, as commented above, "this change will break the workflow of those who expect the output to just appear in the default location". Should we wait to merge this when we bump to v5.0.0
or is it ok to include it in v4.4.0
?
@eine, thanks for your review. I've updated according to your comments.
Done as well
That problem still exists. I've not looked into if this can be solved in GHDL. I consider it a separate problem.
After reading your comment, I realized that only one additional check for |
@ludli505, so quick! Thanks!
Fair enough!
Can you please add a very brief description about this? Ideally, something should be added to the docs (in http://vunit.github.io/py/opts.html#simulation-options and/or vunit.github.io/py/vunit.html#vunit.ui.results.Results.merge_coverage). However, I think it is ok with adding a description to the commit message, at least. |
My last commit adds description of the new Is that the information you're looking for or did I miss something? Cheers! |
That's exactly what I was looking for. Thanks! |
This adds:
Each test case produces a separate .gcda file, and it is then left to the user to merge them as desired. This is in line with what is desired in issue #437.
This change will break the workflow of those who expect the output to just appear in the default location. For compilation these users would currently have problems with the gcno files not being updated at recompile (which is the main reason for this change). For simulation, maybe I should change the behaviour so that vunit only controls the run-time .gcda if the "enable_coverage" flag is set?
Feel free to bash on the code, I'm not a Python wizard and think it needs some feedback :-)