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 thesldvdemo_cruise_controlmodel and generate a test suite that achieves full model coverage. To analyze the model to generate test cases that provide model coverage, use thesldvrunfunction. 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

Thesldvruntestfunction simulates the model with the existing test suite. Thecvhtmlfunction produces a coverage report that indicates the initial coverage of thesldvdemo_cruise_controlmodel.

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_modmodel. The controller target speed value is limited to 70, by using aSaturationblock.

load_system“sldvdemo_cruise_control_mod”; load_system'sldvdemo_cruise_control_mod/Controller';

Measure the Coverage Achieved by the Existing Test Suite

Thesldvruntestfunction simulates the modifiedsldvdemo_cruise_control_modmodel with an existing test suite and inputs identical tosldvdemo_cruise_controlmodel. Thecvhtmlfunction produces a coverage report that indicates the modifiedsldvdemo_cruise_control_modmodel 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, thesldvgencovfunction 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_modmodified model. Thesldvruntest函数模拟修改后的模型与extended test suite. Thecvhtmlreport shows the total coverage achieved by thesldvdemo_cruise_control_modmodel.

[ 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”);