mcdcinfo
Retrieve modified condition/decision coverage information from
cvdata
object
Syntax
Description
returns modified condition decision coverage (MCDC) results from the
covInfo
= mcdcinfo(cvdo
,modelObject
)cvdata
object cvdo
for the model component
specified by modelObject
.
returns MCDC results from the covInfo
= mcdcinfo(cvdo
, modelObject
, simMode
)cvdata
object
cvdo
for the model component specified by
modelObject
for the simulation mode
simMode
.
returns MCDC results for covInfo
= mcdcinfo(cvdo
,modelObject
,ignoreDescendants
)modelObject
, depending on the value of
ignoreDescendants
.
[
returns MCDC results and text descriptions of each condition/decision in
covInfo
, description
]
= mcdcinfo(cvdo
,modelObject
)modelObject
.
Examples
Collect MCDC coverage for the
slvnvdemo_cv_small_controller
model and determine the
percentage of MCDC coverage collected for the Logic block in the Gain
subsystem:
mdl = 'slvnvdemo_cv_small_controller'; openExample(mdl); open_system(mdl); %Create test specification object testObj = cvtest(mdl) %Enable MCDC coverage testObj.settings.mcdc = 1; %Simulate model data = cvsim(testObj) %Retrieve MCDC results for Logic block blk_handle = get_param([mdl, '/Gain/Logic'], 'Handle'); cov = mcdcinfo(data, blk_handle) %Percentage of MCDC outcomes covered percent_cov = 100 * cov(1) / cov(2)
Open the example and load the model.
openExample("slcoverage/RetrieveCodeCoverageResultsExample");
Use the
setupSILCoverage
function to configure the model for code coverage analysis. The output is aSimulink.SimulationInput
object.simIn = setupSILCoverage("slvnvdemo_counter_harness");
Simulate the model.
simOut = sim(simIn);
To retrieve coverage results for the generated code that represents a specific block, use the block path. For example, retrieve the MCDC results for the Logic block named
And
by passing the block path relative to the top model.covDataSIL = simOut.covdata; mcdcBlockSIL = mcdcinfo(covDataSIL,... "slvnvdemo_counter/And")
mcdcBlockSIL = 2 2
To retrieve coverage results for a function in the generated code, use a cell array that contains the generated source file name and function name. For example, retrieve the MCDC coverage results for the function
slvnvdemo_counter
located in the source fileslvnvdemo_counter.c
.mcdcSILFunction = mcdcinfo(covDataSIL,{"slvnvdemo_counter.c",... "slvnvdemo_counter"})
mcdcSILFunction = 2 2
Open the example and load data into the workspace.
openExample("slcoverage/RetrieveSFunCoverageResultsExample"); load slcoverage_lct_data.mat
Use the
setupSFcnCoverage
function to configure the model for coverage analysis. The output is aSimulink.SimulationInput
object.simIn = setupSFcnCoverage("slcoverage_lct_bus");
Simulate the model.
simOut = sim(simIn);
To retrieve coverage results for an S-function, use the
mcdcinfo
function and specify a cell array that contains the handle or full path of the block, followed by the file name of the S-function source file. Optionally, you can also specify a specific function inside that source file. For this example, retrieve the MCDC results for the function namedcounterbusFcn
in the S-function filecounterbus.c
, which the S-Function blockslcoverage_sfun_counterbus
calls. The S-Function block is inside theTestCounter
subsystem in the modelslcoverage_lct_bus
.covDataSFcn = simOut.covdata; mcdcSFun = mcdcinfo(covDataSFcn,... {"slcoverage_lct_bus/TestCounter/slcoverage_sfun_counterbus",... "counterbus.c","counterbusFcn"})
mcdcSFun = 1 2
Input Arguments
Coverage data, specified as a cvdata
object.
Data Types: cvdata
Model object, specified as a character array, string array, Simulink handle, Stateflow ID, or cell array.
To specify a model object, such as a block or a Stateflow chart, use one of these formats:
Object Specification | Description |
---|---|
| Full path to a model or block |
| Handle to a model or block |
| Handle to a Simulink API object |
| Stateflow ID |
| Handle to a Stateflow API object from a singly instantiated Stateflow chart |
| Cell array with the path to a Stateflow chart or atomic subchart and the ID of an object contained in that chart or subchart |
| Cell array with the path to a Stateflow chart or subchart and a Stateflow object API handle contained in that chart or subchart |
| Cell array with a handle to a Stateflow chart or atomic subchart and the ID of an object contained in that chart or subchart |
To specify an S-Function block or its contents, use one of these formats:
Object Specification | Description |
---|---|
| Cell array with the path to an S-Function block and the name of a source file |
| Cell array with an S-Function block handle and the name of a source file |
| Cell array with the path to an S-Function block, the name of a source file, and a function name |
| Cell array with an S-Function block handle, the name of a source file, and a function name |
To specify a code coverage result, such as coverage data collected during software-in-the-loop (SIL) or processor-in-the-loop (PIL) analysis, use one of these formats:
Object Specification | Description |
---|---|
| Cell array with the name of a source file and a function name |
| Cell array with a model name or model handle and the name of a source file |
| Cell array with a model name or model handle, the name of a source file, and a function name |
Data Types: char
| string
| cell
| Stateflow.State
| Stateflow.Transition
Simulation mode during coverage analysis, specified as one of these options:
Object Specification | Description |
---|---|
| Model in normal simulation mode. |
| Model in software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation mode. |
| Model reference in SIL or PIL simulation mode. |
| Model reference in SIL or PIL simulation mode with the code interface set to top model. |
Data Types: char
| string
Whether to ignore descendants in coverage results, specified as a numeric or logical
1 (true)
or 0 (false)
, where:
0 (false)
includes coverage results of descendant objects.1 (true)
ignores coverage results of descendant objects.
Data Types: single
| double
| logical
Output Arguments
Coverage information, returned as a two-element array of the form
[covered_outcomes,total_outcomes]
if
cvdo
contains MCDC data, or an empty array if it
does not.
covered_outcomes | Number of MCDC outcomes satisfied for
modelObject |
total_outcomes | Total number of MCDC outcomes for
modelObject |
Data Types: double
MCDC coverage description, returned as a structure array with the following fields:
Block exclusion flag, returned as 1
if the
block is excluded and 0
if it is not.
Data Types: double
Block coverage filter rationale, returned as a character array.
Data Types: char
Number of justified coverage objective outcomes, returned as a scalar double.
Data Types: double
Description of the measured objective, returned as a character array.
Data Types: char
Information for individual MCDC outcomes, returned as a structure with the following fields:
MCDC outcome exclusion flag, returned as
1
if the MCDC outcome is
excluded or 0
if it is
not.
Data Types: double
MCDC outcome justification flag, returned as
1
if the MCDC outcome is
justified or 0
if it is
not.
Data Types: double
Coverage filter rationale, returned as a character
array. If a filter is not applied, or the applied
filter does not contain filter rules,
filterRationale
is returned as
an empty array.
Data Types: char
Description of the MCDC outcome, returned as a character array.
Data Types: char
MCDC outcome flag, returned as
1
if the MCDC outcome is fully
satisfied, and 0
if it is not.
The MCDC outcome is fully satisfied if each
condition independently
affects the
decision outcome.
Data Types: double
Condition values that achieve the
true
MCDC result, returned as
a
Data Types: double
Number of time steps the condition is
false
, returned as a
scalar.
Data Types: double
Aggregated coverage test case traceability
information, returned as a structure array. If your
coverage data does not contain aggregated results
from multiple simulations,
trueExecutedIn
is an empty
array. If your coverage data contains aggregated
results, trueExecutedIn
indicates
which test runs executed the true
condition outcome and has the following fields:
uniqueId | Unique identifier for the
cvdata object created by the test
case that executed this condition outcome,
returned as a character array. |
analyzedModel | The name of the model analyzed, returned as a character array. |
description | The test case description, returned as a character array. |
date | The date and time of the simulation that
created the cvdata object,
returned as a character array. |
traceLabel | The short name of the test case, returned as a character array. |
testRunInfo | Test details, returned as a structure array. |
testRunInfo.runid | The identifier of the run that generated the coverage result, returned as a scalar double. |
testRunInfo.runName | The name of the test case that generated the coverage result, returned as a character array. |
testRunInfo.testId | Identifying data for the test case that generated the coverage result, returned as a structure array. |
testRunInfo.testId.uuid | The unique identifier for the test case that generated the coverage result, returned as a character array. |
testRunInfo.testId.contextType | The test context in which the coverage result was obtained, returned as one of these values:
|
Data Types: struct
Aggregated coverage test case traceability
information, returned as a structure array. If your
coverage data does not contain aggregated results
from multiple simulations,
falseExecutedIn
is an empty
array. If your coverage data contains aggregated
results, falseExecutedIn
indicates which test runs executed the
false
condition outcome and has
the following fields:
uniqueId | Unique identifier for the
cvdata object created by the test
case that executed this condition outcome,
returned as a character array. |
analyzedModel | The name of the model analyzed, returned as a character array. |
description | The test case description, returned as a character array. |
date | The date and time of the simulation that
created the cvdata object,
returned as a character array. |
traceLabel | The short name of the test case, returned as a character array. |
testRunInfo | Test details, returned as a structure array. |
testRunInfo.runid | The identifier of the run that generated the coverage result, returned as a scalar double. |
testRunInfo.runName | The name of the test case that generated the coverage result, returned as a character array. |
testRunInfo.testId | Identifying data for the test case that generated the coverage result, returned as a structure array. |
testRunInfo.testId.uuid | The unique identifier for the test case that generated the coverage result, returned as a character array. |
testRunInfo.testId.contextType | The test context in which the coverage result was obtained, returned as one of these values:
|
Data Types: struct
Data Types: double
Data Types: struct
Alternatives
Use the coverage settings to collect MCDC coverage for a model:
Open the model.
In the Model Editor, select Model Settings on the Modeling tab.
On the Coverage pane of the Configuration Parameters dialog box, select Enable coverage analysis.
Under Coverage metrics, select MCDC as the structural coverage level.
Click OK to close the Configuration Parameters dialog box and save your changes.
Simulate the model by clicking the Run button and review the results.
Version History
Introduced in R2006b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)