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.
CAUTION:
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:
-
In the Project Explorer view, right-click the project, then click
Properties.
-
In the left pane of the Properties dialog, expand QNX C/C++
project, then click the Options tab.
-
Select Build with Code Coverage.
-
Click Apply, then select the
Compiler tab.
-
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.
-
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:
- -fprofile-arcs
- 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.
- -ftest-coverage
- An option for test coverage analysis that generates a notes file
that the gcov utility uses to show the program's
code coverage.
-
Click Apply, then select the
Linker tab.
-
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:
- -fprofile-arcs
- Same as above.
- -ftest-coverage
- Same as above.
- -p
- 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.
-
Click OK.
-
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.
-
If you clicked No in the previous step, in the Project
Explorer view:
- Right-click your project and select Clean
Project.
- Right-click your project and select Build
Project.