Main Content

polyspaceBugFinderServer

Run analysis with Polyspace Bug Finder Server using MATLAB scripts

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

Description

polyspaceBugFinderServer(optsObject) runs an analysis on the Polyspace options object in MATLAB®.

example

polyspaceBugFinderServer('-help') displays options that can be supplied to the polyspaceBugFinderServer command to run an analysis with Polyspace Bug Finder™ Server™.

polyspaceBugFinderServer('-sources',sourceFiles) runs an analysis with Polyspace Bug Finder Server on the source files specified in sourceFiles.

example

polyspaceBugFinderServer('-sources',sourceFiles,Name,Value) runs an analysis with Polyspace Bug Finder Server 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 Server Products with MATLAB.

example

Examples

collapse all

This example shows how to run a Polyspace analysis from the MATLAB command-line. For this example:

  • Use the source file numerical.c located in the directory polyspaceroot/polyspace/examples/cxx/BugFinder_example/sources.

  • Include the headers located in the same directory.

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 = 'C:\Polyspace_Results';

Polyspace runs on the file C:\Polyspace_Sources\source.c and stores the result in C:\Polyspace_Results.

Run the analysis with Polyspace Bug Finder Server.

polyspaceBugFinderServer(opts);

This example shows how to run a Polyspace analysis in MATLAB by using DOS/UNIX Options. For this example:

  • Use the source file numerical.c located in the directory polyspaceroot/polyspace/examples/cxx/BugFinder_example/sources.

  • Include the headers located in the same directory.

Define the location of source and include files.

src = fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c');
inc = fullfile(polyspaceroot, 'polyspace', 'examples',...
    'cxx', 'Bug_Finder_Example', 'sources');
res = fullfile(pwd,'results');

To analyze numerical.c, run the following command.

polyspaceBugFinderServer('-sources',src, ...
    '-I',inc, ...
    '-results-dir',res)

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.EnableMisraC3 = true;
opts.CodingRulesCodeMetrics.MisraC3Subset = 'all';
polyspaceBugFinderServer(opts);

Analyze coding rules with DOS/UNIX options.

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

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 polyspace.Options or polyspace.Project.

Example: opts

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.

Version History

Introduced in R2019a