Create Tests That Use Third-Party Test Benches
These examples show how you can use MATLAB® to develop tests that run on third-party test benches using the Simulink® Test™ Support Package for ASAM® XIL Standard. One example configures a third-party test bench and creates a test that controls data acquisition by setting conditions to trigger the start and stop of data logging. The other example has two test points, that each configure a different test bench, but use the same shared test body. For more information on the Simulink Test ASAM XIL workflow, see Create and Run Tests Using the ASAM XIL Standard.
The examples inherit from the sltest.TestCase
      class, so you can load them into the Test Manager using Open > Open MATLAB-Based Simulink Test (.m). Then, run them in the Test Manager. Alternatively, you can run the example
      files at the MATLAB command line, but you cannot push data to the Test Manager from the
      command line.
Note
To run these examples, you must install the Simulink Test Support Package for ASAM XIL Standard. For more information, see Install and Set Up the Simulink Test Support Package for ASAM XIL Standard.
Create ASAM XIL Test with Trigger that Controls Data Acquisition
The xilexample_trigger file demonstrates how to configure a
         third-party test bench and run a test that uses a trigger to control the start and stop of
         data logging, push the logged data to the Test Manager and compare the results
         to baseline data.
The ABCCoTestPoint function creates a Framework
         object, configures a test bench port and maps test variables to test bench variables. For
         more information, see sltest.xil.framework.Framework and sltest.xil.framework.FrameworkConfiguration.
The testBody function initializes the framework to connect to the
         configured test bench and creates instances of the test variables rpm,
            temperature, target_rpm, and
            input1. Then, the function sets up logging of the
            rpm and temperature variables to start when
            rpm becomes greater than 10 and to stop after
            15 seconds. Then, the function uses a Stimulation
         object to set up an external input to the test bench, runs the simulation, pushes the
         logged data to the Test Manager and verifies that the logged data and data in
            baseline.mat are equivalent. For more information on setting up
         inputs and data acquisition controls, see 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
Create ASAM XIL Test with Two Test Benches
The xilexample_polling code file shows how to configure two test
         benches that can use the same test body. 
The ABCCoTestPoint function creates a Framework
         object, configures a test bench port and maps test variables to test bench variables. For
         more information, see sltest.xil.framework.Framework and sltest.xil.framework.FrameworkConfiguration.
The SimulinkRealTimeTestPoint function follows the same steps to
         configure Simulink
            Real-Time™ as a second test bench. 
The testBody function initializes the framework to connect to the
         configured test bench and creates instances of the test variables rpm,
            temperature, target_rpm, and
            input1. Then, the function sets up data acquisition for
            rpm and temperature variables without a trigger
         control, configures the Stimulation object to control input to the test
         bench, and starts the simulation. See sltest.xil.framework.Acquisition and sltest.xil.framework.Stimulation. The function starts the simulation and waits
         for the temperature variable to be less than 50. When
         the temperature variable value is less than or equal to
            50, the function verifies that the rpm variable
         value is greater than 100, stops the simulation, and pushes the results
         to the Test Manager.
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
See Also
sltest.xil.framework.Framework | sltest.xil.framework.FrameworkConfiguration | sltest.xil.framework.Acquisition | sltest.xil.framework.Stimulation | sltest.xil.framework.TestVariable | sltest.TestCase
Topics
- Install and Set Up the Simulink Test Support Package for ASAM XIL Standard
 - Create and Run Tests Using the ASAM XIL Standard
 - ASAM XIL Classes and Methods Supported by Simulink Test