主要内容

本页翻译不是最新的。点击此处可查看最新英文版本。

对 S-Function 代码运行 Polyspace 分析

如果要检查 S-Function 代码是否存在 Bug 或错误,您可以直接从 Simulink® 中的 S-Function 模块运行 Polyspace®

前提条件

在从 MATLAB® 中运行 Polyspace 之前,必须将已安装的 Polyspace 与 MATLAB 相关联。请参阅将 Polyspace 与 MATLAB 和 Simulink 集成

S-Function 分析工作流

要使用 Polyspace 验证 S-Function,请遵循以下建议的工作流:

  1. 编译 S-Function 以与 Polyspace 兼容。

  2. 选择 Polyspace 选项。

  3. 使用以下两种分析模式之一运行 Polyspace Bug Finder™ 分析或 Polyspace Code Prover™ 验证:

    • 此实例 - 使用该模块的输入分析 S-Function 的指定实例。

    • 所有实例 - 使用 S-Function 的每个实例的输入值分析 S-Function。

  4. 在 Polyspace 界面中查看结果。

编译 S-Function 以与 Polyspace 兼容

在使用 Polyspace Code Prover 分析 S-Function 之前,您必须使用以下工具之一编译 S-Function:

  • 代码继承工具,将 def.Options.supportCoverageAndDesignVerifier 设置为 true。请参阅 legacy_code (Simulink)

  • S-Function Builder 模块,在“S-Function Builder”对话框的编译信息选项卡上选择启用对 Design Verifier 的支持

  • Simulink Coverage™ 函数 slcovmex (Simulink Coverage),使用 -sldv 选项。

S-Function 分析示例

此示例显示了使用 Polyspace 分析 S-Function 的工作流。您将使用模型 psdemo_model_link_sl 和 S-Function Command_Strategy

  1. 打开模型并使用代码继承工具编译 S-Function Command_Strategy

    % Open Model
    psdemo_model_link_sl
    
    % Compile S-function Command_Strategy
    def = legacy_code('initialize');
    def.SourceFiles = { 'command_strategy_file.c' };
    def.HeaderFiles = { 'command_strategy_file.h' };
    def.SFunctionName = 'Command_Strategy';
    def.OutputFcnSpec = 'int16 y1 = command_strategy(uint16 u1, uint16 u2)';
    def.IncPaths = { fullfile(polyspaceroot, ...
      'toolbox','polyspace','pslink','pslinkdemos','psdemo_model_link_sl') };
    def.SrcPaths = def.IncPaths;
    def.Options.supportCoverageAndDesignVerifier = true;
    legacy_code('compile',def);
  2. 打开模型 psdemo_model_link_sl/controller

  3. 指定代码分析选项。在 App 选项卡上,选择 Polyspace 代码验证器。然后,在 Polyspace 选项卡上:

    • 选择要运行的产品:Bug FinderCode Prover。Code Prover 分析可检测运行时错误,而 Bug Finder 分析可检测编码缺陷和编码违规。

    • 选择设置。在“配置参数”对话框中,确保设置了以下参数:

      • 设置来源 - 选择工程配置。下拉菜单中的其他值允许检查不同的编码规则,这需要使用 Bug Finder 作为模式

      • 验证后自动打开结果 - 打开

    应用设置并关闭“配置参数”对话框。

  4. 右键点击 Command_Strategy 模块并选择 Polyspace > 验证 S-Function > 此实例

  5. 按照 MATLAB 命令行窗口中的分析进行操作。分析完成后,结果将在 Polyspace 界面中打开。

另请参阅

主题