Unit Test Subsystem Code with SIL/PIL Manager - MATLAB & Simulink (original) (raw)

If you have a model that contains subsystems, you can use Simulink® Test™ and the SIL/PIL Manager to perform unit tests on code generated from the subsystems. This workflow tests the generated subsystem code as part of the code generated from the parent model.

To perform unit tests on code generated from an atomic subsystem:

  1. Open the model that contains the atomic subsystem. For example, in the Command Window, enter:
    openExample('ecoder/SILPILVerificationExample', ...
    supportingFile='SILBlock.slx')
  2. In a new folder, save the model as plant_model.
  3. Modify configuration parameter settings that are not supported for this workflow. In the Command Window, enter:
    set_param('plant_model', ...
    'CreateSILPILBlock','None', ...
    'PreserveStaticInFcnDecls', 'Off');

% For this example, use these values for block parameters.
set_param('plant_model/Controller', ...
'RTWSystemCode','Nonreusable function', ...
'RTWFileNameOpts', 'Auto');
Note
For a function-call subsystem that is mapped to an AUTOSAR runnable, you can use this workflow even if:

  1. Generate code for the model that contains the atomic subsystem. In the Command Window, enter:
  2. Create a test harness for the subsystem. Right-click theController subsystem and select > .
  3. In the Create Test Harness dialog box, on the Basic Properties tab, specify these properties:
    • Namecontroller_subsystem_harness
    • Sources and SinksInport andOutport
    • Open harness after creation — Enabled
  4. On the Advanced Properties tab, ensure that Verification Mode is set to Normal.
  5. Click OK. Simulink Test creates a test harness for the Controller subsystem.
    Simulink Editor shows test harness for Controller subsystem.
  6. Specify format for saving data. In the Command Window, enter:
    set_param('controller_subsystem_harness', ...
    'SaveFormat','Dataset')
  7. In the Test Harness window, open the SIL/PIL Manager. On theApps tab, click SIL/PIL Manager.
  8. If required, configure code coverage.
  9. Run back-to-back model and SIL simulations:
  10. In the Mode section, selectAutomated Verification.
  11. In the Run Automated Verification section, click Run Verification.
  12. From the Results gallery, you can:

For more information about limitations, see Subsystem Block SIL/PIL Limitations.

See Also

Topics