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.

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

[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.

Note

cvsim ignores model parameters listed in the Coverage pane of the Configuration Parameters window. Create a cvtest object to set coverage options, or use sim instead.

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

example

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

Note

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

Examples

collapse all

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

Open the sldemo_engine example model.

modelName = 'sldemo_engine'; 
open_system(modelName); 

Create a test 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.

[cvdo,simOut] = cvsim(testObj,paramStruct);
cvhtml('CoverageReport.html', cvdo);

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.

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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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 all model parameters that are supported by sim, 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 Evaluate Coverage Results for a list of info functions.

See cvdata Properties for the object structure.

simOut, returned as a Simulink.SimulationOutput object.

Introduced before R2006a