...
<INSTALL_DIR>/bin/cpptestcc
- A coverage tool that integrates into your build process to instrument your application to collect raw coverage data.<INSTALL_DIR>/bin/engine/coverage/runtime
- A coverage runtime library that needs to be integrated with the instrumented application.
Collecting coverage with cpptestcc
involves three phases:
- Instrumenting the application by integrating the
cpptestcc
tool into your build. - Executing instrumented code and collecting raw coverage data.
- Reviewing the coverage with C/C++test by importing the raw coverage data into C/C++test with a built-in test configuration.
...
Add the path to
<INSTALL_DIR>/bin
the to thePATH
system variable to enable execution of thecpptestcc
tool.- Update your compilation command to include the
cpptestcc
executable as a prefix to the compiler command using--
as a separator. For example:Original compilation command line
Code Block cc -I app/includes -D defines -c source.cpp
Updated compilation command line
Code Block cpptestcc -compiler gcc_7 -line-coverage -- cc -I app/includes -D defines -c source.cpp
Info At a minimum, the cpptestcc
tool requires the following parameters to be configured on the command line:- a compiler identifier:
-compiler <COMPILER_ID>
- a coverage metric (for example,
-decision-coverage
)See Command Line Reference for cpptestcc for information about other options.
- Update your linker command with the path to the pre-built coverage runtime library shipped with C/C++test to add the library to your application. For example:
Original command line
Code Block lxx -L app/lib app/source.o somelib.lib -o app.exe
Updated command line
Code Block lxx -L app/lib app/source.o somelib.lib [INSTALL_DIR]/bin/engine/coverage/runtime/lib/cpptest.lib -o app.exe
Info icon false title Important If the coverage runtime library is linked as a shared (dynamic-load) library, you must ensure that it can be loaded when the instrumented application is started. This typically requires adding
<INSTALL_DIR>/bin
/engine/coverage/runtime/bin
to thePATH
environment variable (on Windows) or<INSTALL_DIR>/bin
/engine/coverage/runtime/lib
to theLD_LIBRARY_PATH
environment variable (on Linux).Info icon false C/C++test provides the pre-built coverage runtime library for native Windows and Linux applications. For cross-platform and embedded testing, the runtime library needs to built from sources that are available in
<INSTALL_DIR>
/bin/engine/coverage/runtime.
See Coverage Runtime Library for details. - Build the application. When instrumenting the code,
cpptestcc
creates the.cpptest/cpptestcc
folder where important coverage-related data ("coverage maps") are stored. By default, the folder is located in the working directory of the current compilation. You can change the default location using the-workspace <path>
option; see Command Line Reference for cpptestcc for details. - Run the application. The coverage data ("coverage log") will be stored it the
cpptest_results.clog
file. - In your IDE where C/C++test is installed, create a new project that includes all the source files of the application.
Ensure that the files and all the paths remain unchanged.
- Select the project and choose Parasoft> Test Configurations> Utilities> Load Application Coverage from your IDE menu to import the coverage data (see Importing the Coverage Data for details).
- Review the coverage information (see Reviewing Coverage Information).
...
Table of Content Zone | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||
-compiler <name|path>Specifies the name of the compiler configuration you want to use for code analysis and instrumentation. See Compilers for the list of supported compilers or use the Examples:
Configuration file format (see -psrc): -list-compilersPrints out the names of all supported compiler configurations. Configuration file format (see -psrc): -include <file|pattern> and -exclude <file|pattern>Includes into or excludes from the instrumentation scope all the file(s) that match the specified pattern. Final filtering is determined only after all include/exclude entries have been specified in the order of their specification. The following wildcards are supported:
To prevent shells from expanding
Configuration file format (see -psrc): Example 1:Sample project layout:
If your project has the above layout, the following command will exclude all the files in the
Example 2:Sample project layout:
If your project has the above layout, the following command will only instrument the header files (the source files will not be instrumented):
-ignore <pattern>Specifies the source files that will be ignored during processing. The files that match the specified pattern will be compiled, but they will not be parsed or instrumented.
You can use the The following wildcards are supported:
To prevent shells from expanding
Configuration file format (see -psrc): Example:
-line-coverageEnables collecting line coverage. Runtime coverage results are being written to the results log as the code is executed. This imposes some overhead on the tested code execution time, it but it allows you to ensure that that coverage data is collected even if the application crashes. Configuration file format (see -psrc): -optimized-line-coverageEnables collecting optimized line coverage. Runtime coverage results are stored in memory and then written to the results log either after the application finishes or on user request. This results in better performance, but results may be lost if the application crashes. Configuration file format (see -psrc): -function-coverageEnables collecting function coverage. Configuration file format (see -psrc): -optimized-function-coverageEnables collecting optimized function coverage. Configuration file format (see -psrc):
-statement-coverageEnables collecting statement coverage. Configuration file format (see -psrc):
-optimized-statement-coverageEnables collecting statement coverage. Configuration file format (see -psrc): -block-coverageEnables collecting block coverage. Configuration file format (see -psrc): -optimized-block-coverageEnables collecting optimized block coverage. Configuration file format (see -psrc): -path-coverageEnables collecting path coverage. Configuration file format (see -psrc): -decision-coverageEnables collecting decision coverage. Configuration file format (see -psrc): -optimized-decision-coverageEnables collecting optimized decision coverage. Configuration file format (see -psrc): -simple-condition-coverageEnables collecting simple condition coverage. Configuration file format (see -psrc): -optimized-simple-condition-coverageEnables collecting optimized simple condition coverage. Configuration file format (see -psrc): -mcdc-coverageEnables collecting MC/DC coverage. Configuration file format (see -psrc): -call-coverageEnables collecting call coverage. Configuration file format (see -psrc): -optimized-call-coverageEnables collecting optimized call coverage. Configuration file format (see -psrc): -coverage-early-initEnables initializing the coverage module at the beginning of the application entry point. Configuration file format (see -psrc): -coverage-auto-finalizationIf enabled, collecting coverage will be automatically finalized at the application exit. This option is enabled by default. Configuration file format (see -psrc): -optimized-coverage-corruption-detectionEnables corruption detection algorithms for optimized coverage metrics. Configuration file format (see -psrc): -template-coverageEnables collecting coverage for template classes and functions Configuration file format (see -psrc): -workspace <path>Specifies a custom directory where information about code structure will be stored during code analysis and instrumentation. The By default, the information is stored in the working directory of the current compilation. If your compilation uses more than one working directory, we recommend that you specify a custom directory to ensure that all coverage data is stored in the same location. Configuration file format (see -psrc):
Specifies the path to a configuration file where you can configure additional By default,
-versionPrints out information about the version -help Prints out the help message and exits. |
...
File | Description |
---|---|
<INSTALL_DIR>/bin/engine/coverage/runtime/lib/cpptest.a | 32-bit import library to be used with Cygwin GNU GCC compilers. To be added to linking command line. |
<INSTALL_DIR>/bin/engine/coverage/runtime/lib/cpptest64.a | 64-bit import library to be used with Cygwin GNU GCC compilers. To be added to linking command line. |
<INSTALL_DIR>/bin/engine/coverage/runtime/lib/cpptest.lib | 32-bit import library to be used with Microsoft Visual C++ compilers. To be added to linking command line. |
<INSTALL_DIR>/bin/engine/coverage/runtime/lib/cpptest64.lib | 64-bit import library to be used with Microsoft Visual C++ compilers. To be added to linking command line. |
<INSTALL_DIR>/bin/engine/coverage/runtime/bin/cpptest.dll | 32-bit dynamic-link library. <INSTALL_DIR> /bin/engine/coverage/runtime/bin should be added to PATH environmental variable. |
<INSTALL_DIR>/bin/engine/coverage/runtime/bin/cpptest64.dll | 64-bit dynamic-link library. <INSTALL_DIR> /bin/engine/coverage/runtime/bin should be added to PATH environmental variable. |
Linux (x86 and x86-64)
File | Description |
---|---|
<INSTALL_DIR>/bin/engine/coverage/runtime/lib/libcpptest.so | 32-bit shared library. To be added linking command line. <INSTALL_DIR> /bin/engine/coverage/runtime/lib should be added to LD_LIBRARY_PATH |
<INSTALL_DIR>/bin/engine/coverage/runtime/lib/libcpptest64.so | 64 bit shared library. To be added linking command line. <INSTALL_DIR>/bin/engine/coverage/runtime/lib should be added to LD_LIBRARY_PATH |
...
- Locate the linker command line in your build scripts
Modify the build scripts so that the coverage runtime library is specified somewhere in the linker command line - preferably after all object files. For example:
Code Block $(LXX) $(PRODUCT_OBJ) $(OFLAG_EXE)$(PROJ_EXECUTABLE) $(LXXFLAGS) $(SYSLIB) $(EXECUTABLE_LIB_LXX_OPTS) <INSTALL_DIR>/bin/engine/coverage/runtime/lib/cpptest.lib
Ensure that the path to the
lib
directory is added to thePATH
environment variable so that the library can be located when the tested program is started. You may also consider copyingcpptest.dll
(orcpptest64.dll
) file to the same directory as your executable file or to another location that is scanned for dynamic-link libraries during tested application startup.
...
- Locate the linker command line in your build scripts
Modify the build scripts so that the coverage runtime library is specified somewhere in the linker command line - preferably after all object files. For example:
Code Block $(LXX) $(PRODUCT_OBJ) $(OFLAG_EXE)$(PROJ_EXECUTABLE) $(LXXFLAGS) $(SYSLIB) $(EXECUTABLE_LIB_LXX_OPTS) -L <INSTALL_DIR>/bin/engine/coverage/runtime/lib -lcpptest
Note that the
-L
and-lcpptest
options are added.- Ensure that the path to the
lib
directory is added to theLD_LIBRARY_PATH
environmental variable to allow the tested executable to find the path to the shared library.
...