Main Content

complexityinfo

Retrieve cyclomatic complexity coverage information from cvdata object

Syntax

complexity = complexityinfo(cvdo, object)
complexity = complexityinfo(cvdo, object, mode)

Description

complexity = complexityinfo(cvdo, object) returns complexity coverage results from the cvdata object cvdo for the model component object.

complexity = complexityinfo(cvdo, object, mode) returns complexity coverage results from the cvdata object cvdo for the model component object for the simulation mode mode.

Input Arguments

cvdo

cvdata object

object

The object argument specifies an object in the model or Stateflow® chart that received decision coverage. Valid values for object include the following:

Object SpecificationDescription

BlockPath

Full path to a model or block

BlockHandle

Handle to a model or block

slObj

Handle to a Simulink® API object

sfID

Stateflow ID

sfObj

Handle to a Stateflow API object from a singly instantiated Stateflow chart

{BlockPath, sfID}

Cell array with the path to a Stateflow chart or atomic subchart and the ID of an object contained in that chart or subchart

{BlockPath, sfObj}

Cell array with the path to a Stateflow chart or subchart and a Stateflow object API handle contained in that chart or subchart

{BlockHandle, sfID}

Cell array with a handle to a Stateflow chart or atomic subchart and the ID of an object contained in that chart or subchart

When specifying an S-function block, valid values for object include the following:

Object SpecificationDescription

{BlockPath, fName}

Cell array with the path to an S-Function block and the name of a source file.

{BlockHandle, fName}

Cell array with an S-Function block handle and the name of a source file.

{BlockPath, fName, funName}

Cell array with the path to an S-Function block, the name of a source file, and a function name.

{BlockHandle, fName, funName}

Cell array with an S-Function block handle, the name of a source file an a function name.

For coverage data collected during Software-in-the-Loop (SIL) mode or Processor-in-the-Loop (PIL) simulation mode, valid values for object include the following:

Object SpecificationDescription

{fileName, funName}

Cell array with the name of a source file and a function name.

{Model, fileName}

Cell array with a model name (or model handle) and the name of a source file.

{Model, fileName, funName}

Cell array with a model name (or model handle), the name of a source file, and a function name.

mode

The mode argument specifies the simulation mode for coverage. Valid values for mode include the following:

Object SpecificationDescription

'Normal'

Model in Normal simulation mode.

'SIL' (or 'PIL')

Model in Software-in-the-Loop (SIL) or Processor-in-the-Loop (PIL) simulation mode.

'ModelRefSIL' (or 'ModelRefPIL')

Model reference in Software-in-the-Loop (SIL) or Processor-in-the-Loop (PIL) simulation mode.

'ModelRefTopSIL' (or 'ModelRefTopPIL')

Model reference in Software-in-the-Loop (SIL or Processor-in-the-Loop (PIL) simulation mode with code interface set to top model.

Output Arguments

complexity

If cvdo does not contain cyclomatic complexity coverage results for object, complexity is empty.

If cvdo contains cyclomatic complexity coverage results for object, complexity is a two-element vector of the form [total_complexity local_complexity]:

total_complexityCyclomatic complexity coverage for object and its descendants (if any)
local_complexityCyclomatic complexity coverage for object

If object has variable-size signals, complexity also contains the variable complexity.

Examples

collapse all

This example shows how to retrieve cyclomatic complexity information for the Gain subsystem of the slvnvdemo_cv_small_controller model.

Load the slvnvdemo_cv_small_controller model.

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

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

Alternatives

Use the coverage settings to collect and display cyclomatic complexity coverage results in the coverage report:

  1. Open the model.

  2. In the Simulink Editor, select Model Settings on the Modeling tab.

  3. On the Coverage pane of the Configuration Parameters dialog box, select Enable coverage analysis.

  4. Under Coverage metrics, select MCDC as the structural coverage level.

  5. Click OK to close the Configuration Parameters dialog box and save your changes.

  6. Simulate the model and review the results in the HTML report.

Introduced in R2011a