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 without access to 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
Preserving the Simulink model context information when running a Polyspace analysis 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.
Generate and Package Polyspace Options Files
To generate and package Polyspace options file for analyzing code generated from a Simulink model, use
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.tlcas the System target file
To 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
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
polyspacePackNGofunction :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
Optionally, you can use a
pslinkoptionsobject as a second argument to modify the default model configuration for the Polyspace analysis. Create a
pslinkoptionsobject, 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
slbuildfunction. 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);
polyspacepackNGoreturns the full path to the archive containing the options files. The files are located in the
polyspacefolder within the archived folder hierarchy. The content of the
polyspacefolder depends on the inputs of
If you do not specify the optional second and third arguments, then the folder
polyspacecontains 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.
linksData.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 named
polyspace_within the code archive. The folder
<referenced model name>
polyspacecontains 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
On a Windows® or Linux® command line, run:
productname-options-file optionsFile.txt -results-dir
corresponds to one of: polyspace-bug-finder, polyspace-code-prover, polyspace-bug-finder-server, or polyspace-code-prover-server.
corresponds to the location of the Polyspace results. This argument is optional.
To link the generated code with the Simulink model, the file
linksData.xmlis required. In case the file
linksData.xmlis 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_modelas links to model.
If you are using Polyspace Access to view the results, upload the file
linksData.xmlin the same folder as your Polyspace results. You cannot link the code with Simulink model if you do not have the file
linksData.xmlor 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.