Skip to Main Content Skip to Search
Product Documentation

Parameter Configuration Example

About This Example

This example describes how to create and analyze a simple Simulink model, for which you generate test cases that achieve decision coverage. However, in this example, achieving complete decision coverage is possible only when the Simulink Design Verifier software treats a particular block parameter as a variable during its analysis. This example explains how to specify parameter configurations for use with the analysis.

The following workflow guides you through the process of completing this example.

TaskDescriptionSee...
1

Construct the example model.

Constructing the Example Model

2

Specify a variable as the value of a Constant block parameter.

Parameterizing the Constant Block

3

Constrain the value of the variable that the Constant block specifies.

Specifying a Parameter Configuration

4

Generate test cases for your model and interpret the results.

Analyzing the Example Model

5

Simulate the test cases and measure the resulting decision coverage.

Simulating the Test Cases

Constructing the Example Model

Construct a simple Simulink model to use in this example:

  1. Create an empty Simulink model.

  2. Copy the following blocks into your empty model window:

    • From the Sources library:

      • Two Inport blocks to initiate the input signals

      • A Constant block to control the switch

    • From the Signal Routing library: A Multiport Switch block to provide simple logic

    • From the Sinks library: An Outport block to receive the output signal

  3. Double-click the Multiport Switch block to access its dialog box and specify its Number of data ports option as 2.

  4. Connect the blocks so that your model looks like this:

  5. Select Simulation > Configuration Parameters.

  6. In the Select tree on the left side of the Configuration Parameters dialog box, click the Solver category. Under Solver options on the right side, set the Type option to Fixed-step, and then set the Solver option to discrete (no continuous states).

  7. Click OK to apply your changes and close the Configuration Parameters dialog box.

  8. Save your model as ex_defining_params_example.mdl for use in the next procedure.

Parameterizing the Constant Block

Parameterize the Constant block in your model by specifying a variable as the value of the Constant block's Constant value parameter:

  1. Double-click the Constant block.

  2. In the Constant value box, enter A.

  3. Click OK to apply your change and close the Constant block parameter dialog box.

  4. Save your model for use in the next step.

Preloading the Workspace Variable

Preload the value of the MATLAB workspace variable A referenced by the Constant block:

  1. Select File > Model Properties.

  2. Click the Callbacks tab.

  3. In the PreLoadFcn, enter:

    A = int8(1);

    When you open the model, the PreLoadFcn defines a variable A of type int8 whose value is 1.

  4. To close the Model Properties dialog box and save your changes, click OK.

  5. Save your model for use in the next step.

Specifying a Parameter Configuration

Create the parameter configuration file so that it constrains the variable A, and configure the analysis to use this file:

  1. In the model window, select Tools > Design Verifier > Options.

    The Simulink Design Verifier software options appear in the Configuration Parameters dialog box.

  2. In the Select tree on the left side of the Configuration Parameters dialog box, click the Design Verifier > Parameters category.

  3. In the Parameters pane on the right side, select the Apply parameters parameter.

    Enabling the Apply parameters option provides access to the Parameter configuration file option; the file name sldv_params_template.m appears in the text box.

  4. Click Edit next to the Parameter configuration file option.

    The Simulink Design Verifier software opens sldv_params_template.m in an editor.

  5. Replace the existing content with the following:

    function params = params_example_function
        % This function defines a parameter configuration for the
        % example model that the documentation discusses.
        
        params.A = int8([1 2]);

    This code defines a function params_example_function that constrains the parameter A to the int8 values 1 and 2.

  6. Save your changes to the template as params_example_function.m in the same folder as the example model.

  7. Close the MATLAB Editor.

  8. In the Configuration Parameters dialog box, click Browse next to the Parameter configuration file option, and then select your parameter configuration file, params_example_function.m.

  9. Click OK to apply your change and close the Configuration Parameters dialog box.

  10. Save your model for use in the next step.

Analyzing the Example Model

Analyze the model using the parameter configuration file you just created and generate the analysis report:

  1. In the model window, select Tools > Design Verifier > Generate Tests.

    The Simulink Design Verifier software begins analyzing your model to generate test cases.

  2. When the software completes its analysis, in the log window, select Generate detailed analysis report.

    The Simulink Design Verifier software displays an HTML report named ex_defining_params_example_report.html.

    Keep the log window open for the next procedure.

  3. In the Simulink Design Verifier report Table of Contents, click Test Cases.

  4. Click Test Case 1 to display the subsection for that test case.

    This section provides details about Test Case 1 that the Simulink Design Verifier software generated to satisfy a coverage objective in the model. In this test case, a value of 1 for parameter A satisfies the objective.

  5. Scroll down to the Test Case 2 section in the Test Cases chapter.

    This section provides details about Test Case 2, which satisfies another coverage objective in the model. In this test case, a value of 2 for parameter A satisfies the objective.

Simulating the Test Cases

Simulate the generated test cases and review the coverage report that results from the simulation:

  1. In the Simulink Design Verifier log window, select Create harness model.

    The software creates and opens a harness model named ex_defining_params_example_harness.mdl.

  2. The block labeled Inputs in the harness model is a Signal Builder block that contains the test case signals. Double-click the Inputs block to view the test case signals in the Signal Builder block.

  3. In the Signal Builder dialog box, click the Run all button .

    The Simulink software simulates each of the test cases in succession, collects coverage data for each simulation, and displays an HTML report of the combined coverage results at the end of the last simulation.

  4. In the model coverage report, review the Summary section:

    This section summarizes the coverage results for the harness model and its Test Unit subsystem. Observe that the subsystem achieves 100% decision coverage.

  5. In the Summary section, click the Test Unit subsystem.

    The report displays detailed coverage results for the Test Unit subsystem.

    This section reveals that the Multiport Switch block achieves 100% decision coverage because the test cases exercise each of the switch pathways.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS