Main Content

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 the sldvdemo_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 the sldvrun function. Set the design verification parameters with sldvoptions.

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

The sldvruntest function simulates the model with the existing test suite. The cvhtml function produces a coverage report that indicates the initial coverage of the sldvdemo_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 modified sldvdemo_cruise_control_mod model. The controller target speed value is limited to 70, by using a Saturation block.

load_system 'sldvdemo_cruise_control_mod';
load_system 'sldvdemo_cruise_control_mod/Controller';

Measure the Coverage Achieved by the Existing Test Suite

The sldvruntest function simulates the modified sldvdemo_cruise_control_mod model with an existing test suite and inputs identical to sldvdemo_cruise_control model. The cvhtml function produces a coverage report that indicates the modified sldvdemo_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, the sldvgencov 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 the sldvdemo_cruise_control_mod modified model. The sldvruntest function simulates the modified model with the extended test suite. The cvhtml report shows the total coverage achieved by the sldvdemo_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');