Main Content

Verify and Validate Variant Models with Startup Activation Time

This example shows how to verify and validate variant models with startup variant activation time using Simulink® Design Verifier™ and test it using Simulink Test™.

Model

Open the model slexStartupVariantVnVWorkflow. The model contains a Variant Subsystem block, ComputeTargetSpeed, with two variant choices, ComputeTargetSpeed_Config1 and ComputeTargetSpeed_Config2. In this example, we use Simulink Design Verifier to generate test cases for models that contain startup variants and run predefined tests cases for the model using Simulink Test Manager.

  • To launch Simulink Design Verifier and automatically generate test cases for the variant choices in the model, double-click the SLDV Run button.

  • To launch the Simulink Test Manager, click the Open Simulink Test Manager button in the model. The Simulink Test Manager is launched with predefined tests cases for the slexStartupVariantVnVWorkflow model. To run each parameter set iteratively across the selected baseline, click Run. Once the test runs successfully, you will notice that the model output matches the expected output.

Use Simulink Design Verifier to Generate Test Cases

Simulink Design Verifier can analyze all variant choices in single analysis run if the activation time is set to startup. To analyze all variant choices in a single run, the Analyze all Startup Variants configuration parameter must be enabled. To enable the configuration parameter:

  • In the Simulink Editor, on the Modeling tab, click Model Settings.

  • In the Configuration Parameters dialog box, click Design Verifier in the left side pane and select Parameters and Variants. In the Parameters and Variants pane, the Analyze all Startup Variants parameter is selected by default. If you de-select this parameter, Simulink Design Verifier analyzes only the active variant of the variant blocks with Variant activation time parameter set to startup.

In the MATLAB® Command Window, run the script corresponding to each of these steps. The SLDV Run button in the model automates the same script.

Step 1: Set the required Simulink Design Verifier options. For information on the options, see sldvoptions (Simulink Design Verifier).

modelName='slexStartupVariantVnVWorkflow';
open_system(modelName);
%Create a design verification options object for the model.
opts = sldvoptions(modelName);
%Specify the optimization strategy to use when generating test cases.
opts.TestSuiteOptimization = 'Auto';
%Generate and save a Simulink Design Verifier report.
opts.SaveReport = 'on';
%Create unique reports for each variant choice.
opts.MakeOutputFilesUnique = 'on';
%Create a harness model generated by the Simulink Design Verifier analysis.
opts.SaveHarnessModel = 'off';
%Specify the analysis mode.
opts.Mode = 'TestGeneration';
%Display Simulink Design Verifier report.
opts.DisplayReport = 'off';
%Analyze the models for startup Variant.
opts.AnalyzeAllStartupVariants =  on ;

Step 2: Analyze the model.

%Track the execution progress from MATLAB command prompt.
disp([newline 'Performing SLDV Run for Model ' modelName ' for all variant choices']);
disp(newline);
%Analyze the model to generate test cases and display messages in the log window.
[status,fileNames] = sldvrun(modelName, opts, true);

Step 3: Repeat Step 2 for the variant choice ComputeTargetSpeed_Config2.

assignin('base','speedConfig',2);
opts.ReportFileName = ([modelName 'report_speedConfig2']);
disp([newline 'Performing SLDV Run for Model ' modelName ' with variant choice : SpeedConfig 2']);
set_param(modelName, 'SimulationCommand', 'Update');
[status1,fileNames] = sldvrun(modelName, opts, true);

Step 4: Display the test generation status.

if status & status1
disp('Simulink Design Verifier test generation completed.');
end

After the analysis is complete, the Simulink Design Verifier Results Summary window opens and shows different ways you can use the results. See Review Analysis Results (Simulink Design Verifier).For more information about analyzing models with variants using Simulink Design Verifier, see Analyze all Startup Variants in Design Verifier Pane: Parameters and Variants (Simulink Design Verifier)

Use Simulink Test to Execute Tests

The startup variant with the fast restart workflow allows you to switch the active variant choice in each iteration without the need to recompile the model to change the active variant. You can create parameter sets with different variant configurations in fast restart mode to test your systems without needing to recompile the model. To make the Simulink Test workflow iterative, use the startup variant activation time and run the test iterations in fast restart.

Start Test Manager

To setup and run the test iterations in Fast restart and compare the model output with the expected output, follow the steps in this tutorial.

1 Open the model, slexStartupVariantVnVWorkflow.

  open_system('slexStartupVariantVnVWorkflow');

2 To start Test manager, on the Apps tab, under Model Verification Validation, and Test click Simulink Test. On the Tests tab, click Simulink Test Manager.

Associate Model and Test Harness

Test suites contain one or more test cases and the default test case is a baseline test. Create a test suite and a new baseline test.

1 From the Test Manager toolstrip, select New > Test Suite. Right-click Test Suite to create a new Baseline Test.

2 Set the test case to use the model. In the above example, the model in use is slexStartupVariantVnVWorkflow. In Test Manager, under System Under Test, click the Use current model button.

3 Select the slexStartupVariantVnVWorkflow_mdlHarness from the Harness drop down under Test Harness.

Create Parameter Sets

Create parameter sets and add the variant control variable with the respective value. Each parameter set aligns with a specific variant control value. In the above example,there are two parameter sets corresponding to the variant control expressions speedConfig = 1 and speedConfig = 2. To override a model parameter,

1 Expand the Parameter Overrides section in the test case and click Add.

2 Click update diagram to get model parameters.

3 Select the variant control parameter from the list. In the above example, it is speedConfig.

Simulink Test Manager allows iterations in the Iterations section of the test case. The Table Iterations provide a quick way to add iterations based items in your model or test case. Click Auto-generate the iterations. Select the Parameter Set option from the list.

Note: If your model has variant configurations defined using Variant Manager for Simulink, you can use those configurations when running tests programmatically (since R2024a) or from Simulink Test Manager (since R2024b). With this workflow, you do not need to create parameter sets to redefine the variant control variable values to use with the test cases or test iterations. For an example, see Run Tests for Variant Models Using Variant Configurations.

Capture Baseline

When a baseline test case executes, the Test Manager captures signal data from signals in the model marked for logging and compares them to the baseline data. 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 and select the option Capture Baselines for Iterations. Specify the path to the iterations. In the above example,the path to DisengageWithDisable has been specified. Notice that the Baseline gets populated in the Table Iterations corresponding to each parameter set.

Run the Baseline Test

Baseline tests compare the outputs from a simulation against the expected outputs. Ensure you have selected the Run Test Iterations in Fast Restart in the Table Iterations section. To run each parameter set iteratively across the selected baseline, click Run.