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: 

  1. Add the CPPTEST_HOME environment variable pointing to [INSTALL_DIR] directory.
  2. Add the [INSTALL_DIR]/bin directory to your PATH variable to ensure access to the cpptest.dll library.
  3. Go to the [INSTALL_DIR]/integration/msbuild directory.
  4. Copy the parasoft-coverage.xml and parasoft-coverage.props files to the directory that contains your Visual Studio solution.
  5. (Optional) Add the parasoft-coverage.xml and parasoft-coverage.props files in the solution directory to source control.
  6. Open your solution with Visual Studio.
  7. Go to View> Other Windows> Property Manager.
  8. 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. 
       
  9. 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: 

  1. Double-click the project, configuration, or the parasoft-coverage.props file to open its Property Pages.
  2. 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.
  3. Go to Configuration Properties> Parasoft C/C++test to select the settings from the drop-down menus; see General Settings.

General Settings

NameValueDescription
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

NameValueDescription
Line Coverage 

Yes

No

Allows you to enable or disable collecting coverage during a build. This option is enabled by default. 

Advanced Settings

NameValueDescription
Enable Coverage Optimization 

Yes

No

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 

Yes

No

Allows you to enable or disable optimized coverage corruption detection. Requires the Coverage Optimization option to be set to Yes.

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 

Yes

No

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 

Yes

No

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:

  1. Ensure the Line Coverage option in Configuration Properties> Parasoft C/C++test> Coverage Settings is enabled (see General Settings).
  2. Choose the configuration and platform you want to use for the run from the drop-down menus on the Visual Studio toolbar.
  3. Run a clean build of your project.
  4. 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 is cpptest_results.clog.

Reporting

You can generate coverage reports from the command line or on desktop.

Generating a Coverage Report from the Command Line

  1. Go to your solution directory.

  2. 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 
  3. 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

  1. In Visual Studio, go to Parasoft> Options> Engines.
  2. Ensure that C/C++test is enabled and its location is configured.
  3. 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.

  4. Run the Coverage built-in configuration on your selected projects.

  5. 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.
  6. View the generated report in the Visual Studio main window.

Removing the Parasoft Integration

To uninstall the parasoft-coverage property sheet:

  1. Go to View> Other Windows> Property Manager.
  2. Browse the projects and configurations for the parasoft-coverage.props files you want to remove. The files must be removed manually from individual configurations.
  3. Right-click the selected files and choose Remove from the context menu.

  4. The parasoft-coverage.props files will be removed only from the project configurations you selected.

  • No labels