Main Content

polyspaceArtifact

Generate artifacts to run Polyspace analysis on code generated from Simulink model

Since R2024a

Description

pathToArtifacts = polyspaceArtifact generates the data range specification file and link-to-model data file for the current system and current configuration. The paths to these Polyspace® artifacts are stored in pathToArtifacts.

To use these artifacts, place them in the working directory of a Polyspace analysis before starting the analysis. The data range specification file allows you to run a more precise Polyspace analysis of generated code. The link-to-model data allows you to identify which block in your model is the root cause of a flagged issue. Using the function polyspaceArtifact, you can generate these artifacts without regenerating the entire code and without requiring an integration between Simulink® and Polyspace.

example

pathToArtifacts = polyspaceArtifact(mdlName) generates the artifacts for the model mdlName and the current configuration.

example

pathToArtifacts = polyspaceArtifact(mdlName,psOpt) generates the artifacts using the configuration specified in psOpt. The object psOpt is a Polyspace options object that is generated by using pslinkoptions. This syntax allows you to generate the artifacts with a custom configuration without directly changing the configuration of the current model.

example

pathToArtifacts = polyspaceArtifact(mdlName,psOpt,asModelRef) uses asModelRef to specify whether to generate option files for model reference code or standalone code.

pathToArtifacts = polyspaceArtifact(mdlName,psOpt,asModelRef,artifacts) generates the artifacts specified in artifacts.

Examples

collapse all

To generate Polyspace artifacts for a Simulink model, use polyspaceArtifact.

Open the Simulink model polyspace_controller_demo. Specify a folder for storing the generated code.

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

To make the model compatible with Polyspace, set SystemTargetFile to ert.tlc.

configSet = getActiveConfigSet(mdlName);
set_param(configSet,'SystemTargetFile','ert.tlc');

After configuring the model, generate code.

slbuild(mdlName)

Generate Polyspace artifacts.

artifacts = polyspaceArtifacts(mdlName);
The paths to the generated artifacts are stored in artifacts.

To specify the Polyspace analysis options when generating data range specifications and links-to-model data files, use pslinktoptions.

Open the Simulink model polyspace_controller_demo and configure the model for generating a code archive that is compatible with Polyspace.

cd(matlabroot);
mdlName = 'polyspace_controller_demo';
openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
'supportingFile',mdlName);
mkdir TempDir;
load_system(mdlName);
cd TempDir;
configSet = getActiveConfigSet(mdlName);
% Configure the model to be Polyspace Compatible
set_param(configSet,'SystemTargetFile','ert.tlc');

After configuring the model, generate code.

slbuild(mdlName)

To specify the model configuration for the Polyspace analysis, use a pslinkoptions object. Create this object by using the function pslinkoptions.

psOpt = pslinkoptions(mdlName);
The object psOpt is a structure whose fields are model configurations that you can specify.

Specify the model configuration by using psOpt object. For example, set InputRangeMode to full range. For a full options list, see the input argument psOpt.

psOpt.InputRangeMode = 'FullRange';

Generate Polyspace artifacts. Use the psOpt object as the second argument in polyspaceArtifacts.

artifacts = polyspaceArtifact(mdlName,psOpt);
The paths to the generated artifacts are stored in artifacts.

To accelerate model simulations, invoke referenced Simulink models as simulation targets. To generate model reference simulation targets from a Simulink model, generate code from the model by using slbuild with the build process specified as ModelReferenceCoderTarget. To generate Polyspace artifacts for analyzing such code, use the function polyspaceArtifacts with the optional argument asModelRef set to true.

Open the Simulink model polyspace_controller_demo and configure the model for generating a code archive that is compatible with Polyspace.

cd(matlabroot);
mdlName = 'polyspace_controller_demo';
openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
'supportingFile',mdlName);
mkdir TempDir;
load_system(mdlName);
cd TempDir;
configSet = getActiveConfigSet(mdlName);
% Configure the model to be Polyspace Compatible
set_param(configSet,'SystemTargetFile','ert.tlc');

