Main Content

Requirements-Based Testing for Model Development

Test an autopilot subsystem against a requirement.

This example demonstrates testing a subsystem against a requirement, using the test manager, test harness, Test Sequence block, and Test Assessment block. The requirements document links to the test case and test harness, andverifystatements assess the component under test.

As you build your model, you can add test cases to verify the model against requirements. Subsequent users can run the same test cases, then add test cases to accomplish further verification goals such as achieving 100% coverage or verifying generated code.

This example tests theRoll Referencesubsystem against a requirement using three scenarios. A Test Sequence block provides inputs, and a Test Assessment block evaluates the component. TheRoll Referencesubsystem is one component of an autopilot control system.Roll Referencecontrols the reference angle of the aircraft's roll control system. The subsystem fails one assessment, prompting a design change that limits the subsystem output at high input angles.

Paths and Example Files

Enter the following to store paths and file names for the example:

topModel ='TestAndVerificationAutopilotExample'; rollModel ='RollAutopilotMdlRef'; testHarness ='RollReference_Requirement1_3'; testFile ='AutopilotTestFile.mldatx'; reqDoc ='RollAutopilotRequirements.txt';

Open the Test File and Model

Open theRollAutopilotMdlRefmodel. The full control systemTestAndVerificationAutopilotExamplereferences this model.

open_system(rollModel)

Open the test file in the Test Manager.

tf = sltest.testmanager.load(testFile); sltest.testmanager.view;

Open the requirements document. In the test browser, expandAutopilotTestFileandBasic Design Test Casesin the tree, and clickRequirement 1.3 test. In the Requirement 1.3 test tab, expandRequirements. Double-click on any of the requirements links to open the Requirements Editor, where you can review the requirements.

In the document, requirement 1.3.1 states: When roll hold mode becomes the active mode, the roll hold reference shall be set to the actual roll angle of the aircraft, except under the conditions described in the child requirements.

  • Child requirement 1.3.1.1 states: The roll hold reference shall be set to zero if the actual roll angle is less than 6 degrees, in either direction, at the time of roll hold engagement.

  • Child requirement 1.3.1.2 states: The roll hold reference shall be set to 30 degrees in the same direction as the actual roll angle if the actual roll angle is greater than 30 degrees at the time of roll hold engagement.

  • Child requirement 1.3.1.3 states: The roll reference shall be set to the cockpit turn knob command, up to a 30 degree limit, if the turn knob is commanding 3 degrees or more in either direction.

The test case creates three scenarios to test the normal conditions and exceptions in the requirement.

需求文档测试要控制痕迹ss using URLs that map to the Test Sequence block and test steps. Open the test harness and highlight the component associated with reference requirement 1.3.

sltest.harness.open([rollModel'/Roll Reference'],testHarness) rmi('highlightModel','RollReference_Requirement1_3')

The Test Sequence block, Test Assessment block, and component under test link to the requirements document. Highlight requirements links by selectingApps > Requirements Managerand then, clicking Highlight Links in the test harness model. You can also highlight links in the Test Sequence Editor by clickingToggle requirements links highlightingin the toolstrip.

Test Sequence

Open the Test Sequence block.

open_system('RollReference_Requirement1_3/Test Sequence')

The Test Sequence block creates test inputs for three scenarios:

In each test, the test sequence sets a signal level, then engages the autopilot. The test sequence checks thatPhiRefis stable for a minimum timeDurationLimitbefore it transitions to the next signal level. For the first two scenarios, the test sequence sets theEndTestlocal variable to1, triggering the transition to the next scenario.

These scenarios check basic component function, but do not necessarily achieve objectives such as 100% coverage.

Test Assessments

Open the Test Assessment block.

open_system('RollReference_Requirement1_3/Test Assessment')

The Test Assessment block evaluatesRoll Reference. The assessment block is a library linked subsystem, which facilitates test assessment reuse between multiple test harnesses. The block containsverifystatements covering:

  • The requirement thatPhiRef=PhiwhenPhioperates inside the low and high limits.

  • The requirement thatPhiRef = 0whenPhi < 6degrees.

  • The requirement thatPhiRef = 30whenPhi > 30degrees.

  • The requirement that whenTurnKnobis engaged,PhiRef = TurnKnobifTurnKnob >= 3degrees.

Verify the Subsystem

To run the test, in the Test Manager, right-clickRequirement 1.3 Testin the Test Browser pane, and clickRun.

The simulation returnsverifystatement results and simulation output in the Test Manager. Theverify_high_posstatement fails.

  1. ClickResults and Artifactsin the test manager.

  2. In the results tree, expandVerify Statements. ClickSimulink: verify_high_pos. The trace shows when the statement fails.

  1. ClickSubplotsin the toolstrip and select two plots arranged vertically. Select the lower plot in theVisualizepane.

  2. In the results tree, expandResults,Requirement 1.3 Test, andSim Output.

  3. SelectPhiRefandPhi. The output traces align with theverifyresults in the above plot. Observe thatPhiRefexceeds 30 degrees whenPhiexceeds 30 degrees.

UpdateRollReferenceto limit thePhiRefsignal.

  1. Close the test harness.

  2. Add a Saturation block to the model as shown.

  3. Set the lower limit to-30and the upper limit to30.

  4. Link the block to its requirement. From the Requirements browser, drag requirement 1.1.2 to the Saturation block. An icon appears on the block, and the requirement is highlighted.

Run the test again. Theverifystatement passes, and the output in the test manager shows thatPhiRefdoes not exceed 30 degrees.

close_system(rollModel,0); close_system(topModel,0); close_system('RollRefAssessLib',0); sltest.testmanager.clear; sltest.testmanager.clearResults; sltest.testmanager.close; cleartopModelreqDocrollModeltestHarnesstestFileharnessLink