MATLAB Examples

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 acheive 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 result appears in the Simulink Design Verifier Results Summary window.


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 sldvdemo_cruise_control model.

open_system 'sldvdemo_cruise_control';
[ outData, initialCov ] = sldvruntest('sldvdemo_cruise_control', files.DataFile, [], true);
cvhtml('Initial coverage',initialCov);

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 acheives 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 acheive 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 acheived 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);

At the end of this process close the model.