Run Polyspace on Code Generated by Using Previous Releases of Simulink
You can use a more recent release of Polyspace® without changing your Simulink® release. See Polyspace Support of MATLAB and Simulink from Different Releases.
In such a cross-release configuration, use the function pslinkrunCrossRelease
to run a Polyspace analysis
on the code generated by using Embedded Coder®. If you use Polyspace and Simulink from the same release, see Run Polyspace Analysis on Code Generated from Simulink Model.
Prerequisite
When starting a Polyspace analysis from a different release of MATLAB® or Simulink:
The Polyspace release must be more recent compared to your Simulink release.
Your Simulink release must be R2020b or later.
You must integrate Polyspace with Simulink. See Integrate Polyspace with MATLAB and Simulink.
This cross-release configuration does not support analyzing the custom code in your Simulink model.
Run a Cross-Release Polyspace Analysis
To run a Polyspace analysis of code generated by using an earlier release of Simulink, generate code archive from the Simulink model and then call the function
pslinkrunCrossRelease
. Create and customize a
pslinkoptions
object to modify the model configuration. For a list of
configuration options that you can modify, see pslinkrunCrossRelease
. To apply Polyspace analysis options, use an options file.
Open the Simulink model
polyspace_controller_demo
and configure the model for code generation. See Recommended Model Configuration Parameters for Polyspace Analysis.cd(matlabroot); model = 'polyspace_controller_demo'; openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample',... 'supportingFile',model); mkdir TempDir; load_system(model); cd TempDir; % Configure the model configSet = getActiveConfigSet(model); set_param(configSet,'Solver','FixedStepDiscrete'); set_param(configSet, 'SystemTargetFile', 'ert.tlc');
The cross-release analysis requires packaging the generated code into a code archive. Set the option
PackageGeneratedCodeAndArtifacts
totrue
.set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true)
Generate code from the model.
slbuild(model);
To specify the model configuration for the Polyspace analysis, use a
pslinkoptions
object. To run a Polyspace Bug Finder™ analysis, setpsOpt.VerificationMode
to'BugFinder'
.Alternatively, set% Create a Polyspace options object from the model. psOpts = pslinkoptions(model); % Set properties that define the Polyspace analysis. psOpts.VerificationMode = 'BugFinder';
psOpt.VerificationMode
to'CodeProver'
to run a Polyspace Code Prover™ analysis.To specify Polyspace analysis options, create an options file. An options file is a text file that contains Polyspace options in a flat list, one line for each option. For instance, to enable Polyspace Bug Finder checkers and CERT C coding rules, create a text file in the current folder containing the corresponding options.
See Complete List of Polyspace Code Prover Analysis Options.% Create Options file optFile = 'Options.txt'; fid = fopen(optFile,'wt'); option1 = '-checkers all'; option2 = '-cert-c all'; fprintf(fid, '%s\n%s', option1, option2); fclose(fid);
Start a Polyspace analysis.
To specify the model configurations for the Polyspace analysis run, set the object
psOpt
as the optional second argument inpslinkrunCrossRelease
.Because the code is generated as standalone code, set the third argument
asModelRef
tofalse
.To specify the Polyspace analysis options, specify the relative path to the created options file as the fourth argument.
Follow the progress of the analysis in the MATLAB Command Window.% Locate options file in the current folder optionsPath = fullfile(pwd,optFile); % Run Polyspace analysis [~,resultsFolder] = pslinkrunCrossRelease(model,psOpts,false,optionsPath); bdclose(model);
Review Results
In a cross-release workflow, direct calls to functions such as
polyspaceBugFinder
or polyspaceCodeProver
are not available. To open the results, use the function pslinkfun
.
To open the results in the Polyspace User Interface, use the function
pslinkfun
. The character vectorresultsFolder
contains the full path to the results folder.pslinkfun('openresults', '-resultsfolder',resultsFolder);
You can upload the results to Polyspace Access. See Upload Results to Polyspace Access.
Review the results, and fix or justify the identified issues. For more information, see Address Results in Polyspace User Interface Through Bug Fixes or Justifications.
See Also
pslinkrunCrossRelease
| polyspacePackNGo
| slbuild
(Simulink) | packNGo
(Embedded Coder) | pslinkfun