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. It allows you to analyze your code and review the results directly in Visual Studio Code.
The extension requires Parasoft C/C++test Standard to be installed and licensed.
Features
- 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 analysis results in the Problems view and 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.
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
- Ensure that Parasoft C/C++test Standard is installed and licensed.
See Installing and licensing C/C++test Standard.
- Open a 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.
Working with the C/C++test Extension
Integrating with a Build System
To analyze a project with C/C++test extension, you need to enable C/C++test Standard, which runs under the hood, 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.
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:
- Import coverage results from a local file or CI pipeline - see below for details.
Alternatively, put coverage data files (coverage.index
, .json
) directly into the .coverage
folder inside your workspace. This location can be customized in Extensions> C/C++test> Extension Settings> Coverage Data Folder
.
- Choose
C/C++test: Show Coverage...
from the Command Palette.
- 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).
Importing Results from a Local File or URL
You can import static analysis and code coverage results to Visual Studio Code from an external XML report file generated by C/C++test during analysis (report.xml
, coverage.xml
). 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: Load Results From File...
and navigate to a static analysis report file (report.xml
).
- Choose
C/C++test: Load Results From URL...
and enter the URL of a static analysis report file (report.xml
). You can provide an HTTP or HTTPS URL that does not require authentication.
- Choose
C/C++test: Import Coverage From XML File...
and navigate to a coverage report file (coverage.xml
).
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: Load 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: Load 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: Load 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: Load 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: Load 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.
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) 2023 Parasoft Corporation
Version: 2023.2.0 (10.6.3.20231127B867), Commit: a20236a1a91181713c0cf172aab5d3264f18f096, Branch: master