Main Content

polyspace.ModelLinkOptions Class

Namespace: polyspace

Create a project configuration object for running Polyspace analysis on generated code

Description

Run a Polyspace® analysis from MATLAB® by using a project configuration object. To specify source files and customize analysis options, change the object properties.

This class is intended for model-generated code. If you are analyzing handwritten code, use polyspace.Options instead.

Note

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

Construction

psprjConfig = polyspace.ModelLinkOptions creates a project configuration object that is configured for running a Polyspace analysis on generated code.

psprjConfig = polyspace.ModelLinkOptions(lang) creates a project configuration object that is configured to run analysis on code generated in the language lang.

psprjConfig = polyspace.ModelLinkOptions(model) creates a project configuration object that is configured by using model specific information from the Simulink® model model. Prior to extracting options from model, you must load the model and generate code from it.

psprjConfig = polyspace.ModelLinkOptions(model, psOpt) creates a model-specific project configuration object that is configured by using the Polyspace analysis options specified in psOpt.

psprjConfig = polyspace.ModelLinkOptions(model, psOpt, asModelRef) creates a project configuration object that uses asModelRef to specify which type of generated code to analyze—standalone code or model reference code.

Input Arguments

expand all

The language of the analysis specified as 'C-CPP', 'C', or 'CPP'. This argument determines the object properties.

Name or path to model or subsystem, specified as a character vector.

Prior to extracting options from the model, you must:

  1. Load the model. Use load_system (Simulink) or open_system (Simulink).

  2. Generate code from the model. Use slbuild (Simulink) or slbuild (Simulink).

Example: 'psdemo_model_link_sl'

An object containing the options that you use for the Polyspace analysis. You create this by calling the function pslinkoptions. You can customize the options object by changing the properties of the psOpt object.

Example: psOpt = pslinkoptions(model) where model is the name of a Simulink model.

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

  • To analyze generated code used or called elsewhere, set the flag asModelRef to true. This option is equivalent to choosing Analyze Code from > Code Generated as Model Reference on the Polyspace tab in the Simulink toolstrip.

  • To analyze code that is generated to be used as stand-alone code, set the flag asModelRef to false. This option is equivalent to choosing Analyze Code from > Code Generated as Top model on the Polyspace tab in the Simulink toolstrip.

Data Types: logical

Properties

The object properties correspond to the configuration options for Polyspace projects. The properties are organized in the same categories as the Polyspace interface. The property names are a shortened version of the DOS command-line name. For syntax details, see polyspace.ModelLinkOptions Properties.

Methods

copyToCopy common settings between Polyspace options objects
generateProjectGenerate psprj project from options object
toScriptAdd Polyspace options object definition to a script

Examples

collapse all

This example shows how to customize and run an analysis on code generated from a model.

Generate code from the model polyspace_controller_demo. Before code generation, set a system target file appropriate for code analysis. See also Recommended Model Configuration Parameters for Polyspace Analysis.

cd(matlabroot);
modelName = 'polyspace_controller_demo';
openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
'supportingFile',modelName);
mkdir TempDir;
load_system(modelName);
cd TempDir;

% Set parameters for Embedded Coder target
set_param(modelName, 'SystemTargetFile', 'ert.tlc');
set_param(modelName,'Solver','FixedStepDiscrete');
set_param(modelName,'SupportContinuousTime','on');
set_param(modelName,'LaunchReport','off');
set_param(modelName,'InitFltsAndDblsToZero','on');

slbuild(modelName);

Associate a polyspace.ModelLinkOptions object with the model. A subset of the object properties are set from the configuration parameters associated with the model. The other properties take their default values. For details on the configuration parameters, see Bug Finder Analysis in Simulink.

psprjCfg = polyspace.ModelLinkOptions(modelName);

Change the property values if needed. For instance, you can specify that the analysis must check for all MISRA C™: 2012 violations and generate a PDF report of the results. You can also specify a folder for the analysis results.

