cvsave

Save coverage tests and results to file

Syntax

cvsave(filename, model)
cvsave(filename, cvd)
cvsave(filename, cvto1, cvto2, ...)
cvsave(filename, cell_array{ :})

Description

cvsave(filename, model) saves all the tests (cvtest objects) and results (cvdata objects) related to model in the text file filename.cvt. model is a handle to or name of a Simulink® model.

cvsave(filename, cvd) saves all the results (cvdata objects) for the active model in the text file filename.cvt. cvsave also saves information about any referenced models.

cvsave(filename, cvto1, cvto2, ...) saves multiple cvtest objects in the text file filename.cvt. cvsave also saves information about any referenced models.

cvsave(filename, cell_array{ :}) saves the test results stored in each element of cell_array to the file filename.cvt. Each element in cell_array contains test results for a cvdata object.

Input Arguments

filename

Character vector or string containing the name of the file in which to save the data. cvsave appends the extension .cvt to the name of the file when saving it.

model

Handle to a Simulink model

cvd

cvdata object

cvto

cvtest object

cell_array

Cell array of cvtest objects

Examples

collapse all

This example shows how to save coverage data to a file.

Move the current MATLAB® directory to the location that contains the example files.

openExample('slcoverage/SaveCoverageResultsExample')

Start by loading the model into memory.

modelName = 'slvnvdemo_cv_small_controller';
load_system(modelName);

Simulate the model with the coverage settings that are saved with the model. If you have not set coverage settings, then cvsim uses the default settings.

covData = cvsim(modelName);

Save a coverage data file called coverage_data, containing the coverage data in the cvdata object covData.

cvsave('coverage_data',covData);

This example shows how to save more than one coverage data object to a single coverage data file.

Move the current MATLAB® directory to the location that contains the example files.

openExample('slcoverage/SaveCumulativeCoverageDataToAFileExample')

Load the model

First, load the model into memory.

modelName = 'slvnvdemo_ratelim_harness';
load_system(modelName);

Set model parameters for coverage

Create a Simulink.SimulationInput object to set coverage parameters.

covSet = Simulink.SimulationInput(modelName);
covSet = covSet.setModelParameter('CovEnable','on');
covSet = covSet.setModelParameter('CovMetricStructuralLevel','MCDC');
covSet = covSet.setModelParameter('CovScope','Subsystem');
covSet = covSet.setModelParameter('CovPath','/Adjustable Rate Limiter');
covSet = covSet.setModelParameter('CovSaveSingleToWorkspaceVar','on');

Simulate the model to collect coverage data

Load the data files and then simulate the model to collect two sets of coverage data.

load within_lim.mat
covSet = covSet.setModelParameter('CovSaveName','covData1');
simOut1 = sim(covSet);

Now simulate the model a second time using the second data file.

load rising_gain.mat
covSet = covSet.setModelParameter('CovSaveName','covData2');
simOut2 = sim(covSet);

Save the coverage data to a file

Save the results in a cell array.

cov_results{1} = covData1;
cov_results{2} = covData2
cov_results =

  1x2 cell array

    {1x1 cvdata}    {1x1 cvdata}

Save the results to a file.

cvsave('ratelim_testdata',cov_results{:});

Alternatives

Use the coverage settings to save cumulative coverage results for a model:

  1. Open the model for which you want to save cumulative coverage results.

  2. In the Model Editor, select Model Settings on the Modeling tab.

  3. On the Coverage pane of the Configuration Parameters dialog box, select Enable coverage analysis.

  4. In the Results section, select Save last run in workspace variable.

  5. Click OK to close the Configuration Parameters dialog box and save your changes.

  6. Simulate the model by clicking the Run button and review the results.

Introduced before R2006a