Parasoft C/C++test extension for Visual Studio Code
The C/C++test extension for Visual Studio Code provides integration with the static analysis capabilities of Parasoft C/C++test Standard and the code coverage analysis capabilities of Parasoft C/C++test CT. It allows you to analyze your code and review the results directly in Visual Studio Code.
The extension requires Parasoft C/C++test Standard or Parasoft C/C++test CT to be installed and licensed.
Features
The C/C++test extension for Visual Studio Code allows you to:
- Find bugs in your code to comply with coding best practices and industry-specific standards, such as MISRA C/C++ 2023, AUTOSAR C++ 14, CERT C/C++, and more.
- Run static code analysis on your workspace, a project, or a single source file.
- Review static code analysis results in the Problems view and the code editor.
- Review code coverage analysis results in the code editor.
- Suppress unwanted findings.
- Load analysis results directly from external report files, such as CI execution reports.
Requirements
Before you test your code with the C/C++test extension, you need to download, install, and license Parasoft C/C++test Standard or C/C++test CT.
For download and licensing information, or getting a free trial of Parasoft C/C++test, please contact us at info@parasoft.com or via our website.
Getting Started
Static Code Analysis with C/C++test Standard
- Ensure that Parasoft C/C++test Standard is installed and licensed.
See Installing and licensing C/C++test Standard.
- Open a project folder in Visual Studio Code.
To become familiar with the capabilities of the extension, you can use the ATM folder shipped with Parasoft C/C++test Standard in the examples directory.
- Open the Command Palette and choose
C/C++test: Quick Start
or click C/C++test
on the status bar at the bottom.
The Quick Start menu offers easy access to the basic configuration options.
- Choose
Select C/C++test installation...
and select the location where Parasoft C/C++test Standard is installed.
- Choose
Select test configuration...
and select a test configuration you want to use.
A test configuration is a set of static analysis rules designed to cover an industry standard or best coding practices. By default, the Recommended Rules test configuration is configured. See Built-in test configurations for information about available test configurations.
- Choose
Select compiler configuration...
and select a compiler configuration.
You must select the configuration that matches your compiler. See Supported Compilers for information about supported compilers.
- Choose
Analyze project...
to run static analysis on the project you opened.
- Review the results in the Problems view and the code editor.
You can open the rule documentation to learn more about the problem. See Viewing rule documentation.
Code Coverage Analysis with C/C++test CT
- Ensure that Parasoft C/C++test CT is installed and licensed.
See Installing and licensing C/C++test CT.
- Open a project folder in Visual Studio Code.
To become familiar with the capabilities of the extension, you can use the CovGoogleTest folder shipped with Parasoft C/C++test CT in the examples directory.
- Open the list of Build Tasks (
Terminal> Run Build Task...
) and choose Configure
.
The CovGoogleTest CMake project will be configured.
- Open the list of Build Tasks (
Terminal> Run Build Task...
) and choose Build and Run
.
The CovGoogleTest project will be built, unit tests (from goo_test.cpp) will be executed, and the code coverage data will be collected into the .coverage folder.
- Open the goo.cpp source file in the code editor.
- Open the Command Palette, choose
C/C++test: Show Code Coverage...
and select a coverage type (e.g. Line Coverage (LC)
).
You can use the coverage selector in the status bar to quickly access the list of coverage types. It also shows the currently selected coverage type, e.g., Coverage: LC
(for Line Coverage).
- Review the coverage results in the code editor.
Coverable elements will be highlighted in green (covered), yellow (partially covered), red (not covered). You can hover over a coverable element in the code editor to get additional details.
Working with the C/C++test Extension
The following section describes typical use cases for using C/C++test Extension for Visual Studio Code.
Integrating with a Build System for Static Analysis
To perform static analysis with C/C++test extension, you need to enable C/C++test Standard to collect information about the original build commands. Go to Extensions> C/C++test> Extension Settings> Command Line Pattern
and adjust the command line for running C/C++test, depending on your build system.
Analyzing a Makefile-based project
To quickly analyze a Makefile-based project, ensure that the command line pattern includes the -trace
option followed by the original build command, for example:
cpptestcli [C/C++test options] -trace make clean all
Commands that follow -trace
are interpreted as a build command, so other C/C++test options must be listed first in the command line.
The -trace make clean all
option is added to the default command line pattern for running C/C++test.
See also Using Build Data File (.bdf) below.
Analyzing a CMake-based project
To analyze a CMake-based project, ensure that your CMake build can output the compile commands. Then update the command line pattern to include -input <PATH_TO_COMPILE_COMMANDS_JSON>
to pass the location of the output file, for example:
cpptestcli [C/C++test options] -input build/compile_commands.json
You can configure CMake to output the compile commands file with the CMAKE_EXPORT_COMPILE_COMMANDS
variable.
Using a Build Data File
You can generate a Build Data File (.bdf) with the cpptesttrace
or cpptestscan
utility shipped with C/C++test Standard. Using a .bdf file allows you to analyze projects that are built with any build system.
After you generate a .bdf file, update the command line pattern to include -input <PATH_TO_BDF>
to pass the location of the .bdf file, for example:
cpptestcli [C/C++test options] -input cpptest.bdf
See Parasoft C/C++test Standard User Guide to learn more.
Running Static Analysis
Analyzing a project
To analyze all source files in a project, choose C/C++test: Analyze Project
from the Command Palette.
Analyzing selected files
To analyze selected files, right-click the file(s) you want to analyze in the Explorer view and choose C/C++test: Analyze Selected File(s)
from the menu.
Analyzing the active file
To analyze the file you are working on in the editor, click the C/C++test: Analyze Active File
icon in the upper right corner of Visual Studio Code or right-click anywhere in the code and choose C/C++test: Analyze Active File
from the menu.
To cancel the analysis before it completes, choose C/C++test: Cancel Running Analysis
from the Command Palette or click Running C/C++test...
in the status bar at the bottom and confirm when prompted.
By default, the open editors are automatically saved before analysis. To disable automatic file saving, go to Extensions> C/C++test> Extension Settings> Save Before Run
.
Suppressing Violations
You can suppress a violation to prevent it from being reported in subsequent analysis runs.
- Right-click a violation in the Problems view.
- Enter the reason for suppression when prompted.
- Choose where you want to store the suppression. The following options are available:
Use suppression file
- The suppression will be added to a parasoft.suppress file in the same directory where the source file is located.
Use in-code suppressions
- The suppression will be added as a comment in the source file.
Alternatively, you can hover over a violation in the code editor to open the Quick Fix...
menu and choose Suppress violation for [rule_ID]
from the menu.
You can configure the C/C++test extension to always store suppressions either in code or in suppression files, without prompting you to choose. Go to Extensions> C/C++test> Extension Settings> Suppression Type
to configure your preference.
See Suppressing the Reporting of Findings to find out more about suppressing static analysis violations reported by C/C++test.
Explaining Violations Using AI
You can leverage Parasoft AI assistant to explain static analysis violations and receive suggestions for fixing them. The assistant is integrated with GitHub Copilot Chat.
Requirements:
To use this feature, ensure that you have the following installed:
- Complete Parasoft C/C++test Installation, including HTML rules documentation and a valid license for
LLM Integration
. For more information, refer to Installing and licensing C/C++test Standard.
- GitHub Copilot Chat Extension for Visual Studio Code (github.copilot-chat)
- Microsoft C/C++ Extension for Visual Studio Code (ms-vscode.cpptools)
- Visual Studio Code version 1.92.0 or later
How to Use:
Option 1: From the Problems View
- Right-click on a violation in the Problems view.
- Select
Explain violation of [rule_ID]
.
The explanation will be displayed in the Chat View.
Option 2: From the Code Editor
- Hover over the code that contains the violation to bring up the
Quick Fix...
menu.
- Select
Explain violation of [rule_ID]
from the list of available options.
The explanation will be displayed in the Chat View.
Option 3: Using the Chat View
You can also invoke the explain
command directly from the Chat View. Use the following pattern:
@cpptest /explain rule_ID file.ext:startLine:startColumn
AI Guidance Disclaimer
This extension includes features that allow you to interact with an AI model using GitHub Copilot Chat to assist in code development. While the AI aims to provide helpful and accurate suggestions, AI-generated answers can sometimes be incorrect or incomplete. Always verify the AI-generated code, recommendations, or explanations before applying them to your project to ensure they meet your requirements and standards.
Additionally, be aware that your organization may control or limit certain features of GitHub Copilot Chat. Depending on your organization's policies, responses from the AI may be filtered or restricted based on content or compliance requirements. Ensure you are familiar with your organization's policies on AI usage and data handling.
Mapping Violation Severity
By default, all C/C++test's violations are presented in the Problems View as Warnings. You can map C/C++test severity levels (1-5) to Visual Studio Code severity levels (Error/Warning/Information/Hint). Go to Extensions> C/C++test> Extension Settings> Severity Mapping
to configure your mapping. Be sure to restart Visual Studio Code to apply the changes.
Removing Violations from the Problems View
Viewing Rule Documentation
You can find out more about a reported problem in the documentation for the static analysis rule that was violated. Select a violation in the Problems view or the code editor and choose Show documentation for [rule_ID]
from the Quick Fix menu.
Viewing Code Coverage Results
To view C/C++test's code coverage analysis results:
- Generate coverage results with C/C++test CT - see C/C++test CT documentation for details.
- Import the coverage results into your workspace - choose one of the following options:
- Configure your coverage build workflow to place coverage data files (
.cov
) and the coverage index file (coverage.index
) directly into the .coverage
folder inside your workspace. This location can be customized in Extensions> C/C++test> Extension Settings> Coverage Data Folder
.
- Import the coverage results from the CI pipeline - see below for details.
- Choose
C/C++test: Show Coverage...
from the Command Palette and select the coverage type (e.g., Line Coverage
) to enable coverage highlights or None
to remove coverage highlights.
You can use the coverage selector in the status bar to quickly access the list of coverage types. It also shows the currently selected coverage type, e.g., Coverage: LC
(for Line Coverage).
- Review the coverage results in the code editor.
Coverable elements will be highlighted in green (covered), yellow (partially covered), red (not covered). You can hover over a coverable element in the code editor to get additional details.
Importing Results from a Local File or URL
You can import analysis results to Visual Studio Code from an external XML report files or zip archives generated by C/C++test during analysis (report.xml
, coverage.xml
, artifacts.zip
). This may be particularly useful to import C/C++test analysis results generated by CI pipelines.
You can choose the following options from the Command Palette to import results:
- Choose
C/C++test: Import Results From... > File
and navigate to a local report file.
- Choose
C/C++test: Import Results From... > URL
and enter the URL of a remote report file. You can provide an HTTP or HTTPS URL that does not require authentication.
Note: Importing code coverage results generated with C/C++test Standard (coverage.xml
) will be deprecated in the future. Consider using C/C++test CT for running code coverage analysis.
Importing Results from DTP
If your organization uses Parasoft DTP in the development testing workflow, you can import static analysis results to Visual Studio Code directly from DTP.
First import:
- Choose
C/C++test: Import Results From... > DTP
from the Command Palette.
- Enter the full address of your DTP. Examples: dtp.acme.com, dtp.acme.com:8443, https://dtp.acme.com:443/deployment/root.
- Enter your DTP user name.
- Enter your password.
- Select a filter. Filters are identifiers used in DTP for organizing data; see the DTP User Guide for details.
The import will begin immediately.
Subsequent imports:
- Choose
C/C++test: Import Results From... > DTP
from the Command Palette.
- Choose one of the following options:
Import results using previous settings
immediately starts the import using the data you configured for the previous import.
Update settings...
allows you to update the data for import (DTP host name, user name, password, filter).
The imported results are added to the current list of problems in the Problems view.
If you want to delete the previously entered credentials, choose C/C++test: Clear Saved Credentials...
> DTP
.
Importing Results from GitHub, GitLab and Azure DevOps
You can import static analysis or code coverage results from GitHub, GitLab and Azure DevOps if the workflow for your GitHub project or the pipeline for your GitLab or Azure DevOps project is customized to run C/C++test.
To import results from GitHub:
- Choose
C/C++test: Import Results From... > GitHub
from the Command Palette.
- Sign in to your GitHub account when prompted by Visual Studio Code. The prompt will not appear if you've already signed in.
To import results from GitLab:
- Choose
C/C++test: Import Results From... > GitLab
from the Command Palette.
- Enter the host and token associated with your GitLab account. The prompt will not appear if you've already entered this information.
If you want to delete the previously entered credentials, choose C/C++test: Clear Saved Credentials...
> GitLab
.
To import results from Azure DevOps:
- Choose
C/C++test: Import Results From... > Azure DevOps
from the Command Palette.
- Install the Azure Account extension when prompted and sign in to your Azure DevOps account. The prompts will not appear if the extension is already installed and you're signed in.
The import will begin immediately if the artifact that contains the report.xml
, coverage.xml
or coverage.index
file with analysis results is automatically detected. Otherwise, you will be asked to enter additional information to specify the report file from which you want to import results. Depending on your GitHub / GitLab / Azure DevOps account, you may need to specify the repository and branch where the results are stored, the workflow / pipeline that generates the artifact with results, the name of the artifact, and the report file.
About Parasoft C/C++test Standard
Parasoft C/C++test Standard uses a comprehensive set of static analysis techniques, including pattern-based analysis, dataflow analysis, metrics, and more, to help you verify code quality and ensure compliance with industry standards.
Installing and Licensing C/C++test Standard
If you do not have Parasoft C/C++test Standard installed, request a download link and a license at our website.
To install and license Parasoft C/C++test Standard:
- Extract the contents of the installation package to a desired location. The
cpptest
directory that contains all C/C++test files will be created.
- Open the
cpptestcli.properties
configuration file in the installation directory.
- Customize the following license settings to configure a local license:
cpptest.license.use_network=false
cpptest.license.local.password=[the password you received from Parasoft]
For information about a network license and other details, see Setting the Parasoft License.
Customizing Parasoft C/C++test Standard
You can customize Parasoft C/C++test Standard by configuring the settings in the cpptestcli.properties
file shipped in the installation directory.
Alternatively, you can use the cpptestcli.properties
file in your working directory to configure project-specific settings:
- Open the Command Palette and choose
C/C++test: Quick Start
or click C/C++test
on the status bar at the bottom.
- Choose
Add local configuration file...
. This will copy the cpptestcli.properties
file from the installation directory to the working directory of your project and open the file in the Visual Studio Code editor.
- Modify project-specific configuration settings.
You can reopen the file by choosing Open local configuration file...
from the Quick Start menu.
See Parasoft C/C++test Standard Configuration Settings for the list of available settings.
Parasoft C/C++test Standard Documentation
See Parasoft C/C++test Standard User Guide to learn more about the product.
About Parasoft C/C++test CT
Parasoft C/C++test CT provides dynamic testing capabilities for C and C++ projects, including code coverage analysis with a comprehensive set of coverage metrics, requirements traceability reporting and more. C/C++test CT seamlessly integrates with modern CI/CD workflows and third party testing frameworks such as Google Test. It helps teams comply with industry standards for code coverage, unit testing, and requirements testing.
Installing and Licensing C/C++test CT
If you do not have Parasoft C/C++test CT installed, request a download link and a license at our website.
To install and license Parasoft C/C++test CT:
- Extract the contents of the installation package to a desired location. The
cpptest-ct
directory that contains all C/C++test CT files will be created.
- Open the
cpptestct.properties
configuration file in the installation directory.
- Customize the following license settings to configure a local license:
cpptestct.license.use_network=false
cpptestct.license.local.password=[the password you received from Parasoft]
For information about a network license and other details, see README
file in the C/C++test CT installation directory.
References
Usage Data and Telemetry
Please help us improve Parasoft products by sending us usage data. The data will be used to improve the product’s user experience. You can change this setting at any time - this extension respects the telemetry.enableTelemetry
and telemetry.telemetryLevel
settings, which you can learn more about at https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting.
Parasoft will not collect any personally identifiable information that could potentially identify a specific individual. See Parasoft Privacy Policy to learn more.
About
C/C++test extension for Visual Studio Code - Copyright (C) 2024 Parasoft Corporation
Version: 2024.2.0 (10.7.1.20241030B893), Commit: 686e59566099e32aa57a6589e74e06d332cefec7, Branch: master