Main Content

Run Polyspace Analysis on Generated Code by Using Packaged Options Files

When you start a Polyspace® analysis directly from the Simulink® toolstrip, the analysis takes the model-specific context, such a design ranges, into consideration. When running a Polyspace analysis without access to Simulink, you must specify the model-specific information by using options files. Instead of authoring these options files, use the options files generated and packaged by the function polyspacePackNGo.

Preserving the Simulink model context information when running a Polyspace analysis can be useful in various situations. For instance:

  • Distributed workflow: A Simulink user generates code from a model and sends the code to another development environment. In this environment, a Polyspace user, who might not have Simulink, runs a separate analysis of the generated code. By using the packaged options files, the design ranges and other model-specific information is preserved in the Polyspace analysis.

  • Analysis options not available in Simulink: Some Polyspace analysis options are available only when the Polyspace analysis is run separately from Simulink. Use packaged options files to run a separate Polyspace analysis while preserving the model-specific information. For instance, analyze concurrent threads in generated code by running a Polyspace analysis in the generated code by using the packaged options files.

You must have Simulink to run the function polyspacePackNGo. You do not need Polyspace to generate the options files from a Simulink model. The polyspacePackNGo function supports code generated by Embedded Coder® and TargetLink®. For a tutorial on using polyspacePackNGo, see Analyze Code Generated as Standalone Code in a Distributed Workflow.

Generate and Package Polyspace Options Files

To generate and package Polyspace options file for analyzing code generated from a Simulink model, use polyspacePackNGo.

  1. In the Simulink Editor, open the Configuration Parameters dialog box and configure the model for code generation.

  2. To configure the model for compatibility with Polyspace, select ert.tlc as the System target file

  3. To enable generating a code archive, select the option Package code and artifacts. Optionally, provide a name for the options package in the field Zip file name. If your code contains a custom code block, select Use the same custom code settings as Simulation target in the Code Generation> Custom Code pane.

    Alternatively, in the MATLAB® Command Window, enter:

    % Configure the Simulink model mdlName for code generation
    configSet = getActiveConfigSet(mdlName);
    set_param(configSet, 'PackageGeneratedCodeAndArtifacts', true);
    set_param(configSet, 'PackageName', 'CodeArchive.zip');
    set_param(configSet, 'SystemTargetFile', 'ert.tlc');
    set_param(configSet,'RTWUseSimCustomCode','on');

  4. Generate the code archive.

    • To generate an archive of standalone generated code from the top model, use the function slbuild.

    • To generate code as a model reference, use the function slbuild. After generating code as model reference, create the code archive by using the function packNGo (Embedded Coder).

    • Alternatively, you can use TargetLink to generate the code. Create the code archive by archiving the generated code into a zip file.

  5. To generate and package the Polyspace option files, in the MATLAB Command Window ,use the polyspacePackNGo function :

    zipFile = polyspacePackNGo(mdlName);
    See Generate and Package Polyspace Options Files.

    If you use TargetLink to generate code, then use the TargetLink subsystem name as the input argument to polyspacepacknGo.

  6. Optionally, you can use a pslinkoptions object as a second argument to modify the default model configuration for the Polyspace analysis. Create a pslinkoptions object, modify model configurations and specify the object when creating the archive:

    psOpt = pslinkoptions(mdlName);
    psOpt.InputRangeMode = 'FullRange';
    psOpt.ParamRangeMode = 'DesignMinMax';
    zipFile = polyspacePackNGo(mdlName,psOpt);
    
    See Package Polyspace Options Files That Have Specific Polyspace Analysis Options.

  7. Use the optional third argument to specify whether to generate and package Polyspace options files for code generated as a model reference. Suppose you generated code as a model reference by using the slbuild function. To generate and package Polyspace options for the code, at the MATLAB Command Window, enter:

    zipFile = polyspacePackNGo(mdlName,[],true);
    See Package Polyspace Options Files for Code Generated as a Model Reference.

    The function polyspacepackNGo returns the full path to the archive containing the options files. The files are located in the polyspace folder within the archived folder hierarchy. The content of the polyspace folder depends on the inputs of polyspacePackNGo function.

    • If you do not specify the optional second and third arguments, then the folder polyspace contains these options files in a flat hierarchy:

      • optionsFile.txt: This file specifies the source files, the include files, data range specifications, and analysis options required for analyzing the generated code by using Polyspace. If your code contains custom C code, then this file specifies the relative paths of the custom source and header files.

      • modelname_drs.xml: This file specifies the design range specification of the model.

      • linksData.xml: This file links the generated code to the components of the model.

    • If you specify psOpts.ModelbyModelRef = true, then corresponding options files are generated for all referenced models. These options files are stored in separate folders named polyspace_<referenced model name> within the code archive. The folder polyspace contains the options files for the top model.

Run Polyspace Analysis by Using the Packaged Options Files

Once the code archive and the Polyspace option files are generated, you can use the archive to run a Polyspace analysis on the generated code in a different development environment without Simulink.

  1. Unzip the code archive and locate the polyspace folder.

  2. On a Windows® or Linux® command line, run: productname -options-file optionsFile.txt -results-dir resultdir.

    • productname corresponds to one of: polyspace-bug-finder, polyspace-code-prover, polyspace-bug-finder-server, or polyspace-code-prover-server.

    • resultdir corresponds to the location of the Polyspace results. This argument is optional.

    To link the generated code with the Simulink model, the file linksData.xml is required. In case the file linksData.xml is not generated in the options file archive, use the option Code Generator Support in Polyspace desktop User Interface to specify which comments in the code act as links to the Simulink model. In the Polyspace desktop User Interface, select Tools > Preferences and locate the Miscellaneous tab. From the context menu Code comments that act as code-to-model-link, select the code generator that you used. If you select User defined, then specify the comments that act as a code-to-model link by specifying their prefix in the field Comments beginning with. For instance, if you specify the prefix as //Link_to_model, then Polyspace interprets comments starting with //Link_to_model as links to model.

    If you are using Polyspace Access to view the results, upload the file linksData.xml in the same folder as your Polyspace results. You cannot link the code with Simulink model if you do not have the file linksData.xml or if you upload it outside the Polyspace result folder.

  3. To review the result, upload it to Polyspace Access and view the results in a web browser. Alternatively, view the result by using the user interface of the Polyspace desktop products.

See Also

| | (Embedded Coder)

Related Topics