主要内容

Creating and Using Coverage Filters

此示例显示了如何使用Simulink®Coverage™型号金宝app覆盖过滤器将模型项目排除在覆盖范围结果中,并证明报告中缺少覆盖范围。

覆盖范围Filters

在验证过程中,模型可以包含几种防止完整模型覆盖的构造,例如包含未经测试且与验证过程无关的控制器驱动程序的子系统。您可以将此子系统从覆盖范围的结果中排除。

Alternatively, you may have testing criteria that requires exercising certain aspects of a block, such as hitting particular decision points. If it is not feasible to satisfy all objective outcomes for this block, and you did not intend for your tests to exercise these unsatisfied outcomes, then you could justify this missing coverage.

Filtering these constructs in coverage results by excluding or justifying them allows you to focus on other aspects of missing coverage that can and should be tested.

覆盖范围filters are stored in.cvffiles. Each filter consists of rules that exclude or justify certain model objects, or individual coverage objective outcomes. Multiple filter files can be applied to coverage results for a model. Furthermore, multiple models can also make use of the same filter file.

覆盖范围filters can be created and applied either before or after simulating a model. Both workflows are described in this example.

开放型号

This example makes use of theslvnvdemo_covfiltmodel. The model shows some common patterns that might need to be filtered from coverage results. Open the model.

open_system('slvnvdemo_covfilt');

Specify Items to Exclude from Coverage Results before Simulation

库块slvnvdemo_covfilt_lib/protected division防止分裂为零。如果您确定在此上下文中没有预期或打算完全覆盖此块的每个实例的测试,则可以将块排除在覆盖范围之外。

在Simuli金宝appnk编辑器中,右键单击一个实例受保护的师库块并导航到覆盖范围选项。该块的选项允许您过滤库的特定实例或对此库的所有引用。选择Exclude referenced library: slvnvdemo_covfilt_lib/protected divisionto filter all references.

This opens theFilter Editorsection of the覆盖结果探索者。注意a new filter file, initially named无标题,已经创建了,并添加了用于排除对库块的所有引用的过滤规则。

指定Nameand描述对于新的过滤器文件。在桌子中,打开理由field for the new rule and enter text describing why this block is excluded, such as"division by zero protection"。点击Apply完成后保存过滤器文件。文件对话框将提示您指定在何处保存此文件。

Reuse Existing Filter File

You can share and reapply filter files with generalized rules to filter coverage results for various different models that contain similar constructs.

例如,现有过滤器文件Filter_Tick.cvfcaptures a rule to exclude the Stateflow temporal event打钩from coverage results. This event can never be false and, therefore, could prevent full Condition and MCDC coverage in any model using打钩in event-based temporal logic in Stateflow.

Becauseslvnvdemo_covfilt/模式逻辑包含这样的构造,您可以应用过滤器文件Filter_Tick.cvfto the model.

To apply this existing filter file, right-click on the应用过滤器node in the覆盖结果探索者and select负载过滤器。在打开的文件对话框中,选择Filter_Tick.cvf然后单击Open

注意应用过滤器现在列出两者filter_divby0andFilter_Tick

模拟和审查过滤的覆盖结果

点击Run (Coverage)按钮以模拟模型并记录覆盖范围。仿真完成后,模型上突出显示了覆盖范围结果覆盖范围Details窗口打开。

请注意,这两个引用受保护的师library block are colored gray in the Simulink canvas, indicating that they have been excluded from the coverage results.

滚动浏览内容覆盖范围Details窗口,并记下标题为Objects Filtered from Coverage Analysis。This section lists each of the excluded elements and the corresponding rationales for each and is organized by filter file. Bothfilter_divby0andFilter_Tickhave been applied.

Create a New Filter File

这filter files used above capture generalized filter rules that could be broadly applicable to many different models.

Create another filter file to separately capture filter rules exclusively relevant to this model.

