Main Content

cvsim

Simulate and return model coverage results for test objects

Description

cvdo = cvsim(modelName) simulates the model and returns the coverage results in the cvdata object, cvdo. When called using modelName, cvsim uses the coverage metric settings specified in the model configuration parameters.

Note

cvsim will record coverage even if coverage is not enabled in the model configuration parameters.

cvdo = cvsim(testObj) simulates the model and returns the coverage results for the cvtest object, testObj.

Note

The coverage metric settings specified in testObj override coverage metric settings specified in the model configuration parameters.

[cvdo,simOut] = cvsim(__,Name,Value) specifies the model parameters, simulates the model, and returns the coverage results in the cvdata object, cvdo, and the simulation outputs in the Simulink.SimulationOutput object, simOut.

[cvdo,simOut] = cvsim(testObj,paramStruct) sets the model parameters specified in a structure paramStruct.

[cvdo1,...,cvdoN] = cvsim(testObj1,...,testObjN) simulates the model for N test objects, and returns the coverage results for each object.

example

Examples

collapse all

This example shows how to use cvsim with a cvtest object input and a structure of model parameters.

Load the slvnvdemo_cv_small_controller example model.

modelName = 'slvnvdemo_cv_small_controller';
load_system(modelName)

Create a cvtest object and turn on decision coverage.

testObj = cvtest(modelName);
testObj.settings.decision = 1;

Create a structure that defines the following model parameters:

  • Set the absolute tolerance, AbsTol, to 1e-5.

  • Enable the simulation to save states to the workspace with SaveState.

  • Declare the variable name to save the state information in with SaveStateName.

  • Enable Simulink® to save simulation output data to the workspace with SaveOutput.

  • Declare the variable name in which to store the simulation output data with OutputSaveName.

paramStruct.AbsTol =         '1e-5';
paramStruct.SaveState =      'on';
paramStruct.StateSaveName =  'xoutNew';
paramStruct.SaveOutput =     'on';
paramStruct.OutputSaveName = 'youtNew';

Simulate the model with cvsim and generate a coverage report with cvhtml.

[covData,simOut] = cvsim(testObj,paramStruct);
cvhtml('CoverageReport.html',covData,'-sRT=0');

Input Arguments

collapse all

Name of a Simulink Model, specified as a character array or string array. cvsim simulates the model with the current coverage settings.

Data Types: char | string

Coverage test settings, specified as a cvtest object. cvsim collects coverage using the settings specified in testObj.

The coverage metric settings specified in testObj override the coverage metric settings specified in the model configuration parameters. For example, if the Structural coverage level parameter in your model is set to Modified Condition Decision Coverage (MCDC), but your testObj.settings.mcdc property is 0, then covData = cvsim(testObj) will not record MCDC coverage.

Data Types: cvtest

Model parameters, specified as a structure. You can specify model parameters as a structure and use the structure instead of name-value pair arguments to set multiple parameters.

paramStruct fields are the names of model parameters and the values are the corresponding parameter values.

Example: paramStruct.AbsTol = '1e-5';

Data Types: struct

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: [cvdo,simOut] = cvsim(testObj,'AbsTol','1e-5'); specifies that the model is simulated using an absolute tolerance of 1e-5 with coverage settings specified in testObj.

cvsim supports the same model parameters that sim supports, except for parameters in the Coverage pane of the Configuration Parameters window.

Name of a model parameter, specified as a character array or string array. The value of the parameter is specified as the next argument.

Data Types: char | string

Output Arguments

collapse all

cvdo, returned as a cvdata object. When recording coverage for multiple models in a hierarchy, cvdo is a cv.cvdatagroup object instead. cvdo contains the coverage data from the simulated system.

See cvdata for the object structure.

simOut, returned as a Simulink.SimulationOutput object.

Version History

Introduced before R2006a