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.

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.

The settings for the Synchronization Mode parameter are:

  • Synchronize on harness open and close — When you open one or more test harnesses, synchronization occurs from the model to the harness. If only one harness is open, when you close the harness, synchronization occurs from the harness to the model. When more than one harness is open and you close only one of them, synchronization to the model does not occur.

  • Synchronize on harness open — When you open one or more test harnesses, synchronization occurs from the model to the harness.

  • Synchronize only during push and rebuild — When only one test harness is open and you click Push Changes in the toolstrip, synchronization occurs from the harness to the model. When you click Rebuild Harness, synchronization occurs from the model to the harness. When more than one harness is open, synchronization occurs only when you rebuild the model. Push synchronization is not supported.

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

Note

Synchronization copies subsystems from the main model to the subsystem test harness model and from the subsystem test harness model to the main model. Simulink® block copy callbacks run both when the main model synchronizes to the subsystem test harness and when the subsystem test harness synchronizes to the main model. Synchronization for subsystems does not synchronize code or state mappings.

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.

The table indicates whether you can change the model, harness, or the CUT in the model or test harness when one or more test harnesses are open for each synchronization type.

Synchronization TypeSupported Model ElementsLocking When One Harness Is OpenLocking When More Than One Harness Is Open

Synchronize on harness open and close

Available for:

  • Subsystems, including Stateflow charts and MATLAB Function blocks

  • Model blocks

  • S-function blocks

  • Subsystem Reference blocks — only the block parameters are synchronized

Not available for:

  • Block diagrams

  • SIL/PIL harnesses

  • Subsystem model harnesses

  • System Composer models, components, or CUTs

These elements are unlocked:

  • Main models and main model harnesses

  • CUTs that are not subsystems in the main model and harness

  • Subsystem harnesses and CUTs in the harness

These elements are locked:

  • Subsystem CUTs in the main model

These elements are unlocked:

  • Main models and main model harnesses

  • Harness CUTs

  • CUTs that are not subsystems and harnesses, library harnesses, and MATLAB functions

  • Subsystem CUTs in the main model and in the harness, but no synchronization occurs

These elements are locked:

  • Main model CUTs

Synchronize on harness open

Available for:

  • Block diagrams

  • Subsystems, including Stateflow® charts and MATLAB Function blocks

  • Model blocks

  • S-function blocks

  • Subsystem Reference blocks — only the block parameters are synchronized

Not available for:

  • SIL or PIL harnesses

  • Subsystem model harnesses

These elements are unlocked:

  • Main models and main model harnesses

  • CUTs that are not subsystems in the main model and harness

These elements are locked:

  • Subsystem CUTs in the main model and harness

These elements are unlocked:

  • Main models and main model harnesses

  • CUTs that are not subsystems in the main model and harness

  • System Composer main models and CUTs in the harness for inline components

These elements are locked:

  • Subsystem CUTs in the main model and harness

  • System Composer Model reference component CUTs in the main model and harness

Synchronize only during push and rebuild

Available for:

  • Subsystems, including Stateflow charts and MATLAB Function blocks

  • Model blocks

  • S-function blocks

  • Subsystem models — only synchronize on push and rebuild.

Not available for:

  • Block diagrams

  • SIL or PIL harnesses

  • Components in libraries

  • System Composer models, components, or CUTs

These elements are unlocked:

  • Main model, harnesses, and all types of CUTs in the model and harnesses, including subsystems.

These elements are unlocked:

  • Main model, harnesses, and all types of CUTs in the harnesses, including Subsystem harnesses

These elements are locked:

  • Main model CUTs.

Synchronize only during rebuild

Available for:

  • Block diagrams

  • SIL/PIL verification mode components

Not available for:

  • Subsystems, including Stateflow charts and MATLAB Function blocks

  • S-function blocks

  • Components in libraries

  • System Composer models, components, or CUTs

These elements are unlocked:

  • Main models, harnesses, and all types of CUTs, except SIL/PIL verification mode components in the model

These elements are locked:

  • SIL or PIL verification mode components in the harness are locked and masked.

Note

Synchronize only during rebuild is not available for Subsystems.

All elements are unlocked.

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 = "TestDownshiftPointsHarness";
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("TestDownshiftPointsHarness/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.'

5. Close the model without resaving it.

close_system(model,0);

See Also

| |

Topics