Retrieve cyclomatic complexity coverage information from
Retrieve Cyclomatic Complexity Data from Coverage Object
This example shows how to retrieve cyclomatic complexity information for the Gain subsystem of the
modelName = 'slvnvdemo_cv_small_controller'; load_system(modelName);
Create a test specification object and enable decision, condition, and MCDC coverage. Then, simulate the model using
testObj = cvtest(modelName); testObj.settings.decision = 1; testObj.settings.condition = 1; testObj.settings.mcdc = 1; covData = cvsim(testObj);
Retrieve cyclomatic complexity information for the Gain subsystem.
gainPath = [modelName,'/Gain']; gainComplexity = complexityinfo(covData,gainPath)
gainComplexity = 1 0
The Gain subsystem itself does not record cyclomatic complexity, but the contents of the subsystem do. This can be seen in the results because the total complexity is 1, which includes the subsystem and all of its descendants. In contrast, the local complexity is 0, indicating that the one point of complexity comes from one of the descendants, in this case a Switch block.
switchPath = [modelName,'/Gain/Switch']; switchComplexity = complexityinfo(covData,switchPath)
switchComplexity = 1 1
cvdo — Coverage data
Coverage data, specified as a
modelObject — Model object
character array |
string array |
Simulink® handle |
Stateflow® ID |
Model object, specified as a character array, string array, Simulink handle, Stateflow ID, or cell array.
To specify a model object, such as a block or a Stateflow chart, use one of these formats:
Full path to a model or block
Handle to a model or block
Handle to a Simulink API object
Handle to a Stateflow API object from a singly instantiated Stateflow chart
Cell array with the path to a Stateflow chart or atomic subchart and the ID of an object contained in that chart or subchart
Cell array with the path to a Stateflow chart or subchart and a Stateflow object API handle contained in that chart or subchart
Cell array with a handle to a Stateflow chart or atomic subchart and the ID of an object contained in that chart or subchart
To specify an S-Function block or its contents, use one of these formats:
Cell array with the path to an S-Function block and the name of a source file
Cell array with an S-Function block handle and the name of a source file
Cell array with the path to an S-Function block, the name of a source file, and a function name
Cell array with an S-Function block handle, the name of a source file, and a function name
To specify a code coverage result, such as coverage data collected during software-in-the-loop (SIL) or processor-in-the-loop (PIL) analysis, use one of these formats:
Cell array with the name of a source file and a function name
Cell array with a model name or model handle and the name of a source file
Cell array with a model name or model handle, the name of a source file, and a function name
simMode — Simulation mode
character array |
Simulation mode during coverage analysis, specified as one of these options:
Model in normal simulation mode.
Model in software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation mode.
Model reference in SIL or PIL simulation mode.
Model reference in SIL or PIL simulation mode with the code interface set to top model.
complexity — Cyclomatic complexity
Cyclomatic complexity, returned as a two-element array of the form
contains cyclomatic complexity coverage results, or an empty array if it does
|Cyclomatic complexity coverage for |
|Cyclomatic complexity coverage for
modelObject has variable-size signals,
complexity also contains the variable complexity.
Use the coverage settings to collect and display cyclomatic complexity coverage results in the coverage report:
Open the model.
In the Simulink Editor, select Model Settings on the Modeling tab.
On the Coverage pane of the Configuration Parameters dialog box, select Enable coverage analysis.
Under Coverage metrics, select MCDC as the structural coverage level.
Click OK to close the Configuration Parameters dialog box and save your changes.
Simulate the model.
In the docked Coverage Details pane, the coverage report shows the cyclomatic complexity for the model as well as each model object.
Introduced in R2011a