MATLAB Examples

Using Command Line Functions to Support Changing Parameters

This example shows how to use Simulink® Design Verifier™ command-line functions to generate test data that incorporates different parameter values.


Controller Model with an Adjustable Parameter

The example model is a simple controller with a single parameter. The constant parameter 'control_mode' can be either 1 or 2. The parameter must take both values for the test cases to achieve complete coverage. The value determines the switch block output and which enabled subsystem will execute.


Specifying Parameter Values for Analysis

Simulink Design Verifier does not identify parameter values. The tool uses the parameter values at the start of analysis for generating tests and proving properties. You can force the tool to incorporate changing parameter values by repeating analysis with different values.

The first iteration of design verifier will use control_mode=1.

control_mode = 1;

Simulink® Design Verifier™ Options

Simulink Design Verifier functions use options objects created with the sldvoptions function to control all aspects of analysis and output.

In this example, we will run Simulink Design Verifier in test generation mode for a maximum of 60 seconds and produce a harness model. We will disable the report generation.

The default values of the remaining options are set correctly to generate tests. You can use the get command to display all the options and values.

opts = sldvoptions;
opts.Mode = 'TestGeneration';
opts.MaxProcessTime = 60;
opts.SaveHarnessModel = 'on';
opts.SaveReport = 'off';
opts.HarnessModelFileName = '$ModelName$_harness.slx';

                              Mode: 'TestGeneration'
                    MaxProcessTime: 60
    DisplayUnsatisfiableObjectives: 'off'
                 AutomaticStubbing: 'on'
           DesignMinMaxConstraints: 'on'
                         OutputDir: 'sldv_output/$ModelName$'
             MakeOutputFilesUnique: 'on'
                  BlockReplacement: 'off'
         BlockReplacementRulesList: '<FactoryDefaultRules>'
     BlockReplacementModelFileName: '$ModelName$_replacement'
                        Parameters: 'off'
          ParametersConfigFileName: 'sldv_params_template.m'
                    ParameterNames: []
              ParameterConstraints: []
            ParameterUseInAnalysis: []
               ParametersUseConfig: 'off'
                     TestgenTarget: 'Model'
           ModelCoverageObjectives: 'ConditionDecision'
                    TestConditions: 'UseLocalSettings'
                    TestObjectives: 'UseLocalSettings'
                  MaxTestCaseSteps: 10000
             TestSuiteOptimization: 'CombinedObjectives (Nonlinear Extended)'
                        Assertions: 'UseLocalSettings'
                  ProofAssumptions: 'UseLocalSettings'
               ExtendExistingTests: 'off'
                  ExistingTestFile: ''
          IgnoreExistTestSatisfied: 'on'
                IgnoreCovSatisfied: 'off'
                  CoverageDataFile: ''
                         CovFilter: 'off'
                 CovFilterFileName: ''
         IncludeRelationalBoundary: 'off'
                 RelativeTolerance: 0.0100
                 AbsoluteTolerance: 1.0000e-05
                   DetectDeadLogic: 'off'
                 DetectActiveLogic: 'off'
                 DetectOutOfBounds: 'on'
              DetectDivisionByZero: 'on'
             DetectIntegerOverflow: 'on'
                      DetectInfNaN: 'off'
                   DetectSubnormal: 'off'
                 DesignMinMaxCheck: 'off'
                   ProvingStrategy: 'Prove'
                 MaxViolationSteps: 20
                      SaveDataFile: 'on'
                      DataFileName: '$ModelName$_sldvdata'
                SaveExpectedOutput: 'off'
             RandomizeNoEffectData: 'off'
                  SaveHarnessModel: 'on'
              HarnessModelFileName: '$ModelName$_harness.slx'
             ModelReferenceHarness: 'off'
                        SaveReport: 'off'
                   ReportPDFFormat: 'off'
                    ReportFileName: '$ModelName$_report'
             ReportIncludeGraphics: 'off'
                     DisplayReport: 'on'
                       SFcnSupport: 'on'
                  SFcnExtraOptions: ''
              ReduceRationalApprox: 'on'
                    SlTestFileName: '$ModelName$_test'
                 SlTestHarnessName: '$ModelName$_sldvharness'
               SlTestHarnessSource: 'Inport'

Generating Tests and Collecting Coverage

The sldvgencov function generates test suites and model coverage together. All tests that can be generated with the current parameter values will be collected into the harness model and the resulting coverage returned in a coverage data object.

[status,coverageData,files] = sldvgencov('sldvdemo_param_controller',opts);
Checking compatibility for test generation: model 'sldvdemo_param_controller'
Compiling model...done
Checking compatibility...done

'sldvdemo_param_controller' is compatible for test generation with Simulink Design Verifier.

Generating tests using compatibility results from 10-Aug-2018 22:20:55...

Completed normally.

Generating output files:

    Data file:

    Harness model:

Results generation completed.

Integrating Parameter Initialization Into a Test Harness

Generated test cases must be run with the same parameter values used during analysis. An initialization command configures the values during simulation of test cases. The sldvharnessmerge function incorporates initialization commands into test harnesses.

initCmdStr = 'control_mode=1;'
[path,modelName] = fileparts(files.HarnessModel);
initCmdStr =


Modifying Parameters and Repeating Test Generation

Modifying parameter values enables additional test generation. Passing a coverage data object as the third input to sldvgencov forces the function to ignore all model coverage test objectives that have been satisfied. We use the coverage data that was returned from the earlier call to sldvgencov to restrict test generation to unsatisfied test objectives.

[status,newCov,newFiles] = sldvgencov('sldvdemo_param_controller',opts,false,coverageData);
Checking compatibility for test generation: model 'sldvdemo_param_controller'
Compiling model...done
Checking compatibility...done

'sldvdemo_param_controller' is compatible for test generation with Simulink Design Verifier.

Generating tests using compatibility results from 10-Aug-2018 22:21:22...

Completed normally.

Generating output files:

    Data file:

    Harness model:

Results generation completed.

Merging Test Harnesses Into a Single Model

Another call to sldvharnessmerge merges the test data from the new harness and its initialization command into the existing harness model.

newInitCmd = 'control_mode=2;'
[path,newModelName] = fileparts(newFiles.HarnessModel);
newInitCmd =


Executing the Tests in the Harness Model

We close the second harness model that was created because the test cases have been merged into the first harness model. You can execute the suite of tests by clicking the "Run all" button on the Signal Builder.


Clean Up

To complete the example, close the models and remove the generated files.