Documentation

测试两个模拟等效性

在正常和SIL模拟模式下验证模型当量。

此示例显示了如何使用测试安全带和测试管理器测试两个模型之间的等效性。一个模型以正常模式运行,由子系统在循环(SIL)模式下运行的测试线束模型。

The equivalence test case in the test manager compares signal output between two simulations to determine equivalence. Signals from the main model and the test harness are set up for logging in this example. The logged signals are used as the equivalence criteria between normal and SIL mode.

Configure the Model

Open thesltestNormalSILEquivalenceExamplemodel.

MDL='sltestNormalSILEquivalenceExample'; harnessOwner ='sltestNormalSILEquivalenceExample/Controller'; open_system(mdl);

Turn on signal logging in the model.

set_param(MDL,“信号”,'on','signalloggingName','SIL_signals');

Mark the Controller subsystem output and input signals for logging.

ph_controller_in = get_param('sltestNormalalSequivalenceExample/Controller/in1',“ Porthandles”);ph_controller_out= get_param('sltestNormalSILEquivalenceExample/Controller',“ Porthandles”);set_param(ph_controller_in.Outport(1),'DataLogging','on');set_param(ph_controller_out.outport(1),,'DataLogging','on');清除ph_controller_inph_controller_out;

模拟模型并输出已记录的信号。信号数据用作测试线束的输入。

out = sim(mdl);

获取已记录的信号数据。

out_data = out.get('SIL_signals');control_in1= out_data.get(2);

Create a Test Harness for SIL Verification.

The command to create the harness will generate code. Switch to a directory with write permissions.

origdir = pwd;dirname = tempname;mkdir(dirname);CD(dirname);clearup = oncleanup(@()cd(origdir));sltest.harness.create(线束,'Name','SIL_Harness','VerificationMode','SIL');
### Starting build procedure for model: Controller ### Successful completion of build procedure for model: Controller ### Creating SIL block ... Building with 'gcc'. MEX completed successfully.

Open the test harness.

sltest.harness.open(harnessOwner,'SIL_Harness');

Set Up Logging in the Test Harness

Turn on signal logging in the test harness.

set_param('SIL_Harness',“信号”,'on','signalloggingName','SIL_signals');

Mark the test harness outport for signal logging to use in the equivalence test case.

ph_harness_out = get_param('sil_harness/Controller',“ Porthandles”);set_param(ph_harness_out.Outport(1),'DataLogging','on');清除ph_harness_out;

将来自仿真的输入数据分配到测试线束。

set_param('SIL_Harness','LoadExternalInput','on',...'ExternalInput','control_in1.Values');

在测试管理器中创建等效测试用例

Open the test manager by selectingAnalysis > Test Manageror the command

sltestmgr

创建等效测试用例。

  1. From the test manager toolstrip, click theNewarrow and select测试文件>空白测试文件.

  2. Specify the test file astestHarnessEquivalence.mldatx. The test manager creates the test file with a new test suite and baseline test case by default.

  3. 在里面Test Browserpane, select the baseline test case,新的测试用例1, and click删除.

  4. SelectNew Test Suite 1.

  5. 在工具条中,单击Newarrow and select等效测试.

  6. 在里面Test Browserpane, right-click the new equivalence test case and selectRename. Name the new equivalence test caseSIL Equivalence Test.

Assign the test harness to the equivalence test caseSimulation 1.

  1. ExpandSimulation 1System Under Test.

  2. Click theUse current modelbutton to assignsltestNormalSILEquivalenceExampletoModel.

  3. Expand测试安全带.

  4. Click theRefresh按钮以获取最新的可用测试安全带列表。

  5. Select SIL_Harness from theHarness菜单用作System Under Test.

Assign thesltestNormalSILEquivalenceExample模型为Simulation 2.

  1. 坍塌Simulation 1.

  2. ExpandSimulation 2System Under Test.

  3. Click theUse current modelbutton to assignsltestNormalSILEquivalenceExampletoModel.

  4. 坍塌Simulation 2.

Capture the equivalence criteria. UnderEquivalence Criteria, clickCapture运行测试安全带Simulation 1和identify the equivalence signal.

Run the Test Case and View the Results

SelectSIL Equivalence Test在里面Test Browserpane and clickRun在里面toolstrip. The test manager switches to theResults and Artifactspane and runs the equivalence test case. The test case passes because the signal comparison between the model and the test harness matches. Expand the results set and select theController:1选项按钮以绘制信号比较。

close_system(mdl, 0); clearMDLharnessOwner清理control_in1origDiroutout_data;