This example shows how to programatically create a SystemTEst test harness for a model of a fuel rate controller that uses bus inports. The result is a preconfigured TEST-File based on your model.
This example requires the following products to run:
Simulink Model Overview
The Simulink model used in this example is a modified version of the fuel rate controller with one root-level Inport block using a bus object, where each signal in the bus represents:
Exhaust gas (EGO)
Manifold absolute pressure (MAP)
Step 1: Create a SystemTest harness for the model
A test harness can be created using the function SYSTEST.CREATEHARNESS. This will generate a TEST-file with:
A test case whose signals have the same names as the inport blocks
A Simulink element configured with the model and Inport blocks mapped to the signals of the test case
% Define the test file and model name testFileName = 'demosystest_fuelctrl_harness.test'; modelName = 'demosystest_fuelctrl_bus_model.slx'; % Create a test harness systest.createHarness(testFileName, modelName);
Warning: Data/Event <a href="matlab:sf('Open', 100)">'o2_t_thresh'</a> is defined, but is never used in the Stateflow chart. <a href= "matlab: internal.stateflow.dialogs.UnusedObjectDeleter.createDeleter(100)"> Delete this data/event.</a> You can also configure the diagnostic by clicking<a href= "matlab: sfprivate('openConfigParamsSFDiagnostics',20)"> here.</a>
Step 2: Adding test cases to the test harness
Now that the test harness is created, we can add test cases to the harness. Test cases can be added graphically using the Test Case Editor in the SystemTest desktop. You can also add test cases programmatically by importing them from various sources such as Excel® files, a Signal Builder block and Simulink Design Verifier data files.
For more information on adding pre-existing test cases, see the examples: