Main Content

polyspacePackNGo

Generate and package options files to run Polyspace analysis on code generated from Simulink model

Since R2020b

Description

example

archivePath = polyspacePackNGo(mdlName) examines the Simulink® model mdlName, extracts Polyspace® options files from it, and packages the options files in the zip file located at archivePath. Before using polyspacePackNGo, generate code from your Simulink model. Then archive the generated code, for instance, by using packNGo. Generate the Polyspace options files from the Simulink model and include them in the code archive by using polyspacePackNGo. In a different development environment, when running a Polyspace analysis of the generated code, use the options files included in the code archive to preserve model-specific information, such as design range specifications. You must have Embedded Coder® to use slbuild.

example

archivePath = polyspacePackNGo(mdlName,psOpt) generates and packages the Polyspace options files that are generated according to the specification in psOpt. The object psOpt must be a Polyspace options object that is generated by using pslinkoptions. Using psOpt, modify the options for the Polyspace analysis.

example

archivePath = polyspacePackNGo(mdlName,psOpt,asModelRef) generates and packages the Polyspace options files by using asModelRef to specify whether to generate option files for model reference code or standalone code.

Examples

collapse all

To generate and package Polyspace options files for a Simulink model, use polyspacePacknGo.

Open the Simulink model polyspace_controller_demo and 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 enable packing the generated code in an archive, set the option PackageGeneratedCodeAndArtifacts to true. Specify the name of the generated code archive as genCodeArchive.zip.

configSet = getActiveConfigSet(mdlName);
set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true);
set_param(configSet, 'PackageName', 'genCodeArchive.zip');

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

set_param(configSet, 'SystemTargetFile', 'ert.tlc');

After configuring the model, generate code.

slbuild(mdlName)

Because PackageGeneratedCodeAndArtifacts is set to true, the generated code is packed into the archive genCodeArchive.zip.

Generate and package Polyspace options files.

zipFile = polyspacePackNGo(mdlName);
In the code archive genCodeArchive.zip, the Polyspace options files are packaged in the TempDir\polyspace folder.

To specify the Polyspace analysis options when packaging and generating options 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);
% Enable packing the generated code into an archive
set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true);
% Specify a name for the code archive
set_param(configSet, 'PackageName', 'genCodeArchive.zip');
% Configure the model to be Polyspace Compatible
set_param(configSet, 'SystemTargetFile', 'ert.tlc');

After configuring the model, generate code.

slbuild(mdlName)

Because PackageGeneratedCodeAndArtifacts is set to true, the generated code is packed into the archive genCodeArchive.zip.

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 where the fields are model configurations that you can specify.

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

psOpt.InputRangeMode = 'FullRange';

Generate and package Polyspace options files. Use the psOpt object as the second argument in polyspacePacknGo.

zipFile = polyspacePackNGo(mdlName,psOpt);
In the code archive genCodeArchive.zip, the Polyspace options files are packaged in the TempDir\polyspace folder. The file optionsFile.txt contains the specified Polyspace analysis options.

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. Then, package the generated code by using packNGo. To generate and package Polyspace options files for analyzing such code, use the function polyspacePacknGo 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);
% Enable packing the generated code into an archive
set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true);
% Specify a name for the code archive
set_param(configSet, 'PackageName', 'genCodeArchive.zip');
% 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.

To package the code that is generated as a model reference, use the function packNGo. Locate the file buildinfo.mat in <working folder>/slprj/ert/polyspace_controller_demo and use the full path to it as the input to packNGo. This command generates an archive containing the generated code and the object buildinfo.mat. See packNGo (Embedded Coder).

% Locate buildinfo and generate code archive
buildinfo = fullfile(pwd,'slprj','ert',mdlName,'buildinfo.mat');
packNGo(buildinfo)

Generate and package Polyspace options files. Omit the optional second argument. Set the third argument asModelRef to true.

zipFile = polyspacePackNGo(mdlName,[],true);
In the code archive, the Polyspace options files are packaged in the polyspace folder.

Input Arguments

collapse all

A character array containing the name of the model for which you want to generate and package the Polyspace options files.

Example: polyspacePackNGo('modelName')

Data Types: char

Specifies the model configuration for the Polyspace analysis by using a pslinkoptions object. You can modify certain analysis options by modifying psOpt, which is a structure where individual fields represent analysis options. For a fill list of options that you can modify, see the table Polyspace Analysis Options Supported by polyspacePacknGo.

Polyspace Analysis Options Supported by polyspacePacknGo

PropertyValueDescription
EnableAdditionalFileList: Enable an additional file list to be analyzed, specified as true or false. Use with the AdditionalFileList option. truePolyspace verifies additional files specified in the AdditionalFileList option.
false (default)Polyspace does not verify additional files.
AdditionalFileList: 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 arrayPolyspace considers the listed files for verification.
InputRangeMode: Specifies the 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: Specifies the 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 value of parameters specified in the code.
OutputRangeMode: Specifies the 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: Specify the depth for analyzing the models that are referenced by the current model.'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. To analyze the models that are referenced by the top model, specify the property ModelRefVerifDepth as '1'. To analyze models that are referenced by the first level of references, specify this property as '2'.
'All'Polyspace verifies all referenced models.
ModelRefByModelRefVerif: Specify whether you want to analyze all referenced models together or individually.truePolyspace 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: Specifies how lookup tables are used.true (default)Polyspace stubs the lookup tables and verifies the model without analyzing the lookup table code.
falsePolyspace includes the lookup table code in the analysis.
CheckConfigBeforeAnalysis: Specifies the level of configuration checking done 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: polyspacePackNGo('modelName', psOpt), where psOpt is an options object created by calling pslinkoptions

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

  • If asModelRef is false (default), the function generates options files so that Polyspace analyzes the generated code as standalone code.

  • If asModelRef is true, the function generates options files so that Polyspace analyzes the generated code as model reference code.

    Note

    If you set asModelRef to true, use slbuild to generate code.

Example: polyspacePackNGo('modelName', psOpt,true)

Data Types: logical

Output Arguments

collapse all

A character array containing the path to the generated archive. The options files are located in the polyspace folder in the archive. The polyspace folder contains these options files:

  • optionsFile.txt: a text file containing the Polyspace options required to run a Polyspace analysis on the generated code without losing model-specific information, such as design range specification.

  • model_drs.xml: A file containing the design range specification of the model.

  • linksData.xml: A file that links the generated code to the components of the model.

To run a Polyspace analysis on the generated code in an environment that is different than the environment where the code was generated from the Simulink model, use these files.

Data Types: char

Version History

Introduced in R2020b