Test Models in Real Time

You can test your system in environments that resemble your application. You begin with model simulation on a development computer, then use software-in-the-loop (SIL) and processor-in-the-loop (PIL) simulations. Real-time testing executes an application on a standalone target computer that can connect to a physical system. Real-time testing can include effects of timing, signal interfaces, system response, and production hardware.

Real-time testing includes:

  • Rapid prototyping, which tests a system on a standalone target connected to plant hardware. You verify the real-time tests against requirements and model results. Using rapid prototyping results, you can change your model and update your requirements, after which you retest on the standalone target.

  • Hardware-in-the-loop (HIL), which tests a system that has passed several stages of verification, typically SIL and PIL simulations.

Overall Workflow

This example workflow describes the major steps of creating and executing a real-time test:

  1. Create test cases that verify the model against requirements. Run the model simulation tests and save the baseline data.

  2. Set up the real-time target computer.

  3. Create test harnesses for real-time testing, or reuse model simulation test harnesses. In Test Sequence or Test Assessment blocks, verify statements assess the real-time execution. In the test harnesses, use target and host scopes to display signals during execution.

  4. In the Test Manager, create real-time test cases.

  5. For the real-time test cases, configure target settings, inputs, callbacks, and iterations. Add baseline or equivalence criteria.

  6. Execute the real-time tests.

  7. Analyze the results in the Test Manager. Report the results.

Real-Time Testing Considerations

  • If real-time test data returned from the target computer is shifted in time or is missing data points, baseline or equivalence results can consequently display a test failure. When investigating real-time test failures, look for time shifts or missing data points.

  • You cannot override the real-time execution sample time for applications built from models containing a Test Sequence block. The code generated for the Test Sequence block contains a hard-coded sample time. Overriding the target computer sample time can produce unexpected results.

  • Your target computer must have a file system to use verify statements and test case logging.

Complete Basic Model Testing

Real-time testing often takes longer than comparative model testing, especially if you execute a suite of real-time tests that cover several scenarios. Before executing real-time tests, complete requirements-based testing using desktop simulation. Using the desktop simulation results:

  • Debug your model or make design changes that meet requirements.

  • Debug your test sequence. Use the debugging features in the test sequence editor. See Debug a Test Sequence.

  • Update your requirements and add corresponding test cases.

Set up the Target Computer

Real-time testing requires a standalone target computer. Simulink® Test™ only supports target computers running Simulink Real-Time™. For more information, see:

Configure the Model or Test Harness

Real-time applications require specific configuration parameters and signal properties.

Code Generation

A real-time test case requires a real-time system target file. In the model or harness configuration parameters, in the Code Generation pane, set the System target file to slrt.tlc to generate system target code.

If your model 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 model and sets the system target file parameter to slrt.tlc for the model sltestProjectorController.


Data Import/Export Format

Models must use a data format other than dataset. To set the data format:

  1. Open the configuration parameters.

  2. Select the Data Import/Export pane.

  3. Select the Format.

Log Signals from Real-Time Execution

To configure your signals of interest for real-time testing:

  • Enable signal logging in the Configuration Parameters, in the Data Import/Export pane.

  • Connect signals to Scope blocks from the Simulink Real-Time block library. Set the Scope type property to File.

  • Name each signal of interest using the signal properties.

Signal naming is particularly important if you perform baseline or equivalence testing, because unnamed signals can be assigned a default name, which likely does not match the name of the baseline or equivalence signal. This test harness demonstrates four signals configured for real-time testing, using file scopes to return signal data to the Test Manager, and target scopes to display data on the target computer during execution.

View Signals During Real-Time Execution

To display signals on the target computer during real-time execution, add target scopes to your test harness. To display signals in the Simulink Real-Time Explorer, add host scopes. This test harness includes both target and host scopes for signal visualization. See Scope.

Add Test Cases for Real-Time Testing

Use the Test Manager to create real-time test cases. In the toolstrip, click New > Real-Time Test.

Test Type

You can select a baseline, equivalence, or simulation real-time test. For simulation test types, verify statements serve as pass/fail criteria in the test results. For equivalence and baseline test types, the equivalence or baseline criteria also serve as pass/fail criteria.

  • Baseline — Compares the signal data returned from the target computer to the baseline 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.

  • Equivalence — Compares signal data from a simulation and a real-time test, or two real-time tests. To run a real-time test on the target computer, then compare results to a model simulation:

    • Select Simulation 1 on target.

    • Clear Simulation 2 on target.

    The test case displays two simulation sections, Simulation 1 and Simulation 2.

    Comparing two real-time tests is similar, except that you select both simulations on target. In the Equivalence Criteria section, you can capture logged signals from the simulation and apply tolerances for pass/fail analysis.

  • 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.

Load Application From

Using this option, specify how you want to load the real-time application. The real-time application is a DLM file built from your model or test harness. You can load the application from:

  • Model — Choose Model if you are running the real-time test for the first time, or your model changed since the last real-time execution. Model typically takes the longest because it includes model build and download. Model loads the application from the model, builds the real-time application, downloads it to the target computer, and executes it on the target computer.

  • Target Application — Choose Target Application to send the target application from the host to a target computer, and execute the application. Target Application can be useful if you want to load an already-built application on multiple targets.

  • Target Computer — This option executes an application that is already loaded on the real-time target computer. You can update the parameters in the test case and execute using Target Computer.

This table summarizes which steps and callbacks execute for each option.

Test Case Execution Step (first to last)Load Application From
ModelTarget ApplicationTarget Computer
Executes pre-load callbackYesYesYes
Loads Simulink modelYesNoNo
Executes post-load callbackYesNoNo
Sets Signal Builder groupYesNoNo
Builds DLM from modelYesNoNo
Downloads DLM to target computerYesYesNo
Sets runtime parametersYesYesYes
Executes pre-start real-time callbackYesYesYes
Executes real-time application YesYesYes
Executes cleanup callbackYesYesYes


Select the model from which to generate the real-time application.

Test Harness

If you use a test harness to generate the real-time application, select the test harness.

Simulation Settings Overrides

For real-time tests, you can override the simulation stop time, which can be useful in debugging a real-time test failure. 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.


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


Load application from:


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


You can execute iterations in real-time tests. Iterations are convenient for executing real-time tests that sweep through parameter values or Signal Builder groups. Results appear grouped by iteration. For more information on setting up iterations, see Run Combinations of Tests Using Iterations. You can create:

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

  • Tabled iterations from signal builder groups — If your model or test harness uses a signal builder input, under Iterations > Table Iterations, click Auto Generate and select Signal Builder Group. If you use a signal builder group, load the application from the model.

  • Scripted iterations — Use scripts to iterate using model variables or parameters. For example, in the model sltestRealTimeOscillatorTestExample, the SettlingTest harness uses a Test Sequence block to create a square wave test signal for the oscillator system using the parameter frequency.

    In the test file SettlingTestCases, the real-time test scripted iterations 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',...
        % Register iteration
        addIteration(sltest_testCase, testItr);

Assess Real-Time Execution Using verify Statements

In addition to baseline and equivalence signal comparisons, you can assess real-time test execution using verify statements. A verify statement assesses a logical expression and returns results to the Test Manager. Use verify inside a Test Sequence or Test Assessment block. See Assess Simulation Using Logical Statements.

Related Topics

Was this topic helpful?