MATLAB Answers

How do I create a coverage filter for all Simulink blocks with a given Tag?

2 views (last 30 days)
Pat Canny
Pat Canny on 1 Nov 2019
Answered: Pat Canny on 1 Nov 2019
I would like to create a model coverage filter for all Simulink blocks with a given Tag.
I didn't see a way to do this with the BlockSelector workflow.

Accepted Answer

Pat Canny
Pat Canny on 1 Nov 2019
One way to do this is to use find_system to build a list of all Simulink blocks with a given tag.
Then, you can use BlockSelector and FilterRule to add a rule for each block.
modelName = 'filter_by_tag_test';
load_system(modelName)
%% Find blocks with given tag
tag_to_search = 'SOME_TAG';
% Find blocks with tag
blocks_with_tag = find_system(bdroot,'Tag',tag_to_search);
%% Enable coverage collection
set_param(modelName,'CovMetricSettings','dcme','RecordCoverage','on');
%% Iterate through blocks_with_tag, adding a filter for each block
filt = slcoverage.Filter; % instantiate Filter object
num_blocks = length(blocks_with_tag);
for i=1:num_blocks
id = Simulink.ID.getSID(blocks_with_tag{i});
bl = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockInstance,id);
rule = slcoverage.FilterRule(bl,'Edge case');
filt.addRule(rule);
end
filt.save('blfilter');
%% Simulate with coverage enabled, generate report
csim = cvsim(modelName);
csim.filter = 'blfilter';
cvhtml('filter_by_tag_report',csim);
%% Clean up
close_system(modelName)

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!