Main Content

slcoverage.SFcnSelector class

Package: slcoverage

Select S-function criterion for filtering rule

Description

Use objects of the slcoverage.SFcnSelector class to specify the S-function selection criteria for a filter rule.

The slcoverage.SFcnSelector class is a handle class.

Creation

sel = slcoverage.SFcnSelector(type,id) creates an SFcnSelector object of the specified type based on S-Function block id and sets the Type and Id properties.

sel = slcoverage.SFcnSelector(type,id,fileName) creates an SFcnSelector object based on the specified C or C++ fileName, and sets the FileName property.

sel = slcoverage.SFcnSelector(type,id,fileName,functionName) creates an SFcnSelector object based on the specified C or C++ functionName in the specified file and sets the FunctionName property.

sel = slcoverage.SFcnSelector(type,id,fileName,functionName,expr,exprIndex) creates an SFcnSelector object based on the specified expression and exprIndex and sets the Expr and ExprIndex properties.

sel = slcoverage.SFcnSelector(type,id,fileName,functionName,expr,exprIndex,outcomeIndex) creates an SFcnSelector object based on the specified coverage outcome and sets the OutcomeIndex property.

sel = slcoverage.SFcnSelector(type,id,fileName,functionName,expr,exprIndex,outcomeIndex,parentExprIndex) creates an SFcnSelector object based on the specified coverage outcome whose parent is another expression specified by parentExprIndex and sets the DecOrCondIndex property.

Properties

expand all

Type of S-function to select, specified as an enumeration of the slcoverage.SFcnSelectorTjype class:

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

  • slcoverage.SFcnSelectorType.SFcnInstanceCppFileName selects the generated code file for this block. Use this input argument with the fileName argument.

  • slcoverage.SFcnSelectorType.SFcnInstanceCppFunction selects an instance of a C or C++ function. Use this input argument with the fileName and functionName arguments.

  • slcoverage.SFcnSelectorType.SFcnInstanceCppCondition selects a condition in the specified code. Use this input argument with fileName, functionName, expr, and exprIndex arguments.

  • slcoverage.SFcnSelectorType.SFcnInstanceCppDecision selects a decision in the specified code. Use this input argument with fileName, functionName, expr, and exprIndex arguments.

  • slcoverage.SFcnSelectorType.SFcnInstanceCppDecisionOutcome selects a decision outcome in the specified code. Use this input argument with fileName, functionName, expr, exprIndex, and outcomeIndex arguments.

  • slcoverage.SFcnSelectorType.SFcnInstanceCppConditionOutcome selects a condition outcome in the specified code. Use this input argument with fileName, functionName, expr, exprIndex, and outcomeIndex arguments. If the expression that owns the outcome is owned by a parent decision, also use the parentExprIndex argument.

  • slcoverage.SFcnSelectorType.SFcnInstanceCppMCDCOutcome selects an MCDC outcome in the specified code. Use this input argument with fileName, functionName, expr, exprIndex, and outcomeIndex arguments.

  • slcoverage.SFcnSelectorType.SFcnInstanceCppRelationalBoundaryOutcome selects a relational boundary outcome in the specified code. Use this input argument with the fileName, functionName, expr, exprIndex, and outcomeIndex arguments. If the relational operator outcome is owned by a condition that is inside a decision, also use the parentExprIndex argument.

Data Types: slcoverage.SFcnSelectorType

Model element identifier, specified as the property name of the element, the handle to an element, or the Simulink identifier of the element. Use a handle or ID for selector types that select an instance. Use a property name, such as the value of the 'BlockType' property of a block, to select multiple model elements.

Attributes

SetAccess
protected

Data Types: char | string | handle | integer

C or C++ file to select, specified as a character array or string array.

Example: 'myfile.c'

Attributes:

SetAccess
protected

Data Types: char | string

C or C++ function to select, specified as a character array or string array.

Example: 'counterbusFcn'

Attributes:

SetAccess
protected

Data Types: char | string

Expression to select, specified as a character array or string array.

Example: 'inputGElower'

Attributes:

SetAccess
protected

Data Types: char | string

