Main Content

Unit Test Subsystem Code with SIL/PIL Manager

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:

    • Block parameter TreatAsAtomicUnit is not 'on'.

    • Block parameter RTWSystemCode is not 'Nonreusable function' or 'Reusable function'.

    For more information about limitations, see Atomic Subsystem Workflow Limitations.

  4. Generate code for the model that contains the atomic subsystem. In the Command Window, enter:

    slbuild('plant_model')

  5. Create a test harness for the subsystem. Right-click the Controller subsystem and select Test Harness > Create for 'Controller'.

  6. Set the harness properties:

    • Name –– controller_subsystem_harness

    • Sources and Sinks: Inport and Outport

    • Select Open harness after creation.

    Click OK.

    Simulink Test creates a test harness for the Controller subsystem.

  7. Specify format for saving data. In the Command Window, enter:

    set_param('controller_subsystem_harness', ...
              'SaveFormat','Dataset')

  8. In the Test Harness window, open the SIL/PIL Manager. On the Apps tab, click SIL/PIL Manager.

  9. If required, configure code coverage.

  10. Run back-to-back model and SIL simulations:

    1. In the Mode section, select Automated Verification.

    2. In the Run Automated Verification section, click Run Verification.

  11. From the Results gallery, you can:

    • Use the Simulation Data Inspector to analyze results. For example, compare the controller_model_output signals from the model and SIL simulations.

    • Export an equivalence test case.

    For more information, see Analyze Results and Export Test Cases.

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

Related Topics