Main Content

cv.cvdatagroup class

Package: cv

Collection of cvdata objects

Description

A cv.cvdatagroup object contains one or more cvdata objects. Each cvdata object contains coverage results for a model in the model hierarchy.

Simulink® Coverage™ creates a 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

example

cvdg = cv.cvdatagroup(cvdo1,cvdo2,...) creates a cvdatagroup object that contains the specified cvdata objects.

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: (R2022b)
                 id: 383
               type: TEST_DATA
               test: cvtest object
             rootID: 385
           checksum: [1x1 struct]
          modelinfo: [1x1 struct]
          startTime: 31-Aug-2022 03:43:29
           stopTime: 31-Aug-2022 03:43:29
  intervalStartTime: 0
   intervalStopTime: 0
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