Main Content

Create and Run Real-Time Tests

You can use the Simulink Test Manager to convert desktop simulation test cases or to create real-time baseline, equivalence, or simulation tests.You can then define how the tests run by specifying the test settings in the Test Manager. Some settings that appear in the Test Manager are only available in the real-time test cases. For information on general Test Manager settings, see Specify Test Properties in the Test Manager.

For information about configuring your model for real-time testing and setting up the target computer, see Prepare for Real-Time Testing.

Add a Real-Time Test Case

To add a real-time test case to an existing test file:

  1. In the Simulink® Toolstrip, on the Apps tab, under Model Verification, Validation, and Test, click Simulink Test.

  2. In the Tests tab, click Simulink Test Manager.

  3. In the Test Manager, in the File section, click Open and select a test file.

  4. Select New > Test Case > Real-Time Test.

  5. In the New real-time test dialog box, set the Test Type parameter and click Create. You can select a baseline, equivalence, or simulation real-time test:

    • Baseline — Compares the signal data returned from the target computer to the baseline data in the test case. To compare a real-time execution result to a model simulation result, add the model baseline result to the real-time test case and apply optional tolerances to the signals in the Baseline Criteria section. See Baseline Criteria and Set Signal Tolerances.

    • Equivalence — Compares the signal data from a simulation to a real-time test, or compares two real-time tests. When you select this type of test, you can specify the Simulation 1 on target and Simulation 2 on target parameters. To run a real-time test on the target computer and compare results to a model simulation, select Simulation 1 on target and clear Simulation 2 on target. The test case displays two simulation sections, Simulation 1 (Real-Time) and Simulation 2. To compare the signal data from two real-time tests, select Simulation 1 on target and Simulation 2 on target. The test case displays two simulation sections, Simulation 1 (Real-Time) and Simulation 2 (Real-Time).

      You can apply optional tolerances to the signals. See Equivalence Criteria and Set Signal Tolerances.

    • Simulation — Assesses the test result using only verify statements and real-time execution. If no verify statements fail, and the real-time test executes, the test case passes.

For information about converting a desktop test case, see Reuse Desktop Test Cases for Real-Time Testing.

Specify the System Under Test

In the Test Manager, expand the System Under Test section and specify the model and how to load the real-time application. You can also optionally specify a test harness or simulation overrides.

Select Model and Test Harness

You can specify the model you want to test by selecting the model in the currently active Simulink window or by browsing for the model. If your model has a test harness, you can select the test harness for the test case. For information on how to specify the model or test harness for your test, see System Under Test.

Load Application

The real-time application is built from your model or test harness. To choose the application to load, set the Load Application From parameter to:

  • Model – This setting loads the application from the model, builds the real-time application, downloads it to the target computer and executes it on the target computer. Use this setting if you are running the real-time test for the first time, or if your model changed since the last real-time execution. This setting typically takes the longest to run.

    Note

    If your test executes table iterations from Signal Editor scenarios or Test Sequence scenarios, select the Model settings.

  • Target Application – Use this setting to send the target application from the host to a target computer, and execute the application. Use this setting if you want to load an already-built application on multiple targets.

  • Target Computer – This setting updates the parameters in the test case and executes the test. Use this setting to execute an application that is already loaded on the real-time target computer.

This table summarizes which steps and callbacks execute for each option. If your test uses callbacks and test iterations, the callbacks run for each iteration.

Test Case Execution StepLoad Application From Parameter Setting
ModelTarget ApplicationTarget Computer
Executes pre-load callbackYesYesYes
Loads Simulink modelYesNoNo
Executes post-load callbackYesNoNo
Sets Signal Editor scenarioYesNoNo
Builds real-time application from modelYesNoNo
Downloads real-time application to target computerYesYesNo
Sets runtime parametersYesYesYes
Runs Test Sequence scenariosYesNoNo
Executes pre-start real-time callbackYesYesYes
Executes real-time application YesYesYes
Executes cleanup callbackYesYesYes

