This example shows how to use Simulink Design Verifier to extend a test suite such that it satisfies missing model coverage. In this manner, you can reuse test data as you modify a model and limit test generation only to the new or modified portions of that model.
We begin the example by creating an initial test suite for a model. We'll modify the model such that the test suite no longer provides complete coverage. Then we'll instruct Simulink Design Verifier to add to the test suite additional test cases that complete its coverage of the modified model.
Open the cruise control model and generate a test suite that achieves complete coverage.
opts = sldvoptions; opts.Mode = 'TestGeneration'; opts.ModelCoverageObjectives = 'MCDC'; opts.SaveHarnessModel = 'off'; opts.SaveReport = 'off'; open_system 'sldvdemo_cruise_control'; [ status, files ] = sldvrun('sldvdemo_cruise_control', opts);
Starting test generation for model "sldvdemo_cruise_control" Compiling model...done Translating model...done Generating tests... .................................. Test generation completed normally. Generating output files: Data file: C:\Work\Altcweb\matlab\toolbox\sldv\sldvdemos\sldv_output\sldvdemo_cruise_control\sldvdemo_cruise_control_sldvdata7.mat Results generation completed.
Check that the test suite achieves full coverage of the model. The sldvruntest function runs a simulation using the data from any test case in the test suite. It can also run the full test suite and measure the accumulated coverage.
[ outData, initialCov ] = sldvruntest('sldvdemo_cruise_control', files.DataFile, , true); cvhtml('Initial coverage', initialCov); close_system('sldvdemo_cruise_control', 0);
Open a modified version of the cruise control model. The target speed cannot attain a value greater than 70 in the modified model.
Use the sldvruntest function to measure the coverage that the initial test suite achieves for the modified model. This is accomplished easily because both models use identical inputs. Note that if the initial test suite was hand-written or generated by a tool other than Simulink Design Verifier, you can use the cvsim function to accomplish this step.
[ outData, startCov ] = sldvruntest('sldvdemo_cruise_control_mod', files.DataFile, , true); cvhtml('Coverage with the original testsuite', startCov);
Use the sldvgencov function to extend the existing test suite by searching only for test cases that satisfy the remaining objectives.
[ status, covData, files ] = sldvgencov('sldvdemo_cruise_control_mod', opts, false, startCov);
Verify that the new test suite achieves complete coverage of the modified model. Use sldvruntest to measure the coverage that the new test suite provides, and then add it to the original coverage.
[ additionalOut, additionalCov ] = sldvruntest('sldvdemo_cruise_control_mod', files.DataFile, , true); totalCov = startCov + additionalCov; cvhtml('With additional coverage', totalCov); close_system('sldvdemo_cruise_control_mod', 0);