Main Content

本页采用了机器翻译。点击此处可查看英文原文。

背靠背 (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); 
### Starting build procedure for: sltestMILSILEquivalence
### Successful completion of build procedure for: sltestMILSILEquivalence

Build Summary

Top model targets built:

Model                    Action                        Rebuild Reason                                    
=========================================================================================================
sltestMILSILEquivalence  Code generated and compiled.  Code generation information file does not exist.  

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

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

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.选择执行背靠背测试。检查 Simulation1 是否设置为 Normal 以及 Simulation2 是否设置为 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