Override Simulation Settings

For real-time tests, you can use the Simulation Settings Overrides section to override the simulation stop time, which can be useful in debugging real-time test failures. Consider a 60-second test that returns a verify statement failure at 15 seconds due to a bug in the model. After debugging your model, you execute the real-time test to verify the fix. You can override the stop time to terminate the execution at 20 seconds, which reduces the time it takes to verify the fix.

Assign Code to Real-Time Callbacks

Use the Pre-start real-time application callback to execute commands before the application executes on the target computer. Real-time test callbacks execute in a sequence with the model load, build, download, and execute steps. Callbacks and step execution depend on how the test case loads the application.

Sequence

Load application from:

Model

Load application from:

Target application

Load application from:

Target computer

Executes first

Preload callback

Preload callback

Preload callback

 

Post-load callback

 

Pre-start real-time callback

Pre-start real-time callback

Pre-start real-time callback

Executes last

Cleanup callback

Cleanup callback

Cleanup callback

If your test requires a different system target file, you can set the parameter using a test case or test suite callback. After the real-time test executes, set the parameter to its original setting with a cleanup callback. For example, this callback opens the sltestProjectorController model and sets the SystemTargetFile to speedgoat.tlc.

openExample("sltestProjectorController");
set_param("sltestProjectorController",...
   "SystemTargetFile','speedgoat.tlc");

For more information about callbacks, see Callbacks. For information about using callbacks to set the system target file, see Code Generation.

Create Test Iterations

You can use the Iterations section in the Test Manager to execute iterations in real-time tests. Use iterations to execution real-time tests that sweep through parameter values or Signal Editor scenarios. The Test Manager groups the results by iteration. For more information on setting up iterations, see Test Iterations. You can create:

  • Table iterations from a parameter set — Define several parameter sets in the Parameter Overrides section of the test case. Under Table Iterations, click Auto Generate and select Parameter Set.

  • Table iterations from Signal Editor scenarios — If your model or test harness uses a Signal Editor input, below the Table Iterations table, click Auto Generate and select Signal Editor Scenario. If you use a Signal Editor scenario, you must set Load Application From to Model.

  • Table iterations from Test Sequence scenarios — If your test harness uses Test Sequence block scenarios, you can create an iteration for each scenario in the Test Manager. Below the Table Iterations table, click Auto Generate and select Test Sequence Scenario. If you use Test Sequence scenarios, load the application from the model.

  • Scripted iterations — Use scripts to iterate using model variables or parameters. For example, assume you are testing an oscillator system and use a Test Sequence block to create a square wave test signal using the parameter frequency.

    Test sequence block settings for the frequency parameter

    In the Test Manager, in the Scripted Iterations section, you can use real-time test scripted iterations to cover a frequency sweep from 5 Hz to 35 Hz. The script iterates the value of frequency in the Test Sequence block.

    %% Iterate over frequencies to determine best oscillator settings
    
    % Create parameter sets
    freq = 5.0:1.0:35.0;
    
    for i_iter = 1:length(freq)
        % Create iteration object
        testItr = sltestiteration();
        
        % Set parameters
        setVariable(testItr,'Name','frequency','Source',...
        'Test Sequence','Value',freq(i_iter));
        
        % Register iteration
        addIteration(sltest_testCase, testItr);
    end
    

Run Test and View Real-Time Test Results

After you define the test, you can execute the test by clicking Run in the Test Manager. You can access results in the Results and Artifacts pane. If your test is a baseline or equivalence test, the right pane compares the test signal data to the data and tolerances you defined in the baseline or equivalence criteria section. If your test includes verify statements, in the Results and Artifacts pane, expand the Verify Statements section to select an assessment and view results. The right pane displays the pass, fail, and untested results.

Test results for verify statements

You can create a report from the test results. See Generating a Test Results Report and Customize Test Results Reports.

See Also

Apps

Functions

Topics