slcoverage.SFcnSelector Class
Namespace: 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
Type of S-function to select, specified as an enumeration of the
slcoverage.SFcnSelectorType class:
slcoverage.SFcnSelectorType.SFcnNameselects the specified S-function.slcoverage.SFcnSelectorType.SFcnInstanceCppFileNameselects the generated code file for this block. Use this input argument with thefileNameargument.slcoverage.SFcnSelectorType.SFcnInstanceCppFunctionselects an instance of a C or C++ function. Use this input argument with thefileNameandfunctionNamearguments.slcoverage.SFcnSelectorType.SFcnInstanceCppConditionselects a condition in the specified code. Use this input argument withfileName,functionName,expr, andexprIndexarguments.slcoverage.SFcnSelectorType.SFcnInstanceCppDecisionselects a decision in the specified code. Use this input argument withfileName,functionName,expr, andexprIndexarguments.slcoverage.SFcnSelectorType.SFcnInstanceCppDecisionOutcomeselects a decision outcome in the specified code. Use this input argument withfileName,functionName,expr,exprIndex, andoutcomeIndexarguments.slcoverage.SFcnSelectorType.SFcnInstanceCppConditionOutcomeselects a condition outcome in the specified code. Use this input argument withfileName,functionName,expr,exprIndex, andoutcomeIndexarguments. If the expression that owns the outcome is owned by a parent decision, also use theparentExprIndexargument.slcoverage.SFcnSelectorType.SFcnInstanceCppMCDCOutcomeselects an MCDC outcome in the specified code. Use this input argument withfileName,functionName,expr,exprIndex, andoutcomeIndexarguments.slcoverage.SFcnSelectorType.SFcnInstanceCppRelationalBoundaryOutcomeselects a relational boundary outcome in the specified code. Use this input argument with thefileName,functionName,expr,exprIndex, andoutcomeIndexarguments. If the relational operator outcome is owned by a condition that is inside a decision, also use theparentExprIndexargument.
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
1for theFoutcome or2for theToutcome.For the type
slcoverage.SFcnSelectorType.SFcnInstanceCppMCDCOutcome, enter the index number of the condition inside the expression.For a switch/case statement, enter
1for the first case,2for the second case, and so on.For relational boundary
Integer type:
enter
1for type-1.enter
2for type+1.enter
3for type0.
Float type:
enter
1for[-tol 0]or[-tol 0).enter
2for(0 tol]or[0 tol]is outcome2
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:
GetAccess | public |
SetAccess | protected |
Code used to create this selector object, returned as a character vector.
Attributes:
GetAccess | public |
SetAccess | protected |
Methods
allSelectors | Selectors for model or code element |
Examples
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 Command used: slcovmex('-internalfile', 'RejectDoublePress_sfun.c','-R2018a','RejectDoublePress_sfun.c','RejectDoublePress_sfun_wrapper.c','-I/tmp/Bdoc25b_2988451_562900/tp58b68c03/slcoverage-ex97019589','-DUSE_PUBLISHED_ONLY') :
mex -R2018a -I/tmp/Bdoc25b_2988451_562900/tp58b68c03/slcoverage-ex97019589 -DUSE_PUBLISHED_ONLY /tmp/Bdoc25b_2988451_562900/tp22cff910_c418_490f_8b12_959d9ca59fbc/tp6426e4a5_5542_4a9d_b93a_f1e655ff409f.c /tmp/Bdoc25b_2988451_562900/tp22cff910_c418_490f_8b12_959d9ca59fbc/tp354c68f0_4ea7_4291_af04_bfacaf26b1bb.c -L/mathworks/devel/bat/filer/batfs2566-0/Bdoc25b.2988451/build/runnable/matlab/bin/glnxa64 -lmwsl_sfcn_cov_bridge -output RejectDoublePress_sfun
Building with 'gcc'.
MEX completed successfully.
mex -R2018a -I/tmp/Bdoc25b_2988451_562900/tp58b68c03/slcoverage-ex97019589 -DUSE_PUBLISHED_ONLY /tmp/Bdoc25b_2988451_562900/tp22cff910_c418_490f_8b12_959d9ca59fbc/RejectDoublePress_sfun.c RejectDoublePress_sfun_wrapper.c /tmp/Bdoc25b_2988451_562900/tp22cff910_c418_490f_8b12_959d9ca59fbc/tp93e9b706_aaf7_4c86_b764_6d6900ccb24a.c /tmp/Bdoc25b_2988451_562900/tp22cff910_c418_490f_8b12_959d9ca59fbc/tpe9f3392a_f640_4f70_8d62_a0f1445124fc.c -L/mathworks/devel/bat/filer/batfs2566-0/Bdoc25b.2988451/build/runnable/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.
Version History
Introduced in R2017bYou can use the new slcoverage.SFcnSelectorType enumerations to
justify code coverage outcomes without excluding the entire expression:
slcoverage.SFcnSelectorType.SFcnInstanceCppDecisionOutcomeslcoverage.SFcnSelectorType.SFcnInstanceCppConditionOutcomeslcoverage.SFcnSelectorType.SFcnInstanceCppMCDCOutcomeslcoverage.SFcnSelectorType.SFcnInstanceCppRelationalBoundaryOutcome
When using the new slcoverage.SFcnSelectorType enumerations, use
these new properties as optional input arguments:
outcomeIndexDecOrCondIndex
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)