Main Content

pslinkrun

Run Polyspace analysis on model, system, or S-Function

Description

[polyspaceFolder, resultsFolder] = pslinkrun analyzes code generated from the current system using the configuration options associated with the current system. It returns the location of the results folder. The current system is the system returned by the command bdroot (Simulink).

[polyspaceFolder, resultsFolder]= pslinkrun(target) analyzes target with the configuration options associated with the model containing target. Before you run an analysis, you must:

  • Generate code for models and subsystems.

  • Compile S-Functions.

example

[polyspaceFolder, resultsFolder] = pslinkrun('-slcc',target) runs Polyspace® on C/C++ custom code included in C Caller blocks and Stateflow charts in the model.

[polyspaceFolder, resultsFolder] = pslinkrun(target, opts) analyzes target using the configuration options specified in the object opts. It returns the location of the results folder.

example

[polyspaceFolder, resultsFolder] = pslinkrun('-slcc', target, opts) runs Polyspace on C/C++ custom code included in C Caller blocks and Stateflow charts in the model. The analysis uses the configuration options specified in the object opts.

[polyspaceFolder, resultsFolder] = pslinkrun(target, opts, asModelRef) uses asModelRef to specify which type of generated code to analyze—standalone code or model reference code. This option is useful when you want to analyze code that is generated as model reference. Code that is generated as model reference is intended to be called or used in other models or code.

example

[polyspaceFolder, resultsFolder] = pslinkrun('-codegenfolder', codegenFolder, opts) runs Polyspace on C/C++ code generated from MATLAB® code and stored in codegenFolder.

Note

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

example

Examples

collapse all

Use a Simulink® model to generate code, set configuration options, and then run an analysis from the command line.

% Generate code from the model WhereAreTheErrors.
model = 'WhereAreTheErrors';
load_system(model);
slbuild(model);

% Create a Polyspace options object from the model. 
opts = pslinkoptions(model);

% Set properties that define the Polyspace analysis.
opts.VerificationMode = 'CodeProver';
opts.VerificationSettings = 'PrjConfigAndMisraC2012';

% Run Polyspace using the options object.
[polyspaceFolder, resultsFolder] = pslinkrun(model,opts);
bdclose(model);

The results and the corresponding Polyspace project are saved to the results_WhereAreTheErrors folder, listed in the polyspaceFolder variable. The full path to the results folder is in the resultsFolder variable.

Use a Simulink model to generate model reference code, set configuration options, and then run an analysis from the command line.

% Generate code from the model WhereAreTheErrors.
% Treat WhereAreTheErrors as if referenced by another model.
model = 'WhereAreTheErrors';
load_system(model);
slbuild(model,'ModelReferenceCoderTarget');

% Create a Polyspace options object from the model. 
opts = pslinkoptions(model);

% Set properties that define the Polyspace analysis.
opts.VerificationMode = 'CodeProver';
opts.VerificationSettings = 'PrjConfigAndMisraC2012';

% Run Polyspace with the options object.
[polyspaceFolder, resultsFolder] = pslinkrun(model,opts,true);
bdclose(model);

The results and corresponding Polyspace project are saved to the results_mr_WhereAreTheErrors folder, listed in the polyspaceFolder variable. The full path to the results folder is in the resultsFolder variable.

This example shows how to reuse a subset of options for Polyspace analysis of multiple models. Create a generic options object and specify properties that describe the common options. Associate the generic options object with a model-specific options object. Optionally, set some model-specific options and run the Polyspace analysis.

% Generate code from the model WhereAreTheErrors.
model = 'psdemo_model_link_sl';
load_system(model);
slbuild(model);

% Create a generic options object to use for multiple model analyses.
opts = polyspace.ModelLinkOptions();
opts.CodingRulesCodeMetrics.EnableMisraC3 = true;
opts.CodingRulesCodeMetrics.MisraC3Subset = 'all';
opts.MergedReporting.ReportOutputFormat = 'PDF';
opts.MergedReporting.EnableReportGeneration = true;

% Create a model-specific options object.
mlopts = pslinkoptions(model);

% Create a project from the generic options object.
% Associate the project with the model-specific options object. 
prjfile = opts.generateProject('model_link_opts');
mlopts.EnablePrjConfigFile = true;
mlopts.PrjConfigFile = prjfile;
mlopts.VerificationMode = 'BugFinder';

% Run Polyspace with the model-specific options object.
[polyspaceFolder, resultsFolder] = pslinkrun(model,mlopts);
bdclose(model);

After the analysis completes, results open automatically in the Polyspace interface.

This example shows how to analyze C/C++ code generated from MATLAB code.

% Generate code
matlabFileName = fullfile(polyspaceroot, 'polyspace',...
    'examples','doc_cxx','matlab_coder','averaging_filter.m');
codegenFolder = fullfile(pwd, 'codegenFolder');
codegen(matlabFileName, '-config:lib', '-c', '-args', ...
   {zeros(1,100,'double')}, '-d', codegenFolder);

% Configure Polyspace analysis
opts = pslinkoptions('ec');
opts.ResultDir = [tempdir 'results'];
opts.OpenProjectManager = 1;

% Run Polyspace
[polyspaceFolder, resultsFolder] = pslinkrun('-codegenfolder', codegenFolder, opts);

After the analysis completes, results open automatically in the Polyspace interface.

Input Arguments

collapse all

Target of the analysis specified as a character vector, with the model, system, or S-function in single quotes. The default value is the system returned by bdroot (Simulink).

If you analyze custom code in C Caller blocks and Stateflow charts using pslinkrun('-slcc',...), the argument target cannot be an S-Function block.

Example: [polyspaceFolder, resultsFolder] = pslinkrun('demo') where demo is the name of a model.

Example: [polyspaceFolder, resultsFolder] = pslinkrun('path/to/sfunction')

Data Types: char

Specify configuration options of target, specified as a Polyspace options object. The function pslinkoptions creates such an options object. You can customize the options object by changing the pslinkoption properties.

Example: pslinkrun('demo', opts_demo) where demo is the name of a model and opts_demo is an options object.

Indicator for model reference analysis, specified as true or false.

  • If asModelRef is false (default), Polyspace analyzes the generated code as stand-alone code. This option is equivalent to choosing Verify Code Generated For > Model in the Simulink Polyspace options.

  • If asModelRef is true, Polyspace analyzes the generated code as a model reference code. This option is equivalent to choosing Verify Code Generated For > Referenced Model in the Simulink Polyspace options. Specifying model reference code indicates that Polyspace must look for the generated code in a different location from the location for standalone code.

Data Types: logical

Folder containing C/C++ code generated from MATLAB code, specified as a character vector. You specify this folder with the codegen command using the flag -d.

Output Arguments

collapse all

Name of the folder containing Polyspace project and results, specified as a character vector. The default value of this variable is results_$ModelName$.

To change this value, see Output folder.

Full path to subfolder containing Polyspace results, specified as a character vector.

The folder results_$ModelName$ contains your Polyspace project and a subfolder $ModelName$ with the analysis results. This variable gives you the full path to the subfolder. You can use this path with a polyspace.BugFinderResults or polyspace.CodeProverResults object.

To change the parent folder results_$ModelName$, see Output folder.

Version History

Introduced in R2012a