Main Content

cvsave

Save coverage settings and results to file

    Description

    cvsave(fileName,model) saves all the coverage settings and results related to model in the file fileName.

    cvsave(fileName,covData) saves all the coverage settings and results contained in the cvdata object covData.

    cvsave(fileName,covSettings1,...,covSettingsN) saves multiple cvtest objects and information about any referenced models.

    Examples

    collapse all

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

    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.

    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.

    Load the Model

    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);
    

    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{:});
    

    Input Arguments

    collapse all

    Name of coverage data file, specified as a character array or a string array. cvsave appends the extension .cvt to the name of the file when saving it.

    Example: 'myCoverageDataFile'

    Data Types: char | string

    Simulink model that has coverage data, specified as a character array or a string array. model can be the name of a model or a handle to a model.

    Example: 'mySimulinkModel'

    Data Types: char | string

    Coverage settings, specified as a cvtest object, or a cell array of cvtest objects.

    Data Types: cvtest | cell

    Coverage data, specified as a cvdata object or a cell array of cvdata objects.

    Data Types: cvdata | cell

    Alternatives

    You can save coverage results to a MATLAB workspace variable when you run your model in Simulink:

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

    2. On the Modeling tab, select Model Settings.

    3. In the left pane of the Configuration Parameters dialog box, select Coverage.

    4. Select Enable coverage analysis.

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

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

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

    Introduced before R2006a