psprjCfg.CodingRulesCodeMetrics.EnableMisraC3 = true;
psprjCfg.CodingRulesCodeMetrics.MisraC3Subset = 'all';
psprjCfg.MergedReporting.EnableReportGeneration = true;
psprjCfg.MergedReporting.ReportOutputFormat = 'PDF';
psprjCfg.ResultsDir = 'newResfolder';

Create a polyspace.Project object. Associate the Configuration property of this object to the options that you previously specified.

proj = polyspace.Project;
proj.Configuration = psprjCfg;

Optionally, you might want to submit the analysis to a remote server to run batches of analysis together. To setup analysis in batch mode, set the property BatchBugFinder or BatchCodeProver to true, depending on your analysis. Then, specify the head node that manages the Polyspace analysis jobs:

% Setup batch analysis
psprjCfg.MergedComputingSettings.BatchBugFinder = true; 
psprjCfg.Advanced.Additional = '-scheduler NodeID';

Run analysis and open results.

cpStatus = proj.run('codeProver');
proj.Results.getResults('readable');

This example shows how to analyze generated code used as a callable entity in another model or code.

Load the Simulink model polyspace_controller_demo and configure it for a Polyspace analysis. For details, see Recommended Model Configuration Parameters for Polyspace Analysis for details.

cd(matlabroot);
model = 'polyspace_controller_demo';
openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
'supportingFile',modelName);
mkdir TempDir;
load_system(model);
cd TempDir;;
% Configure the model for generating code
set_param(model, 'SystemTargetFile', 'ert.tlc');
set_param(model,'MatFileLogging','off');
set_param(model,'GenerateComments','on');
set_param(model,'Solver','FixedStepDiscrete');
set_param(model,'LaunchReport','off');

To generate code as a model reference from the Simulink model, use slbuild (Simulink). Set the buildspec parameter to 'ModelReferenceCoderTarget'.

slbuild(model,'ModelReferenceCoderTarget');

To configure the Polyspace analysis of the generated code, create an options object psOpt by using the function pslinkoptions. Change the properties of the object as needed. For instance, to run a Code Prover analysis, set the Verificationmode to 'CodeProver'.

psOpt = pslinkoptions(model);
psOpt.VerificationMode = 'CodeProver';

To run a Polyspace analysis, create and configure a Polyspace project configuration object.

  • To create the Polyspace project configuration object, use the function polyspace.ModelLinkOptions.

  • To associate the Polyspace analysis options with the project configuration, set the object psOpt as the second argument in polyspace.ModelLinkOptions().

  • To specify that the generated code must be analyzed as a model reference, specify the third argument as 'true'.

For instance:

psprjCfg = polyspace.ModelLinkOptions(model, psOpt,true);

To configure the Polyspace project, change the properties of the psprjCfg object. For instance, to enable checkers for the mandatory MISRA C: 2012 rules and to generate a PDF report of the results, use:

psprjCfg.CodingRulesCodeMetrics.EnableMisraC3 = true;
psprjCfg.CodingRulesCodeMetrics.MisraC3Subset = 'mandatory-required';
psprjCfg.MergedReporting.EnableReportGeneration = true;
psprjCfg.MergedReporting.ReportOutputFormat = 'PDF';
For convenience, you can specify a separate result folder.
psprjCfg.ResultsDir = 'newResfolder';

Create a Polyspace project by using polyspace.Project and associate the project configuration with it.

proj = polyspace.Project;
proj.Configuration = psprjCfg;

Run the Polyspace analysis by using the run function of the object proj.

cpStatus = proj.run('codeProver');

Because you enabled PDF report generation, the result of the Polyspace analysis is reported in a PDF file, which can be found in newResfolder/Polyspace-Doc. To view the results in a MATLAB table, use:

result = proj.Results.getResults('readable');

Alternatives

If you are analyzing handwritten code, use a polyspace.Project object directly. Alternatively, use a polyspace.Options object.

Version History

Introduced in R2017a