Main Content

pslinkrunCrossRelease

Analyze C/C++ code generated by R2020b or newer Embedded Coder versions by using a different version of Polyspace that is more recent than the Simulink version

Since R2021a

Description

[polyspaceFolder, resultsFolder] = pslinkrunCrossRelease(ModelOrSubsystem) runs a Polyspace® analysis of the code generated from ModelOrSubsystem by using Embedded Coder® from an earlier release of Simulink®.

example

[polyspaceFolder, resultsFolder] = pslinkrunCrossRelease(ModelOrSubsystem,psOpt) runs a Polyspace analysis of the code generated from ModelOrSubsystem through an earlier release of Simulink. The analysis uses the model configuration options that are specified in the pslinkoptions object psOpt.

example

[polyspaceFolder, resultsFolder] = pslinkrunCrossRelease(ModelOrSubsystem,psOpt,asModelRef) runs a Polyspace analysis of the code generated as a model reference from ModelOrSubsystem through an earlier release of Simulink.The analysis uses asModelRef to specify which type of generated code to analyze—standalone code or model reference code.

example

[polyspaceFolder, resultsFolder] = pslinkrunCrossRelease(ModelOrSubsystem,psOpt,asModelRef,OptionsFile) runs a Polyspace analysis of the code generated from ModelOrSubsystem through an earlier release of Simulink. The analysis uses the Polyspace analysis options specified in the options file OptionsFile.

example

Examples

collapse all

To run a Polyspace analysis on code generated by using an earlier release of Simulink, use the function pslinkrunCrossRelease. The analysis uses the configuration options associated with ModelOrSubsystem. The Simulink release must be R2020b or later. Before you run an analysis, you must integrate Polyspace with Simulink. See MATLAB Release Earlier Than Polyspace.

  1. Open the Simulink model polyspace_controller_demo and configure the model for code generation.

    cd(matlabroot);
    mdlName = 'polyspace_controller_demo';
    openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
    'supportingFile',mdlName);
    mkdir TempDir;
    load_system(mdlName);
    cd TempDir;
    configSet = getActiveConfigSet(model);
    set_param(configSet,'Solver','FixedStepDiscrete');
    set_param(configSet, 'SystemTargetFile', 'ert.tlc');

  2. To enable packing the generated code in an archive, set the option PackageGeneratedCodeAndArtifacts to true.

    set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true)
    

  3. Generate code from the model.

    slbuild(model);
    

  4. Start a Polyspace analysis.

    % Run Polyspace analysis
    [~,resultsFolder] = pslinkrunCrossRelease(model);
    bdclose(model);
    
    The character vector resultsFolder contains the full path to the results folder.

To run a Polyspace analysis with modified model configurations, use a pslinkoptions object. For a list of model configurations related to Polyspace analysis that you can modify, see the table Polyspace Configuration Parameters Supported by pslinkrunCrossRelease on this page. Before you run an analysis, you must integrate Polyspace with Simulink. See MATLAB Release Earlier Than Polyspace.

  1. Open the Simulink model polyspace_controller_demo and configure the model for code generation.

    cd(matlabroot);
    mdlName = 'polyspace_controller_demo';
    openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
    'supportingFile',mdlName);
    mkdir TempDir;
    load_system(mdlName);
    cd TempDir;
    configSet = getActiveConfigSet(model);
    set_param(configSet,'Solver','FixedStepDiscrete');
    set_param(configSet, 'SystemTargetFile', 'ert.tlc');

  2. To enable packing the generated code in an 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 configurations for the Polyspace analysis, use a pslinkoptions object. Create this object by using the function pslinkoptions. To run a Bug Finder analysis, set psOpt.VerificationMode to 'BugFinder'. To assert the range defined in a block on its input variables, specify psOpts.InputRangeMode as 'DesignMinMax'.

    % Create a Polyspace options object from the model. 
    psOpts = pslinkoptions(model);
    
    % Set model configurtion for the Polyspace analysis.
    psOpts.VerificationMode = 'BugFinder';
    psOpts.InputRangeMode = 'DesignMinMax';
    
    

  5. Start a Polyspace analysis. To specify model configuration for the Polyspace analysis, set the object psOpt as the optional second argument in pslinkrunCrossRelease.

    % Run Polyspace analysis
    [~,resultsFolder] = pslinkrunCrossRelease(model,psOpt);
    bdclose(model);
    
    The character vector resultsFolder contains the full path to the results folder.

