Best way to achieve 100% line coverage with LCOV for Safety compliance? #38274
Unanswered
JeremyWirzB
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone
My goal:
For my software module, I'm trying to figure out the best way to create a Zephyr unit test, that provides 100% line coverage in one LCOV report, to comply with Safety standards. My module contains code parts, that are included/excluded via kconfig. Therefore, the report should combine the line coverage data of different test runs with different kconfig combinations. In addition, my module is designed as a Zephyr Device Driver. This means there are Device Driver macros (e.g. DT_INST_FOREACH_STATUS_OKAY) used inside my module.
My idea:
My idea to achieve my goal, is by including the C-source-file of my module into the test file and treat it as the File Under Test.
This way, it is possible to use a mocking framework, to mock the APIs used by my module, which is necessary to achieve 100 % line coverage. The only external modules used are "device.h" and the standard C libs. The Device Driver macros should not be a problem, because I expect them to expand to nothing, if I do not add any corresponding nodes to the devicetree. But I'll have to manually construct an instance of the Device Driver (struct device) of my module.
The use of twister allows the creation of the LCOV report over multiple different builds of the test application, built according to the activated kconfigs.
I worry, that LCOV will not recognize my File Under Test at the loacation it is stored, because it was included and compiled inside the test file. If so, the desired line coverage report info would only be available inside the report of the test file, which doesn't seem like a proper solution.
So the test file according to my idea would look something like this:
Does anyone have a better approach to this problem or has improvement propositions to my idea?
Cheers!
Update:
I created a sample unit test according to my idea and it worked. LCOV recognizes my File Under Test at its original location and merges the coverage results of all tests executed in one call of twister. As expected, the Zephyr device macros did not pose a problem. Furthermore, I was able to mock all required device structs and APIs.
Beta Was this translation helpful? Give feedback.
All reactions