Main Content

Run Tests with Simulink Test and Verify Fault Effects

This example shows how to run tests that inject faults and then verify the fault behavior. If you have Simulink® Test™, you can create simulation tests that inject faults into your models and run them concurrently in a test suite. You can create a test suite where each test injects a fault by using a test callback. After you inject faults, you can assess the signals to determine if the faults caused the desired outputs by using temporal assessments.

For more information on how to create basic tests in Simulink Test, see Create a Simple Baseline Test (Simulink Test). If you want to run multiple simulations without automating the verification of your model behavior, you can use the Multiple Simulations panel. For an example, see Evaluate Fault Combinations on a Fault-Tolerant Fuel System.

Open the Model

Open the sldemo_fuelsys_fault_analyzer model and set up the faults by using the fuelSysFaultTestSetup helper function.

mdlName = "sldemo_fuelsys_fault_analyzer";

The model represents a fuel control system for a gasoline engine, and is a modified version of the model in Model a Fault-Tolerant Fuel Control System. The model produces a fuel mode signal after detecting faults in the controller. When the controller detects a single fault, the controller changes the fuel_mode signal from LOW, which represents low emissions, to RICH, which represents a rich mixture. When the controller detects a fault, the model logs this behavior by setting the normal_operation signal to false.

The model contains four faults. Open the Fault Table pane to view the faults. In the Apps tab, click Fault Analyzer. Then, in the Fault Analyzer tab, in the View section, click Fault Table. Expand each model element to view the faults. Each fault uses a timed trigger, where the fault is injected at the specified simulation time.

The starting Fault Table pane. The model has four faults. Each fault is on a different model element.

View the Tests

Each fault causes the normal_operation signal to output false after the fault is injected. In this example, you run tests in the Test Manager to verify this behavior. Open the Test Manager and load the fault_tests_example.mldatx test file. In the Apps tab, click Simulink Test. In the Tests tab, click Simulink Test Manager. In the Test Manager, open the fault_tests_example.mldatx test file.

tf = sltest.testmanager.load("fault_tests_example.mldatx");

The test file has four test cases.


Each test case injects a fault model by running a Post-Load callback that enables one model element by using the Simulink.fault.enable function. To view the callback, in the Test Manager, in the left pane, click Test Browser. Expand the test file and the test suite, and select a test. Expand the Callbacks section to view the callback script. This image shows the script for the test case that injects the throttle_fault fault.

The Callbacks section for the test case that injects the throttle_fault fault. The Post-Load script is expanded.

If your model element has more than one fault, you can select the active fault by retrieving the faults by using the Simulink.fault.findFaults function and then by using the activate function.

To verify that the fault produces the desired behavior, each test case includes a temporal assessment. See Assess Temporal Logic by Using Temporal Assessments (Simulink Test). In a test, expand the Logical and Temporal Assessments section. The assessment checks when the faulted signal equals the injected value. If the signal value equals the injected value from the fault, then the normal_operation signal must be false. This image shows the temporal assessment for the test case that injects the throttle_fault fault.

The temporal assessment for the test case that injects the throttle_fault fault. The assessment has two symbols, and a trigger response assessment. The assessment is expanded. 

Run the Tests

Run the test suite.

ts = getTestSuites(tf);

Select Results and Artifacts, then expand the results. Each test case passes, which means the controller detects when each fault is injected.

The test results. The test suite is expanded. The results show that each test passed.

Expand each test to view additional details.

See Also

(Simulink Test)

Related Topics