Main Content

complexityinfo

Retrieve cyclomatic complexity coverage information fromcvdataobject

    Description

    complexity= complexityinfo(cvdo,modelObject)returns complexity coverage results from thecvdataobjectcvdofor the model componentmodelObject.

    complexity= complexityinfo(cvdo,modelObject,simMode)returns complexity coverage results from thecvdataobjectcvdofor the model componentmodelObjectfor the simulation modesimMode.

    Examples

    collapse all

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

    Load theslvnvdemo_cv_small_controllermodel.

    modelName ='slvnvdemo_cv_small_controller'; load_system(modelName);

    Create a test specification object and enable decision, condition, and MCDC coverage. Then, simulate the model usingcvsim.

    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

    Input Arguments

    collapse all

    Coverage data, specified as acvdataobject.

    Data Types:cvdata

    Model object, specified as a character array, string array, Simulink handle, Stateflow ID, or cell array.

    To specify a model object, for example a block or a Stateflow chart, use one of the following formats:

    Object Specification Description

    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

    To specify an S-Function block or its contents, use one of the following formats:

    Object Specification Description

    {BlockPath, fName}

    Cell array with the path to anS-Functionblock and the name of a source file

    {BlockHandle, fName}

    Cell array with anS-Functionblock handle and the name of a source file

    {BlockPath, fName, funName}

    Cell array with the path to anS-Functionblock, the name of a source file, and a function name

    {BlockHandle, fName, funName}

    Cell array with anS-Functionblock handle, the name of a source file an a function name

    To specify a code coverage result, for example coverage data collected during software-in-the-loop (SIL) or processor-in-the-loop (PIL) analysis, use one of the following formats:

    Object Specification Description

    {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

    Data Types:char|string|cell|Stateflow.State|Stateflow.Transition

    Simulation mode during coverage analysis, specified as one of the following:

    Object Specification Description

    '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')

    模型参考我n software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation mode.

    'ModelRefTopSIL' (or 'ModelRefTopPIL')

    模型参考我n software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation mode with the code interface set to top model.

    Data Types:char|string

    Output Arguments

    collapse all

    Cyclomatic complexity, returned as a two-element array of the form[total_complexity,local_complexity]ifcvdocontains cyclomatic complexity coverage results, or an empty array if it does not.

    total_complexity Cyclomatic complexity coverage formodelObject和its descendants (if any)
    local_complexity Cyclomatic complexity coverage formodelObject

    IfmodelObjecthas variable-size signals,complexityalso contains the variable complexity.

    Data Types:double

    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, selectModel Settingson theModelingtab.

    3. On theCoveragepane of the Configuration Parameters dialog box, selectEnable coverage analysis.

    4. Under覆盖率度量中,选择MCDCas the structural coverage level.

    5. ClickOKto close the Configuration Parameters dialog box and save your changes.

    6. Simulate the model.

    7. In the dockedCoverage Detailspane, the coverage report shows the cyclomatic complexity for the model as well as each model object.

    Version History

    Introduced in R2011a