Main Content

Extracting Detailed Information from Coverage Data

This example shows how coverage utility commands can be used to extract information for an individual subsystem, block, or Stateflow® object from cvdata objects.

Example Model

This example illustrates command line access of coverage data for a small model that contains aspects of various supported coverage metrics.

Use the following commands to open the model 'slvnvdemo_cv_small_controller' and its subsystem 'Gain.'

open_system('slvnvdemo_cv_small_controller');
open_system('slvnvdemo_cv_small_controller/Gain');

Generate Coverage Data and an HTML Report

Simulate the model using sim. Use a Simulink.SimulationInput object to capture coverage settings and use it as an input to sim. After the simulation, coverage data will be stored in a cvdata object.

simIn = Simulink.SimulationInput('slvnvdemo_cv_small_controller');
simIn = simIn.setModelParameter('CovEnable','on');
simIn = simIn.setModelParameter('CovMetricStructuralLevel','MCDC');
simIn = simIn.setModelParameter('CovSaveSingleToWorkspaceVar','on');
simIn = simIn.setModelParameter('CovSaveName','covData');
simIn = simIn.setModelParameter('CovScope','EntireSystem');
simIn = simIn.setModelParameter('CovMetricLookupTable','on');
simIn = simIn.setModelParameter('CovMetricSignalRange','on');
simOut = sim(simIn);

Process the coverage data returned from a cvsim command with the report generation command cvhtml. The resulting report is a convenient representation of model coverage for the entire model.

cvhtml('tempfile.html',covData);

The coverage data is also available in the simulation output object.

simOut
simOut = 

  Simulink.SimulationOutput:
                covData: [1x1 cvdata] 
                   tout: [59x1 double] 
                   yout: [59x1 double] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

Extract Decision Coverage Information

Use the decisioninfo command to extract decision coverage information for individual Simulink blocks or Stateflow objects.

The following command extracts a coverage array for the entire model. The first element is the number of coverage objective outcomes satisfied for the model; the second element is the total number of coverage objective outcomes for the model.

cov = decisioninfo(covData,'slvnvdemo_cv_small_controller')
percent = 100*cov(1)/cov(2)
cov =

     4     6


percent =

   66.6667

Retrieve coverage information for the 'Saturation' block using the full path to that block. Provide a second return argument for textual descriptions of the coverage objective outcomes within that block.

[blkCov, description] = decisioninfo(...
    covData,'slvnvdemo_cv_small_controller/Saturation')

decision1 = description.decision(1).text
out_1a = description.decision(1).outcome(1).text
count_1a = description.decision(1).outcome(1).executionCount
out_1b = description.decision(1).outcome(2).text
count_1b = description.decision(1).outcome(2).executionCount
blkCov =

     3     4


description = 

  struct with fields:

           isFiltered: 0
    justifiedCoverage: 0
          isJustified: 0
      filterRationale: ''
             decision: [1x2 struct]


decision1 =

    'U >= LL'


out_1a =

    'false'


count_1a =

     0


out_1b =

    'true'


count_1b =

     7

Quantitative coverage information is available for every outcome in the hierarchy that contains or has coverage objective outcomes. Textual descriptions are generated only for objects that have coverage objective outcomes themselves. For example, invoke decisioninfo for the virtual subsystem Gain, and the description return value is empty.

[blkCov, description] = decisioninfo(...
    covData,'slvnvdemo_cv_small_controller/Gain')
blkCov =

     1     2


description = 

  struct with fields:

           isFiltered: 0
    justifiedCoverage: 0
          isJustified: 0
      filterRationale: ''

In some cases an object has internal coverage objectives but also contains descendants with additional coverage objectives. Coverage information normally includes all the descendants unless a third argument for ignoring descendants is set to 1.

subsysOnlycov = decisioninfo(...
    covData,'slvnvdemo_cv_small_controller/Gain',1)
subsysOnlycov =

     []

The decisioninfo command also works with block handles, Stateflow IDs, and Stateflow API objects.

blkHandle = get_param('slvnvdemo_cv_small_controller/Saturation','Handle')
blkCov = decisioninfo(covData,blkHandle)
blkHandle =

  335.0027


blkCov =

     3     4

If an object has no decision coverage, the command returns empty outputs.

missingBlkCov = decisioninfo(covData,'slvnvdemo_cv_small_controller/Sine1')
missingBlkCov =

     []

Extract Condition Coverage Information

Condition coverage indicates if the logical inputs to Boolean expressions have been evaluated to both true and false. In Simulink, conditions are the inputs to logical operations.

The conditioninfo command for extracting condition coverage information is very similar to the decisioninfo command. It normally returns information about an object and all its descendants, but can take a third argument that indicates if descendants should be ignored. It can also return a second output containing descriptions of each condition.

