Main Content

Run Polyspace Analysis on S-Function Code

R2026b

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:

  1. Compile your S-function to be compatible with Polyspace.

  2. Select your Polyspace options.

  3. 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.

  4. Review results in the Polyspace interface.

Compile S-Functions to Be Compatible with Polyspace

Before you analyze your S-function with Polyspace, you must compile your S-function with one of following tools:

  • The Legacy Code Tool with the def.Options.supportCoverageAndDesignVerifier set to true. See legacy_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.

  1. 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);
  2. Open the model psdemo_model_link_sl/controller.

  3. 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 Model Settings. In the Configuration Parameters dialog box, set the following parameters:

      • Open results automatically after verification — On

      • Settings from — Expand the Advanced parameters section and set Settings from to Project configuration. Other values in the drop down menu enable checking different coding rules, which require using Bug Finder as the Mode.

        Note

        Settings from will be removed in a future release. See Settings from (C).

    Apply your settings and close the Configuration Parameters.

  4. Right-click the Command_Strategy block and select Polyspace > Verify S-Function > This Occurrence.

  5. Follow the analysis in the MATLAB Command Window. When the analysis is finished, your results open in the Polyspace Platform user interface.

See Also

Topics