Documentation

sltest.harness.import

Import Simulink model to test harness

Syntax

sltest.harness.import(harnessOwner,'ImportFileName',importModel,'ComponentName',TestedComponent)
sltest.harness.import(harnessOwner,'ImportFileName',importModel,'ComponentName',TestedComponent,Name,Value)

Description

sltest.harness.import(harnessOwner,'ImportFileName',importModel,'ComponentName',TestedComponent) creates a test harness from the Simulink® model importModel, with a default harness name, associated with harnessOwner, with TestedComponent the harness component under test.

sltest.harness.import(harnessOwner,'ImportFileName',importModel,'ComponentName',TestedComponent,Name,Value) uses additional Name,Value arguments to specify test harness properties.

Examples

collapse all

This example shows how to use sltest.harness.import to create a test harness by importing a standalone verification model. You create a test harness for a basic cruise control subsystem.

The standalone model contains a Signal Builder block driving a copy of the Controller subsystem, with a subsystem verifying that the throttle output goes to 0 if the brake is applied for three consecutive time steps.

exPath = fullfile(matlabroot,'examples','simulinktest');
mainModel = 'sltestBasicCruiseControl';
harnessModel = 'sltestBasicCruiseControlHarnessModel';

1. Load the main model.

load_system(fullfile(exPath,mainModel))

2. Create a test harness from the standalone model. Create the harness for subsystem Controller in the main model, with Controller the harness component under test.

sltest.harness.import([mainModel '/Controller'],'ImportFileName',harnessModel,...
    'ComponentName',[harnessModel '/Controller'],'Name',...
    'VerificationSubsystemHarness')

3. Return the properties of the new test harness.

testHarnessProperties = sltest.harness.find([mainModel '/Controller'])
testHarnessProperties = 

  struct with fields:

                  model: 'sltestBasicCruiseControl'
                   name: 'VerificationSubsystemHarness'
            description: ''
                   type: 'Testing'
            ownerHandle: 6.0018
          ownerFullPath: 'sltestBasicCruiseControl/Controller'
              ownerType: 'Simulink.SubSystem'
                 isOpen: 0
            canBeOpened: 1
               lockMode: 0
       verificationMode: 0
         saveExternally: 0
          rebuildOnOpen: 0
       rebuildModelData: 0
    postRebuildCallback: ''
              graphical: 0
                origSrc: 'Signal Builder'
               origSink: 'Outport'
    synchronizationMode: 2

close_system(mainModel,0)

Input Arguments

collapse all

Model or component handle or path, specified as a character vector or double

Example: 1.9500e+03

Example: 'model_name'

Example: 'model_name/Subsystem'

Path to the standalone model to import as a test harness

Example: 'C:\MATLAB\sltestBasicCruiseControlTestModel'

The name or path and name of the tested component in the standalone model. After import, this component is linked to the harnessOwner component in the main model.

Example: 'Controller'

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example:

collapse all

The name for the harness you create, specified as the comma-separated pair consisting of 'Name' and a valid MATLAB filename.

Example:

'Name','harness_name'

An option to specify when the component under test synchronizes between the main model and the test harness.

  • 'SyncOnOpenAndClose' rebuilds the component under test from the main model when the test harness opens, and pushes changes from the component under test to the main model when the test harness closes.

  • 'SyncOnOpen' rebuilds the component under test from the main model when the test harness opens. It does not push changes from the component under test to the main model when the test harness closes.

  • 'SyncOnPushRebuildOnly' rebuilds and pushes changes only when you manually initiate rebuild or push for the entire test harness. For more information, see Synchronize Changes Between Test Harness and Model.

Example:

'SynchronizationMode','SyncOnOpen'

Option to have the harness rebuild when it opens, specified as the comma-separated pair consisting of 'UseDefaultName' and false or true.

Example:

'RebuildOnOpen',true

Option to have the configuration set and model workspace entries updated during test harness rebuild, specified as the comma-separated pair consisting of 'RebuildModelData' and true or false.

Example:

'RebuildModelData',true

Option to have each test harness saved as a separate SLX file, specified as the comma-separated pair consisting of 'SaveExternally' and true or false. A model cannot use both external and internal test harness storage. If a model already has test harnesses, a new test harness follows the storage type of the existing harnesses, which this option does not override. See Manage Test Harnesses.

Example:

'SaveExternally',true

If 'SaveExternally' is specified, you can specify a location for the external harness SLX file using a comma-separated pair consisting of 'HarnessPath' and a character vector..

Example:

'HarnessPath','C:\MATLAB\SafetyTests'

Introduced in R2017a

Was this topic helpful?