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:
Open the model that contains the atomic subsystem. For example, in the Command Window, enter:
openExample('ecoder/SILPILVerificationExample', ... supportingFile='SILBlock.slx')
In a new folder, save the model as
Modify configuration parameter settings that are not supported for this workflow. In the Command Window, enter:For more information about limitations, see Atomic Subsystem Workflow Limitations.
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');
Generate code for the model that contains the atomic subsystem. In the Command Window, enter:
Create a test harness for the subsystem. Right-click the
Controllersubsystem and select Test Harness > Create for 'Controller'.
Set the harness properties:
Sources and Sinks:
Select Open harness after creation.
Simulink Test creates a test harness for the
Specify format for saving data. In the Command Window, enter:
set_param('controller_subsystem_harness', ... 'SaveFormat','Dataset')
In the Test Harness window, open the SIL/PIL Manager. On the Apps tab, click SIL/PIL Manager.
If required, configure code coverage.
Run back-to-back model and SIL simulations:
In the Mode section, select Automated Verification.
In the Run Automated Verification section, click Run Verification.
From the Results gallery, you can:
Use the Simulation Data Inspector to analyze results. For example, compare the
controller_model_outputsignals 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.