Code coverage in C

I want to have code coverage in C. I cannot rely on tools like gcov as I work on different platforms / compilers.

Basically, I'm looking for a strategy to include code coverage in my (own implementation) unit test framework.

+1


source to share


4 answers


It would be very helpful if you update your question to describe the platforms and compilers you are using.

The strategy I have used is to run the system on an emulator that can track all instructions. This trace can then be used to develop code coverage.

On UNIX, you can also start a process using ptrace () one step in the application and thereby capture the executable instructions.



If you just want to keep track of function calls, you can do some nasty hacking of the procedure linkage table to jump into some specialized registration code, but that is probably going crazy.

Again, you need more details about the runtime and level of detail to get a useful answer.

+1


source


Do you have so much platform-specific code that you want to measure the unit test coverage on each platform? What I mean is that unless you have very much platform-specific code, your unit testing coverage should be the same across all of your goals, so you might not need to measure it against every goal you have. It might be interesting to port your platform-specific code to platform-specific modules so that the coverage of the common code is not diminished by specific code.

Are you looking at branch coverage or feature coverage? If the latter you can just use gcc to encode your code so that each function will output its name or its address to a file and write a script to aggregate the results from all platforms.



Sorry for answering questions only ... HTH

+1


source


A page on Code Coverage Tools says that something called GCT by Brian Marik implements code coverage by translating source to source, so you can transform your C code and then build it with your platform-specific compiler. I haven't tracked the details.

+1


source


You can create a suite of test cases as part of the application itself, or as an alternative build target. The application can then test itself, with the added benefit of having access to all internals, instead of trying to test all branches using black box methods.

0


source







All Articles