complexityinfo

Retrieve cyclomatic complexity coverage information from cvdata object

Syntax

complexity = complexityinfo(cvdo, object)

Description

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

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]

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

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

Open the sldemo_fuelsys model and create the test specification object testObj. Enable decision, condition, and MCDC coverage for sldemo_fuelsys and execute testObj using cvsim. Use complexityinfo to retrieve cyclomatic complexity results for the Throttle subsystem. The Throttle subsystem itself does not record cyclomatic complexity coverage results, but the contents of the subsystem do record cyclomatic complexity coverage.

mdl = 'sldemo_fuelsys';
open_system(mdl);
testObj = cvtest(mdl)
testObj.settings.decision = 1;
testObj.settings.condition = 1;
testObj.settings.mcdc = 1;
data = cvsim(testObj);
blk_handle = get_param([mdl, ...
     '/Engine Gas Dynamics/Throttle & Manifold/Throttle'],...
     'Handle');
coverage = complexityinfo(data, blk_handle);
coverage

Alternatives

Use the Coverage Settings dialog box to collect and display cyclomatic complexity coverage results in the coverage report:

  1. Open the model.

  2. In the Model Editor, select Analysis > Coverage > Settings.

  3. On the Coverage tab, select Coverage for this model.

  4. Under Coverage metrics, select:

    • Decision

    • Condition

    • MCDC

  5. On the Reporting tab, click HTML Settings.

  6. In the HTML Settings dialog box, select:

    • Include cyclomatic complexity numbers in summary

    • Include cyclomatic complexity numbers in block details

  7. Click OK to close the HTML Settings dialog box and save your changes.

  8. Click OK to close the Coverage Settings dialog box and save your changes.

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

Was this topic helpful?