Main Content

Real-Time Testing with the Simulink Test Support Package for ASAM XIL Standard

The Simulink® Test™ Support Package for ASAM® XIL Standard implements the ASAM XIL API, which is a standard that defines communication between test automation tools, such as Simulink Test, and test benches, such as Simulink Real-Time™ and third-party test benches. The ASAM XIL API enables running real-time hardware-, software-, and model-in-the-loop (HIL, SIL and MIL, respectively) test cases created in Simulink Test using its XIL framework. The Simulink Test framework includes methods for mapping variables from the test code to the test bench, configuring the ports to use, specifying test bench startup and shutdown order, and other commands to query and control the test bench.

Simulink Test ASAM XIL Standard Workflow

This workflow describes the steps for creating a test that uses the Simulink Test Support Package for ASAM XIL Standard. The workflow tasks are:

If you want to use more than one test bench, repeat the set up and configuring the test bench tasks for each test bench. For detailed examples, see Create Tests Using the Simulink Test Support Package for ASAM XIL Standard.

Configure the Test Bench

Follow these steps to configure the test bench port, add the port to the Simulink Test ASAM XIL framework, and map variables from the model to the test bench variables. You can include the code for these steps in the same file as the test body (see Create the Test Body).

  1. Create an instance of the sltest.xil.framework.Framework class. Use only one Framework object at a time.

  2. Use the displayAvailableTestbenches method of sltest.xil.framework.Framework to obtain the names of the available test benches.

  3. Create an XML port configuration file. The configuration options depend on the test bench. Replace the product version number shown in the sample port configuration file with the version you have. Sample port configuration files are:

    • Simulink Real-Time

      Use createPortConfigureFile (Simulink Real-Time) to create the file.

    • NI™ VeriStand

      <?xml version="1.0" encoding="UTF-8"?>
      <NIVSPortConfig>
         <Version Major="2020" Minor="4" Fix="0" Build="0"/>
         <Project>C:\NIProjects\Project.nivsproj</Project>
      </NIVSPortConfig>
      

    • dSPACE®

      <?xml version="1.0" encoding="utf-8"?>
      <PortConfigurations 
         xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
         <MAPortConfig>
            <SystemDescriptionFile>
               C:\DSPACEProjects\smd_1104_sl.sdf
            </SystemDescriptionFile>
            <PlatformName>DS1104</PlatformName>
         </MAPortConfig>
      </PortConfigurations>
      

  4. Add the port to use with the Simulink Test ASAM XIL framework. See Create Tests Using the Simulink Test Support Package for ASAM XIL Standard for where to include this code in the MATLAB® code file with the test body. Replace the product version number shown in the sample port file with the version you have.

    • Simulink Real-Time.

      To use all of the Simulink Real-Time functionality, add all three ports.

      framework.Configuration.addModelAccessPort(...
         'MAPort', ...
         'asamxil.v2_1', ...
         'VendorName','MathWorks', ...
         'ProductName','XIL API', ...
         'ProductVersion','1.0', ...
         'PortConfigFile',fullfile(pwd,'myConfigureFile.xml'));
      framework.Configuration.addECUCalibrationPort(...
         'ECUCPort', ...
         'asamxil.v2_1', ...
         'VendorName','MathWorks', ...
         'ProductName','XIL API', ...
         'ProductVersion','1.0', ...
         'PortConfigFile',fullfile(pwd,'myConfigureFile.xml'),...
         'TargetState','started');
      framework.Configuration.addECUMeasurementPort(...
         'ECUMPort', ...
         'asamxil.v2_1', ...
         'VendorName','MathWorks', ...
         'ProductName','XIL API', ...
         'ProductVersion','1.0', ...
         'PortConfigFile', fullfile(pwd,'myConfigureFile.xml'));
      

    • NI™ VeriStand

      framework.Configuration.addModelAccessPort(...
        'MAPort1',...
        'asamxil.v2_1', ... 
        'VendorName','National Instruments', ... 
        'ProductName','NI VeriStand ASAM XIL Interface',... 
        'ProductVersion','2020', ... 
        'PortConfigFile',fullfile(pwd,'NIVeriStandPortConfig.xml'));

    • dSPACE

      framework.Configuration.addModelAccessPort(...
         'MAPort1', ...
         'asamxil.v2_1', ...
         'vendorName','dSPACE GmbH', ...
         'productName','XIL API', ...
         'productVersion','2021-A', ...
         'portConfigFile',fullfile(pwd,'dSpaceConfig.XML'));
      

      Use framework.Configuration to display a summary of your configuration.

  5. Map the test variable names used in the test to the test bench variable names for the specified test bench. Optionally, also specify the task (that is, the logging rate) for the variables. To display the available test bench variable IDs, use the displayAllTestbenchVariables method of the sltest.xil.framework.Framework class. To view the associated tasks, use the displayAllTaskInfo method. See Create Tests Using the Simulink Test Support Package for ASAM XIL Standard for where to include this code in the MATLAB code file with the test body.

    • This example maps the RPM test variable name to the Targets/Controller/Simulation Models/Models/simple_R2020a_2/Outports/Out3 test bench variable name.

      framework.Configuration.addTestVariableMapping(...
         'RPM','MAPort1',...
         ['Targets/Controller/Simulation Models/Models'...
         '/simple_R2020a_2/Outports/Out3']);
      

