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
sltestCruiseControlDefectivemodel in the
To start the Test Manager, on the Apps tab, under Model Verification, Validation, and Test, click Simulink Test. On the Tests tab, click Simulink Test Manager.
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
Set the current folder to a writable folder.
Create a test file. From the Test Manager toolstrip, select New > Test File.
Name the file
Tutorial Testsand 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.
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.
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 Editor 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
Click Run in the Test Manager Toolstrip.
When you click Run, the left navigation changes from the Test Browser to the Results and Artifacts pane.
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
Click BrakeAssertion and select the check box to visualize the results. You can see that the test failed at .23 seconds.
Plot signals from the output. From the Data Inspector tab, click Subplots and select three plots.
After you create the plots, the
BrakeAssertionsignal stays in the first plot. Click a plot where you want a signal to appear and then click the signal. Using this technique, add
Inputs1:3(brake input) in plot 2 and
throtin plot 3.
These plots show you that when the brake goes on (
Inputs1: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
Create and Run a Baseline Test
Baseline tests compare the outputs from a simulation against the expected outputs. 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
Open the model
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.
Rename the test case
My Baseline Test.
In the test case, under System Under Test, click Use current model .
Capture the Baseline
You can capture the baseline test 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.
In the test case, under Baseline Criteria, click Capture.
Set File format to
baseline1for the filename, 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.