cov = conditioninfo(covData,'slvnvdemo_cv_small_controller/Gain/Logic')
[cov, desc] = conditioninfo(...
    covData,'slvnvdemo_cv_small_controller/Gain/Logic');
desc.condition(1)
desc.condition(2)
cov =

     2     4


ans = 

  struct with fields:

            isFiltered: 0
           isJustified: 0
       filterRationale: ''
                  text: 'port1'
              trueCnts: 59
             falseCnts: 0
     trueOutcomeFilter: [1x1 struct]
    falseOutcomeFilter: [1x1 struct]
        trueExecutedIn: []
       falseExecutedIn: []


ans = 

  struct with fields:

            isFiltered: 0
           isJustified: 0
       filterRationale: ''
                  text: 'port2'
              trueCnts: 0
             falseCnts: 59
     trueOutcomeFilter: [1x1 struct]
    falseOutcomeFilter: [1x1 struct]
        trueExecutedIn: []
       falseExecutedIn: []

Extract Modified Condition/Decision Coverage Information

Modified Condition/Decision Coverage (MCDC) is satisfied for a condition within a Boolean expression if there are two evaluations of the expression, representing an independence pair, which illustrate that the value of the condition independently affects the outcome of the entire expression. That is to say, for these evaluations, toggling the value of the condition would cause the expression outcome to toggle as well.

In this example, the logical AND block is analyzed for MCDC and this information can be extracted using the mcdcinfo command. This command uses the same syntax as conditioninfo and decisioninfo commands.

[cov, desc] = mcdcinfo(covData,'slvnvdemo_cv_small_controller/Gain/Logic')
desc.condition(1)
desc.condition(2)
cov =

     0     2


desc = 

  struct with fields:

                 text: 'Output'
            condition: [1x2 struct]
           isFiltered: 0
      filterRationale: ''
    justifiedCoverage: 0


ans = 

  struct with fields:

               text: 'port1'
           achieved: 0
           trueRslt: '(TT)'
          falseRslt: '(FT)'
         isFiltered: 0
        isJustified: 0
    filterRationale: ''
     trueExecutedIn: []
    falseExecutedIn: []


ans = 

  struct with fields:

               text: 'port2'
           achieved: 0
           trueRslt: '(TT)'
          falseRslt: 'TF'
         isFiltered: 0
        isJustified: 0
    filterRationale: ''
     trueExecutedIn: []
    falseExecutedIn: []

Extract Lookup Table Coverage Information

Lookup table coverage records the frequency that lookup occurs for each interpolation interval. Valid intervals for coverage purposes also include values less than the smallest breakpoint and values greater than the largest breakpoint. For consistency with the other commands, this information is returned as a pair of counts with the number of intervals that executed and the total number of intervals.

A second output argument causes tableinfo to return the execution counts for all interpolation intervals. If the table has M-by-N output values, execution counts are returned in an M+1-by-N+1 matrix.

A third output argument causes tableinfo to return the counts where the input was exactly equal to the breakpoint. This is returned in a cell array of vectors, one for each dimension in the table.

[cov,execCnts,brkEq] = tableinfo(covData, ...
    'slvnvdemo_cv_small_controller/Gain/Gain Table')
cov =

    23   121


execCnts =

     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     2    12    14    10     2     0     0     0
     0     0     4    12     0     0     0    12     0     0     0
     0     0    22     0     0     0     0     0    12     0     0
     0     0    21     0     0     0     0     0    59     0     0
     0     0    21     0     0     0     0     0    29     0     0
     0     0     7    28     0     0     0    28     6     0     0
     0     0     0     4    22    18    23     5     0     0     0
     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0


brkEq =

  1x2 cell array

    {10x1 double}    {10x1 double}

Extract Signal Range Information

The signal range metric records the smallest and largest value of Simulink block outputs and Stateflow data objects. The sigrangeinfo command returns two return arguments for the minimum and maximum values, respectively.

The sigrangeinfo command works only for leaf blocks that perform a computation, otherwise the command returns empty arguments. A leaf block is a block that does not have any child blocks, such as a Product block. A non-leaf block is a block that does have child blocks, like a subsystem.

For example, compare the signal range results for the leaf block named Gain Table with the signal range results for the subsystem block named Gain.

[sigMin, sigMax] = sigrangeinfo(covData,...
    'slvnvdemo_cv_small_controller/Gain/Gain Table')

[sigMin, sigMax] = sigrangeinfo(covData,...
    'slvnvdemo_cv_small_controller/Gain')
sigMin =

    3.3656


sigMax =

    7.6120


sigMin =

     []


sigMax =

     []