%% Record Coverage Data Using |cvsim|
% This example shows how to use |cvsim| with a |cvtest| object input and a
% structure of model parameters.

% Copyright 2020 The MathWorks, Inc.

%%
% Load the |slvnvdemo_cv_small_controller| example model.

modelName = 'slvnvdemo_cv_small_controller';
load_system(modelName)

%%
% Create a |cvtest| object and turn on decision coverage.

testObj = cvtest(modelName);
testObj.settings.decision = 1;

%%
% Create a structure that defines the following model parameters:
%
% * Set the absolute tolerance, |AbsTol|, to |1e-5|.
% * Enable the simulation to save states to the workspace with
% |SaveState|.
% * Declare the variable name to save the state information in with
% |SaveStateName|.
% * Enable Simulink&reg; to save simulation output data to the workspace
% with |SaveOutput|.
% * Declare the variable name in which to store the simulation output
% data with |OutputSaveName|.
%

paramStruct.AbsTol =         '1e-5';
paramStruct.SaveState =      'on';
paramStruct.StateSaveName =  'xoutNew';
paramStruct.SaveOutput =     'on';
paramStruct.OutputSaveName = 'youtNew';

%%
% Simulate the model with |cvsim| and generate a coverage report with
% |cvhtml|.

[covData,simOut] = cvsim(testObj,paramStruct);
cvhtml('CoverageReport.html',covData,'-sRT=0');