在里面覆盖结果探索者, right-click on the应用过滤器node and selectNew filter

Enter a name and description for this filter file. ClickApply并指定在哪里保存文件。

Exclude Items from Coverage Results after Simulation

这previous sections of this example show how to specify filter rules to apply before running a simulation. You can also create and apply filter rules to coverage results after simulation. This allows you to review coverage results, create or adjust filters, and generate a new coverage report without having to rerun the simulation.

Consider, for example, the Switchable config subsystem. It is a common design pattern to use constant values to drive subsystem enable ports for changing model configurations; however, the enable logic and subsystem contents might lead to missing coverage. This configuration is not used in this model, and therefore can be excluded from coverage results.

在Simuli金宝appnk编辑器中,单击可切换配置子系统。这覆盖范围Details窗口将导航到此子系统的详细信息。在这些详细信息下,单击Justify or Exclude关联。

A new filter rule is added to the currently selected filter file in theFilter Editor。By default, the mode for this rule is set to"Excluded"。Enter the rationale for this rule, such as"unused config"

点击Apply当完成。这样可以保存更改过滤器文件,并自动更新模型上显示的覆盖范围结果。请注意,可开关配置子系统现在显示为灰色,表明它已从覆盖范围结果中排除。

从覆盖范围的结果中证明个人目标结果合理

在Simuli金宝appnk编辑器中,单击饱和block and review the coverage results in the覆盖范围Detailswindow. Notice that two Decision outcomes are unsatisfied. This is because the饱和块的下限为0以及上限200。However, the input to this block is the速度信号,永远不会小于或等于0。因此,lower limit of the饱和block is not expected to be fully exercised, so the corresponding Decision outcome can be justified.

单击添加理由规则旁边的图标错误的决策结果"input > lower limit"

A new filter rule is added to the currently selected filter file in theFilter Editor。指定justification rationale, such as“速率> 0”

点击Applywhen finished to save the filter file and update the coverage results shown on the model.

请注意,在覆盖范围Details窗口,饱和Block的合理结果以浅蓝色突出显示,并具有与理由的链接。这真的outcome of the decision"input >= upper limit"未过滤,据报道不满意。因此,饱和模型中仍然突出显示了块,以表示缺少覆盖范围。

Automatically Generate Filter Rules for Dead Logic

在某些情况下,missing coverage is due to dead logic. The associated coverage objectives are unsatisfiable. If this logic is meant for constructs that you do not wish to remove from your model, then those coverage objectives can be justified.

If you have a Simulink Design Verifier™ license, then you can automatically create justification filter rules for dead logic.

在里面覆盖结果探索者,选择应用过滤器node. In theFilter Editor窗格,选择选项Make justification filter rules for dead logic (using Simulink Design Verifier)

此选项使用Simulink Des金宝appign Verifier™来分析死亡逻辑的模型。完成后,将创建一个新的过滤文件,并为每个相应的覆盖范围成果添加了理由规则。

为此过滤器指定名称和说明。点击Apply当完成。在生成的文件对话框,specify where to save this filter file.

Close the金宝appSimulink设计验证程序结果windows that opened.

Review Filtered Coverage Results

在Simuli金宝appnk编辑器中,导航到审查结果section of the覆盖范围应用,然后单击覆盖范围Highlighting

After applying all four filters used in this example, the simulation now achieves 100% Condition, 63% Decision, and 75% Execution coverage for this model. Note that the coverage results no longer contain any model objects that receive MCDC, so this metric is not listed.

这remaining missing coverage in the模式逻辑图表,时间捕获子系统和饱和块表示测试不足,应通过使用进一步的模拟和更彻底地行使这些元素的输入值来解决。

结论

覆盖范围过滤提供了各种方法,用于指示模型的各个方面,这些方法是在当前的测试环境中预期或打算完全行使的。

Filtering model objects and coverage objective outcomes that do not need to be exercised allows you to focus on the missing coverage for constructs that can and should be tested.