Expression index, specified as an integer. If you are filtering an outcome, this property is the index of the expression that owns that outcome. If you are filtering an expression, this property is the index of that expression inside the body of the function.

Example: 2

Attributes:

SetAccess
protected

Data Types: single | double | int

Index of outcome to select, specified as an integer:

  • For a Boolean expression, enter 1 for the F outcome or 2 for the T outcome.

  • For a switch/case statement, enter 1 for the first case, 2 for the second case, and so on.

  • For relational boundary

    • Integer type:

      • enter 1 for type -1.

      • enter 2 for type +1.

      • enter 3 for type 0.

    • Float type:

      • enter 1 for [-tol 0] or [-tol 0).

      • enter 2 for (0 tol] or [0 tol] is outcome 2

    For more information about relational boundary coverage, see Relational Boundary Coverage.

Example: 2

Attributes

SetAccess
protected

Data Types: single | double | int

Parent expression index, specified as an integer. Use this input to filter an expression that is owned by a parent decision or condition; this is the index of the parent decision or condition relative to the function.

Example: 2

Attributes

SetAccess
protected

Data Types: single | double | int

Description of the selector, returned as a character vector. Simulink Coverage™ creates the description based on the selector.

Attributes

SetAccess
protected

Code used to create this selector object, returned as a character vector.

Attributes

SetAccess
protected

Methods

expand all

Examples

collapse all

This example shows how to create an S-Function selector.

Load the model by using load_system.

load_system('slvnvdemo_covfilt');

Create an S-Function selector by using slcoverage.SFcnSelector. To select the S-Function based on its name, enter slcoverage.SFcnSelectorType.SFcnName as the first input. The second input is the path to the S-Function.

sel = slcoverage.SFcnSelector(slcoverage.SFcnSelectorType.SFcnName,...
                         'slvnvdemo_covfilt/Mode Logic/ SFunction')
sel = 

  SFcnSelector with properties:

           FileName: ''
       FunctionName: ''
               Expr: ''
       OutcomeIndex: []
     DecOrCondIndex: []
        Description: 'N/A'
               Type: SFcnName
                 Id: 'slvnvdemo_covfilt/Mode Logic/ SFunction'
    ConstructorCode: 'slcoverage.SFcnSelector(slcoverage.SFcnSelectorType.SFcnName, 'slvnvdemo_covfilt/Mode Logic/ SFunction')'

This example shows how to create a selector for an S-Function using the slcoverage.SFcnSelector class.

In this example, your model has an S-Function named RejectDoublePress_sfun. Inside the S-Function, suppose that the condition rtb_AccelResSwOUT is never false, and you want to justify this false outcome in the coverage report.

Load the model.

modelName = 'ex_cc_cruise_control_doublepress_sfun';
load_system(modelName)

Configure coverage settings using a Simulink.SimulationInput object.

covSet = Simulink.SimulationInput(modelName);
covSet = covSet.setModelParameter('CovEnable','on');
covSet = covSet.setModelParameter('CovMetricStructuralLevel','ConditionDecision');
covSet = covSet.setModelParameter('CovSFcnEnable','on');
covSet = covSet.setModelParameter('CovSaveSingleToWorkspaceVar','on');
covSet = covSet.setModelParameter('CovSaveName','covData');
covSet = covSet.setModelParameter('SimAnalyzeCustomCode','on');

Simulate the model using covSet as the input.

simOut = sim(covSet);
covData = simOut.covData;