Create the Test Body

Write the test body in a MATLAB code file. If you write the test body as a function, you can call it from functions that define different configurations. The test body steps are independent of a test bench. Once you define the test body, you use it as is with any test bench configuration.

The test body typically includes these steps:

  1. Use init to initialize the test bench.

  2. Instantiate the mapped test variables so you can use them in the rest of the test body.

  3. Tune parameters in the model to desired values for your test. You can change these values at any time, but if you change values in the middle of the test, the timing is not deterministic.

  4. Set up the acquisition, including trigger conditions, and start it.

  5. Set up the stimulation and start it.

  6. At any point, if desired, call the sltest.TestCase methods, such as sltest.TestCase.verifyThat, to determine the pass or fail status of the test case.

  7. Wait for acquisition or simulation to complete, or stop the simulation using the stop method.

  8. Fetch the logged data.

  9. Push the logged data results to the Test Manager. Include pushing the logged data only if you plan to run your test using the Test Manager.

Run the Test

After you configure the test bench and write the test body, run your test in the Test Manager or at the command line.

  • The MATLAB code file inherits from sltest.TestCase, which enables you to open and run the MATLAB code test file in the Test Manager. In the test body code, you can include pushing the logged data results to the Test Manager, and then load the file into the Test Manager using Open > Open MATLAB-Based Simulink Test (.m). Then, run the test like you run other test cases in the Test Manager.

  • You can run your code at the MATLAB command line, however you cannot push data to the Test Manager from the command line.

Perform additional analysis on the logged data, such as using the verifySignalsMatch method to compare the results to the baseline data.

Limitations

These limitations of the ASAM XIL standard apply when doing real-time testing using the Simulink Test Support Package for ASAM XIL Standard.

  • The ASAM XIL standard does not provide support for setting the stop time of the model. On some test benches, simulation stops at the stop time the model was built with. Other test benches force the stop time to be Inf.

  • On some test benches, logging does not start at the same time as simulation starts. This timing difference might cause your tests to not be precisely repeatable. Use an Acquisition trigger to repeatedly capture a region of interest in the logged data. The trigger corresponds to t = 0.

  • The ASAM XIL standard does not provide support for verifying results. Use the verify methods from sltest.TestCase to analyze your captured data.

  • The ASAM XIL standard does not support enumerated, fixed point, or bus data types.

Troubleshooting

You can display information about available test benches, variables, and tasks by using these sltest.xil.framework.Framework methods:

  • displayAllAvailableTestbenches

  • displayAllTestbenchVariables

  • displayAllTaskInfo

See Also

| | | |

Related Topics

External Websites