Main Content

polyspaceBugFinder

Run Polyspace Bug Finder analysis from MATLAB

For easier scripting, run Polyspace® analysis using a polyspace.Project object.

Description

status = polyspaceBugFinder opens Polyspace Bug Finder™.

status = polyspaceBugFinder(projectFile) opens a Polyspace project file in Polyspace Bug Finder.

example

status = polyspaceBugFinder(optsObject) runs an analysis on the Polyspace options object in MATLAB®.

Note

When you use a Polyspace options object to run an analysis, use only the Polyspace options object to specify options of the analysis. Using name-value arguments is not supported when the first argument is a Polyspace options object.

example

status = polyspaceBugFinder(projectFile, '-nodesktop') runs an analysis on the Polyspace project file in MATLAB.

status = polyspaceBugFinder(resultsFile) opens a Polyspace results file in Polyspace Bug Finder.

status = polyspaceBugFinder('-results-dir',resultsFolder) opens a Polyspace results file from resultsFolder in Polyspace Bug Finder.

example

status = polyspaceBugFinder('-help') displays options that can be supplied to the polyspaceBugFinder command to run a Polyspace Bug Finder analysis.

status = polyspaceBugFinder('-sources',sourceFiles) runs a Polyspace Bug Finder analysis on the source files specified in sourceFiles.

example

status = polyspaceBugFinder('-sources',sourceFiles,Name,Value) runs a Polyspace Bug Finder analysis on the source files with additional options specified by one or more Name,Value pair arguments.

Note

Before you run Polyspace from MATLAB, you must link your Polyspace and MATLAB installations. See Integrate Polyspace with MATLAB and Simulink.

example

[status, jobID] = polyspaceBugFinder(___,'-batch','-scheduler',scheduler) offloads the analysis to a remote cluster. Here, scheduler specifies the head node of the cluster that manages the analysis submissions from multiple clients. See also Manipulate Two Jobs in the Cluster.

Examples

collapse all

This example shows how to open a Polyspace project file with extension .psprj from MATLAB. In this example, you open the project file Bug_Finder_Example.psprj from the folder polyspaceroot\polyspace\examples\cxx\Bug_Finder_Example.

Open the project Bug_Finder_Example.psprj in the Polyspace interface.

prjFile = fullfile(polyspaceroot, 'polyspace', 'examples', 'cxx', ...
         'Bug_Finder_Example', 'Bug_Finder_Example.psprj');
polyspaceBugFinder(prjFile);

This example shows how to open a Polyspace results file from MATLAB. In this example, you open the results file from the folder polyspaceroot\polyspace\examples\cxx\Bug_Finder_Example\Module_1\BF_Result.

Open the results of resFolder.

resFolder = fullfile(polyspaceroot, 'polyspace', 'examples',  ...
         'cxx', 'Bug_Finder_Example', 'Module_1', 'BF_Result');
polyspaceBugFinder('-results-dir',resFolder)

This example shows how to run a Polyspace analysis from the MATLAB command-line using objects.

Create an options object and add the source file and include folder to the properties.

opts = polyspace.Options;
opts.Sources = {fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c')};
opts.EnvironmentSettings.IncludeFolders = {fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources')};
opts.ResultsDir = fullfile(pwd,'results');

Run the analysis and view the results.

polyspaceBugFinder(opts);
polyspaceBugFinder('-results-dir',opts.ResultsDir)

This example shows how to run a Polyspace analysis in MATLAB using DOS/UNIX-style options.

Run the analysis and open the results.

sourceFiles = fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c');
includeFolders = fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources');
resultsDir = fullfile(pwd,'results');
polyspaceBugFinder('-sources',sourceFiles, ...
             '-I',includeFolders, ...
             '-results-dir',resultsDir);

To view the results, enter:

polyspaceBugFinder('-results-dir',resultsDir);

This example shows two different ways to customize an analysis in MATLAB. You can customize as many additional options as you want by changing properties in an options object or by using Name-Value pairs. Here you specify checking of MISRA C™ 2012 coding rules.

Create variables to save the source file path and results folder path. You can use these variables for either analysis method.

sourceFileName = fullfile(polyspaceroot, 'polyspace','examples', 'cxx', 'Bug_Finder_Example','sources','dataflow.c');
resFolder1 = fullfile('Polyspace_Results_1');
resFolder2 = fullfile('Polyspace_Results_2');

Analyze coding rules with an options object.

opts = polyspace.Options();
opts.Sources = {sourceFileName};
opts.ResultsDir = resFolder1;
opts.CodingRulesCodeMetrics.MisraC3Subset = 'all';
opts.CodingRulesCodeMetrics.EnableMisraC3 = true;
polyspaceBugFinder(opts);
polyspaceBugFinder('-results-dir',resFolder1);

Analyze coding rules with DOS/UNIX options.

polyspaceBugFinder('-sources',sourceFileName,'-results-dir',resFolder2,'-misra3','all');
polyspaceBugFinder('-results-dir',resFolder2);

Input Arguments

collapse all

Polyspace options object name, specified as the object handle.

To create an options object, use one of the Polyspace options classes.

Example: opts

Name of project file with extension .psprj, specified as a character vector.

If the file is not in the current folder, projectFile must include a full or relative path.

Example: 'C:\Polyspace_Projects\myProject.psprj'

Data Types: char

Name of results file with extension .psbf, specified as a character vector.

If the file is not in the current folder, resultsFile must include a full or relative path.

Example: 'myResults.psbf'

Data Types: char

Name of result folder, specified as a character vector. The folder must contain the results file with extension .psbf. If the results file resides in a subfolder of the specified folder, this command does not open the results file.

If the folder is not in the current folder, resultsFolder must include a full or relative path.

Example: 'C:\Polyspace\Results\'

Data Types: char

Comma-separated C or C++ source file names, specified as a single character vector.

If the files are not in the current folder, sourceFiles must include a full or relative path.

Example: 'myFile.c', 'C:\mySources\myFile1.c,C:\mySources\myFile2.c'

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: '-target','i386','-compiler','gnu4.6' specifies that the source code is intended for an i386 target and contains non-ANSI C syntax for GCC 4.6.

For option names and values, see the Command-Line Information section in Complete List of Polyspace Bug Finder Analysis Engine Options.

Output Arguments

collapse all

If the Polyspace Bug Finder analysis completes without error, status is false. Otherwise, it is true.

The analysis might fail for multiple reasons, including:

  • You provided a source file, project file, or results file that does not exist.

  • You specified an invalid path.

  • One of your files did not compile.

If you offload the Polyspace analysis to a remote cluster, the command returns the ID of the job associated with the submitted analysis on the remote cluster. You can use this ID to manage the job or download the analysis results once the job completes. See also polyspaceJobsManager.

Version History

Introduced in R2013b