After configuring the model, generate a model reference simulation target from it by using the function slbuild. Specify the option ModelReferenceCoderTarget. See slbuild.

slbuild(mdlName,'ModelReferenceCoderTarget');
The code that is generated is stored in the folder slprj.

Generate and package Polyspace artifacts. Use an empty array as the second argument to use the current configurations. Set the third argument asModelRef to true.

artifacts = polyspaceArtifacts(mdlName,[],true);
The paths to the generated artifacts are stored in artifacts.

Input Arguments

collapse all

Name of Simulink model for which you want to generate and package the Polyspace artifacts, specified as a character vector or string.

Example: polyspaceArtifact(mdlName)

Data Types: char | string

Polyspace analysis options, specified as a pslinkoptions object. You can modify certain analysis options by modifying psOpt, which is a structure whose individual fields represent analysis options. The table shows full list of options that you can modify.

PropertyValueDescription
EnableAdditionalFileList — Option to enable an additional file list to be analyzed, specified as true or false. Use with the AdditionalFileList option. true Polyspace verifies additional files specified in the AdditionalFileList option.
false (default) Polyspace does not verify additional files.
AdditionalFileList — Option to specify list of additional files to be analyzed, specified as a cell array of files. To add these files to the analysis, use the EnableAdditionalFileList option.cell array of file paths Polyspace considers the listed files for verification.
InputRangeMode — Option to set range of the input variables. 'DesignMinMax' (default) Polyspace uses the input range defined in the workspace or a block.
'Fullrange' Polyspace uses full-range inputs.
ParamRangeMode — Option to set range of the constant parameters. 'DesignMinmax' Polyspace uses the constant parameter range defined in the workspace or in a block.
'None' (default) Polyspace uses the values of parameters specified in the code.
OutputRangeMode — Option to set output assertions. 'DesignMinMax' Polyspace applies assertions to outputs by using a range defined in a block or the workspace.
'None' (default) Polyspace does not apply assertions to the output variables.
ModelRefVerifDepth — Option to set depth of model reference hierarchy to be analyzed. 'Current model only' (default) Polyspace analyzes only the top model without analyzing the referenced models. Use this option when you refer to models that do not need to be analyzed, such as library models.
'1'|'2'|'3' Polyspace analyzes referenced models up to the specified depth in the reference hierarchy.
'All' Polyspace verifies all referenced models.
ModelRefByModelRefVerif — Option to analyze all referenced models together or individually. true Polyspace analyzes the top model and the referenced models together. Use this option to check for integration or scaling issues.
false (default) Polyspace analyzes the top model and the referenced models individually.
AutoStubLUT — Option to specify how lookup tables are used. false (default) Polyspace stubs the lookup tables and verifies the model without analyzing the lookup table code.
true Polyspace includes the lookup table code in the analysis.
CheckConfigBeforeAnalysis — Option to specify level of configuration checking before the Polyspace analysis starts. 'Off' Polyspace checks only for errors. The analysis stops if errors are found.
'OnWarn' (default) Polyspace stops the analysis when errors are found and displays a message when warnings are found.
'OnHalt' Polyspace stops the analysis when either errors or warnings are found.

Example: polyspaceArtifact(mdlname,psOpt)

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

  • falsepolyspaceArfitact generates artifacts assuming the that code is generated and analyzed as standalone code.

  • truepolyspaceArfitact generates artifacts assuming the that code is generated and analyzed as model reference code.

Example: polyspaceArtifact(mdlname,psOpt,true)

Data Types: logical

List of artifacts to generate, specified as a cell array containing one or both of these character vectors:

  • 'drs'polyspaceArtifact generates the file drs.xml containing the data range specifications.

  • 'linksdata'polyspaceArtifact generates the file linksdata.xml containing link-to-model data.

Example: polyspaceArtifact(mdlName',psOpt,true,{'drs'})

Data Types: char

Output Arguments

collapse all

Full paths to the generated artifacts, returned as a cell array of character vectors.

Use the generated artifacts to run a more precise Polyspace analysis. Keep the artifacts in the working directory of the Polyspace analysis.

Data Types: char

Version History

Introduced in R2024a