Main Content

allSelectors

Class: slcoverage.BlockSelector, slcoverage.CodeSelector, slcoverage.Selector, slcoverage.MetricSelector, slcoverage.SFcnSelector
Package: slcoverage

Selectors for model or code element

Syntax

sel = slcoverage.Selector.allSelectors(element)
sel = slcoverage.BlockSelector.allSelectors(element)
sel = slcoverage.CodeSelector.allSelectors(element)
sel = slcoverage.CodeSelector.allSelectors(element,Name,Value)
sel = slcoverage.MetricSelector.allSelectors(element)
sel = slcoverage.SFcnSelector.allSelectors(element)
sel = slcoverage.Selector.allSelectors(element,Name,Value)

Description

sel = slcoverage.Selector.allSelectors(element) returns all the selectors for the model element.

sel = slcoverage.BlockSelector.allSelectors(element) returns all the block selectors for element.

sel = slcoverage.CodeSelector.allSelectors(element) returns all the custom C/C++ code selectors for element.

sel = slcoverage.CodeSelector.allSelectors(element,Name,Value) , where element is a model and Name,Value specifies the simulation mode, returns all the custom C/C++ code selectors for the model in the specified simulation mode.

sel = slcoverage.MetricSelector.allSelectors(element) returns all the metric selectors for element.

sel = slcoverage.SFcnSelector.allSelectors(element) returns all the S-function selectors for element.

sel = slcoverage.Selector.allSelectors(element,Name,Value) returns selectors for element, with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Model element to select, specified as a handle or the model element Simulink® identifier.

Example: 'sldemo_lct_bus:18'

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: 'Type',slcoverage.BlockSelectorType.BlockInstance,'Description','F outcome'

Selector type refinement specified as one of the slcoverage.BlockSelectorTypeslcoverage.CodeSelectorType, slcoverage.MetricSelectorType, or slcoverage.SFcnSelectorType values. Possible values:

  • Block selector types:

    • slcoverage.BlockSelectorType.BlockInstance — An instance of a block.

    • slcoverage.BlockSelectorType.BlockType — All blocks of the specified block type.

    • slcoverage.BlockSelectorType.Chart — A Stateflow® chart.

    • slcoverage.BlockSelectorType.MaskType — Blocks that use the specified mask type.

    • slcoverage.BlockSelectorType.State — A Stateflow state.

    • slcoverage.BlockSelectorType.StateAllContent — Stateflow state and its contents.

    • slcoverage.BlockSelectorType.StateflowFunction — A Stateflow function.

    • slcoverage.BlockSelectorType.Subsystem — A subsystem block.

    • slcoverage.BlockSelectorType.SubsystemAllContent — A subsystem and its contents.

    • slcoverage.BlockSelectorType.TemporalEvent — A Stateflow temporal event.

    • slcoverage.BlockSelectorType.Transition — A Stateflow transition.

  • Code selector types:

    • slcoverage.CodeSelectorType.File — Custom C/C++ code file name.

    • slcoverage.CodeSelectorType.Function — Custom C/C++ code function name.

    • slcoverage.CodeSelectorType.Decision — A custom C/C++ code decision.

    • slcoverage.CodeSelectorType.Condition — A custom C/C++ code condition.

  • Metric selector types:

    • slcoverage.MetricSelectorType.ConditionOutcome objects select condition metric objective outcomes.

    • slcoverage.MetricSelectorType.DecisionOutcome objects select decision metric objective outcomes.

    • slcoverage.MetricSelectorType.MCDCOutcome objects select MCDC metric objective outcomes.

    • slcoverage.MetricSelectorType.RelationalBoundaryOutcome objects select outcome metrics related to relational boundary outcomes.

    • slcoverage.MetricSelectorType.SaturationOverflowOutcome objects select outcome metrics related to saturation on integer overflow outcomes.

  • S-function selector types:

    • slcoverage.SFcnSelectorType.SFcnName selects the specified S-function.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppFileName selects the coverage data in the generated code file for this block.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppFunction selects a function.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppCondition selects a condition outcome of the S-function block.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppDecision selects a decision outcome of the S-function block.

