Main Content

Use a Specification Model for Requirements-Based Testing

This example shows how to use a specification model to perform requirements-based testing. In this example, you follow a systematic approach to verify your design model against requirements. For a detailed description of specification model, see What is a Specification Model?.

Step 1: Author Requirements in the Requirements Editor

This example uses a roll autopilot controller, RollAutopilotMdlRef which is a design model that controls the roll angle of an aircraft. The roll autopilot controller operates in two high-level modes:

1. Roll hold mode: This mode either maintains the current roll angle of the aircraft or changes it according to user-specified angle.

2. Heading hold mode: This mode either maintains the current heading or rolls the aircraft to achieve the user-specified heading value. For detailed information on the Roll Autopilot Controller system,see Requirements-Based Testing for Model Development (Simulink Test).

For the autopilot controller, the requirements describe the system interfaces, high-level system modes, and the expected behavior of the controller. These requirements are authored in the Requirements Editor and saved in the AP_Controller.slreqx file. For more information on the Requirements Editor, see Work with Requirements in the Requirements Editor (Requirements Toolbox). To view the requirements, open the Requirements Editor by entering:'AP_Controller');

The Requirements Editor displays the high-level requirements for the Roll Hold and Heading Hold modes. When you click on each requirement, the tab lists the details for the requirement.

Step 2: Create a Specification Model

When you create specification model, you need to consider several factors such as the type of requirements, choice of model blocks, and level of abstraction.Follow the guidelines described in Creating a Specification Model.

Open the sldvexSpecPartial specification model that covers the set of autopilot requirements:

spec_model = 'sldvexSpecPartial';

The sldvexSpecPartial model consists of input and output interfaces. The truth table captures the requirements.

To open the truth table,enter:

open_system('sldvexSpecPartial/AP Controller Requirements');

Step 3. Link Requirements to the Specification Model

Perform these steps to link the requirements to the specification model.

1. Right-click the truth table named AP Controller Requirements in the specification model. In the context menu, click Requirements > Select for linking with Simulink.

2. Open the requirements in the Requirements Editor. Right-click on the requirement you want to link to the truth table and click Link from AP Controller Requirements (Truth Table). If you have multiple truth tables, each specifying a group of requirements, link them as well.

Step 4: Generate Test Cases for the Specification Model

Use sldvoptions to generate test cases for the specification model. Each requirement has been associated with an individual test generation objective using sldv.test().

opts = sldvoptions;
opts.Mode = 'TestGeneration';
opts.ModelCoverageObjectives = 'None';
[~, files] = sldvrun(spec_model,opts,true);

After the analysis completes, the Results Summary window displays that six out of six of the objectives are satisfied.

Step 5: Create a Test Conversion System to Run Tests on the Design Model

The autopilot controller specification model and the design model have different interfaces which means that the tests generated in step 4 are not supported for performing simulation on the design model.

For example, Aircraft Roll Angle is of the enumeration range type in the specification, but is of double type in the design model.

During the test conversion process, if a signal value, such as RA_Horizontal, is a range, you can choose any value that falls in that range. Various heuristics, such as midpoint (where you can choose midpoint of the range), boundary value (where you can choose lower or upper bound of range), or even random strategy (where you choose a random value in the range) may be used. For the autopilot controller, the subsystem sldvexDesignHarness/Test Conversion implements the midpoint strategy in the harness model as shown below:

design_model = 'sldvexDesignHarness';
open_system('sldvexDesignHarness/Test Conversion');

Step 6: Simulate Test Cases on the Design Model and Identify Missing Requirements

The design model is developed independently by using the requirements document. To verify the design, create a harness model that contains these four subsystems:

(i) The specification model.

(ii) The design model.

(iii) The test conversion subsystem described in step 5.

(iv) A runtime verification block. This block checks whether the design signal value is in the range specified by the specification model.

Run the tests from step 5 on the design model by using sldvruntest and generate a model coverage report.

cvopts = sldvruntestopts;
cvopts.coverageEnabled =  true;
[~, initCov] = sldvruntest(design_model,files.DataFile,cvopts);

The analysis results report that full coverage is not achieved for the roll_ap_mod, and subsystem coverage is achieved for the design model.

Step 7: Update the Specification Model by Adding Missing Requirements

Add the requirement to the sldvexSpecFull specification model for analysis.

spec_model = 'sldvexSpecFull';

(a) Generate Test Cases on the Updated Specification Model

Use sldvoptions to generate test cases.

opts = sldvoptions;
opts.Mode = 'TestGeneration';
opts.ModelCoverageObjectives = 'None';
[~, files] = sldvrun(spec_model,opts,true);

(b) Simulate Test Cases on the Design Model and Generate a Coverage Report

Open the sldvexDesignHarness model that contains the design model, specification model, and test conversion subsystem.

design_model = 'sldvexDesignHarness';

Simulate the test cases by using sldvruntest and generate a model coverage report.

cvopts = sldvruntestopts;
cvopts.coverageEnabled =  true;
[~, FinalCov] = sldvruntest(design_model,files.DataFile,cvopts);
cvhtml('FinalCov', FinalCov);

The coverage report shows that full coverage is achieved of the design model.


Related Topics