Generating 'RejectDoublePress_sfun.c' ....Please wait
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ### <a href="matlab:edit('RejectDoublePress_sfun.c')">'RejectDoublePress_sfun.c'</a> created successfully                                                                                                                                                                                                                                                                                                                                                                                                           ### <a href="matlab:edit('RejectDoublePress_sfun_wrapper.c')">'RejectDoublePress_sfun_wrapper.c'</a> created successfully                                                                                                                                                                                                                                                                                                                                                                                           ### <a href="matlab:edit('RejectDoublePress_sfun.tlc')">'RejectDoublePress_sfun.tlc'</a> created successfully                                                                                                                                                                                                                                                                                                                                                                                                       
### Building S-function 'RejectDoublePress_sfun.c' for ex_cc_cruise_control_doublepress_sfun/RejectDoublePress
mex -I/tmp/Bdoc21b_1757077_173636/tpfb10f3b0/ex97019589 -I/ -I/ /tmp/Bdoc21b_1757077_173636/tp04e1900b_ae88_436b_bfb5_a84650863e7d/tpff64a341_d169_4460_ac73_6b4117b5e568.c /tmp/Bdoc21b_1757077_173636/tp04e1900b_ae88_436b_bfb5_a84650863e7d/tp6c32d22c_7c21_4c87_8d3a_8ce75eb36ecf.c -L/mathworks/devel/bat/Bdoc21b/build/matlab/bin/glnxa64 -lmwsl_sfcn_cov_bridge -output RejectDoublePress_sfun
Building with 'gcc'.
MEX completed successfully.
mex -I/tmp/Bdoc21b_1757077_173636/tpfb10f3b0/ex97019589 -I/ -I/ /tmp/Bdoc21b_1757077_173636/tp04e1900b_ae88_436b_bfb5_a84650863e7d/RejectDoublePress_sfun.c RejectDoublePress_sfun_wrapper.c /tmp/Bdoc21b_1757077_173636/tp04e1900b_ae88_436b_bfb5_a84650863e7d/tpf0bed1e9_416e_4e14_8b8e_bf23c5b94534.c /tmp/Bdoc21b_1757077_173636/tp04e1900b_ae88_436b_bfb5_a84650863e7d/tp22d2e36c_db62_4699_9994_ed3f0c60d142.c -L/mathworks/devel/bat/Bdoc21b/build/matlab/bin/glnxa64 -lmwsl_sfcn_cov_bridge -output RejectDoublePress_sfun
Building with 'gcc'.
MEX completed successfully.

Create a selector object for the outcome missing coverage by using the slcoverage.SFcnSelector class. To select a condition outcome inside an S-Function, use the SFcnInstanceCppConditionOutcome enumeration as the first input. The second input is the block ID or block path to the S-Function. The third input is the file name of the source file that contains the expression, RejectDoublePress_sfun_wrapper.c. The fourth input is the name of the function that contains the condition, RejectDoublePress_sfun_Outputs_wrapper. The fifth input is the expression which owns the outcome, which is rtb_AccelResSwOUT && CoastSetSwIn[0], because this parent decision owns the condition rtb_AccelResSwOUT.

The sixth input is the index of the expression that owns the outcome relative to its parent, and because rtb_AccelResSwOUT is the first condition in its parent decision, this input is 1. The seventh input is the outcome index, which is 1 because this is the F case of a Boolean expression. The final input is the index of the parent expression relative to the function, and because rtb_AccelResSwOUT && CoastSetSwIn[0] is the second decision in the function, this input is 2.

enum = slcoverage.SFcnSelectorType.SFcnInstanceCppConditionOutcome;
SFunID = Simulink.ID.getSID([modelName, '/RejectDoublePress']);
sel = slcoverage.SFcnSelector(enum,SFunID,'RejectDoublePress_sfun_wrapper.c',...
   'RejectDoublePress_sfun_Outputs_wrapper','rtb_AccelResSwOUT && CoastSetSwIn[0]',1,1,2);

Create a Filter object and a rule based on the selector, then add the rule to the filter.

filt = slcoverage.Filter;
rule = slcoverage.FilterRule(sel,'Tested elsewhere',...
           slcoverage.FilterMode.Justify);
addRule(filt,rule);
setFilterName(filt,'S-Function Filter')

Save the filter as sfunfilter and add it to the cvdata object for my_func.c by setting the filter property to the filter file name.

save(filt,'sfunfilter');
covData.filter = 'sfunfilter';

Generate a coverage report.

cvhtml('codeCovReport',covData)

Review the report. Click the RejectDoublePress_sfun link under S-Function Code Coverage Results to see the filtered outcome under Objects Filtered from Coverage Analysis.

Introduced in R2017b