Main Content

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 300 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 = 300;
opts.SaveHarnessModel = 'on';
opts.SaveReport = 'off';
opts.HarnessModelFileName = '$ModelName$_harness.slx';

                               Mode: 'TestGeneration'
                     MaxProcessTime: 300
                  AutomaticStubbing: 'on'
                        UseParallel: 'off'
            DesignMinMaxConstraints: 'on'
                          OutputDir: 'sldv_output/$ModelName$'
              MakeOutputFilesUnique: 'on'
                   BlockReplacement: 'off'
          BlockReplacementRulesList: '<FactoryDefaultRules>'
      BlockReplacementModelFileName: '$ModelName$_replacement'
             ParameterConfiguration: 'None'
           ParametersConfigFileName: 'sldv_params_template.m'
                     ParameterNames: []
               ParameterConstraints: []
             ParameterUseInAnalysis: []
                      TestgenTarget: 'Model'
            ModelCoverageObjectives: 'ConditionDecision'
                     TestConditions: 'UseLocalSettings'
                     TestObjectives: 'UseLocalSettings'
                   MaxTestCaseSteps: 10000
              TestSuiteOptimization: 'Auto'
                         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'
                DeadLogicObjectives: 'ConditionDecision'
                  DetectOutOfBounds: 'on'
               DetectDivisionByZero: 'on'
              DetectIntegerOverflow: 'on'
                       DetectInfNaN: 'off'
                    DetectSubnormal: 'off'
                  DesignMinMaxCheck: 'off'
          DetectDSMAccessViolations: 'off'
      DetectHISMViolationsHisl_0002: 'off'
      DetectHISMViolationsHisl_0003: 'off'
      DetectHISMViolationsHisl_0004: 'off'
      DetectHISMViolationsHisl_0028: 'off'
    DetectBlockInputRangeViolations: 'off'
                    ProvingStrategy: 'Prove'
                  MaxViolationSteps: 20
                       DataFileName: '$ModelName$_sldvdata'
                 SaveExpectedOutput: 'off'
              RandomizeNoEffectData: 'off'
                   SaveHarnessModel: 'on'
               HarnessModelFileName: '$ModelName$_harness.slx'
              ModelReferenceHarness: 'on'
                      HarnessSource: 'Signal Editor'
                         SaveReport: 'off'
                    ReportPDFFormat: 'off'
                     ReportFileName: '$ModelName$_report'
              ReportIncludeGraphics: 'off'
                      DisplayReport: 'on'
                        SFcnSupport: 'on'
           CodeAnalysisExtraOptions: ''
         CodeAnalysisIgnoreVolatile: 'on'
               ReduceRationalApprox: 'on'
                     SlTestFileName: '$ModelName$_test'
                  SlTestHarnessName: '$ModelName$_sldvharness'
                SlTestHarnessSource: 'Inport'
                 StrictEnhancedMCDC: 'off'
         RebuildModelRepresentation: 'IfChangeIsDetected'
          AnalyzeAllStartupVariants: 'on'

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);
19-Aug-2023 15:23:40
Checking compatibility for test generation: model 'sldvdemo_param_controller'
Compiling model...done
Building model representation...done

19-Aug-2023 15:23:44

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

Generating tests using model representation from 19-Aug-2023 15:23:44...

19-Aug-2023 15:23:56

Completed normally.

Generating output files:

    Harness model:

19-Aug-2023 15:24:05
Results generation completed.

    Data file:

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 sldvmergeharness 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);
19-Aug-2023 15:24:11
Validating cached model representation from 19-Aug-2023 15:23:44...change detected

19-Aug-2023 15:24:11
Checking compatibility for test generation: model 'sldvdemo_param_controller'
Compiling model...done
Building model representation...done

19-Aug-2023 15:24:14

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

Generating tests using model representation from 19-Aug-2023 15:24:14...

19-Aug-2023 15:24:19

Completed normally.

Generating output files:

    Harness model:

19-Aug-2023 15:24:26
Results generation completed.

    Data file:

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 Editor.


Clean Up

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