Main Content

Synchronize Changes Between Test Harness and Model

A test harness provides an isolated environment to test design changes. You can synchronize changes from the test harness to the main model, or from the main model to the test harness. Synchronization includes these model elements:

  • Component under test (CUT) — CUT block and blocks, signals, and other entities in the CUT.

  • Block parameters — Values of parameters associated with the block. To see the parameters of a block, right-click on the block and select Block Parameters from the context menu.

  • Optionally, the active configuration set of the model or test harness. See Manage Configuration Sets for a Model for information on configuration sets

To synchronize the active configuration set and model workspace parameters between the test harness and main model, select Update Configuration Parameters and Model Workspace data on rebuild in the Advanced Properties tab of the Create Test Harness dialog box.

You do not need to synchronize base workspace data because it is available to both the test harness and main model. Subsystem model test harnesses always sync with their underlying models.

Set Synchronization for a New Test Harness

When you create a test harness, you specify when changes in the test harness are synchronized with the main model. Synchronization can occur automatically or manually. If you plan to try different component designs in the test harness, use manual synchronization to avoid overwriting the component in the main model. Depending on the type of component under test (CUT) in your harness, you can select from different synchronization types. These options are available in the Create Test Harness dialog box or by using the SynchronizationMode property of sltest.harness.create.

For all synchronization types, you can simulate the main model even if a test harness is open. You can also create harnesses for model components other than the current component under test and its nested subsystems. You can have more than one harness owned by the same model open at the same time.

Note

Synchronization differs depending on whether one test harness or more than one test harness is open. See the Description column of this table for information.

The locking information in the table indicates whether you can change the model, harness, or CUT in the model or harness when the test harness is open.

Synchronization TypeDescriptionAvailabilityModel, CUT, and Harness Locking When Harness Is Open

Synchronize on harness open and close

When you open only one test harness, the harness components and parameters synchronize from the model to the test harness. When you close the only open test harness, the same elements synchronize from the harness to the model.

When you open multiple harnesses, synchronization occurs from the model to the harness, but if any harnesses remain open, synchronization does not occur when you close a harness.

Available for:

  • Subsystems, including Stateflow charts and MATLAB Function blocks

  • For Subsystem Reference blocks, only the block parameters are synchronized

  • Model blocks

  • S-function blocks

Not available for:

  • Block diagrams

  • SIL/PIL harnesses

  • Subsystem model harnesses

When only one harness is open, CUTs in the main model are unlocked, but CUTs in subsystems are locked.. Subsystem CUTs in the harness are unlocked.

When more than one harness is open, the CUTs in model harnesses, subsystem harnesses, library harnesses, and MATLAB functions are locked.

Synchronize on harness open

When you open one or more test harnesses, the harness components and parameters synchronize from the model to the test harness.

Available for:

  • Block diagrams

  • Subsystems, including Stateflow® charts and MATLAB Function blocks

  • For Subsystem Reference blocks, only the block parameters are synchronized

  • Model reference blocks

  • S-function blocks

Not available for:

  • SIL/PIL harnesses

  • Subsystem model harnesses

When only one harness is open, CUTs in the main model and harness are unlocked, but CUTs in subsystems in the main model and harness are locked.

When more than one harness is open, the CUTs in model harnesses, subsystem harnesses, library harnesses, and MATLAB functions are locked.

Synchronize only during push and rebuild

When only one harness is open, synchronization occurs when you click Push Changes or Rebuild Harness. Clicking Push synchronizes the changes from the test harness to the model. Clicking Rebuild synchronizes changes the from the model to the test harness.

When more than one harness is open, synchronization occurs only when you rebuild the model. Push synchronization is not supported.

Available for:

  • Subsystems, including Stateflow charts and MATLAB Function blocks

  • Model reference blocks

  • S-function blocks

  • Subsystem models, which always synchronize on the push and rebuild only.

Not available for:

  • Block diagrams

  • SIL/PIL harnesses

  • Components in libraries

When one or more harnesses are open, the main model, harness, and all types of CUTs in the model and harness, including subsystems, are unlocked.

Synchronize only during rebuild

When one or more harnesses are open, synchronization occurs only when you click Rebuild Harness. Changes synchronize from the model to the test harness.

Available for:

  • Block diagrams

  • Model reference blocks

  • SIL/PIL verification mode components

Not available for:

  • Subsystems, including Stateflow charts and MATLAB Function blocks

  • S-function blocks

  • Components in libraries

The main model, harness, and all types of CUTs in the model are unlocked. All types of CUTs in the harness are unlocked, except SIL/PIL verification mode components, which are locked and masked.

Note

If you create a test harness in software-in-the-loop (SIL) or processor-in-the-loop (PIL) mode for a Model block, the block mode in the test harness is changed to SIL or PIL, respectively. This mode is not updated to the main model when you close the test harness.

If you use a SIL or PIL block in the test harness, consider setting the test harness to rebuild every time it opens. Regularly rebuilding the test harness keeps the generated code referenced by the SIL/PIL block as a reflection of the main model.

