Generate Test Cases for a Subsystem
You can analyze a subsystem within a model. This technique is good for large models, where you want to review the analysis in smaller, manageable reports. Following two methods help you to generate test cases for subsystem in different modes:
Generate Test Cases for Subsystems for Normal Mode
This example shows how to analyze the Controller
subsystem in
the sldvdemo_cruise_control
model.
Open the example model:
sldvdemo_cruise_control
Right-click the
Controller
subsystem, and select Design Verifier > Enable ‘Treat as Atomic Unit’ to Analyze.The Function Block Parameters dialog box for the
Controller
subsystem opens.Select Treat as atomic unit.
An atomic subsystem executes as a unit relative to the parent model. Subsystem block execution does not interleave with parent block execution. You can extract atomic subsystems for use as standalone models.
To analyze a subsystem with Simulink® Design Verifier™, set the Treat as atomic unit parameter.
After you set the parameter, other parameters become available, but you can ignore them.
To close the dialog box, click OK.
On the Simulation tab, in the File section, select Save > Save As and save the Cruise Control Test Generation model with a new name.
To start the subsystem analysis and generate test cases, right-click the
Controller
subsystem, and select Design Verifier > Generate Tests for Subsystem.The Simulink Design Verifier software analyzes the subsystem. When the analysis is complete, view the analysis results for the
Controller
subsystem by clicking one of the following options:Highlight analysis results on model
View tests in Simulation Data Inspector
Detailed analysis report
Create harness model
Export test cases to Simulink Test
Simulate tests and produce a model coverage report
Note
After processing a certain number of objectives, if the analysis stops, or if the analysis times out, you can use the Test Generation Advisor to better understand which subsystems are causing the problem. For more information, see Use Test Generation Advisor to Identify Analyzable Components.
Review the results of the subsystem analysis and compare the results to the results of the full-model analysis as described in Analyze a Model:
The subsystem analysis analyzes the Controller as a standalone model.
The Controller subsystem contains all the test objectives in the Cruise Control Test Generation model. Both the analyses generate the same test cases.
Generate Test Cases for Subsystems for Software-in-the-Loop Mode
This example shows how to generate test cases for atomic subsystems in
software-in-the-loop (SIL) mode by using the
sldvdemo_cruise_control_ATS
model.
Open the example model:
sldvdemo_cruise_control_ATS
model = 'sldvdemo_cruise_control_ATS'; open_system(model);
In the Configuration Parameters window, click Code Generation and set System Target File to
ert.tlc
. Alternatively, enter:set_param(model,'SystemTargetFile','ert.tlc');
Click Hardware Implementation, then set Device vendor and Device type to the vendor and type of your SIL system. For example, for a 64-bit Linux machine, set Device vendor to
Intel
and Device type tox-86-64 (Linux)
. Alternatively, enter:if ismac lProdHWDeviceType = 'Intel->x86-64 (Mac OS X)'; elseif isunix lProdHWDeviceType = 'Intel->x86-64 (Linux 64)'; else lProdHWDeviceType = 'Intel->x86-64 (Windows64)'; end set_param(model, 'ProdHWDeviceType', lProdHWDeviceType);
Generate the code for the target. For subsystem analysis in SIL mode, code needs to be generated before invoking test generation.
If the test generation target is Code Generated as Top model, generate the code for the target by entering:
slbuild(model,'StandaloneCoderTarget');
If the test generation target is Code Generated as Model Reference, generate the code for the target by entering:
slbuild(model,'ModelReferenceCoderTargetOnly');
Note
If there is a mismatch of the test generation target and the generated code interface target, then test generation returns an error.
If you generate a code for both targets, the test generation returns an error.
Set up the function packaging of the subsystem by right-clicking PI Controller > Block Parameters (Subsystem) > Code Generation > Function Packaging and set as Reusable function or Nonreusable function.
Alternatively enter:
ssPath = [model '/PI Controller']; set_param(ssPath, 'RTWSystemCode', 'Reusable function'); % For Resuable function set_param(ssPath, 'RTWSystemCode', 'Nonreusable function'); % For Nonresuable function
In the Apps tab, click Design Verifier. Then, in the Design Verifier tab, set Target to Code Generated as Top Model. Generate tests by using one of these methods:
Right click the PI Controller block, then click Design Verifier > Generate Tests for Subsystems.
Select the PI Controller block by unpinning it from the toolstrip. Then click Generate Tests.
Create a harness for the subsystem and then invoke test generation by right-clicking the PI Controller block, then clicking Test Harness > Create for PI Controller.
Select the harness name and click OK.
Open the new harness. Then click Design Verifier and click Generate Tests.
Alternatively, you can use the API to generate the tests by entering:
opts = sldvoptions; opts.TestgenTarget = Sldv.utils.Options.TestgenTargetGeneratedCodeStr; [status, fileNames] = sldvrun(ssPath,opts,true);
Review the results of the subsystem analysis and compare the results to the results of the full-model analysis as described in Generate Test Cases for Subsystems for Normal Mode.