-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Import coverage generation module from Zephyr #17000
base: master
Are you sure you want to change the base?
Conversation
This allows generating coverage information on real hardware (not just native) for GNU Gcov. The imported `sys/coverage` module writes coverage information on `exit()` to the UART. The output generated by `sys/coverage` can then be parsed using the `dist/tools/coverage/coverage.py` script which generates `.gcda` files from the output. These files can then be passed to Gcov frontends like gcovr or lcov to generate HTML coverage visualizations. See: * https://docs.zephyrproject.org/1.14.1/guides/coverage.html * https://github.com/zephyrproject-rtos/zephyr/tree/main/subsys/testsuite/coverage * https://github.com/zephyrproject-rtos/zephyr/blob/main/scripts/gen_gcov_files.py
For some reason, GCC does not refrain from instrumenting functions with the `interrupt` attribute by default. Instrumenting the RISC-V interrupt handler causes a load page fault for some reason. I didn't run into this on the nucleo-f401re but not sure if it affects architectures other than RISC-V.
Would it make sense to provide a
BTW, is it possible to combine the results of the coverage tests? If so we could integrate that into our CI in the future, maybe. |
I guess that would then be |
It should theoretically be possible to ship the coverage generation code from Zephyr in
What do you mean by combine? |
E.g. if I run |
Ah, I think there are some Gcov frontends which allow merging coverage data. For example lcov allows merging multiple trace files by passing |
Indeed, but given that Zephyr did not put it in its own repository, that seems indeed to be overkill... How long does the fetch take with |
just copy those files over |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Ping @nmeum? |
Ping? I ran into a situation where I would be very interested in that :-) |
Sorry, I didn't have the time to work further on this so far. However, last time I used this it did actually work fine. Is there anything that I need to do apart from rebasing and resolving merge conflicts? :) |
From #17000 (comment)
and then the conclusion #17000 (comment)
Not sure if this was addressed. Other than that, I guess the dedicated make target and the merging of coverage data from several tests can be addressed in a separate PR, once this is in place. |
Oh, now after looking at the code again, maybe, instead of adding the dumping to the |
This includes support for GCC 12. While at it, also make the RIOT CI happy.
I also tested the current version again using With this board, I was able to successfully generate coverage for @miri64 could you take another look and maybe test if it also works for you? :) |
@@ -1,5 +1,33 @@ | |||
# Debugging Tools {#debugging-tools} |
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.
Not sure if this is the best subsection for the coverage documentation.
Maybe it makes sense to rename this to Developer Tooling
or something along those lines?
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 like how little changes this needs in the code base.
Just some CI nits and a rebase is needed, I think this is then good to merge.
Applied @benpicco's suggestions (thanks!) and rebased against master. |
CI still has come complaints about formatting. |
Please squash |
Please add a test application that makes use of the If the call to It would only work if the test is run in the main thread, but I think that's the case for the kind of coverage reports we could create here. |
Good idea, will do so later.
No, it's no longer mandatory. I haven't updated the original PR description. See the Doxygen Documentation and #17000 (comment) |
Added a preliminary coverage test application which checks that a coverage dump is properly performed. Ideally, it would also be cool to check the validity of the obtained data by generating gcov files via |
When I run
Could this be solved by adding the |
This is not intended to be run on
Sounds promising, I will look into it. |
FYI (since AFAIK @nmeum is not on the forum): https://forum.riot-os.org/t/unit-test-code-coverage-using-gcov/2387/7 |
Contribution description
This PR imports a slightly modified version of the coverage generation code from Zephyr and allows generating coverage information on real hardware (not just native) for GNU Gcov. The imported
sys/coverage
module writes coverage information onexit()
to the UART. The output generated bysys/coverage
can then be parsed using thedist/tools/coverage/coverage.py
script which generates.gcda
files from the output. These files can then be passed to Gcov frontends like gcovr or lcov to generate HTML coverage visualizations.See also:
Testing procedure
A simple test can be performed with a
hello-world
application modified as follows:Compile the application as follows:
Flash the application using:
Afterwards wait a few seconds and run
make term
as follows:Reset the board and wait until
GCOV_COVERAGE_DUMP_END
appears in the output, close the terminal as soon as it does and run the following command:If you see errors about invalid UTF-8 sequences, check the
log.txt
and remove these manually for now and re-run the script (see To-Do below). If the script terminates successfully, this should cause various.gcda
files to be generated (find . -name '*.gcda'
). These files can then be passed to a Gcov frontend (e.g.gcovr
) to generate HTML files:Finally open
coverage.html
in a web browser.To-Do
I think the tooling could be improved significantly. For example, a
make coverage
target which works similar tomake term
but invokes the./dist/tools/coverage/coverage.py
script directly and terminates as soon as it seesGCOV_COVERAGE_DUMP_END
would be nice to have IMHO. Furthermore, I occasionally noticed UTF-8 decode errors when using the python script since resetting the board sometimes causes invalid UTF-8 sequences to be generated. This should probably be addressed as well. In general, I haven't tested this a lot yet and would welcome general feedback on the idea and the integration.