Extend Test Cases for Model with Temporal Logic
Create Starting Test Case
This example uses the sldvdemo_sbr_extend_design
model. This
model includes a Stateflow® chart SBR
that uses temporal logic. The transition
from the KEY_OFF
state to the KEY_ON
state
occurs after the Stateflow chart has been simulated 500 times. To test this transition requires a
test case with 500 time steps.
In this example, you create a test case that forces the transition to
KEY_ON
by setting the KEY
input to
1
for the duration of the test case. You simulate the model
using this test case, satisfying the objectives for the
KEY_OFF/KEY_ON
transition. Then you analyze the model,
ignoring the objectives already satisfied by the test case you create.
Open the example model:
openExample('sldv/DefiningExtendingExistingTestsCasesExample',... 'supportingFile','sldvdemo_sbr_extend_design');
Open the
SBR
Stateflow chart to see theKEY_OFF
/KEY_ON
transition.Create a model reference harness model:
[~, harnessModelFilePath] = ... sldvmakeharness('sldvdemo_sbr_extend_design',[],[],true);
The harness model,
sldvdemo_sbr_extend_design_harness
, includes:A Model block named Test Unit that references the original model,
sldvdemo_sbr_extend_design
.A Signal Editor block named Inputs that contains the test-case inputs to the model referenced in the Model block.
Initially, the Signal Editor block contains only the default test case, with all three inputs set to
0
.A DocBlock block named Test Case Explanation that documents the test case.
Initially, the Test Case Explanation block does not have any content for the default test case.
sldvmakeharness
returns the path to the harness model file inharnessModelFilePath
. Extract the name of the harness model file intoharnessModel
, for later use:[~, harnessModel] = fileparts(harnessModelFilePath);
In order to analyze the KEY_OFF
to KEY_ON
state transition, create a test case that makes the transition to the
KEY_ON
state in 500 time steps in Signal
Editor block. Close the Signal Editor block.
Log Starting Test Case
The next step is to log the starting test case that you created. You can then specify that Simulink® Design Verifier™ ignore the objectives satisfied by that test case when performing an analysis.
The sldvlogsignals
function records the
test case data in a MAT-file that contains an sldvData
structure.
This structure stores all the data that the
software gathers and produces during the analysis.
To log the starting test cases:
Save the name of the Model block in the harness model that references the
sldvdemo_sbr_extend_design
model:[~, modelBlock] = find_mdlrefs(harnessModel, false);
Simulate the model referenced by the Model block using the new test case, and log the input signals in the workspace variable
loggeddata
:loggeddata = sldvlogsignals(modelBlock{1});
Save the logged data in a MAT-file named
existingtestcase.mat
:save('existingtestcase.mat', 'loggeddata');
You will specify this file when you analyze the
sldvdemo_sbr_extend_design
model.
Extend Existing Test Cases
You can now analyze the sldvdemo_sbr_extend_design
model and
specify that the analysis extend the test cases already satisfied. The analysis uses
the existing test-case data as a starting point, and does not try to generate test
cases for the KEY_OFF
to KEY_ON
transition in
the SBR Stateflow chart.
Specify the starting test case and analyze the model:
Open the model.
open_system('sldvdemo_sbr_extend_design');
On the Design Verifier tab, click Test Generation Settings.
In the Configuration Parameters dialog box, on the Test Generation pane, under Existing test cases, select Extend existing test cases.
In the Data file field, enter the name of the MAT-file that contains the logged data:
existingtestcase.mat
Clear Ignore objectives satisfied by existing test cases.
When you clear this option, the software includes the starting test case in the final test suite. You will see that the complete test suite achieves 100% model coverage.
To close the Configuration Parameters dialog box, click OK.
Save the
sldvdemo_sbr_extend_design
model on the MATLAB® path with the namesldvdemo_sbr_extend_design_test
.Click Generate Tests.
The log window first lists the objectives that the starting test case satisfied.
The log window then lists the objectives generated beyond the starting test case.
Verify Analysis Results
To make sure that this analysis creates a complete test suite, generate the harness model so you can simulate the model with the generated test cases:
On the Design Verifier tab, in the Review Results section, click Create Test Harness Model.
In the harness model
sldvdemo_sbr_extend_design_test_harness
, open the Signal Editor block named Inputs.To simulate the model using all the test cases, click the Run all and produce coverage button .
When the simulation is complete, the model coverage report is displayed.
View the coverage information for the
sldvdemo_sbr_extend_design_test
model to see that the complete test suite achieves 100% coverage.