创建使用第三方测试平台的测试
这些示例展示了如何使用 MATLAB® 开发使用 Simulink® Test™ ASAM® XIL 标准支持包在第三方测试平台上运行的测试。一个示例配置第三方测试平台并创建一个测试,通过设置条件来触发数据记录的开始和停止,从而控制数据采集。另一个示例有两个测试点,每个测试点配置不同的测试平台,但使用相同的共享测试体。有关 Simulink Test ASAM XIL 工作流程的更多信息,请参阅 使用 ASAM XIL 标准创建并运行测试。
这些示例继承自 sltest.TestCase
类,因此您可以使用打开 > 来打开基于 MATLAB 的 Simulink 测试(.m)将它们加载到测试管理器中。然后,在测试管理器中运行它们。或者,您可以在 MATLAB 命令行运行示例文件,但您不能从命令行将数据推送到测试管理器。
注意
要运行这些示例,您必须安装 ASAM XIL 标准的 Simulink Test 支持包。有关更多信息,请参阅安装并设置 Simulink XIL 标准的 ASAM Test 支持包。
使用控制数据采集的触发器创建 ASAM XIL 测试
xilexample_trigger
文件演示了如何配置第三方测试平台并运行测试,该测试使用触发器控制数据记录的开始和停止,将记录的数据推送到测试管理器并将结果与基线数据进行比较。
ABCCoTestPoint
函数创建一个 Framework
对象,配置一个测试平台端口并将测试变量映射到测试平台变量。有关更多信息,请参阅 sltest.xil.framework.Framework
和 sltest.xil.framework.FrameworkConfiguration
。
testBody
函数初始化框架以连接到配置的测试平台,并创建测试变量 rpm
、temperature
、target_rpm
和 input1
的实例。然后,该函数设置 rpm
和 temperature
变量的记录,当 rpm
大于 10
时开始,并在 15
秒后停止。然后,该函数使用 Stimulation
对象设置测试平台的外部输入,运行仿真,将记录的数据推送到测试管理器,并验证记录的数据和 baseline.mat
中的数据是否等效。有关设置输入和数据采集控制的更多信息,请参阅 sltest.xil.framework.Stimulation
sltest.xil.framework.Acquisition
。
classdef xilexample_trigger < sltest.TestCase methods (Test) function ABCCoTestPoint(testCase) import sltest.xil.framework.*; frm = Framework; frm.Configuration.addModelAccessPort(... 'MAPort1', ... 'asamxil.v2_1', ... 'VendorName','ABC Co.', ... 'ProductName','ABC Test Bench', ... 'ProductVersion','1.7', ... 'PortConfigFile',fullfile(pwd,'myConfigureFile.xml')); frm.Configuration.addTestVariableMapping(... 'rpm','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Outports/Out3']); frm.Configuration.addTestVariableMapping(... 'temperature','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Outports/Out4']); frm.Configuration.addTestVariableMapping(... 'target_rpm','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Parameters/K']); frm.Configuration.addTestVariableMapping(... 'input1','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Inports/Inport']); % Beyond this point the configuration is done and % the test is generic with no test bench specifics testBody(testCase,frm); end end methods (Access = 'private') function testBody(testCase,frm) import sltest.xil.framework.*; frm.init; rpm = frm.createVariable('rpm'); temperature = frm.createVariable('temperature'); target_rpm = frm.createVariable('target_rpm'); input1 = frm.createVariable('input1'); target_rpm.write(50); % Start acquisition when rpm reaches more than 10 and % stop after 15 seconds. frm.Acquisition.setupWithVariables([rpm,temperature], ... 'triggerVariables',rpm, ... 'startTriggerType','condition', ... 'startTriggerVal','rpm > 10', ... 'stopTriggerType','duration', ... 'stopTriggerVal',15); frm.Acquisition.start; % Set up a stimulation (external input) for the model. % Waveform defined here lasts 5 seconds and LoopCount % of 2 doubles its duration to 10 seconds. tseries = timeseries(cos(2*pi*(0:1000)/200)*10,(0:1000)/200); frm.Stimulation.setupWithVariablesAndData(... {{input1,tseries}},'LoopCount',2); frm.Stimulation.start; frm.start; disp(temperature.read); frm.Acquisition.wait; frm.stop; result = frm.Acquisition.fetch; frm.pushDataToSimulinkTestManager(testCase,result); testCase.verifySignalsMatch(result,'baseline1.mat'); end end end
使用两个测试平台创建 ASAM XIL 测试
xilexample_polling
代码文件展示了如何配置两个可以使用相同测试体的测试平台。
ABCCoTestPoint
函数创建一个 Framework
对象,配置一个测试平台端口并将测试变量映射到测试平台变量。有关更多信息,请参阅 sltest.xil.framework.Framework
和 sltest.xil.framework.FrameworkConfiguration
。
SimulinkRealTimeTestPoint
函数按照相同的步骤将 Simulink Real-Time™ 配置为第二个测试平台。
testBody
函数初始化框架以连接到配置的测试平台,并创建测试变量 rpm
、temperature
、target_rpm
和 input1
的实例。然后,该函数设置没有触发控制的 rpm
和 temperature
变量的数据采集,配置 Stimulation
对象以控制测试平台的输入,并启动仿真。请参阅 sltest.xil.framework.Acquisition
和 sltest.xil.framework.Stimulation
。该函数开始仿真并等待 temperature
变量小于 50
。当 temperature
变量值小于或等于 50
时,该函数会验证 rpm
变量值是否大于 100
,停止仿真,并将结果推送至测试管理器。
classdef xilexample_polling < sltest.TestCase methods (Test) function ABCCoTestPoint(testCase) import sltest.xil.framework.*; frm = Framework; % Add the ports frm.Configuration.addModelAccessPort(... 'MAPort1', ... 'asamxil.v2_1', ... 'VendorName','ABC Co.', ... 'ProductName','ABC Test Bench', ... 'ProductVersion','1.7', ... 'PortConfigFile',fullfile(pwd,'myConfigureFile.xml')); % Create the mapping from test variables to % test bench port variables frm.Configuration.addTestVariableMapping(... 'rpm','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Outports/Out3']); frm.Configuration.addTestVariableMapping(... 'temperature','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Outports/Out4']); frm.Configuration.addTestVariableMapping(... 'target_rpm','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Parameters/K']); frm.Configuration.addTestVariableMapping(... 'input1','MAPort1',... ['Targets/Controller/Simulation Models/'... 'Models/simpleXIL/Inports/Inport']); % Beyond this point the configuration is done and % the test is generic with no test bench specifics % Call the generic test body testBody(testCase, frm); end function SimulinkRealTimeTestPoint(testCase) import sltest.xil.framework.*; frm = Framework; % Create ports frm.Configuration.addModelAccessPort(... 'MAPort', ... 'asamxil.v2_1', ... 'VendorName', 'MathWorks', ... 'ProductName', 'XIL API', ... 'ProductVersion', '1.0', ... 'PortConfigFile', fullfile(pwd,'myConfigureFile.xml')); % Create the mapping from test variables to % test bench port variables frm.Configuration.addTestVariableMapping(... 'rpm','MAPort','simpleXIL/Gain:1','TaskName','SubRate1'); frm.Configuration.addTestVariableMapping('temperature',... 'MAPort','simpleXIL/Gain2:1','TaskName','SubRate2'); frm.Configuration.addTestVariableMapping('target_rpm',... 'MAPort','simpleXIL/Gain/Gain'); frm.Configuration.addTestVariableMapping('input1',... 'MAPort','simpleXIL/Inport:1'); % Beyond this point the configuration is done and % the test is generic with no test bench specifics % Call the generic test body testBody(testCase,frm); end end methods (Access = 'private') function testBody(testCase, frm) import sltest.xil.framework.*; frm.init; rpm = frm.createVariable('rpm'); temperature = frm.createVariable('temperature'); target_rpm = frm.createVariable('target_rpm'); input1 = frm.createVariable('input1'); target_rpm.write(100); frm.Acquisition.setupWithVariables([rpm, temperature]); frm.Acquisition.start; % Set up a stimulation (external input) for the model. % Waveform defined here lasts 5 seconds and LoopCount % of 2 doubles its duration to 10 seconds. tseries = timeseries(cos(2*pi*(0:1000)/200)*10,(0:1000)/200); frm.Stimulation.setupWithVariablesAndData(... {{input1,tseries}},'LoopCount',2); frm.Stimulation.start; frm.start; while(temperature.read > 50) pause(1); end testCase.verifyTrue(rpm.read >= 100); frm.stop; result = frm.Acquisition.fetch; frm.pushDataToSimulinkTestManager(testCase,result); end end end
另请参阅
sltest.xil.framework.Framework
| sltest.xil.framework.FrameworkConfiguration
| sltest.xil.framework.Acquisition
| sltest.xil.framework.Stimulation
| sltest.xil.framework.TestVariable
| sltest.TestCase