I do system testing of various embedded software(Embedded C) which runs on a microcontroller. How to take a code coverage report in this case as we run the software on the micro and not on a pc?

At this point we cannot afford a simulation model of the system.(I know this makes it easy to have a coverage tool, simulator and tests run together on PC and get a coverage report).


2 Answers 2


Depending what your code does, you may be able to compile it for x86 architecture to run your unit tests and use traditional code-coverage tools; anything written for C will work in that case. This assumes you're not using any of the peripherals of the embedded processor; otherwise, you may need to write a wrapper layer to simulate them, but then, you'd probably want to do that in your unit test framework in order to adequately simulate the external dependencies of the program anyway. Inline assembly instructions would also prevent this technique from working, of course.

You may be able to break up the code into modules and test some modules on x86 with code coverage tools running while others have to be tested on the device and thus cannot have the code coverage counted. You may be able to use techniques in other answers to measure the coverage of code that is not able to run on an x86 processor. It depends how well you've designed your code.


Your question doe not provide insight on the feature/facilities available and restrictions if any, for the development environment. As any solution will depend on the what are the capabilities of development environment. Its difficult to have fit all solution like what is possible for PC or web based system.

If real time requirements are not too stringent on your system, you can write a per-processor which will insert counters at the start and end of every function to start with (and at the start and end of every control path in advanced version). Once it is in place you can write offline program on PC to map counters with code. All nonzero counters shows control path traveled and count indicates how many times particular control path has been hit.

However this is effort consuming approach and will be useful if you think return on investment is justified.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.