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:

  • The component under test

  • Block parameters

  • Optionally, the model or test harness configuration set

  • Optionally, the model workspace parameters

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

Set Synchronization for a New Test Harness

When creating 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 out 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 in your harness, you can select from several synchronization options, which are combinations of the following actions:

  • Synchronize on harness open — When the test harness opens, the test harness components, configuration set, and parameters synchronize from the model to the test harness. This option is available for:

    • Block diagrams

    • Subsystems, including Stateflow® charts and MATLAB Function blocks

    • For Subsystem Reference blocks, only the block parameters are synced, not the block contents.

    • Model reference blocks

    • S-function blocks

    The Synchronize on harness open option is not available for:

    • SIL/PIL harnesses

    • Subsystem model harnesses

  • Synchronize on harness open and close — When the test harness opens, the test harness components, configuration set, and parameters synchronize from the model to the test harness. When the test harness closes, the same elements synchronize from the harness to the model. This option is available for:

    • Block diagrams

    • Subsystems, including Stateflow charts and MATLAB Function blocks

    • For Subsystem Reference blocks, only the block parameters are synced, not the block contents.

    • Model reference blocks

    • S-function blocks

    • Subsystem model harnesses

    The Synchronize on harness open and close option is not available for:

    • Block diagrams

    • SIL/PIL harnesses

    • Subsystem model harnesses

  • Synchronize only during push and rebuild — Synchronizes when you click Push Changes or Rebuild Harness. Push Changes synchronizes changes from the test harness to the model. Rebuild Harness synchronizes changes from the model to the test harness. This option is available for:

    • Subsystems, including Stateflow charts and MATLAB Function blocks

    • Model reference blocks

    • S-function blocks

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

    The Synchronize only during push and rebuild option is not available for:

    • Block diagrams

    • SIL/PIL harnesses

    • Components in libraries

  • Synchronize only during rebuild — Synchronizes only when you click Rebuild Harness. Rebuild Harness synchronizes changes from the model to the test harness. This option is available for:

    • Block diagrams

    • Subsystems, including Stateflow charts and MATLAB Function blocks

    • Model reference blocks

    • S-function blocks

    • SIL/PIL verification mode components

    The Synchronize only during rebuild option is not available for:

    • Components in libraries

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

Note

If you create a test harness in SIL or 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.

Maintain SIL or PIL Block Fidelity

If you use a software-in-the-loop (SIL) or processor-in-the-loop (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 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 reference 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 Test Harnesses and Select Properties and sltest.harness.rebuild.

Push Changes from Test Harness to Model

After changing your system in the test harness, you can push changes to the main model. In the test harness, select Push Changes. This process overwrites the component in the main model.

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 sltestCar. The model includes a transmission shift controller algorithm and simplified powertrain and vehicle dynamics.

open_system('sltestCar');

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.

sltest.harness.open('sltestCar/shift_logic','ShiftLogic_InportHarness');

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

shiftLogicMask = Simulink.Mask.get('ShiftLogic_InportHarness/shift_logic');
maskParamValue = shiftLogicMask.Parameters.Value;
shiftLogicMask.Parameters.Value = '4';   % Set to new parameter value

Check Synchronization between Test Harness and Main Model

On the command line, run the sltest.harness.check function.

[comparison,details] = sltest.harness.check('sltestCar/shift_logic',...
    'ShiftLogic_InportHarness');

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, open the Test Manager. On the Apps tab, under Model Verification, Validation, and Test, click Simulink Test. Then, on the Tests tab, click Simulink Test Manager.

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

sltest.harness.push('sltestCar/shift_logic','ShiftLogic_InportHarness')

Re-check Synchronization between Test Harness and Main Model

On the command line, update the main model and test harness. Then, run the sltest.harness.check function.

set_param('sltestCar','SimulationCommand','update');
set_param('ShiftLogic_InportHarness','SimulationCommand','update');
[comparison,details] = sltest.harness.check('sltestCar/shift_logic',...
    'ShiftLogic_InportHarness');

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('sltestCar',0);

See Also

| |

Related Topics