Main Content

sltest.harness.import

Import Simulink model to test harness

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.

mainModel = 'sltestBasicCruiseControl';
harnessModel = 'sltestBasicCruiseControlHarnessModel';

1. Load the main model.

load_system(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']);
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 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: 'Name','harness_name','RebuildOnOpen',true

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'

Option to specify when the component under test synchronizes the main model and the test harness. Subsystem model test harnesses are always synchronized with their underlying model.

  • "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 numeric or logical 1 (true) or 0 (false).

Example: RebuildOnOpen=true

Option to have the configuration set and model workspace entries updated during test harness rebuild, specified as numeric or logical 1 (true) or 0 (false). This option is set to true for Subsystem model test harnesses.

Example: RebuildModelData=true

Option to have each test harness saved as a separate SLX file, specified as numeric or logical 1 (true) or 0 (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'

Data Types: char

Version History

Introduced in R2017a