Main Content

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:

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.

  1. 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');

  2. The cross-release analysis requires packaging the generated code into a code archive. Set the option PackageGeneratedCodeAndArtifacts to true.

    set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true)
    

  3. Generate code from the model.

    slbuild(model);
    

  4. To specify the model configuration for the Polyspace analysis, use a pslinkoptions object. To run a Polyspace Bug Finder™ analysis, set psOpt.VerificationMode to 'BugFinder'.

    % Create a Polyspace options object from the model. 
    psOpts = pslinkoptions(model);
    
    % Set properties that define the Polyspace analysis.
    psOpts.VerificationMode = 'BugFinder';
    
    Alternatively, set psOpt.VerificationMode to 'CodeProver' to run a Polyspace Code Prover™ analysis.

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

    % 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);
    See Complete List of Polyspace Bug Finder Analysis Engine Options.

  6. Start a Polyspace analysis.

    • To specify the model configurations for the Polyspace analysis run, set the object psOpt as the optional second argument in pslinkrunCrossRelease.

    • Because the code is generated as standalone code, set the third argument asModelRef to false.

    • To specify the Polyspace analysis options, specify the relative path to the created options file as the fourth argument.

    %  Locate options file in the current folder
    optionsPath = fullfile(pwd,optFile);
    % Run Polyspace analysis
    [~,resultsFolder] = pslinkrunCrossRelease(model,psOpts,false,optionsPath);
    bdclose(model);
    
    Follow the progress of the analysis in the MATLAB Command Window.

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.

  1. To open the results in the Polyspace User Interface, use the function pslinkfun. The character vector resultsFolder 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.

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

| | (Simulink) | (Embedded Coder) |

Related Topics