Extend an Existing Test Suite
This example shows how to use Simulink® Design Verifier™ to extend an existing test suite to obtain missing model coverage.
You analyze an example model and generate test suite to achieve full coverage. Then, modify the model such that test cases no longer achieve full coverage. Finally, you analyze the modified model to obtain missing coverage by using Simulink® Design Verifier™.
Generate an Initial Test Suite
Analyze thesldvdemo_cruise_control
model and generate a test suite that achieves full model coverage. To analyze the model to generate test cases that provide model coverage, use thesldvrun
function. Set the design verification parameters withsldvoptions
.
open_system'sldvdemo_cruise_control'; opts = sldvoptions; opts.Mode ='TestGeneration'; opts.ModelCoverageObjectives ='MCDC'; opts.SaveHarnessModel ='off'; opts.SaveReport ='off'; [ status, files ] = sldvrun('sldvdemo_cruise_control', opts, true);
The test generation analysis result appears in the Simulink Design Verifier Results Summary window.
close_system('sldvdemo_cruise_control',0);
Verify Complete Coverage
Thesldvruntest
function simulates the model with the existing test suite. Thecvhtml
function produces a coverage report that indicates the initial coverage of thesldvdemo_cruise_control
model.
open_system'sldvdemo_cruise_control'; [ outData, initialCov ] = sldvruntest('sldvdemo_cruise_control', files.DataFile, [], true); cvhtml('Initial coverage',initialCov); close_system('sldvdemo_cruise_control',0);
Modify the Model
Load the modifiedsldvdemo_cruise_control_mod
model. The controller target speed value is limited to 70, by using aSaturation
block.
load_system“sldvdemo_cruise_control_mod”; load_system'sldvdemo_cruise_control_mod/Controller';
Measure the Coverage Achieved by the Existing Test Suite
Thesldvruntest
function simulates the modifiedsldvdemo_cruise_control_mod
model with an existing test suite and inputs identical tosldvdemo_cruise_control
model. Thecvhtml
function produces a coverage report that indicates the modifiedsldvdemo_cruise_control_mod
model no longer achieves full coverage.
[ outData, startCov ] = sldvruntest(“sldvdemo_cruise_control_mod”, files.DataFile, [], true); cvhtml('Coverage with the original testsuite',startCov);
Extend an Existing Test Suite
To achieve full model coverage, thesldvgencov
function analyzes the model and extends the existing test suite.
[ status, covData, files ] = sldvgencov(“sldvdemo_cruise_control_mod”, opts, true, startCov);
Verify Complete Coverage
Verify that the new test suite achieves full coverage for thesldvdemo_cruise_control_mod
modified model. Thesldvruntest
函数模拟修改后的模型与extended test suite. Thecvhtml
report shows the total coverage achieved by thesldvdemo_cruise_control_mod
model.
[ additionalOut, additionalCov ] = sldvruntest(“sldvdemo_cruise_control_mod”, files.DataFile, [], true); totalCov = startCov + additionalCov; cvhtml('With additional coverage',totalCov);
To complete the example, close the model.
close_system(“sldvdemo_cruise_control_mod”);