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.

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:

  • On harness open — The component in the test harness is updated when the harness opens. Synchronizing on harness open is useful if you update the design in the main model.

  • On harness close — The component in the main model is updated when the harness closes. Synchronizing on harness close is useful if you make design changes in the test harness. Avoid synchronizing on harness close if you want to prevent inadvertent changes to the component in the main model.

  • During push — Synchronization occurs manually, by selecting Analysis > Test Harness > Push Component and Parameters to Main Model.

  • During rebuild — Synchronization occurs manually, by selecting Analysis > Test Harness > Rebuild Harness from Main Model.

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 ensures that the generated code referenced by the SIL/PIL block reflects 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 Analysis > Test Harness > Check 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 Analysis > Test Harness > Rebuild Harness from Main Model. 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.

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 Analysis > Test Harness > Push Component and Parameters to Main Model. 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 the 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, select Analysis > Test Harness > Push Component and Parameters to Main Model.

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