Keil Logo

COVERAGE GCOV Export

Export coverage files in gcov tool format using the COVERAGE command:

COVERAGE GCOV module // generate the report for a single module
COVERAGE GCOV *      // generate the report for all modules

µVision exports module.gcov files for each module and places the generated files into the project's Output folder.

Example output

     -:     0:Source:../main.c
     -:     0:Graph:
     -:     0:Runs:1
     -:     0:Programs:1
     -:     1:#include <stdio.h>
     -:     2:
     -:     3:int main (void)
     1:     4:{
     1:     5:  int i = 1;
     -:     6:
     1:     7:  while (i < 10) {
     9:     8:          if (i % 3 == 0)
     3:     9:                  printf ("%d is divisible by 3\n", i);
     9:    10:    if (i % 11 == 0)
######:    11:      printf ("%d is divisible by 11\n", i);
     9:    12:          i++;
     -:    13:    }
######:    14:   return 0;
     -:    15:}

The first column shows whether a line has been executed (including the number of times) or not (#####). Irrelevant lines are marked with -. The second column shows the source file's line number, while the third column shows the actual code.

The GCOV output matches the display in the µVision debugger:

Code coverage in µVision Debugger

Note

For details on the code execution markers, refer to Disassembly Window.

Branch coverage

Branch coverage provides details about execution of conditional instructions. For example, given an if statement, have both the true and false branches been executed? To generate a GCOV report that includes branch coverage information, use the DETAILS option of the COVERAGE command:

COVERAGE GCOV * DETAILS

Example output

     -:     0:Source:../main.c
     -:     0:Graph:
     -:     0:Runs:1
     -:     0:Programs:1
     -:     1:#include <stdio.h>
     -:     2:
     -:     3:int main (void)
     1:     4:{
     1:     5:  int i = 1;
     -:     6:
     1:     7:  while (i < 10) {
branch 0 executed 1
branch 1 skipped 1
branch 2 executed 1
branch 3 skipped 1
branch 4 executed 0
branch 5 skipped 1
     9:     8:          if (i % 3 == 0)
branch 0 executed 1
branch 1 skipped 1
     3:     9:                  printf ("%d is divisible by 3\n", i);
     9:    10:    if (i % 11 == 0)
branch 0 executed 0
branch 1 skipped 1
######:    11:      printf ("%d is divisible by 11\n", i);
     9:    12:          i++;
     -:    13:    }
######:    14:   return 0;
     -:    15:}

For each conditional instruction at least two 'branch' lines are added:

branch (seq_number) executed {0|1}    // marks branch path taken: false=0, true=1
branch (seq_number) skipped {0|1}     // marks branch path not taken: false=0, true=1

GCOVR

gcovr is an open-source tool that generates summarized code coverage reports in various formats, such as HTML for display in a browser, or XML for further processing using a Jenkins server:
Code coverage report
This report was generated from the GCOV file above using the following command line:

gcovr -v -gk --html --html-details -o coverage.html -s

The report is showing the same data as before, in a slightly different way:

  • The header shows a summary of the source file that is displayed.
  • The "Line" column shows the line number.
  • The "Branch" column shows the branches that have been executed (✔) or skipped (x). This corresponds to the entries in the GCOV file.
  • The "Exec" column shows how often a certain line has been executed.
  • The "Source" column shows the actual source code.
  • Green lines have been executed while red lines have not been.

Note

While µVision is capable of merging multiple coverage runs internally (using the COVERAGE SAVE/LOAD command), this only works as long as the executable has not been changed. gcovr is able to merge different GCOV files. With the source code, it can generate merged coverage reports from multiple test runs.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.