slcoverage.CodeSelector class

Package: slcoverage

Select custom C/C++ code for coverage filter

Description

Specify custom C/C++ code selection criteria for a filter rule.

Construction

sel = slcoverage.CodeSelector(type,file) creates the selector based on the C or C++ file.

sel = slcoverage.CodeSelector(type,file,function) creates the selector based on the C or C++ function in the file.

sel = slcoverage.CodeSelector(type,file,function,expression,index) creates the selector based on the index of the decision or condition expression.

Input Arguments

expand all

Type of custom C/C++ code to select, as one of these values:

  • 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.

Example: slcoverage.CodeSelectorType.Function

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

Example: 'myfile.c'

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

Example: 'counterbusFcn'

Decision or condition expression to select, specified as a character vector or string.

Example: 'inputGElower'

Matrix position of expression to select, specified as an integer.

Example: 2

Outputs

expand all

Selector object, returned as an slcoverage.CodeSelector object or array of slcoverage.CodeSelector objects.

Properties

expand all

This property is read-only.

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

This property is read-only.

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

This property is read-only.

Identifier of the model element, returned as character vector of the Simulink ID, model element property, or handle. This property is empty for the slcoverage.CodeSelector class.

This property is read-only.

Selector type, returned as one of these slcoverage.CodeSelectorType values:

  • File

  • Function

  • Decision

  • Condition

Methods

allSelectorsSelectors for model or code element

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).

Examples

collapse all

Select custom C/C++ code to add a rule for and select a code construct to add a rule for. The resulting filter has one rule. You can simulate your model for coverage by using the filter to see the effect.

Open the model. Specify coverage settings and turn on coverage recording.

modelName = 'slexCCallerExample';
open_system(modelName);
set_param(modelName, 'SimAnalyzeCustomCode', 'on', 'CovMetricSettings','dcme', 'RecordCoverage','on');

Add a filter rule for the custom C function times2.

sel = slcoverage.CodeSelector(slcoverage.CodeSelectorType.Function, 'my_func.c', 'times2');

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

filt = slcoverage.Filter;
rule = slcoverage.FilterRule(sel, 'Tested elsewhere', slcoverage.FilterMode.Exclude);
filt.addRule(rule);

Save the filter as codefilter. Simulate the model for code coverage. Add the filter file to the filter property of the resulting cvdata object.

filt.save('codefilter');
csim = cvsim(modelName);
csim.get('my_func.c').filter = 'codefilter';

Generate a coverage report.

cvhtml('cov',csim);

Review the report. Click the my_func.c Custom Code File(s) link and find the filter rule that you added under Objects Filtered from Coverage Analysis.

Introduced in R2018b