cv.cvdatagroup - Collection of cvdata objects - MATLAB (original) (raw)
cv.cvdatagroup Class
Namespace: cv
Collection of cvdata
objects
Description
Objects of the cv.cvdatagroup
class contain one or more cvdata objects. Each cvdata
object contains coverage results for a model in the model hierarchy. A cv.cvdatagroup
cannot contain multiplecvdata
objects that have the same model name, simulation mode, and release.
Simulink® Coverage™ creates a cv.cvdatagroup
object when you simulate a model containing model references when coverage is enabled, or if your model uses external code files and you selected external files for coverage analysis. Use theget
and getAll
class methods to retrieve coverage data for specific models in your model reference hierarchy. Use theallNames
method to retrieve the cvdata
object names to use with the get
class method.
The cv.cvdatagroup
class is a handle class.
Creation
Description
`cvdg` = cv.cvdatagroup([cvdo](#mw%5F440622aa-6cf6-440f-ace4-959cf4e95d2c)1,[cvdo](#mw%5F440622aa-6cf6-440f-ace4-959cf4e95d2c)2,...)
creates a cvdatagroup
object that contains the specifiedcvdata
objects.
Note
If you create a cv.cvdatagroup
object by using multiplecvdata
objects that have the same model name, simulation mode, and release, the resulting cv.cvdatagroup
object contains only the last matching cvdata
object, and Simulink Coverage issues a warning.
Input Arguments
Coverage data, specified as one or more cvdata
objects.
Data Types: cvdata
Properties
Object name, specified as a character array.
Example: cvdg.name = 'myDataGroup';
Attributes:
GetAccess | public |
---|---|
SetAccess | public |
Data Types: char
Methods
allNames | Get names of cvdata objects incv.cvdatagroup object |
---|---|
allSimulationModes | Get names of all simulation modes associated with cvdata objects in cv.cvdatagroup |
get | Get specified cvdata object incvdatagroup |
getAll | Get allcvdata objects in cvdatagroup object |
add | Add cvdata object into cv.cvdatagroup object |
These methods specialize standard MATLAB® operators and functions for objects in this class.
+ | Performs a plus operation on the cvdata objects that match items inside each cvdatagroup object.Coverage data objects match if they have the same model name, simulation mode, and release.If acvdata object exists in onecvdatagroup object and not in the other, the+ operator adds it to the returnedcvdatagroup object. |
---|---|
- | Returns the set difference between coverage data in the left and right operands. The returned cv.cvdatagroup object contains only the coverage satisfied by the left operand, but not the right operand. Use - to determine how much additional coverage is attributed to a specific simulation or test. |
* | Returns the intersection between compatible coverage data contained in two cv.cvdatagroup objects. The returned cv.cvdatagroup object contains only the coverage satisfied by both operands. Use * to detect overlapping coverage between simulations. |
Examples
This example shows how to retrieve a specified coverage data object, all coverage data objects, or all coverage data object names from a cv.cvdatagroup
object.
Load the example model.
modelName = 'slvnvdemo_eml_model_coverage_demo'; load_system(modelName);
Use the Simulink.SimulationInput
class to set up the simulation scenario with coverage enabled.
simIn = Simulink.SimulationInput(modelName); simIn = setModelParameter(simIn,'CovEnable','on'); simIn = setModelParameter(simIn,'CovMetricStructuralLevel','MCDC'); simIn = setModelParameter(simIn,'CovSaveSingleToWorkspaceVar','on'); simIn = setModelParameter(simIn,'CovSaveName','covData'); simIn = setModelParameter(simIn,'CovSaveOutputData','off');
Simulate the model by passing the SimulationInput
object to the sim
function, and then retrieve the coverage data from the SimulationOutput
object.
simOut = sim(simIn); covData = simOut.covData
covData = ... cv.cvdatagroup
slcoverageExternalFile (simulation mode: Normal) slvnvdemo_eml_model_coverage_demo (simulation mode: Normal)
The example model contains a MATLAB® Function block that calls an external MATLAB function. Because Simulink Coverage returns the coverage data for the MATLAB function in a separate cvdata
object, sim
returns a cv.cvdatagroup
object that contains the coverage results for both the model and the MATLAB function.
To determine the name associated with each cvdata
object inside the cv.cvdatagroup
, use the class method allNames
.
covDataNames = allNames(covData)
covDataNames =
2×1 cell array
{'slcoverageExternalFile' }
{'slvnvdemo_eml_model_coverage_demo'}
The cv.cvdatagroup
contains the coverage results for the model as well as the MATLAB function.
To retrieve the coverage data for the model, use the get
class method.
modelCovData = get(covData,modelName)
modelCovData = ... cvdata version: (R2025a) id: 882 type: TEST_DATA test: cvtest object rootID: 884 checksum: [1x1 struct] modelinfo: [1x1 struct] startTime: 01-Feb-2025 15:48:16 stopTime: 01-Feb-2025 15:48:16 intervalStartTime: intervalStopTime: simulationStartTime: 0 simulationStopTime: 1 filter: simMode: Normal
To retrieve coverage data for both the model and the external file, use the getAll
class method.
covDataArray = getAll(covData)
covDataArray =
2×1 cell array
{1×1 cvdata}
{1×1 cvdata}
This example shows how to create a cvdatagroup
object using two cvdata
objects.
Record coverage for slvnvdemo_cv_small_controller
.
model_1 = 'slvnvdemo_cv_small_controller'; load_system(model_1) cvdo1 = cvsim(model_1);
Record coverage for slvnvdemo_powerwindow_controller
.
model_2 = 'slvnvdemo_powerwindow_controller'; load_system(model_2) cvdo2 = cvsim(model_2);
Create a cv.cvdatagroup
object that contains two cvdata
objects.
cvdg = cv.cvdatagroup(cvdo1,cvdo2);
This example shows how to use the +
operator to merge cv.cvdatagroup
objects.
Load the model.
modelName = "slcovDataGroup"; load_system(modelName);
Prepare the model for coverage analysis by creating a Simulink.SimulationInput
object. Then, make the coverage data accessible in the MATLAB® workspace by setting the CovSaveSingleToWorkspaceVar
parameter to on
.
simIn = Simulink.SimulationInput(modelName); simIn = setModelParameter(... simIn,"CovSaveSingleToWorkspaceVar","on");
The model requires four variables set in the MATLAB workspace. For the first run:
a = 1; b = 0; c = 1; d = 0;
Simulate the model and assign the coverage data to a variable named covData1
. Because the slcovDataGroup
model calls an external MATLAB function, Simulink® Coverage™ returns the coverage results in a cv.cvdatagroup
object. One cvdata
object contains the coverage results for the model, and the other contains coverage results for the external MATLAB file.
simOut1 = sim(simIn); covData1 = simOut1.covdata; class(covData1)
Check the decision coverage for the external MATLAB function slcoverageExternalFile
by using decisioninfo
.
[decCov1,decInfo] = decisioninfo(covData1,"slcoverageExternalFile")
decCov1 =
2 3
decInfo =
struct with fields:
isFiltered: 0
justifiedCoverage: 0
isJustified: 0
filterRationale: ''
decision: [1×2 struct]
In the external MATLAB file, the false case of the if
statement does not execute and is missing decision coverage. You can verify that this is true by using the optional description output of decisioninfo
. For example, the second decision represents the if statement.
ans =
struct with fields:
text: 'if (z)'
filterRationale: ''
isFiltered: 0
isJustified: 0
outcome: [1×2 struct]
And the first outcome of that decision represents the false case, which has an execution count of zero.
decInfo.decision(2).outcome(1)
ans =
struct with fields:
text: 'false'
executionCount: 0
executedIn: []
isFiltered: 0
isJustified: 0
filterRationale: ''
In order to satisfy this decision, change the variable c
to zero and run the coverage analysis a second time.
c = 0; simOut2 = sim(simIn); covData2 = simOut2.covdata;
Use the +
operator to aggregate the coverage for the two runs. Then check the decision coverage again.
covDataTot = covData1 + covData2; decCovTot = decisioninfo(covDataTot,"slcoverageExternalFile")
In the aggregated cv.cvdatagroup
object, the external MATLAB file slcoverageExternalFile
now has 100% decision coverage.
Version History
Introduced in R2007b