Main Content

Analyze Code Generated as Standalone Code in a Distributed Workflow

Generate and package Polyspace® options files from a Simulink® model by using the function polyspacepackNGo. Use these options files to run a Polyspace analysis on the generated code that uses model-specific information, such as design range specifications, without requiring Simulink.

Open Model

The model demo_math_operations performs various mathematical operations on the model inputs. The model has a C Function block that executes a custom C code. The model also has a C Caller block that calls the C function GMean, which is implemented in the source file GMean.c. To open the model for code generation and packaging Polyspace options file, search for the current topic in the MATLAB help browser and click the Open Model button. Alternatively, in the MATLAB Command Window, paste and run the following code.


Configure Model

To configure the model for generating code and packaging Polyspace options files, specify these configuration parameters:

  • To create an archive containing the generated code, set 'PackageGeneratedCodeAndArtifacts' to true.

  • Specify a name for the code archive. For instance, set the name to

  • To use the custom code setting specified in Simulation Target during code generation, set 'RTWUseSimCustomCode' to 'on'.

  • To make the model and the generated code compatible with Polyspace, set ert.tlc as the system target file. See Recommended Model Configuration Parameters for Polyspace Analysis (Polyspace Bug Finder).

In Command Window or Editor, enter these parameter configurations:

configSet = getActiveConfigSet('demo_math_operations');
set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true);
set_param(configSet, 'PackageName', '');
set_param(configSet, 'SystemTargetFile', 'ert.tlc');

Generate Code Archive

Specify a folder for storing the generated code. To start code generation, in the Command Window or in the Editor, enter:

codegenFolder = 'demo_math_operations_ert_rtw';
if exist(fullfile(pwd,codegenFolder), 'dir') == 0

Because PackageGeneratedCodeAndArtifacts is set to true, the generated code is packed into the archive

Generate and Package Polyspace Options File

To generate Polyspace options files for the generated code, in the Command Window or in the Editor, enter:

zipFile = polyspacePackNGo('demo_math_operations');

In the archive, find the options files in the folder <current folder>/polyspace.

Run Polyspace Analysis by Using the Packaged Options Files

  1. Unzip the code archive and locate the <current folder>/polyspace folder.

  2. Open a command-line terminal and change your working folder to the polyspace subfolder of the unzipped folder by using the cd command.

  3. Start a Polyspace analysis.

    • To run a desktop Polyspace analysis, use either polyspace-code-prover or polyspace-bug-finder. To run the Polyspace analysis in a server, use either polyspace-bug-finder-server or polyspace-code-prover-server. Polyspace Bug Finder and Code Prover analyze the code differently. See Choose Between Polyspace Bug Finder and Polyspace Code Prover (Polyspace Bug Finder).

    • Specify the file optionsFile.txt as the argument to -options-file.

    To run a Code prover analysis, run this command: polyspace-code-prover -options-file optionsFile.txt -results-dir Results.

  4. Follow the progress of the analysis in the log file that is generated in the Results folder.

  5. To view the results in the desktop user interface, in the command-line interface, enter: polyspace Results\ps_results.pscp. The extension of the ps_results file changes depending on whether you run a Code Prover analysis or a Bug Finder analysis. The result contains several orange checks.

    Alternatively, upload the result to Polyspace Access. See Upload Results to Polyspace Access (Polyspace Bug Finder Access).

  6. Address the results. For more information, see Address Results Through Bug Fix or Comments (Polyspace Bug Finder).

See Also

| | (Embedded Coder)