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 for Distributed Analysis
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 and click the Open Model button. Alternatively, in the MATLAB® Command Window, paste and run the following code.
openExample('sl_poly_bf_poly_code_prover/OpenModelForPolyspacePackNGoExample'); open_system('demo_math_operations');
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'
totrue
.Specify a name for the code archive. For instance, set the name to
genCodeArchive.zip
.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', 'genCodeArchive.zip'); set_param(configSet, 'SystemTargetFile', 'ert.tlc'); set_param(configSet,'RTWUseSimCustomCode','on')
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 slbuild('demo_math_operations') end
Because PackageGeneratedCodeAndArtifacts
is set to
true
, the generated code is packed into the archive
genCodeArchive.zip
.
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 genCodeArchive.zip
, find the options files in the
folder
.<current
folder>
/polyspace
Run Polyspace Analysis by Using the Packaged Options Files
Unzip the code archive
genCodeArchive.zip
and locate the
folder.<current folder>
/polyspaceOpen a command-line terminal and change your working folder to the
polyspace
subfolder of the unzipped folder by using thecd
command.Start a Polyspace analysis.
To run a desktop Polyspace analysis, use either
polyspace-code-prover
orpolyspace-bug-finder
. To run the Polyspace analysis in a server, use eitherpolyspace-bug-finder-server
orpolyspace-code-prover-server
. Polyspace Bug Finder and Code Prover analyze the code differently. See Differences 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
.Follow the progress of the analysis in the log file that is generated in the
Results
folder.To view the results in the desktop user interface, in the command-line interface, enter:
polyspace Results\ps_results.pscp
. The extension of theps_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).
Address the results. For more information, see Address Results Through Bug Fix or Comments (Polyspace Bug Finder).
See Also
polyspacePackNGo
| slbuild
| packNGo
(Embedded Coder)