Main Content

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.

  1. Open the example model sldemo_mdlref_basic.

    openExample('sldemo_mdlref_basic');

    The Model blocks CounterA, CounterB, and CounterC reference the model sldemo_mdlref_counter.

  2. On the Apps tab, click the arrow on the right of the Apps section.

    Under Model Verification, Validation, and Test, click Coverage Analyzer.

  3. On the Coverage tab, click Settings.

  4. 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_counter becomes visible, corresponding to CounterA and CounterB. Coverage is not enabled for CounterC because the reference model CounterC is in Accelerator simulation mode.

    • Specify which types of coverage to record during simulation. Under Coverage metrics, select MCDC.

  5. 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.

    • In the cvdata object name field, enter covdata_original to specify a unique name for the coverage data workspace variable.

  6. Click OK.

  7. To record the coverage data, start the simulation of the sldemo_mdlref_basic model.

    After the simulation, the coverage report opens. The report indicates that the following coverage is achieved for the referenced model sldemo_mdlref_counter:

    • Decision: 25%

    • Condition: 50%

    • MCDC: 0%

    The simulation saves the coverage data in the MATLAB workspace variable covdata_original, a cvdata object that contains the coverage data.

  8. Save the coverage data in a file on the MATLAB path:

    cvsave('existingcov',covdata_original);

    Keep the model open as you continue through this example.

Find Test Cases for the Missing Coverage

To achieve 100% coverage for the sldemo_mdlref_counter model, run a test-generation analysis that uses the existing coverage data.

  1. Open the referenced model. At the command line, enter:

    openExample('sldemo_mdlref_counter');
  2. Create an sldvoptions object:

    opts = sldvoptions;

    When you create the sldvoptions object, specify:

    • That the analysis ignores satisfied coverage data.

    • The file name containing the satisfied coverage data (existingcov.cvt)

    Enter the following commands to specify these options:

    opts.IgnoreCovSatisfied = 'on';
    opts.CoverageDataFile = 'existingcov.cvt';
  3. 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 analysis created.

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.

  1. Open the referenced model. At the command line, enter:

    openExample('sldemo_mdlref_counter');
  2. Create a cvtest object 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;
  3. Specify recording coverage and set the name of the cvtest object.

    runOpts = sldvruntestopts;
    runOpts.coverageEnabled = true;
    runOpts.coverageSetting = cvt;
  4. Simulate the model with the cvtest object, cvt, and the test case, as defined in fileNames.DataFile. Save the recorded coverage data in the workspace variable covdata_missing.

    [~, 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 referenced model, sldemo_mdlref_counter, enter the following command:

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.

Note

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 sldemo_mdlref_counter model, run a missing coverage analysis on the harness model generated by Simulink Design Verifier.

  1. Open the example model:

    openExample('sldemo_mdlref_counter');
  2. Create a harness model for referenced model sldemo_mdlref_counter:

    [savedHarnessFilePath] = sldvmakeharness('sldemo_mdlref_counter');

    For more information about the harness model, see Manage Simulink Design Verifier Harness Models.

  3. In the harness model sldemo_mdlref_counter_harness, specify Format as Dataset. This causes the referenced model sldemo_mdlref_counter and the harness model sldemo_mdlref_counter_harness to have the same parameter settings. For more information see, Model Configuration Parameters: Data Import/Export.

  4. Simulate the sldemo_mdlref_counter_harness model to record the coverage achieved by the test cases in the harness model. After the simulation, the coverage report appears. The report shows the coverage achieved for sldemo_mdlref_counter:

    Coverage report for sldemo_mdlref_counter model.

Generate Test Cases for the Missing Coverage

  1. Open the harness model:

    open_system('sldemo_mdlref_counter_harness');

    Harness model sldemo_mdlref_counter_harness showing Inputs, Test Case Explanation, and Test_Unit.

    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.

  2. The Signal Editor Block Parameters dialog box of the Input block shows the Test Case_2 added along with Test Case_1.

    Signal Editor dialog box. The Active scenario list TestCase_1 and TestCase_2 as values to choose from.

  3. In the harness model, click Run all (Coverage) . 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 sldemo_mdlref_counter.

    Coverage report for sldemo_mdlref_counter model.

Update Simulink Design Verifier Analysis Options

Open the harness model.

open_system('sldemo_mdlref_counter_harness');

On the Design Verifier tab, click Test Generation Settings. The Configuration Parameters dialog box for referenced model sldemo_mdlref_counter opens. 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.

open_system('sldemo_mdlref_counter');

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 Generate sldvData Structure.

Limitations

  • 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 to Find Constraints.

Related Topics