Main Content

sltest.import.sldvData

Create test cases from Simulink Design Verifier results

Description

[owner,testHarness,testFile,testCase] = sltest.import.sldvData(dataFile) creates a test harness and test file using Simulink® Design Verifier™ analysis results contained in dataFile. The function returns the model component owner associated with the test case, the test harness, the test file, and test case. If a test case or iteration is for a Requirements Table block, the corresponding requirements are linked automatically in the test case or iteration.

[owner,testHarness,testFile,testCase] = sltest.import.sldvData(dataFile,Name,Value) creates a test harness and test file using additional options specified by one or more Name,Value pair arguments. Specify name-value pair arguments after the data file input argument.

Examples

collapse all

Open the sldvdemo_cruise_control model. Set the option to generate the test. Then, use sldvrun to generate the Simulink Design Verifier data file. Import the Simulink Design Verifier data so it is usable by Simulink Test.

open_system('sldvdemo_cruise_control');

opts = sldvoptions;
opts.Mode = 'TestGeneration';     

[status,files] = sldvrun('sldvdemo_cruise_control',opts)
05-Sep-2024 22:14:53
Checking compatibility for test generation: model 'sldvdemo_cruise_control'
Compiling model...done
Building model representation...done

05-Sep-2024 22:15:03

'sldvdemo_cruise_control' is compatible for test generation with Simulink Design Verifier.

Generating tests using model representation from 05-Sep-2024 22:15:03...


Generating output files:

05-Sep-2024 22:15:26
Results generation completed.

    Data file:
    /tmp/Bdoc24b_2725827_3677076/tpf4212701/simulinktest-ex90358021/sldv_output/sldvdemo_cruise_control/sldvdemo_cruise_control_sldvdata.mat
status = 
1
files = struct with fields:
                                DataFile: '/tmp/Bdoc24b_2725827_3677076/tpf4212701/simulinktest-ex90358021/sldv_output/sldvdemo_cruise_control/sldvdemo_cruise_control_sldvdata.mat'
                            HarnessModel: ''
                          SystemTestFile: ''
                                  Report: ''
                               PDFReport: ''
                                 LogFile: ''
                          ExtractedModel: ''
                   BlockReplacementModel: ''
    ModelReferenceBlockReplacementModels: ''
                              SLTestFile: ''

[owner,testharness,testfile,testcase] = sltest.import.sldvData...
   (files.DataFile,'TestHarnessName','CoverageHarness',...
   'TestFileName','CoverageTests')
owner = 
'sldvdemo_cruise_control'
testharness = 
'CoverageHarness'
testfile = 
'/tmp/Bdoc24b_2725827_3677076/tpf4212701/simulinktest-ex90358021/CoverageTests.mldatx'
testcase = 
  TestCase with properties:

             Name: 'New Test Case 1'
         TestFile: [1x1 sltest.testmanager.TestFile]
         TestPath: 'CoverageTests > New Test Suite 1 > New Test Case 1'
         TestType: 'baseline'
      RunOnTarget: {[0]}
    RunOnPlatform: {[Desktop]}
           Parent: [1x1 sltest.testmanager.TestSuite]
     Requirements: [0x1 struct]
      Description: ''
          Enabled: 1
             Tags: [0x0 string]

open(testfile)

% Clean up Test Manager
sltest.testmanager.clear
sltest.testmanager.clearResults
sltest.testmanager.close

Input Arguments

collapse all

Path and filename of the MAT data file generated by Simulink Design Verifier sldvrun analysis, specified as a character vector or string scalar. The data file can contain one or more baseline test cases and optionally, expected outputs. When there are multiple test cases in the file, each test case is imported as an iteration. When you import the file into Simulink Test™, the import function creates an MLDATX test file, and if you specify the ExcelFilePath, an Excel® file containing input values at that location. If the Excel file already exists, a new sheet is added to the file.

Example: 'ShiftLogic0/ShiftLogic0_sldvdata.mat'

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'TestHarnessName','DatafileHarness','CreateHarness',false

Option to add or reuse a test harness for the model or model component, which corresponds to the test cases in the test file, specified as a comma-separated pair consisting of 'CreateHarness' and true or false.

If you specify true, the import function Simulink Design Verifier creates a new test harness with the name you specify using the 'TestHarnessName' name-value pair.

If you specify false, the import function reuses the existing test harness you specify using the 'TestHarnessName' name-value pair.

Note

If the model under analysis is a test harness, the CreateHarness default value is false.

Example: 'CreateHarness',false

The test harness used for running the test cases, specified as the comma-separated pair consisting of 'TestHarnessName' and the name of a test harness.

A new test harness with the specified TestHarnessName is created if CreateHarness is true. An existing test harness with the specified TestHarnessName is reused if CreateHarness is false.

Example: 'TestHarnessName','ModelCoverageTestHarness'

The source of the test harness if CreateHarness is true, specified as the comma-separated pair consisting of 'TestHarnessSource' and 'Inport' or 'Signal Editor'.

  • Inport — The inputs are contained in the Simulink Design Verifier data file and mapped to Inport blocks in the test harness. Using the Inport option allows you to map other inputs to the test harness Inport blocks, which can be useful for running multiple test cases or iterations using the same test harness. Both MAT and Excel files are supported when the source is Inport.

  • Signal Editor — The inputs are in scenarios in a Signal Editor block inside the test harness. The Signal Editor block supports MAT files that contain these inputs. You can edit the scenarios in the Signal Editor.

Example: 'TestHarnessSource','Inport'

The name for the test file created for the test cases, specified as the comma-separated pair consisting of 'TestFileName' and the name of a test file, the name of the text file followed by the MLDATX extension, or the full path to the test file.

Example: 'TestFileName','ModelCoverageTests'

Example: 'TestFileName','ModelCoverageTests.mldatx'

Example: 'TestFileName','C:\myTests\coverage\ModelCoverageTests.mldatx'

The path to the model extracted from Simulink Design Verifier analysis, specified as the comma-separated pair consisting of 'ExtractedModelPath' and a path.

Simulink Test uses the extracted model to generate the test harness. By default, sltest.import.sldvData looks for the extracted model in the output folder specified in the Simulink Design Verifier configuration parameters. Use ExtractedModelPath if the extracted model is in a different location.

Simulink Design Verifier does not use an extracted model when you analyze a top-level model.

Example: 'Tests/ExtractedModels/'

The existing test case to use for the import operation, specified as the comma-separated pair consisting of 'TestCase' and an sltest.testmanager.TestCase object. Do not specify any other name-value pair when you use this option.

Example: 'TestCase',myTestCase

Path of the Excel file that contains input values to test, specified as a character vector or string scalar. If you specify this path, the input signals for each iteration are saved to an Excel file. If the file already exists, a new sheet is added to it.

Example: 'ExcelFilePath','ShiftLogic_sldvdata.xlsx'

Output Arguments

collapse all

Path of the component under test, returned as a character vector

Example: 'ShiftLogic0/ShiftLogic0_sldvdata'

Name of the test harness for running the test cases, returned as a character vector.

Name of the test file created or updated using the test cases, returned as a character vector.

Name of the newly created or updated test case, returned as an sltest.testmanager.TestCase object. For multiple test cases, each test case is captured as an iteration.

Version History

Introduced in R2015b