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
plant_model
.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.
Generate code for the model that contains the atomic subsystem. In the Command Window, enter:
slbuild('plant_model')
Create a test harness for the subsystem. Right-click the
Controller
subsystem and select Test Harness > Create for 'Controller'.Set the harness properties:
Name ––
controller_subsystem_harness
Sources and Sinks:
Inport
andOutport
Select Open harness after creation.
Click OK.
Simulink Test creates a test harness for the
Controller
subsystem.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_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.