Enable code coverage for a project

You can create a new project or use an existing project to build with code coverage enabled.
CAUTION:
Code coverage uses a signal to tell the application to deliver its information back to the IDE. Depending on the design of the application, there are several possible risks that can result from running code coverage from the IDE:
  • It can modify or break the behavior of applications that are monitored by code coverage.
  • It can cause code to run that a test suite does not actually test.
  • It can result in data not actually being collected at all.
  1. In the Project Explorer view, right-click your project, and then click Properties. The properties dialog for your project appears.
  2. In the left pane, expand QNX C/C++ project, and then select the Options tab.
  3. Select Build with Code Coverage.
  4. Click Apply and then select the Compiler tab.
  5. In the Code generation area, for the Optimization level select the No optimize from the dropdown list.
    Note: Coverage data matches the source files more closely if you do not optimize.
  6. In the Other options area, you'll want to add - Wc ,- fprofile -arcs - Wc ,- ftest -coverage. The result will appear in the Compilation options area and will look similar to the following:
    -O0 -Wc,-fprofile-arcs  -Wc,-ftest-coverage

    where:

    -fprofile-arcs
    Add 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 it's taken or returned from that branch.
    -ftest-coverage
    An option for test coverage analysis that generates a notes file that the gcov code coverage utility uses to show program coverage.
  7. Click Apply and then select the Linker tab.
  8. In the Other options area, you'll want to add -fprofile-arcs -ftest-coverage -p . The result will appear in the Linker options area where:
    -fprofile-arcs
    Same as above.
    -ftest-coverage
    Same as above.
    -p
    Generate additional code to write profile information suitable for the analysis program. This is a required option when compiling the source files you want data for, and you must also use it when linking.
  9. Click the OK.
  10. When prompted to rebuild a project, click Yes if this is the first time building this project; otherwise, click No because you'll want to clean your project before build it with code coverage enabled.
  11. If you clicked No in the previous step, in the Project Explorer view, right-click your project and select Clean Project.
  12. In the Project Explorer view, right-click your project and select Build Project.