This section explains how to integrate C/C++test with MSBuild to collect code coverage in Visual Studio.
Integration with MSBuild is supported for C/C++test 32-bit.
Installation
The following instructions assume that [INSTALL_DIR] refers to the C/C++test installation directory. The default name of this directory is cpptest.
To integrate the Parasoft coverage functionality with MS Build:
- Add the CPPTEST_HOME environment variable pointing to [INSTALL_DIR] directory.
- Add the [INSTALL_DIR]/bin directory to your PATH variable to ensure access to the cpptest.dll library.
- Go to the [INSTALL_DIR]/integration/msbuild directory.
- Copy the parasoft-coverage.xml and parasoft-coverage.props files to the directory that contains your Visual Studio solution.
- (Optional) Add the parasoft-coverage.xml and parasoft-coverage.props files in the solution directory to source control.
- Open your solution with Visual Studio.
- Go to View> Other Windows> Property Manager.
- Select the solution projects or specific build configurations of the projects for which you want to generate a coverage report.
You might want to create dedicated build configurations that will be used only for the purpose of collecting coverage.
- Right-click the selected projects or configurations, choose Add Existing Property Sheet… from the context menu and point to the parasoft-coverage.props file in your solution directory.
If you select a project, the file will be added to all test configurations in the project. In the above example, the file will be added to all four configurations in the ATM project, and only two selected configurations in the BugDetective project.
Configuration
You can configure code instrumentation with Property Pages on the level of your project, configuration, or the parasoft-coverage.props file.
To configure code instrumentation:
- Double-click the project, configuration, or the parasoft-coverage.props file to open its Property Pages.
- If you modify the Property Pages from the project level, select the test configuration and the platform from the drop-down menu. Your settings will only apply to the selected configuration.
Go to Configuration Properties> Parasoft C/C++test to select the settings from the drop-down menus; see General Settings.
General Settings
Name | Value | Description |
---|---|---|
Engine Location | [path] | Specifies the location of C/C++test. The default is the value set for your CPPTEST_HOME environment variable. |
Compiler Configuration | [complier configuration] | Specifies the configuration of your compiler. The default is AutoDetect . |
Workspace Location | [path] | Specifies the directory that contains data used to generate the coverage report. The default is your solution directory location. |
Coverage Settings
Name | Value | Description |
---|---|---|
Line Coverage |
| Allows you to enable or disable collecting coverage during a build. This option is enabled by default. |
Advanced Settings
Name | Value | Description |
---|---|---|
Enable Coverage Optimization |
| Allows you to enable or disable coverage optimization. If enabled, execution time overhead will be reduced. This option is enabled by default. |
Enable Optimized Coverage Corruption Detection |
| Allows you to enable or disable optimized coverage corruption detection. Requires the Coverage Optimization option to be set to If enabled, it allows detection of corrupted coverage memory buffers, which are used when the Coverage Optimization is enabled. This option is disabled by default. |
Enable Coverage Early Initialization |
| Allows you to enable or disable coverage early initialization. If enabled, the process of collecting coverage will start automatically. If disabled, the process must be initiated manually. This option is enabled by default. Contact Parasoft Support for more information about manual initialization of collecting coverage. |
Enable Coverage Auto-Finalization |
| Allows you to enable or disable automatic coverage finalization. If enabled, the process of collecting coverage information will be finalized automatically. If disabled, the process must be finalized manually. This option is enabled by default. Contact Parasoft Support for more information about manual finalization of collecting coverage. |
Important
If the settings selected on the project or configuration level differ from the settings specified on the parasoft-coverage.props level, the project or configuration level settings will have priority and will be used during the build. The settings selected on a given level are in bold, whereas the settings inherited from the higher level are in a regular font.
Build and Execution
To build your code-instrumented application and collect coverage information during a run of the executable:
- Ensure the Line Coverage option in Configuration Properties> Parasoft C/C++test> Coverage Settings is enabled (see General Settings).
- Choose the configuration and platform you want to use for the run from the drop-down menus on the Visual Studio toolbar.
- Run a clean build of your project.
- Run the executable that was built. You can run the executable from the command line, with the Visual Studio Debugger or in any other way required for your project.
A.clog
file that contains coverage information will be generated in your current working directory. The default name of the file iscpptest_results.clog
.
Reporting
You can generate coverage reports from the command line or on desktop.
Generating a Coverage Report from the Command Line
Go to your solution directory.
Run
cpptestcli.exe
with the Coverage built-in configuration and the.clog
file as an input. Your command may resemble the following:cpptestcli.exe -config "builtin://Coverage" -input ATM/Debug/cpptest_results.clog
Review the XML and HTML coverage reports which are generated in the reports subdirectory of your solution directory.
Important
If your configured workspace location is different than the default solution directory, use the -workspace switch with the path to the directory that is specified as workspace location.
Generating a Coverage Report on Desktop
- In Visual Studio, go to Parasoft> Options> Engines.
- Ensure that C/C++test is enabled and its location is configured.
Enter a new set of parameters in the Arguments field to reconfigure the run:
-${configuration}
: Uses the test configuration specified in the Parasoft> Configuration settings. Ensure that the active test configuration is set to Coverage; see Setting the Active Test Configuration.
--input <path/to/file.clog>
: Specifies the path to the.clog
file that contains coverage information.
- (optional)${scope}
: Uses the current UI selection to set the scope and allows you to report coverage for individuals projects or files selected in Solution Explorer.Important
Ensure that your coverage Workspace is the same location as the plugin Working directory. In case the locations are different, provide the
–workspace <path/to/workspace>
parameter in the Arguments field.Run the Coverage built-in configuration on your selected projects.
- Select the Generate reports check box in the pop-up window when the run is completed. You can use the Configure… link to specify report configuration settings.
- View the generated report in the Visual Studio main window.
Removing the Parasoft Integration
To uninstall the parasoft-coverage property sheet:
- Go to View> Other Windows> Property Manager.
- Browse the projects and configurations for the parasoft-coverage.props files you want to remove. The files must be removed manually from individual configurations.
Right-click the selected files and choose Remove from the context menu.
The parasoft-coverage.props files will be removed only from the project configurations you selected.