Code Coverage

From Texas Instruments Wiki
Jump to: navigation, search

Code Coverage in CCSv4/v5

Code Coverage provides coverage data for all functions for the complete run of a program. Note that the code coverage feature describe below is only supported on simulators.

Note: target application must be built with minimal debug option turned on for profiling/Code Coverage to work ([Project Properties]->Tool Settings->Basic Options->Debug model should be set to symdebug:skeletal or symdebug:dwarf). For RTSC project, use 'debug' configuration ... WHOLE_PROGRAM_DEBUG will not work.

Note: Code coverage supports the targets listed in this FAQ entry.

Enable Code Coverage

  • Goto Menu Tools->Profile->Setup Profile Data Collection and select Collect Code Coverage and Exclusive Profile Data
  • Click on properties to select the events to be collected along with code coverage.

Profile setup4.jpg

  • Load the application & run.

Code Coverage Result

  • To view the code coverage results, click Menu Tools->Profile->View Code Coverage Results. Function Coverage & Line Coverage window will pop-up.

Profile output1.jpg

  • To highlight Line coverage info inside the editor window, click on Highlight coverage info in editor icon on the Function Coverage & Line Coverage window.

Profile output2.jpg

Profile Control Points

Profile Control Points enable to collect Function Profiling/Code Coverage for a range or functions. Profile control point works similar to a breakpoint and can be set via Unified Breakpoint Manager (UBM).

  • Click on new breakpoint drop-down menu & select Profile Control Point

Profile control2.jpg

  • Profile Control point menu will pop-up. Need to specify the address & action. Actions are Pause Profiling , Resume Profiling & Terminate Profiling.
    • Pause Profiling - Pause collecting profile informations
    • Resume Profiling - Resume collecting profile informations
    • Terminate Profiling - Stops/Terminate collecting profile informations

Profile control1.jpg

Note: Simulator will not halt at these profile control points and Profiler need to be enabled at the beginning.

Code Coverage in CCSv3.3

Code Coverage is supported on CCSv3.3 as well.


Q. In an old code coverage user guide (spru624) I see a limitation that Code Coverage does not work for programs compiled with dwarf debug info. Is this valid anymore?

This is a very old document and has been removed from external web. Code coverage indeed works with dwarf debug info and has been the way for years now. The older doc had the limitation as dwarf was just getting introduced at that time.

Q. Can I gather Code Coverage results on non-terminating applications (e.g. BIOS-based apps)?

Yes (note that BIOS-based applications are "non-terminating" as they simply enter the idle loop when there is nothing that can be run).

  • Enable Code Coverage & run the applications till a logical point where you want to stop collecting coverage result.
  • Place Profile Control Point for "Terminate Profiling" at that locations.
  • Once you cross the profile control point, click Menu Tools->Profile->View Code Coverage Results to view the coverage result.

Alternative method:

  • Enable Code Coverage & run the applications till a logical point where you want to stop collecting coverage result.
  • Click reset->CPU & click Menu Tools->Profile->View Code Coverage Results to view the coverage result.

Q. How do I view coverage for inline functions?

Functional coverage for inline functions can be viewed indirectly. When you build a project containing inline functions with the ‘-g’ build option, inline functions behave as normal functions and do not become inline at places where they are called. For example, assume you have a source file called file1.c with the following code:

inline float volume_sphere(float r) {

return 4.0/3.0 * PI * r * r * r; 


int foo(...) {

volume = volume_sphere(radius); 


If the above source file is build with the ‘-g’ option, then the function volume_sphere would not behave as an inline function. If code coverage was run for this project, the volume_sphere function would be listed in the Function Coverage table (summary worksheet in CCS3.3). However, the function would not behave as an inline function. If the project is built with the Release configuration build option, the functions specified with an inline keyword will retain their inlining behavior.

Q. How do I view code coverage for files with the same name in a project?

Currently, the Code Coverage tool feature only supports functional coverage for the functions listed in files that have identical names. Line coverage for these files is reported incorrectly. It is recommended not to use files with the same name in a project.

Q. Why do I see multiple entries for the same function in the Function Coverage table?

A static function is listed in the assembly as many times as it is called. This is valid for static functions declared and defined in the header file. Therefore, functional coverage is listed for each call of the static function