Create and Run a Baseline Test

In this tutorial, you set up and run two tests:

  • The first test verifies whether a model meets a requirement.

  • The second test compares a simulation result to baseline data.

Start Test Manager

  1. Open the sltestCruiseControlDefective model in the matlab/examples/simulinktest folder.

  2. To start the Test Manager, select Analysis > Test Manager from the Simulink® model menu.

Verify Model Behavior Against Requirements

In this example, you create a test file structure, add a test case to it, and run the test.

Create the Test File Structure

  1. Set the current folder to a writable folder.

  2. Create a test file. From the Test Manager toolstrip, select New > Test File.

  3. Name the file Tutorial Tests and save it.

    A test file contains one or more test suites, and test suites contain one or more test cases. Use this structure to organize related tests. This structure also helps you run tests individually or to run all tests in the file or suite.

  4. The default test case is a baseline test. Convert it to a Simulation test. Select the test case and, from the context menu, select Convert to > Simulation Test and click Yes to confirm the conversion.

  5. Rename the test My Verification Test. You can use the context menu in the test browser and select Rename. Or, you can click the name and type a new one in the test case.

Assign a Model to the Test Case

The model uses a Verification Subsystem block from the Simulink Design Verifier™ library. The subsystem contains an Assertion block that checks whether the system disengages if the brake has been applied for three time steps. Signal logging is enabled for the Signal Builder block outputs.

Set the test case to use the sltestCruiseControlDefective model. In Test Manager, under System Under Test, click the Use current model button .

You can run this test case without specifying other assessments, because the model contains an Assertion block. Using the Test Manager, as opposed to simulating the model itself, allows you to view, manage, and export results. Also, it sets up a test framework for you to add more tests, capture baseline data, and reuse tests for other verification activities such as code generation verification.

Run the Test and Examine Results

  1. Click the Run button in the Test Manager toolstrip.

    When you click Run, the left navigation changes from the Test Browser to the Results and Artifacts pane.

  2. Examine the results. The test failed. Right-click the newest result and select Expand All Under to see all the results. The test failed because BrakeAssertion failed.

  3. Click BrakeAssertion and select the check box to visualize the results. You can see that the test failed at 2.3 seconds.

  4. Plot signals from the output. From the Data Inspector toolstrip, click Subplots and select three plots.

  5. After you create the plots, the BrakeAssertion signal stays in the first plot. Click a plot where you want a signal to appear and then click the signal. Using this technique, add Input 3 (brake input) in plot 2 and throt in plot 3.

    These plots show you that when the brake goes on (Input 3) the throttle stays on. The throttle should go to 0.

Locate the Source of the Failure

To locate the source of failure in the model, in the test results, right-click the BrakeAssertion failure and select Highlight in Model. The model highlights the BrakeAssertion block.

Create and Run a Baseline Test

In a corrected version of the model, the throttle goes to 0 if the brake is applied for three time steps. Because the model is correct, you want to commit the correct results to a test case to test against in the future.

Create Test Case and Assign System Under Test

  1. Open the model sltestBasicCruiseControlHarnessModel.

  2. In the test browser, select the test file Tutorial Tests. From the Test Manager toolstrip, select New > Baseline Test.

    The test file contains a new test suite that contains a new baseline test case.

  3. Rename the test case My Baseline Test.

  4. In the test case, under System Under Test, click the Use current model button .

Capture the Baseline

In a baseline test, you compare the outputs from a simulation against the expected outputs. You can capture the outputs in Test Manager as an Excel® file or a MAT-file. Alternatively, you can add an external file to the test case as the baseline.

  1. In the test case, under Baseline Criteria, click Capture.

  2. Set File format to Excel, enter baseline1 for the file name, and click Capture.

    The test case adds the baseline data—the output from the logged signals and the two Outport blocks.

Open the Excel file and observe the data. Select the baseline and click Edit. Time-series values appear for each of the logged signals and outputs in the model. Close the Excel file.

Run a Baseline Test

One reason to run a baseline test is for regression testing, to see whether the model output still matches the baseline. In this example, because you just created the baseline, you expect the test to pass.

Select the test case and click Run. The results match the baseline and the test passes. When you expand the results, you can see that the verify statements now pass.

Related Topics