主要内容

原子子系统的背靠背 (MIL/SIL) 等效性测试

此示例说明如何为原子子系统创建并运行背靠背测试(也称为等效性测试)。

Model with plant and controller subsystems

为模型生成代码

打开模型,配置运行 Simulink 的系统,然后为整个模型生成代码。

model = 'sltestMILSILEquivalence'; 
open_system(model);
% Configure for code generation
if ismac
    lProdHWDeviceType = 'Intel->x86-64 (Mac OS X)';
elseif isunix
    lProdHWDeviceType = 'Intel->x86-64 (Linux 64)';
else
    lProdHWDeviceType = 'Intel->x86-64 (Windows64)';
end

set_param(model, 'ProdHWDeviceType', lProdHWDeviceType);
slbuild(model); 
### Searching for referenced models in model 'sltestMILSILEquivalence'.
### Total of 1 models to build.
### Starting build procedure for: sltestMILSILEquivalence
### Successful completion of build procedure for: sltestMILSILEquivalence

Build Summary

Top model targets:

Model                    Build Reason                                         Status                        Build Duration
==========================================================================================================================
sltestMILSILEquivalence  Information cache folder or artifacts were missing.  Code generated and compiled.  0h 0m 21.641s 

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 23.726s

使用测试管理器和“为模型组件创建测试”向导创建背靠背测试

1.打开测试管理器。

sltest.testmanager.view;

2.点击新建 > 为模型组件创建测试

Menu selection for Test for Model Component

3.点击“使用当前模型”图标 icon.png,以将 sltestMILSILEquivalence 模型添加到顶层模型字段中。选择 Controller 并点击加号。然后点击下一步

Create test for model component wizard with controller subsystem selected

4.选择使用来自顶层模型的组件输入作为测试输入。然后点击下一步

Create test for model component wizard with using component input from the top model as test input selected

5.选择执行背靠背测试。检查并确保仿真 1 设置为 Normal,并且仿真 2 设置为 Software-in-the-Loop (SIL)。然后点击下一步

Create test for model component wizard with back-to-back testing selected

6.保留用于保存测试数据和生成的测试的默认值:

  • 选择测试框架输入源Inports

  • 指定文件格式MAT

  • 指定保存测试数据的位置sltest_sltestMILSILEquivalence

  • 测试文件位置:sltest_sltestMILSILEquivalence_tests

然后,点击完成。“为模型组件创建测试”会生成背靠背(等效性)测试,然后返回到测试管理器。

Create test for model component wizard with Inports as the test harness input source, MAT as the file format, and the default locations to save the test data and generated test.

7.在测试管理器的测试浏览器窗格中,选择测试文件 sltest_sltestMILSILEquivalence_tests。展开覆盖率设置部分以启用覆盖率收集。在要收集的覆盖率下,选中记录在测系统的覆盖率。在覆盖率度量下,选中决策MCDC。覆盖率评估测试的完整性。

Coverage settings

8.选择 sltestMILSILEquivalence_Harness1 测试用例。展开仿真 1 部分和仿真 2 部分及其子部分包括在测系统仿真设置和版本覆盖以查看设置。

Test Manager with simulation one set for normal mode

Test Manager with simulation two set for software-in-the-loop mode

运行测试并查看结果

1.点击测试管理器工具栏中的运行

2.测试运行完成后,在结果和工件窗格中,选择结果并查看聚合覆盖率结果部分。普通仿真和 SIL 仿真的覆盖率均为 100%,这表明针对所选模型覆盖率度量的测试是完全的。

Aggregated coverage results

3.展开结果层次结构,并选择 Equivalence Criteria Result 下的 Out1:1。普通仿真和 SIL 仿真之间的差值为零,这表明两种仿真产生相同的结果。

Results display showing matching sim output for both simulations and zero difference between the signals

关闭模型,然后清除和关闭测试管理器

close_system(model,0)
sltest.testmanager.clear
sltest.testmanager.clearResults
sltest.testmanager.close

另请参阅

主题