Enabling Code Coverage for QNX C/C++ projects

For QNX C/C++ Projects, you can define the necessary compiler and linker options in the QNX C/C++ properties, without having to manually modify the build commands.

Code coverage instrumentation uses a signal to tell the program to deliver its data to the IDE. Depending on your design, the Code Coverage tool poses several risks:
  • It can modify or break the behavior of programs being monitored.
  • It can cause code to run even though the test suite does not actually execute it.
  • It can result in data not actually being collected at all.
To enable Code Coverage for a QNX C/C++ project:
  1. In the Project Explorer view, right-click the project, then click Properties.
  2. In the left pane of the Properties dialog, expand QNX C/C++ project, then click the Options tab.
  3. Select Build with Code Coverage.
  4. Click Apply, then select the Compiler tab.
  5. In the Code generation panel, for Optimization level, select No optimize from the dropdown list.
    Coverage data matches the source files more closely if you do not optimize.
  6. In the Other options text field, add - Wc,- fprofile -arcs - Wc,- ftest -coverage.
    The result appears in the Compilation options area and the flags have these meanings:
    Adds code to ensure that program flow arcs are instrumented. During execution, the program records how many times each branch and call is executed, as well as the number of times a branch is taken or the program returns from it.
    An option for test coverage analysis that generates a notes file that the gcov utility uses to show the program's code coverage.
  7. Click Apply, then select the Linker tab.
  8. In the Other options area, add -fprofile-arcs -ftest-coverage -p.
    The result appears in the Linker options area and the flags have these meanings:
    Same as above.
    Same as above.
    Generates additional code to write profiling information for the program. This is a required option when compiling and when linking the source files you want data for.
  9. Click OK.
  10. When prompted to rebuild your project, click Yes if this will be your first time building it; otherwise, click No because you'll want to clean your project before building it with Code Coverage enabled.
  11. If you clicked No in the previous step, in the Project Explorer view:
    1. Right-click your project and select Clean Project.
    2. Right-click your project and select Build Project.