Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Use Coverage Commands in a Script

The following script demonstrates some common model coverage commands.

This script:

  • Creates two data files to load before simulation.

  • Creates two cvtest objects, testObj1 and testObj2, and simulates them using the default model parameters. Each cvtest object uses the setupCmd property to load a data file before simulation.

  • Enables decision, condition, and MCDC coverage.

  • Retrieves the decision coverage results for the Adjustable Rate Limited subsystem.

  • Uses cvhtml to display the coverage results for the two tests and the cumulative coverage.

  • Compute cumulative coverage with the + operator and save the results

mdl = 'slvnvdemo_ratelim_harness';
mdl_subsys = 'slvnvdemo_ratelim_harness/Adjustable Rate Limiter';

open_system(mdl);
open_system(mdl_subsys);

t_gain = (0:0.02:2.0)'; u_gain = sin(2*pi*t_gain);
t_pos = [0;2]; u_pos = [1;1]; t_neg = [0;2]; u_neg = [-1;-1];
save('within_lim.mat','t_gain','u_gain','t_pos','u_pos', ...
    't_neg', 'u_neg');
t_gain = [0;2]; u_gain = [0;4]; t_pos = [0;1;1;2]; 
u_pos = [1;1;5;5]*0.02; t_neg = [0;2]; u_neg = [0;0];
save('rising_gain.mat','t_gain','u_gain','t_pos','u_pos', ...
    't_neg', 'u_neg');

testObj1               = cvtest(mdl_subsys);
testObj1.label         = 'Gain within slew limits';
testObj1.setupCmd      = 'load(''within_lim.mat'');';
testObj1.settings.mcdc = 1;
testObj1.settings.condition = 1;
testObj1.settings.decision = 1;

testObj2          = cvtest(mdl_subsys);
testObj2.label    = 'Rising gain that temporarily exceeds slew limit';
testObj2.setupCmd = 'load(''rising_gain.mat'');';
testObj2.settings.mcdc = 1;
testObj2.settings.condition = 1;
testObj2.settings.decision = 1;

[dataObj1,simOut1] = cvsim(testObj1);
decision_cov1 = decisioninfo(dataObj1,mdl_subsys);
percent_cov1 = 100 * decision_cov1(1) / decision_cov1(2)
cc_cov2 = complexityinfo(dataObj1, mdl_subsys);

[dataObj2,simOut2] = cvsim(testObj2,[0 2]);
decision_cov2 = decisioninfo(dataObj2,mdl_subsys);
percent_cov2 = 100 * decision_cov2(1) / decision_cov2(2)
cc_cov2 = complexityinfo(dataObj1, mdl_subsys);


cvhtml('ratelim_report',dataObj1,dataObj2);
cumulative = dataObj1+dataObj2;

cvsave('ratelim_testdata',cumulative);

close_system('slvnvdemo_ratelim_harness',0);
Was this topic helpful?