技术文章和新闻通讯

为什么要收集模型测试覆盖率指标

帕特·坎尼(Pat Canny),数学


系统测试您的simulink金宝app®设计可以确保你占了两个tended and unintended behavior before generating code. During requirements-based simulation testing, parts of your design might not be exercised due to subtle design errors, incomplete tests, or missing requirements. Model test coverage helps you identify these gaps in testing by measuring how much of your Simulink design has been exercised during simulation.

A common cause of incomplete model test coverage during requirements-based testing is missing requirements. This type of missing model test coverage is often a result of design elements that cannot be traced to a higher-level requirement. Collecting model test coverage helps you account for this situation. This article describes an example in which testing of a triplex selection algorithm design is found to be incomplete due to a missing requirement.

Triplex Selection Algorithm: Overview and Requirements

Triplex signal selection algorithms are commonly used in aerospace control system software. In triplex signal selection, a single “voted” signal is selected from three independent sensors for use in the control of the aircraft. A sensor is “valid” if there are no faults detected for that sensor.

For this example, the aircraft Airspeed signal will be selected. The requirements for the Airspeed signal selection algorithm are as follows:

  • HLR_1选择三重传感器的空速信号:The flight control computer shall select the middle value of the three sensors when three Airspeed signals are valid.
  • HLR_2 Selecting Airspeed Signal for Dual Sensors:当仅两个空速信号有效时,飞行控制计算机应选择两个传感器的平均值。
  • HLR_3 Selecting Airspeed Signal of Single Sensor:The flight control computer shall select the valid signal when only one Airspeed signal is valid.

Figure 1 shows the Simulink implementation of these requirements.

图1. Simuli金宝appnk实现了空速信号选择算法。

图1. Simuli金宝appnk实现了空速信号选择算法。

Implementing the Algorithm and Collecting Model Test Coverage Metrics

我们在模型中的专用子系统中实现每个要求,并为每个测试案例编写一个单独的测试用例。在进行这些测试之前,我们需要确保捕获模型测试覆盖率指标。

模型测试覆盖率指标可以是个体(用于单个测试)或累积(在多个测试中汇总)。我们将在基于需求的测试中收集累积覆盖范围,以衡量我们的完整测试套件的整个设计。

There are many types of model test coverage metrics, such as execution coverage, decision coverage, signal range coverage, and relational boundary coverage. In this example, we are interested in decision coverage, a type of structural coverage that measures execution of all possible logical outcomes for a decision in the model. Simulink model objects such as Switch blocks receive full decision coverage if all inputs to the switch have been selected at least once during simulation.

We enable model test coverage collection on a model using the Coverage Analyzer app in theAppsSimulink工具条金宝app的选项卡(图2)。

图2. Simulink工具条中的“应用程序”选项卡。金宝app

图2.AppsSimulink工具条金宝app中的选项卡。

打开覆盖范围分析仪应用程序后,我们可以使用Coverage ON/OFFbutton in theCoveragetab. We also enable cumulative coverage using theCumulative Collection按钮。然后,我们使用使用该模型模拟模型button, now labeledAnalyze Coverage(Figure 3). We simulate several times with different test vectors used in each simulation.

图3.启用覆盖范围收集的Coverage Analyzer应用程序。

图3.启用覆盖范围收集的Coverage Analyzer应用程序。

图4显示了最终的覆盖范围。绿色突出显示表示完整的模型测试覆盖范围,包括每个子系统中的所有模型对象,而红色表示不完整的覆盖范围。

图4.空速信号选择算法的测试结果。

Figure 4. Coverage results from tests of the Airspeed signal selection algorithm.

在Multiport开关块上似乎缺少决策范围。为了了解为什么会发生这种情况,我们通过打开Simulink中的覆盖范围详细信息来检查单个块的模型测试覆盖范围(图5)。金宝app

Figure 5. Opening the Simulink coverage details pane.

Figure 5. Opening the Simulink coverage details pane.

然后,我们单击MultiportSwitch块以查看其覆盖范围的详细信息(图6)。

Figure 6. Coverage details pane for the Multiport Switch block.

Figure 6. Coverage details pane for the Multiport Switch block.

The first input to the Multiport Switch was never 0 during simulation. Recall the model shown in Figure 1, where the first input to the Multiport Switch is the number of valid signals. As a result, we did not test a case where none of the Airspeed signals was valid.

这种丢失的模型测试覆盖范围是由于缺少的高级要求。当没有空速信号有效时,均不应选择哪个信号。但是,看来设计包含逻辑以解决此条件。

我们添加了这个缺失的要求:

  • HLR_4 Selecting Airspeed Signal of No Valid Sensor:The flight control computer shall hold the selected Airspeed signal when none of the three Airspeed signals are valid.

然后,我们添加一个新的测试用例并重新运行测试。现在,我们获得了完整的决策范围(图7)。

图7.添加新要求后的覆盖范围结果。

图7.添加新要求后的覆盖范围结果。

As this example showed, model test coverage is a reliable way to identify missing requirements during requirements-based testing. You can use the model test coverage results to ensure that the correct parts of your design are being exercised.

模型测试覆盖范围不完整的另一个常见原因是dead logic。死逻辑是Simulink模型或状态流的任何部分金宝app®在模拟过程中永远无法执行的图表,例如无法选择的开关块的输入,或者在状态计算机中无法进行的过渡。最佳实践是使用Simulink Design Ver金宝appifier™在编写和执行基于需求的测试之前分析模型并解决死亡逻辑。您还可以在Simulink Check™中使用Model Slicer功能来完善和调试Dead L金宝appogic。

Published 2019

查看有关相关功能的文章

View Articles for Related Industries