Main Content

Extend Existing Test Cases After Applying Parameter Configurations

This example shows how to achieve missing coverage by extending existing test cases after applying parameter configurations.

In this example, you generate test cases for a model and review the analysis results. The results show that the model consists of unsatisfiable objectives and does not achieve full coverage. Then, you apply parameter configurations in the model and reuse the previously generated test cases to achieve full model coverage.

Step 1: Generate Initial Test Cases and Review Results

The sldvexParameterController model is a cruise control model that controls the throttle speed by selecting a P Controller or PI Controller. The ControllerModeSelection subsystem uses the SelectMode parameter to select the controller mode. Define the enumerated data type for Selectmode by using the function Simulink.defineIntEnumType. For more information on enumerated values, see Use Enumerated Data in Simulink Models.

Simulink.defineIntEnumType('EnumForControllerSelection',...
{'Pmode','PImode'},[1;2]);
SelectMode = Simulink.Parameter;
SelectMode.Value = EnumForControllerSelection.Pmode;
model = 'sldvexParameterController';
open_system(model);

Set the sldvoptions and analyze the model by using the specified options.

opts = sldvoptions;
opts.Mode = 'TestGeneration';
opts.ModelCoverageObjectives = 'MCDC';
[ status, files ] = sldvrun(model, opts, true);

After the analysis completes, the Results Summary window displays that 15 out of 54 objectives are unsatisfiable.

In the Results Summary window, click Highlight analysis results on model. Double-click the ControllerModeSelection subsystem. The PI_ModeSelection and P_ModeSelection subsystems are highlighted in red and consist of unsatisfiable objectives.

To view the model coverage report, in the Results Summary window, click Simulate tests and produce a model coverage report. The report shows that the model does not achieve full coverage.

Full coverage is not achieved because the parameter value SelectMode is restricted to the default value of EnumForControllerSelection.Pmode. Consequently, full coverage is not achieved for the PI_ModeSelection subsystem.

Step 2: Configure Parameter Configurations and Extend Existing Test Cases

If you apply parameter configurations, Simulink Design Verifier treats the parameter as a variable during analysis and constraints the values based on the constraint values that you specify.

Apply parameter configurations for the SelectMode parameter by specifying the constraint values for parameterValue.

controlParameter = [ {'SelectMode'}];
parameterValue = [ {'[EnumForControllerSelection.Pmode EnumForControllerSelection.PImode]'}];
opts.Parameters = 'on';
opts.ParametersUseConfig = 'on';
opts.ParameterNames = controlParameter;
opts.ParameterConstraints = parameterValue;
opts.ParameterUseInAnalysis = {'on'};

To reuse the previously generated test cases, configure the analysis option to extend the existing test cases and specify the existing test file.

opts.ExtendExistingTests = 'on';
opts.IgnoreExistTestSatisfied = 'off';
opts.ExistingTestFile = files.DataFile;

Step 3: Perform Analysis and Review Coverage Report

Analyze the model by using the specified options.

[status, fileNames] = sldvrun(model, opts, true);

After the analysis completes, the Results Summary window displays that all the objectives are satisfied.

To generate model coverage report, click Simulate tests and produce a model coverage report. The report shows that the model achieves full coverage.

To complete this example, close the model.

close_system('sldvexParameterController', 0);

See also