Consider a top model that consists of components A
,
B
, C
, and D
:
A
and B
are existing components for
which code has previously been generated and tested.
C
, a referenced model, and D
, a
subsystem, are new components.
With software-in-the-loop (SIL) and processor-in-the-loop (PIL) simulations, you can use the following approaches to numerical equivalence testing:
Test code from all components together. See Test Top-Model Code.
Test new components separately (before testing code from all components). See Test Referenced Model Code and Test Subsystem Code.
For some forms of testing, you require a test harness model. The test harness model:
Generates test vectors or stimulus inputs that feed the block under test.
Makes it possible for you to observe or capture output from the block.
The following example shows a simple test harness model.
The block under test is a Model block. The Sine Wave block generates the input for the Model block. Through the Scope block, you can observe the output from the Model block. For information about creating and using test harnesses, see:
Create Test Harnesses and Select Properties (Simulink Test)
Code Generation Verification Workflow with Simulink Test (Simulink Test)
SIL Verification for a Subsystem (Simulink Test)
To test code generated from the top-model components together
(A
, B
, C
, and
D
), you can use top-model SIL/PIL or Model block SIL/PIL.
Top-model SIL/PIL:
Create test vectors or stimulus inputs in the MATLAB workspace.
Run the top model in normal, SIL, and PIL simulation modes. The software loads the test vectors or stimulus inputs from the MATLAB® workspace.
For each simulation mode, observe or capture outputs.
Verify numerical equivalence by comparing normal outputs against SIL and PIL outputs.
Model block SIL/PIL:
Create a Model block that contains the top-model components.
Insert the Model block in a simulation model, for example, your test harness model.
Run simulations, switching the Model block
between normal, SIL, and PIL modes. For the SIL and PIL
simulation modes, set the Code
interface
Model block parameter to Top
model
.
Verify numerical equivalence by comparing normal outputs against SIL and PIL outputs.
To test code generated from the component C
as part of a model
reference hierarchy, use the Model block SIL/PIL approach:
Insert the Model block C
in a simulation model, for
example, your test harness model.
Run simulations, switching the Model block between
normal, SIL, and PIL modes. For the SIL and PIL simulation modes, set
the Code interface
Model block parameter to Model
reference
.
Verify numerical equivalence by comparing normal outputs against SIL and PIL outputs.
To test code generated from the subsystem D
, use the SIL or PIL
block approach:
Insert the subsystem in a simulation model, for example, your test harness model.
Run a normal mode simulation, capturing the outputs.
Create a SIL or PIL block from the subsystem.
In the model, replace the subsystem with the SIL or PIL block.
Run a simulation of the model, capturing the outputs.
Verify numerical equivalence by comparing normal mode subsystem outputs against SIL or PIL block outputs.
Simulation Type | Component From Which Code Is Generated | Steps | Generated Code Interface | Test Signal Source |
---|---|---|---|---|
Top-model SIL/PIL | Top model | In SIL/PIL Manager:
| Standalone | MATLAB workspace |
Model block SIL/PIL | Model referenced by Model block |
| Determined by Model block parameter Code interface: standalone or model reference. | Simulation model, for example, test harness model |
SIL or PIL block | Subsystem | Manual block substitution | Standalone | Simulation model, for example, test harness model. |