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

3 ビュー (過去 30 日間)
Pat Canny
Pat Canny 2019 年 11 月 1 日
回答済み: Pat Canny 2019 年 11 月 1 日
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.

採用された回答

Pat Canny
Pat Canny 2019 年 11 月 1 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAddress Missing Coverage についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by