To accelerate model simulations, invoke referenced Simulink models as simulation targets. To generate model reference simulation targets from a Simulink model, generate code from the ModelOrSubsystem by using slbuild with the build process specified as ModelReferenceCoderTarget. Package the generated code by using packNGo (Embedded Coder). Then, analyze the generated code by running a cross-release Polyspace analysis. Before you run an analysis, you must integrate Polyspace with Simulink. See MATLAB Release Earlier Than Polyspace.

  1. Open the Simulink model polyspace_controller_demo and configure the model for code generation.

    cd(matlabroot);
    mdlName = 'polyspace_controller_demo';
    openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
    'supportingFile',mdlName);
    mkdir TempDir;
    load_system(mdlName);
    cd TempDir;
    configSet = getActiveConfigSet(model);
    set_param(configSet,'Solver','FixedStepDiscrete');
    set_param(configSet, 'SystemTargetFile', 'ert.tlc');
    set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true)

  2. Generate code from the model. Specify the option ModelReferenceCoderTarget. See slbuild (Simulink).

    slbuild(model,'ModelReferenceCoderTarget');
    The generated code is stored in the folder slprj

  3. To package the code that is generated as a model reference, use the function packNGo. Locate the file buildinfo.mat in <working folder>/slprj/ert/polyspace_controller_demo and use the full path to it as the input to packNGo. This command generates an archive containing the generated code and the object buildinfo.mat. See packNGo (Embedded Coder).

    % Locate buildinfo and generate code archive
    buildinfo = fullfile(pwd,'slprj','ert',model,'buildinfo.mat');
    packNGo(buildinfo)

  4. To specify the Polyspace analysis options, use a pslinkoptions object. Create this object by using the function pslinkoptions. To run a 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';
    psOpts.InputRangeMode = 'DesignMinMax';
    
    

  5. Start a Polyspace analysis. To specify Polyspace analysis options, set the object psOpt as the optional second argument in pslinkrunCrossRelease. To analyze the code as a model reference, set the optional third argument asModelRef to true.

    % Run Polyspace analysis
    [~,resultsFolder] = pslinkrunCrossRelease(model,psOpt,true);
    bdclose(model);
    
    The character vector resultsFolder contains the full path to the results folder.

  1. Open the Simulink model polyspace_controller_demo and configure the model for code generation.

    cd(matlabroot);
    mdlName = 'polyspace_controller_demo';
    openExample('polyspace_code_prover/OpenSimulinkModelForPolyspaceAnalysisExample', ...
    'supportingFile',mdlName);
    mkdir TempDir;
    load_system(mdlName);
    cd TempDir;
    configSet = getActiveConfigSet(model);
    set_param(configSet,'Solver','FixedStepDiscrete');
    set_param(configSet, 'SystemTargetFile', 'ert.tlc');

  2. To enable packing the generated code in an 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. Create this object by using the function pslinkoptions. To run a 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';
    psOpts.InputRangeMode = 'DesignMinMax';
    

  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 all Bug Finder checkers and AUTOSAR C++14 coding rules, create a text file named OptionFile.txt. In the text file, enter:

    -checkers all
    -autosarcpp14 all
    Save the options file. You can save the preceding options in an options file named Options.txt in the default work folder.

    See Complete List of Polyspace Code Prover Analysis 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
    optionsPath = fullfile(userpath,'Options.txt');
    % Run Polyspace analysis
    [~,resultsFolder] = pslinkrunCrossRelease(model,psOpts,false,optionsPath);
    bdclose(model);
    
    The character vector resultsFolder contains the full path to the results folder.

Input Arguments

collapse all

Target of the analysis specified as a character vector with the model or system in single quotes. The default value is the system returned by bdroot (Simulink).

Example: resultsDir = pslinkrunCrossRelease('polyspace_controller_demo') where polyspace_controller_demo is the name of a model.

Data Types: char

