How to create a .cvf file to exclude external m-files from coverage report?

Hi, I'm trying to exclude external m-files coverage from coverage report in Simulink Test. I tried creating coverage filter file refering to https://in.mathworks.com/help/slcoverage/ref/slcoverage.blockselector-class.html
I'm trying to exclude mutiple functions from coverage. Below is my edited script for it.
files = dir('*.m');
for i = 1:length(files)
selector = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockInstance, files(i).name);
filt = slcoverage.Filter;
rule = slcoverage.FilterRule(selector, '', slcoverage.FilterMode.Exclude);
filt.addRule(rule);
end
setFilterName(filt,'MFileExclusion');
save(filt,'MFileExclusion')
I tried adding this cvf file to Simulink Test, but its not working. I'm using R2024a.
Is there an issue with the script? Is there any alternate solution here?
Thanks in advance.

 Réponse acceptée

Hi Shardul,
The issue is that the filter you create is overwritten in every loop iteration and the .cvf file is not saved correctly. You should create the filter once, add multiple rules to it, and then save it. Also ensure the selector correctly references the model objects you want to exclude.
You can modify the script like this:
files = dir('*.m');
filt = slcoverage.Filter;
for i = 1:length(files)
selector = slcoverage.BlockSelector( ...
slcoverage.BlockSelectorType.BlockInstance, files(i).name);
rule = slcoverage.FilterRule(selector,'',slcoverage.FilterMode.Exclude);
filt.addRule(rule);
end
setFilterName(filt,'MFileExclusion');
save('MFileExclusion.cvfilter','filt');
You can refer to the following documentation for correct usage of coverage filters: https://www.mathworks.com/help/slcoverage/ref/slcoverage.filter-class.html
I hope it resolves your query.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Report Generator dans Centre d'aide et File Exchange

Produits

Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by