Run Polyspace Analysis on S-Function Code
If you want to check your S-function code for bugs or errors, you can run Polyspace® directly from your S-function block in Simulink®.
Prerequisites
Before you run Polyspace from MATLAB®, you must link your Polyspace and MATLAB installations. See Integrate Polyspace with MATLAB and Simulink.
S-Function Analysis Workflow
To verify an S-function with Polyspace, follow this recommended workflow:
Compile your S-function to be compatible with Polyspace.
Select your Polyspace options.
Run a Polyspace Bug Finder™ analysis or a Polyspace Code Prover™ verification using one of the two analysis modes:
This Occurrence — Analyzes the specified occurrence of the S-function with the input for that block.
All Occurrences — Analyzes the S-function with input values from every occurrence of the S-function.
Review results in the Polyspace interface.
For information about navigating through your results, see Filter and Group Results in Polyspace Desktop User Interface.
For help reviewing and understanding the results, see Complete List of Polyspace Bug Finder Results.
Compile S-Functions to Be Compatible with Polyspace
Before you analyze your S-function with Polyspace Bug Finder , you must compile your S-function with one of following tools:
The Legacy Code Tool with the
def.Options.supportCoverageAndDesignVerifier
set totrue
. Seelegacy_code
(Simulink).The S-Function Builder block, with Enable support for Design Verifier selected on the Build Info tab of the S-Function Builder dialog box.
The Simulink Coverage™ function
slcovmex
(Simulink Coverage), with the option-sldv
.
Example S-Function Analysis
This example shows the workflow for analyzing S-functions with Polyspace. You use the model psdemo_model_link_sl
and the
S-function Command_Strategy
.
Open the model and use the Legacy Code Tool to compile the S-function
Command_Strategy
.% Open Model psdemo_model_link_sl % Compile S-function Command_Strategy def = legacy_code('initialize'); def.SourceFiles = { 'command_strategy_file.c' }; def.HeaderFiles = { 'command_strategy_file.h' }; def.SFunctionName = 'Command_Strategy'; def.OutputFcnSpec = 'int16 y1 = command_strategy(uint16 u1, uint16 u2)'; def.IncPaths = { fullfile(polyspaceroot, ... 'toolbox','polyspace','pslink','pslinkdemos','psdemo_model_link_sl') }; def.SrcPaths = def.IncPaths; def.Options.supportCoverageAndDesignVerifier = true; legacy_code('compile',def);
Open the model
psdemo_model_link_sl/controller
.Specify the code analysis options. On the Apps tab, select Polyspace Code Verifier. Then, on the Polyspace tab:
Select the product to run: Bug Finder or Code Prover. A Code Prover analysis detects run-time errors while a Bug Finder analysis detects coding defects and coding rule violations.
Select Settings. In the Configuration Parameters dialog box, make sure that the following parameters are set:
Settings from — Select
Project configuration
. Other values in the drop down menu enables checking different coding rules, which require using Bug Finder as the Mode.Open results automatically after verification — On
Apply your settings and close the Configuration Parameters.
Right-click the Command_Strategy block and select Polyspace > Verify S-Function > This Occurrence.
Follow the analysis in the MATLAB Command Window. When the analysis is finished, your results open in the Polyspace interface.