Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do code coverage on embedded

I write a project for a non POSIX embedded system so I cannot use gcc option --coverage (i don't have read or write). What else can I do to produce gcov like output. I do have an output function.

like image 551
Guy Avatar asked Dec 19 '11 17:12

Guy


2 Answers

It can be most easily done with by a processor with embedded trace, a board design that exposes the trace port, and a suitable hardware debugger and associate software. For example, many Cortex-M based devices include ARM's embedded trace macrocell (ETM), and this is supported by Keil's uVision IDE and ULINK-Pro debugger to provide code coverage and instruction/source level trace as well as real-time profiling. Hardware trace has the advantage that it is non-intrusive - the code runs in real-time.

If you do not have the hardware support, you may have to resort to simulation. Many tool-chains include an instruction level simulator that will perform trace, code-coverage, and profiling, but you may have to create debug scripts or code stubs to simulate hardware to coerce the execution of all paths.

A third alternative is to build the code on a desktop platform with stubs to replace target hardware dependencies, and perform testing and code coverage on that. You have to trust that the target C compiler and the test system compiler both translate the source with identical semantics. The advantage here is that the debug tools available are often superior to those available to embedded systems. You can also test much of your code before any hardware is available, and in most cases execute code much faster, possibly allowing more extensive testing.

Not having a POSIX API does not preclude using GCC, it merely precludes using the GNU C library. On embedded systems without POSIX, alternative C libraries are used such as Newlib. Newlib has a system porting layer where I/O and basic heap management are implemented.

like image 163
Clifford Avatar answered Oct 26 '22 07:10

Clifford


Disclaimer: The company (Rapita Systems) I work for provides a code coverage solution aimed at embedded applications.

Because embedded systems bring their own, special and widely varying requirements, the "best" solution for code coverage also varies widely.

  • Where you have trace-based devices, like ARM chips with ETM or NEXUS-enabled parts, you can perform coverage without instrumentation via debuggers.
  • Otherwise, you are most likely faced with an instrumentation-based solution:
    • For RAM-limited solutions, a good solution is to write instrumentation to an I/O port
    • Alternatively, you can record instrumentation to a RAM buffer, and use a wide variety of means to extract this from the target.

Of course lots of different flavours of code coverage are also available: function, statement, decision/branch, MC/DC

like image 26
Andrew Coombes Avatar answered Oct 26 '22 07:10

Andrew Coombes