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
— Type of S-function
slcoverage.SFcnSelectorType
enumeration
Type of S-function to select, specified as an enumeration of the
slcoverage.SFcnSelectorType
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 thefileName
argument.slcoverage.SFcnSelectorType.SFcnInstanceCppFunction
selects an instance of a C or C++ function. Use this input argument with thefileName
andfunctionName
arguments.slcoverage.SFcnSelectorType.SFcnInstanceCppCondition
selects a condition in the specified code. Use this input argument withfileName
,functionName
,expr
, andexprIndex
arguments.slcoverage.SFcnSelectorType.SFcnInstanceCppDecision
selects a decision in the specified code. Use this input argument withfileName
,functionName
,expr
, andexprIndex
arguments.slcoverage.SFcnSelectorType.SFcnInstanceCppDecisionOutcome
selects a decision outcome in the specified code. Use this input argument withfileName
,functionName
,expr
,exprIndex
, andoutcomeIndex
arguments.slcoverage.SFcnSelectorType.SFcnInstanceCppConditionOutcome
selects a condition outcome in the specified code. Use this input argument withfileName
,functionName
,expr
,exprIndex
, andoutcomeIndex
arguments. If the expression that owns the outcome is owned by a parent decision, also use theparentExprIndex
argument.slcoverage.SFcnSelectorType.SFcnInstanceCppMCDCOutcome
selects an MCDC outcome in the specified code. Use this input argument withfileName
,functionName
,expr
,exprIndex
, andoutcomeIndex
arguments.slcoverage.SFcnSelectorType.SFcnInstanceCppRelationalBoundaryOutcome
selects a relational boundary outcome in the specified code. Use this input argument with thefileName
,functionName
,expr
,exprIndex
, andoutcomeIndex
arguments. If the relational operator outcome is owned by a condition that is inside a decision, also use theparentExprIndex
argument.
Data Types: slcoverage.SFcnSelectorType
Id
— Model element identifier
Simulink® ID (default) | property | handle
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
FileName
— C or C++ file to select
character array
| string array
C or C++ file to select, specified as a character array or string array.
Example: 'myfile.c'
Attributes:
SetAccess | protected |
Data Types: char
| string
FunctionName
— C or C++ function to select
character array
| string array
C or C++ function to select, specified as a character array or string array.
Example: 'counterbusFcn'
Attributes:
SetAccess | protected |
Data Types: char
| string
Expr
— Expression to select
character array
| string array
Expression to select, specified as a character array or string array.
Example: 'inputGElower'
Attributes:
SetAccess | protected |
Data Types: char
| string
ExprIndex
— Expression index
scalar
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
OutcomeIndex
— Index of outcome to select
integer
Index of outcome to select, specified as an integer:
For a Boolean expression, enter
1
for theF
outcome or2
for theT
outcome.For the type
slcoverage.SFcnSelectorType.SFcnInstanceCppMCDCOutcome
, enter the index number of the condition inside the expression.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 type0
.
Float type:
enter
1
for[-tol 0]
or[-tol 0)
.enter
2
for(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
DecOrCondIndex
— Parent expression index
integer
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
— Description of the selector
character vector
Description of the selector, returned as a character vector. Simulink Coverage™ creates the description based on the selector.
Attributes:
GetAccess | public |
SetAccess | protected |
ConstructorCode
— Code used to create this selector object
character array
Code used to create this selector object, returned as a character vector.
Attributes:
GetAccess | public |
SetAccess | protected |
Methods
Public Methods
allSelectors | Selectors for model or code element |
Examples
Create an S-Function Selector
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')'
Create an S-Function Outcome Selector
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/Bdoc24b_2679053_1170566/tp466e0ee9/slcoverage-ex97019589','-DUSE_PUBLISHED_ONLY') : mex -R2018a -I/tmp/Bdoc24b_2679053_1170566/tp466e0ee9/slcoverage-ex97019589 -DUSE_PUBLISHED_ONLY /tmp/Bdoc24b_2679053_1170566/tp7652263b_bb11_4fe2_bcc2_c6587119e7ea/tpb043fffe_7d73_43e4_a133_1cca29a3ffcc.c /tmp/Bdoc24b_2679053_1170566/tp7652263b_bb11_4fe2_bcc2_c6587119e7ea/tp9dcb4d14_760d_41bd_b6a7_ed9203f5b761.c -L/mathworks/devel/bat/filer/batfs2561-0/Bdoc24b.2679053/build/runnable/matlab/bin/glnxa64 -lmwsl_sfcn_cov_bridge -output RejectDoublePress_sfun Building with 'gcc'. MEX completed successfully. mex -R2018a -I/tmp/Bdoc24b_2679053_1170566/tp466e0ee9/slcoverage-ex97019589 -DUSE_PUBLISHED_ONLY /tmp/Bdoc24b_2679053_1170566/tp7652263b_bb11_4fe2_bcc2_c6587119e7ea/RejectDoublePress_sfun.c RejectDoublePress_sfun_wrapper.c /tmp/Bdoc24b_2679053_1170566/tp7652263b_bb11_4fe2_bcc2_c6587119e7ea/tpe928edaf_0214_4ad6_ac1a_8cb9884c7e18.c /tmp/Bdoc24b_2679053_1170566/tp7652263b_bb11_4fe2_bcc2_c6587119e7ea/tp317fa5fd_20b5_4c97_91fe_33e20c5cf854.c -L/mathworks/devel/bat/filer/batfs2561-0/Bdoc24b.2679053/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 R2017bR2021a: Justify unsatisfied code coverage outcomes
You can use the new slcoverage.SFcnSelectorType
enumerations to
justify code coverage outcomes without excluding the entire expression:
slcoverage.SFcnSelectorType.SFcnInstanceCppDecisionOutcome
slcoverage.SFcnSelectorType.SFcnInstanceCppConditionOutcome
slcoverage.SFcnSelectorType.SFcnInstanceCppMCDCOutcome
slcoverage.SFcnSelectorType.SFcnInstanceCppRelationalBoundaryOutcome
When using the new slcoverage.SFcnSelectorType
enumerations, use
these new properties as optional input arguments:
outcomeIndex
DecOrCondIndex
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)