This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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. The model contains some blocks with coverage points at the root level and others at the subsystem level.

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');

Generating Coverage Data and an HTML Report

Simulate the model with the cvsim command. This command captures coverage data as a side-effect and returns this information in a cvdata object. The cvdata object is a MATLAB® object that references the internal data stored in the coverage tool and the model data structures that produce that data.

testObj = cvtest('slvnvdemo_cv_small_controller');
testObj.settings.decision = 1;
testObj.settings.condition = 1;
testObj.settings.mcdc = 1;
testObj.settings.tableExec = 1;
testObj.settings.sigrange = 1;
data = cvsim(testObj)
data = ... cvdata
                 id: 1621
               type: TEST_DATA
               test: cvtest object
             rootID: 1623
           checksum: [1x1 struct]
          modelinfo: [1x1 struct]
          startTime: 01-Jul-2018 00:20:16
           stopTime: 01-Jul-2018 00:20:16
  intervalStartTime: 0
   intervalStopTime: 0
simulationStartTime: 0
 simulationStopTime: 10
            metrics: [1x1 struct]
             filter: 
            simMode: Normal

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',data);

Extracting 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 points satisfied for the model; the second element is the total number of coverage points for the model.

cov = decisioninfo(data,'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 points within that block.

[blkCov, description] = decisioninfo(data,'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: [1×2 struct]


decision1 =

    'U > LL'


out_1a =

    'false'


count_1a =

     0


out_1b =

    'true'


count_1b =

     6

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

[blkCov, description] = decisioninfo(data,'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 points but also contains descendants with additional coverage points. Coverage information normally includes all the descendants unless a third argument for ignoring descendants is set to 1.

subsysOnlycov = decisioninfo(data,'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(data,blkHandle)
blkHandle =

   34.0012


blkCov =

     3     4

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

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

     []

Extracting 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(data,'slvnvdemo_cv_small_controller/Gain/Logic')
[cov, desc] = conditioninfo(data,'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: [1×1 struct]
    falseOutcomeFilter: [1×1 struct]


ans = 

  struct with fields:

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

Extracting 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(data,'slvnvdemo_cv_small_controller/Gain/Logic')
desc.condition(1)
desc.condition(2)
cov =

     0     2


desc = 

  struct with fields:

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


ans = 

  struct with fields:

               text: 'port1'
           achieved: 0
           trueRslt: '(TT)'
          falseRslt: '(FT)'
         isFiltered: 0
    filterRationale: ''


ans = 

  struct with fields:

               text: 'port2'
           achieved: 0
           trueRslt: '(TT)'
          falseRslt: 'TF'
         isFiltered: 0
    filterRationale: ''

Extracting 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(data, '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 =

  1×2 cell array

    {10×1 double}    {10×1 double}

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

[sigMin, sigMax] = sigrangeinfo(data,'slvnvdemo_cv_small_controller/Gain/Gain Table')  % Leaf
[sigMin, sigMax] = sigrangeinfo(data,'slvnvdemo_cv_small_controller/Gain')             % Nonleaf
sigMin =

    3.3656


sigMax =

    7.6120


sigMin =

     []


sigMax =

     []

Finish by closing the model.

close_system('slvnvdemo_cv_small_controller',0);