sltest.harness.create

Create test harness

Description

sltest.harness.create(harnessOwner) creates a test harness for the model component harnessOwner, using default properties.

sltest.harness.create(harnessOwner,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Create harness for the f14 model. The harness is called sample_harness and has a Signal Builder block source and a scope sink.

f14;
sltest.harness.create('f14','Name','sample_harness','Source',...
'Signal Builder','Sink','Scope')

Create a harness for the Controller subsystem of the f14 model.

f14;
sltest.harness.create('f14/Controller');

Create a harness that uses a Stateflow® Chart as the test harness scheduler for the Controller subsystem of the f14 model.

f14;
sltest.harness.create('f14/Controller','SchedulerBlock','Chart');

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'

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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Name','controller_harness','Source','Signal Builder','Sink','To File' specifies a harness named controller_harness, with a signal builder block source and To File block sinks for the component under test.

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

Example: 'Name','harness_name'

The harness description, specified as the comma-separated pair consisting of 'Description' and a character vector.

Example: 'Description','A test harness'

The input to the component, specified as the comma-separated pair consisting of 'Source' and one of the possible source values.

Example: 'Source','Signal Builder'

For a custom source, the path to the library block to use as the source, specified as the comma-separated pair consisting of 'CustomSourcePath' and the path.

Example: 'CustomSourcePath','simulink/Sources/Sine Wave'

The output of the component, specified as the comma-separated pair consisting of 'Sink' and one of the possible sink values.

If your test harness contains a To Workspace block, the block variable is not saved in the base workspace after the test finishes running. Upon test completion, the base workspace is restored to its original state.

Example: 'Sink','Scope'

For a custom sink, the path to the library block to use as the sink, specified as the comma-separated pair consisting of 'CustomSinkPath' and the path.

Example: 'CustomSinkPath','simulink/Sinks/Display'

Option to add a separate Test Assessment block to the test harness, specified as a comma-separated pair consisting of 'SeparateAssessment' and false or true.

Example: 'SeparateAssessment',true

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 specify harness creation without compiling the main model, specified as a comma-separated pair consisting of 'CreateWithoutCompile' and false or true. This option is set to true for Subsystem model test harnesses.

false compiles the model and runs other operations to support the harness build. true creates the harness without model compilation.

Example: 'CreateWithoutCompile',false

An option to specify what type of block to use in the test harness, specified as a comma-separated pair consisting of 'VerificationMode' and the type of block to use. SIL and PIL blocks require Simulink Coder. This option is set to normal for Subsystem models.

Example: 'VerificationMode','SIL'

Path to main build folder of existing generated code verified using SIL/PIL, specified as a string or character vector. If you specify a build folder, the existing code in that folder is used, which enables faster harness creation time. If you do not specify a build folder, the code is regenerated.

Example: 'ExistingBuildFolder','C:\TestMdl\SILHarness\Amplifier_ert_rtw'

Option to have the harness rebuild when it opens, specified as the comma-separated pair consisting of 'UseDefaultName' and false or true. This option is set to true for Subsystem model test harnesses.

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. 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 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'

Use a post create callback function to customize a test harness. The post create callback function executes after the harness is created. For more information, see Customize Test Harnesses.

Example: 'PostCreateCallback','HarnessCustomization'

Use a post rebuild callback function to customize a test harness. The post rebuild callback function executes after the harness rebuild. For more information, see Customize Test Harnesses.

Example: 'PostRebuildCallback','HarnessCustomization'

Option to drive model initialize, reset, and terminate ports with the chosen test harness source, specified as the comma-separated pair consisting of 'ScheduleInitTermReset' and false or true. This option only applies to harnesses created for a block diagram. This option is set to false for Subsystem models.

Example: 'ScheduleInitTermReset',true

Option to include a scheduler block in the test harness, specified as the comma-separated pair consisting of 'SchedulerBlock' and the type of block to use. The block is included if the test harness is created for a model block diagram or a Model block and contains function calls or periodic event ports. To include no scheduler block and connect all ports to harness source blocks, use 'None' .

Example: 'SchedulerBlock','Test Sequence'

Example: 'SchedulerBlock','None'

Option to shape scalar and double values to match the dimension of the input signals to the component under test, specified as the comma-separated pair consisting of 'AutoShapeInputs' and false or true. This option only applies to harnesses with Inport, Constant, Signal Builder, From Workspace, or From File blocks. This option is set to false for Subsystem models.

Example: 'AutoShapeInputs',true

Name of reusable library subsystem function interface, specified as a string or character vector. The test harness is created for the function interface of the reusable library subsystem.

Example: 'FunctionInterfaceName','double_RLS'

Compatibility Considerations

expand all

Not recommended starting in R2018b

Introduced in R2015a