Achieve Missing Coverage in Referenced Model
If you simulate a referenced model that does not achieve full coverage, you can use Simulink® Design Verifier™ to generate test cases that achieve full coverage. There are two approaches:
Programmatically achieve missing coverage: Generate test cases for a referenced model with APIs for test-generation analysis.
Incrementally increase coverage: Generate test cases for the test harness model with missing coverage analysis features.
Programmatically Achieve Missing Coverage in Referenced Model
This example model uses a referenced model that does not achieve full coverage. When you run a test-generation analysis on the referenced model and combine it with previously recorded coverage data, you can achieve 100% coverage for the referenced model.
Record Coverage Data for Example Model
Simulate the example model. Record condition, decision, and MCDC coverage.
Open the Component-Based Modeling with Model Reference example model
The Model blocks CounterA, CounterB, and CounterC reference the model
On the Apps tab, click the arrow on the right of the Apps section.
Under Model Verification, Validation, and Test, click Coverage Analyzer.
On the Coverage tab, click Settings.
On the Coverage pane of the Configuration Parameters dialog box, set the following options:
Select Enable coverage analysis.
Select Referenced Models.
Click Select Models. In the Select Models for Coverage Analysis dialog box, select the check box for the referenced model
sldemo_mdlref_counter. Click OK.
The check box for
sldemo_mdlref_counterbecomes visible, corresponding to CounterA and CounterB. Coverage is not enabled for CounterC because the reference model CounterC is in
Specify which types of coverage to record during simulation. Under Coverage metrics, select MCDC.
In the Coverage > Results pane of the Configuration Parameters. Set the following options:
Select Save last run in workspace variable to save the collected coverage data from the most recent simulation run in a variable in the MATLAB® workspace.
Select Generate report automatically after analysis to specify that the simulation create a coverage report.
In the cvdata object name field, enter
covdata_originalto specify a unique name for the coverage data workspace variable.
To record the coverage data, start the simulation of the
After the simulation, the coverage report opens. The report indicates that the following coverage is achieved for the referenced model
The simulation saves the coverage data in the MATLAB workspace variable
cvdataobject that contains the coverage data.
Save the coverage data in a file on the MATLAB path:
Keep the model open as you continue through this example.
Find Test Cases for the Missing Coverage
To achieve 100% coverage for the
model, run a test-generation analysis that uses the existing coverage
Open the referenced model. At the command line, enter:
opts = sldvoptions;
When you create the
That the analysis ignores satisfied coverage data.
The file name containing the satisfied coverage data (
Enter the following commands to specify these options:
opts.IgnoreCovSatisfied = 'on'; opts.CoverageDataFile = 'existingcov.cvt';
Analyze the referenced model,
sldemo_mdlref_counter, by using the specified options:
[status, fileNames] = sldvrun('sldemo_mdlref_counter',opts,true);
The Simulink Design Verifier™ analysis satisfies seven objectives and creates one test case for the referenced model.
The next procedure simulates the referenced model,
sldemo_mdlref_counter, with the test case that the
Achieve Missing Coverage
To achieve the missing coverage for the referenced model,
sldemo_mdlref_counter, simulate the model by using the
test case from the Simulink
Design Verifier analysis.
Open the referenced model. At the command line, enter:
cvtestobject for the simulation and specify recording decision, condition, and MCDC coverage.
cvt = cvtest('sldemo_mdlref_counter'); cvt.settings.decision = 1; cvt.settings.condition = 1; cvt.settings.mcdc = 1;
Specify recording coverage and set the name of the
runOpts = sldvruntestopts; runOpts.coverageEnabled = true; runOpts.coverageSetting = cvt;
Simulate the model with the
cvt, and the test case, as defined in
fileNames.DataFile. Save the recorded coverage data in the workspace variable
[~, covdata_missing] = sldvruntest('sldemo_mdlref_counter', fileNames.DataFile, runOpts);
Verify Complete Model Coverage
You saved the coverage data from the simulation of the top-level model,
sldemo_mdlref_basic, in the workspace variable
covdata_original. To create a report that combines the
coverage data from the top-level model with the missing coverage data from the
sldemo_mdlref_counter, enter the following
cvhtml('Coverage Summary', covdata_original, covdata_missing);
The report shows that by analyzing the referenced model and using those results to record coverage, you can achieve 100% decision, condition, and MCDC coverage.
Increase Coverage for Referenced Models in a Test Harness
You can incrementally achieve full coverage for a generated test harness model. This example shows how to first generate a test harness model that does not achieve full coverage. Next, it shows how to run missing coverage analysis on the test harness model to generate test cases for 100% coverage.
This approach supports only test harness models generated by Simulink Design Verifier that reference the input model. The Design Verifier app is not available for test harness models when the test unit is copied from the top model. For more information see, Reference input model in generated harness.
Generate Test Harness Model and Record Coverage Data
To achieve full coverage for the
model, run a missing coverage analysis on the Simulink
Design Verifier generated harness
Open the example model:
Create a harness model for referenced model
[savedHarnessFilePath] = sldvmakeharness('sldemo_mdlref_counter');
For more information about the harness model, see Manage Simulink Design Verifier Harness Models.
In the harness model
sldemo_mdlref_counter_harness, the Format parameter must be
Datasetto make the referenced model
sldemo_mdlref_counterand the harness model
sldemo_mdlref_counter_harnesshave the same parameter settings. For more information see, Model Configuration Parameters: Data Import/Export.
sldemo_mdlref_counter_harnessmodel to record the coverage achieved by the test cases in the harness model. After the simulation, the coverage report appears. The report indicates that the following coverage is achieved for
Generate Test Cases for the Missing Coverage
Open the harness model:
To generate test cases for the missing coverage, on the Design Verifier tab, click Add Missing Coverage. A notification indicates the number of new tests that are added.
The Signal Builder dialog box shows the Missing coverage test case 1 added to the previous Test Case 1.
In the Signal Builder dialog box, click Run all . The software simulates the harness model by using all the test cases, collects model coverage information, and displays a coverage report. The coverage report indicates that the missing coverage analysis records 100% coverage for
Update Simulink Design Verifier Analysis Options
Open the harness model.
On the Design Verifier tab, click Test Generation Settings. The Configuration Parameters dialog box for referenced model
sldemo_mdlref_counteropens. You can set design verifier options for missing coverage analysis. For more information see, Options in Configuration Parameters Dialog Box.
View Active Results for Missing Coverage Analysis
Open the referenced model.
On the Design Verifier tab, in the Review Results section, click Load Earlier Results. Browse to the previously generated data file and click Open.
To view active results for missing coverage test cases, click Results Summary. The Results Summary window opens with the missing coverage analysis results. For more information on active results, see Review Analysis Results. The missing coverage test cases data is stored in a MAT-file that contains a structure named
sldvData. For more information see, Contents of sldvData Structure.
Missing Coverage analysis is a user interface-based workflow. Command-line functions are not available for Missing Coverage analysis.
Constraining values for parameters is not supported in the Missing Coverage analysis workflow. For more information see, Use Parameter Table.