Description text to match for the selector that you want to return, specified as a character vector or string. For example, if you want to return only the selectors that include the text F outcome in the description, use this syntax:

s = slcoverage.Selector.allSelectors(id,'Description','F outcome')

Simulation mode to run when selecting code filters, entered as one of the following:

Object SpecificationDescription

'normal' (default)

Extract code selectors for custom code in normal simulation, such as custom code called from a C Caller block or a Stateflow chart.

'sil'

Extract code selectors for code generated in Simulation-in-the-Loop (SIL) mode and code selectors for the top model code interface

'pil'

Extract code selectors for code generated in Processor-in-the-Loop (PIL) mode and code selectors for the top model code interface

'xil'

If SIL-mode code exists, extract code selectors for code generated in SIL mode and extract code selectors for the top model code interface; otherwise, extract code selectors for code generated in PIL mode and extract code selectors for the top model code interface

'modelrefsil'

Extract code selectors for the model reference code interface in SIL mode

'modelrefpil'

Extract code selectors for the model reference code interface in PIL mode

'modelrefxil'

If SIL-mode code exists, extract code selectors for the model reference code interface in SIL mode, if the model is in SIL mode; otherwise,extract code selectors for the model reference code interface in PIL mode

Output Arguments

expand all

Selectors for the model or code element, returned as an array of Selector objects.

Examples

expand all

This example shows how to get all the selectors for an And block and then add a rule to justify or exclude a selector. Metric selectors can only be justified.

Move the current MATLAB® directory to the location that contains the example files.

openExample('slcoverage/GetAllSelectorsExample');

Load the model and set coverage settings

modelName = 'slvnvdemo_covfilt';
load_system(modelName);
set_param(modelName,'CovEnable','on','CovMetricSettings','dcme');

First, get the block handle for the And block.

id = getSimulinkBlockHandle([modelName,'/Saturation']);

Get the selectors using the block handle.

sel = slcoverage.Selector.allSelectors(id)
sel = 

  1x10 heterogeneous Selector (BlockSelector, MetricSelector) array with properties:

    Description
    Type
    Id
    ConstructorCode

The block has eight selectors. You can index into each one to see their contents. In this example, you want to justify the sixth selector.

sel(6)
ans = 

  MetricSelector with properties:

     ObjectiveIndex: 2
       OutcomeIndex: 2
        Description: 'T outcome of input >= upper limit in Saturate block "Saturation"'
               Type: DecisionOutcome
                 Id: 'slvnvdemo_covfilt:5'
    ConstructorCode: 'slcoverage.MetricSelector(slcoverage.MetricSelectorType.DecisionOutcome, 'slvnvdemo_covfilt:5', 2, 2)'

Create a justify rule, then create a filter object and add the rule to it.

rule = slcoverage.FilterRule(sel(6),'Expected result');
filt = slcoverage.Filter;
filt.addRule(rule);

Save the filter and generate a coverage report.

filt.save('metrfilter');
csim = cvsim(modelName);
csim.filter = 'metrfilter';
cvhtml('cov',csim,'-sRT=0');

This example shows how to get a selector by type and description. In this example, you get all selectors for the False outcomes of the And block whose type is ConditionOutcome.

Load the model into memory.

modelName = 'sldemo_lct_bus';
load_system(modelName);

Get the false outcome condition selectors for the And block by searching for descriptions that include F.

id = getSimulinkBlockHandle([modelName,'/slCounter/And']);
sel = slcoverage.Selector.allSelectors(id, ...
         'Type',slcoverage.MetricSelectorType.ConditionOutcome, ...
         'Description','F')
sel = 

  1x2 MetricSelector array with properties:

    ObjectiveIndex
    OutcomeIndex
    Description
    Type
    Id
    ConstructorCode

Look at the constructor code for the two selectors that were returned.

sel.ConstructorCode
ans =

    'slcoverage.MetricSelector(slcoverage.MetricSelectorType.ConditionOutcome, 'sldemo_lct_bus:23', 1, 2)'


ans =

    'slcoverage.MetricSelector(slcoverage.MetricSelectorType.ConditionOutcome, 'sldemo_lct_bus:23', 2, 2)'

Introduced in R2017b