Specifies the model configuration for the Polyspace analysis by using a pslinkoptions object. You can modify certain analysis options by modifying psOpt, which is an object where individual fields represent model configuration options. For a full list of options that you can modify, see this table.

Polyspace Configuration Parameters Supported by pslinkrunCrossRelease

PropertyDescriptionValueDescription
EnableAdditionalFileListEnable an additional file list to be analyzed, specified as true or false. Use with the AdditionalFileList option. truePolyspace verifies additional files specified in the AdditionalFileList option.
false (default)Polyspace does not verify additional files.
AdditionalFileListList of additional files to be analyzed, specified as a cell array of files. To add these files to the analysis, use the EnableAdditionalFileList option.cell arrayPolyspace considers the listed files for verification.
VerificationModePolyspace analysis mode specified as 'BugFinder', for a Bug Finder analysis, or 'CodeProver', for a Code Prover verification.'BugFinder'Polyspace runs a Bug Finder analysis.
'CodeProver' (default)Polyspace runs a Code Prover analysis.
InputRangeModeSpecifies the range of the input variables.'DesignMinMax' (default)Polyspace uses the input range defined in the workspace or a block.
'Fullrange'Polyspace uses full range inputs.
ParamRangeModeSpecifies the range of the constant parameters.'DesignMinmax'Polyspace uses the constant parameter range defined in the workspace or in a block.
'None' (default)Polyspace uses the value of parameters specified in the code.
OutputRangeModeSpecifies the output assertions.'DesignMinMax'Polyspace applies assertions to outputs by using a range defined in a block or the workspace.
'None' (default)Polyspace does not apply assertions to the output variables.
ModelRefVerifDepthSpecify the depth for analyzing the models that are referenced by the current model.'Current model Only' (default)Polyspace analyzes only the top model without analyzing the referenced models. Use this option when you refer to models that do not need to be analyzed, such as library models.
'1'|'2'|'3'Polyspace analyzes referenced models up to the specified depth in the reference hierarchy. To analyze the models that are referenced by the top model, specify the property ModelRefVerifDepth as '1'. To analyze models that are referenced by the first level of references, specify this property as '2'.
'All'Polyspace verifies all referenced models.
ModelRefByModelRefVerifSpecify whether you want to analyze all referenced models together or individually.truePolyspace analyzes the top model and the referenced models together. Use this option to check for integration or scaling issues.
false (default)Polyspace analyzes the top model and the referenced models individually.
AutoStubLUTSpecifies how lookup tables are used.true (default)Polyspace stubs the lookup tables and verifies the model without analyzing the lookup table code.
falsePolyspace includes the lookup table code in the analysis.
CheckConfigBeforeAnalysisSpecifies the level of configuration checking done before the Polyspace analysis starts.'Off'Polyspace checks only for errors. The analysis stops if errors are found.
'OnWarn' (default)Polyspace stops the analysis when errors are found and displays a message when warnings are found.
'OnHalt'Polyspace stops the analysis when either errors or warnings are found.

Example: pslinkrunCrossRelease('polyspace_controller_demo', psOpt), where psOpt is an options object created by calling pslinkoptions

Indicator for model reference analysis, specified as true or false.

  • If asModelRef is false (default), the function generates options files so that Polyspace analyzes the generated code as standalone code.

  • If asModelRef is true, the function generates options files so that Polyspace analyzes the generated code as model reference code.

Example: pslinkrunCrossRelease('polyspace_controller_demo', psOpt,true)

Data Types: logical

Relative path to a text file that contains a list of Polyspace analysis options. The options file must have each option in a separate line.

Example: pslinkrunCrossRelease('polyspace_controller_demo', psOpt,true,'OptionsFile.txt')

Data Types: char

Output Arguments

collapse all

Name of the folder containing Polyspace projects and results, specified as a character vector. The default value of this variable is results_$ModelName$.

To change this value, see Output folder.

Full path to subfolder containing Polyspace results, specified as a character vector.

The folder results_$ModelName$ contains your Polyspace project and a subfolder $ModelName$ containing the analysis results. This variable provides the full path to the subfolder.

To change the parent folder results_$ModelName$, see Output folder.

Version History

Introduced in R2021a