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, seeWhat is a Specification Model?.

Step 1: Author Requirements in the Requirements Editor

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

1.辊保持状态: This mode either maintains the current roll angle of the aircraft or changes it according to user-specified angle.

2.标题持有莫de: 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,seeRequirements-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 theAP_Controller.slreqxfile. For more information on the Requirements Editor, seeWork with Requirements in the Simulink Editor(Simulink Requirements). To view the requirements, open the Requirements Editor by entering:

slreq.open('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 inCreating a Specification Model.

Open thesldvexSpecPartialspecification model that covers the set of autopilot requirements:

spec_model ='sldvexSpecPartial'; open_system(spec_model);

ThesldvexSpecPartialmodel 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 namedAP Controller Requirementsin the specification model. In the context menu, clickRequirements>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 clickLink 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

Usesldvoptionsto generate test cases for the specification model. Each requirement has been associated with an individual test generation objective usingsldv.test().

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

在分析完成后,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 Angleis 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 subsystemsldvexDesignHarness/Test Conversionimplements the midpoint strategy in the harness model as shown below:

design_model ='sldvexDesignHarness'; load_system(design_model); 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 usingsldvruntestand generate a model coverage report.

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

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

Step 7: Update the Specification Model by Adding Missing Requirements

添加的需求sldvexSpecFullspecification model for analysis.

spec_model ='sldvexSpecFull'; open_system(spec_model);

(a) Generate Test Cases on the Updated Specification Model

Usesldvoptionsto 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 thesldvexDesignHarnessmodel that contains the design model, specification model, and test conversion subsystem.

design_model ='sldvexDesignHarness'; open_system(design_model);

Simulate the test cases by usingsldvruntestand 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.

bdclose('all'); slreq.clear;

Related Topics