Main Content

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 multiple cvdata 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 the get and getAll class methods to retrieve coverage data for specific models in your model reference hierarchy. Use the allNames 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(cvdo1,cvdo2,...) creates a cvdatagroup object that contains the specified cvdata objects.

Note

If you create a cv.cvdatagroup object by using multiple cvdata objects that have the same model name, simulation mode, and release, the resulting cv.cvdatagroup object contains only one of the cvdata objects.

example

Input Arguments

expand all

Coverage data, specified as one or more cvdata objects.

Data Types: cvdata

Properties

expand all

Object name, specified as a character array.

Example: cvdg.name = 'myDataGroup';

Attributes:

GetAccess
public
SetAccess
public

Data Types: char

Methods

expand all

Examples

collapse all

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 =

  2x1 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: (R2024b)
                 id: 882
               type: TEST_DATA
               test: cvtest object
             rootID: 884
           checksum: [1x1 struct]
          modelinfo: [1x1 struct]
          startTime: 06-Sep-2024 01:20:11
           stopTime: 06-Sep-2024 01:20:11
  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 =

  2x1 cell array

    {1x1 cvdata}
    {1x1 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);

Version History

Introduced in R2007b