Change Synchronization of an Existing Test Harness

To change a test harness synchronization mode:

  1. Close the test harness.

  2. In the main model, click the harness badge on the block or the Simulink® canvas.

  3. In the test harness thumbnail preview, click the Harness operations icon and select Properties.

  4. Change the Synchronization Mode in the properties dialog box.

If you use the command line, set the SynchronizationMode property with sltest.harness.set.

Synchronize Configuration Set and Model Workspace Data

To synchronize the active configuration set and workspace parameters between the test harness and main model, select Update Configuration Parameters and Model Workspace data on rebuild in the harness creation or harness properties dialog box.

Check for Unsynchronized Component Differences

If your test harness does not synchronize changes, you can check for unsynchronized component differences between the test harness and main model. Checking for unsynchronized differences can be useful if:

  • You are making tentative design changes in the test harness and want to check that the main model component is not overwritten.

  • You have made design changes to the main model and want to check which test harnesses must be rebuilt.

From the test harness window, select Check Harness to check for differences. If the component differs, you can push changes from the test harness to the main model, or rebuild the test harness from the main model. Also see the sltest.harness.check function.

Consider these conditions when checking for unsynchronized differences:

  • sltest.harness.check only includes the block diagram, block parameters, and mask parameters in the comparison between the test harness and main model. Port options, compiled attributes, hidden parameters, and Model block data logging parameters are not included in the comparison.

  • If the component contains a Simscape™ Solver Configuration block, the check result always shows that the component differs between the test harness and main model. The Solver Configuration block is affected by Simscape blocks outside the component, and therefore always differs between the test harness and main model.

Rebuild a Test Harness

Rebuild a test harness to reflect the latest state of the main model. In the test harness, select Rebuild Harness. In addition to updating the component under test and block parameters, this operation rebuilds harness conversion subsystems. If the test harness does not have conversion subsystems, rebuilding adds them.

Rebuilding can disconnect signal lines. For example, if signal names changed in the main model, signal lines in the test harness can be disconnected. If lines are disconnected, reconnect signal lines to the component under test or conversion subsystems. If you specified to use existing generated code for a SIL/PIL subsystem using sltest.harness.create or sltest.harness.set, the harness rebuild uses that code instead of regenerating it.

For more information, see Create or Import Test Harnesses and Select Properties and sltest.harness.rebuild.

Push Changes from Test Harness to Model

After changing your system in the test harness, if only one harness is open, you can push changes to the main model. In the test harness, select Push Changes. This process overwrites the component in the main model. Pushing changes to the model is not supported when more than one harness is open.

Check Component and Push Parameter to Main Model

This example shows a basic workflow of updating a parameter in a test harness, checking the synchronization between the test harness and main model, and pushing the parameter change from the test harness to the main model.

This example also includes programmatic steps.

Open the model sf_car. The model includes a transmission shift controller algorithm and simplified powertrain and vehicle dynamics.

model = "sf_car";
open_system(model);

Update the Mask Parameter in the Test Harness

1. Open the test harness. Click the badge on the shift_logic chart and select the ShiftLogic_InportHarness test harness. The test harness is set to synchronize only when you push to or rebuild from the main model.

To open the test harness from the command line, use:

chart = "sf_car/shift_logic";
harness = "ShiftLogic_InportHarness";
sltest.harness.open(chart,harness);

2. Double-click the shift_logic subsystem. For Delay before gear change (tick), enter 4 and click OK.

To change the value from the command line, use:

shiftLogicMask = Simulink.Mask.get("ShiftLogic_InportHarness/shift_logic");
maskParamValue = shiftLogicMask.Parameters.Value;
shiftLogicMask.Parameters.Value = "4";

3. Check the synchronization between the test harness and the main model. At the command line, run the sltest.harness.check function.

[comparison,details] = sltest.harness.check(chart,harness);

The results show that the component under test is different in the test harness due to the updated mask parameter.

comparison
comparison =

  logical

   0

details
details = 

  struct with fields:

     overall: 0
    contents: 1
      reason: 'The contents of harnessed component and the contents of the component in the main model are same, but they differ in terms of block or mask parameters.'

Update the Parameter to the Main Model

1. In the test harness, on the Harness tab, click Push Changes.

2. In the main model, double-click the shift_logic subsystem. The parameter value is updated.

To push the change using the command line, use:

sltest.harness.push(chart,harness)

3. Update the main model and test harness.

set_param(model,SimulationCommand="update");
set_param(harness,SimulationCommand="update");

4. Re-check the synchronization between the test harness and the main model by running the sltest.harness.check function a second time.

[comparison,details] = sltest.harness.check(chart,harness);

The results show that the component under test is the same between the test harness and the main model.

comparison
comparison =

  logical

   1

details
details = 

  struct with fields:

     overall: 1
    contents: 1
      reason: 'The checksum of the harnessed component and the component in the main model are same.'

close_system(model,0);

See Also

| |

Related Topics