Run Polyspace Analysis on Generated Code by Using Packaged Options Files
When you start a Polyspace® analysis directly from the Simulink® toolstrip, the analysis takes the model-specific context, such a design
ranges, into consideration. When running a Polyspace analysis from outside Simulink, you must specify the model-specific information by using options files.
Instead of authoring these options files, use the options files generated and packaged by
the function polyspacePackNGo
.
Preserving the Simulink model context information when running a Polyspace analysis from outside Simulink can be useful in various situations. For instance:
Distributed workflow: A Simulink user generates code from a model and sends the code to another development environment. In this environment, a Polyspace user, who might not have Simulink, runs a separate analysis of the generated code. By using the packaged options files, the design ranges and other model-specific information is preserved in the Polyspace analysis.
Analysis options not available in Simulink: Some Polyspace analysis options are available only when the Polyspace analysis is run separately from Simulink. Use packaged options files to run a separate Polyspace analysis while preserving the model-specific information. For instance, analyze concurrent threads in generated code by running a Polyspace analysis in the generated code by using the packaged options files.
You must have Simulink to run the function polyspacePackNGo
. You do not need
Polyspace to generate the options files from a Simulink model. The polyspacePackNGo
function supports code
generated by Embedded Coder® and TargetLink®. For a tutorial on using polyspacePackNGo
, see Analyze Code Generated as Standalone Code in a Distributed Workflow (Simulink).
Generate and Package Polyspace Options Files
To generate and package Polyspace options file for analyzing code generated from a Simulink model, use polyspacePackNGo
.
In the Simulink Editor, open the Configuration Parameters dialog box and configure the model for code generation.
To configure the model for compatibility with Polyspace, select
ert.tlc
as the System target fileTo enable generating a code archive, select the option Package code and artifacts. Optionally, provide a name for the options package in the field Zip file name. If your code contains a custom code block, select Use the same custom code settings as Simulation target in the Code Generation> Custom Code pane.
Alternatively, in the MATLAB® Command Window, enter:
% Configure the Simulink model mdlName for code generation configSet = getActiveConfigSet(mdlName); set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true); set_param(configSet, 'PackageName', 'CodeArchive.zip'); set_param(configSet, 'SystemTargetFile', 'ert.tlc'); set_param(configSet,'RTWUseSimCustomCode','on');
Generate the code archive.
To generate an archive of standalone generated code from the top model, use the function
slbuild
(Simulink).To generate code as a model reference, use the function
slbuild
(Simulink). After generating code as model reference, create the code archive by using the functionpackNGo
(Embedded Coder).Alternatively, you can use TargetLink to generate the code. Create the code archive by archiving the generated code into a zip file.
To generate and package the Polyspace option files, in the MATLAB Command Window ,use the
polyspacePackNGo
function :See Generate and Package Polyspace Options Files.zipFile = polyspacePackNGo(mdlName);
If you use TargetLink to generate code, then use the TargetLink subsystem name as the input argument to
polyspacepacknGo
.Optionally, you can use a
pslinkoptions
object as a second argument to modify the default model configuration for the Polyspace analysis. Create apslinkoptions
object, modify model configurations and specify the object when creating the archive:See Package Polyspace Options Files That Have Specific Polyspace Analysis Options.psOpt = pslinkoptions(mdlName); psOpt.InputRangeMode = 'FullRange'; psOpt.ParamRangeMode = 'DesignMinMax'; zipFile = polyspacePackNGo(mdlName,psOpt);
Use the optional third argument to specify whether to generate and package Polyspace options files for code generated as a model reference. Suppose you generated code as a model reference by using the
slbuild
function. To generate and package Polyspace options for the code, at the MATLAB Command Window, enter:See Package Polyspace Options Files for Code Generated as a Model Reference.zipFile = polyspacePackNGo(mdlName,[],true);
The function
polyspacepackNGo
returns the full path to the archive containing the options files. The files are located in thepolyspace
folder within the archived folder hierarchy. The content of thepolyspace
folder depends on the inputs ofpolyspacePackNGo
function.If you do not specify the optional second and third arguments, then the folder
polyspace
contains these options files in a flat hierarchy:optionsFile.txt
: This file specifies the source files, the include files, data range specifications, and analysis options required for analyzing the generated code by using Polyspace. If your code contains custom C code, then this file specifies the relative paths of the custom source and header files.
: This file specifies the design range specification of the model.modelname
_drs.xmllinksData.xml
: This file links the generated code to the components of the model.
If you specify
psOpts.ModelbyModelRef = true
, then corresponding options files are generated for all referenced models. These options files are stored in separate folders namedpolyspace_
within the code archive. The folder<referenced model name>
polyspace
contains the options files for the top model.
Run Polyspace Analysis by Using the Packaged Options Files
Once the code archive and the Polyspace option files are generated, you can use the archive to run a Polyspace analysis on the generated code in a different development environment without Simulink.
Unzip the code archive and locate the
polyspace
folder.On a Windows® or Linux® command line, run:
.productname
-options-file optionsFile.txt -results-dirresultdir
corresponds to one of: polyspace-bug-finder, polyspace-code-prover, polyspace-bug-finder-server, or polyspace-code-prover-server.productname
corresponds to the location of the Polyspace results. This argument is optional.resultdir
To link the generated code with the Simulink model, the file
linksData.xml
is required. In case the filelinksData.xml
is not generated in the options file archive, use the option Code Generator Support in Polyspace desktop User Interface to specify which comments in the code act as links to the Simulink model. In the Polyspace desktop User Interface, select Tools > Preferences and locate the Miscellaneous tab. From the context menu Code comments that act as code-to-model-link, select the code generator that you used. If you select User defined, then specify the comments that act as a code-to-model link by specifying their prefix in the field Comments beginning with. For instance, if you specify the prefix as//Link_to_model
, then Polyspace interprets comments starting with//Link_to_model
as links to model.If you are using Polyspace Access to view the results, upload the file
linksData.xml
in the same folder as your Polyspace results. You cannot link the code with Simulink model if you do not have the filelinksData.xml
or if you upload it outside the Polyspace result folder.To review the result, upload it to Polyspace Access and view the results in a web browser. Alternatively, view the result by using the user interface of the Polyspace desktop products.
See Also
polyspacePackNGo
| polyspace.Project
| slbuild
(Simulink) | packNGo
(Embedded Coder)