Documentation Center

  • Trial Software
  • Product Updates

Programmatic Test Case and Signal Authoring

Overview

The functionality of the Test Case Editor, as described in this chapter, is also available via a command-line interface. The functions allow you to do the following tasks programmatically:

  • create test cases, signals, and segments

  • add test cases, signals, and segments to a SystemTest™ test

  • configure and edit test cases, signals, and segments in a test

  • extract test cases, signals, and segments from a test

For information on usage and syntax of the functions, see these reference pages.

The objects:

The saving and loading functions:

The signal manipulation functions:

Load and Save Test Cases

If you have a test with test cases you can load and save them programmatically. The test cases can be created using the Test Case Editor, as described in this chapter, or they can be created with the automatic test harness generation feature. A test can be generated automatically from Simulink® (see Generate a Test Harness from Simulink), or via the command line (see Generate Test Harness at the Command Line).

In this example workflow, we will generate a test automatically, then load the test cases, modify them, then save the test cases.

  1. Create a SystemTest test called myTest.test from the command line based on the model myModel.

    systest.createHarness('myModel', 'C:\Work\myTest.test'); 

    The test is created and put into your C:\Work folder.

  2. As part of the test generation, one or more test cases are created with signal names corresponding to the Inport blocks in your model. You can now access the test case(s) programmatically.

    Load the test cases contained in the test myTest.test.

    testCases = stLoadTestCases ('myTest.test');
  3. You can now modify the test cases, using the functions listed in Overview. For example, you could add and/or modify signals contained in the test case(s).

  4. After you have finished working with the test case(s), you can save them back to the test.

    stSaveTestCases('myTest.test', testCases);
  5. Load the test in the SystemTest desktop.

    systemtest('myTest.test')

Edit Test Cases

You can add test cases, signals, and segments to a test and configure and edit existing test cases, signals, and segments in a test.

signal = systest.signals.Signal(segment_type) creates a signal with a segment of type segment_type.

For a list of supported segment types and their properties, see the reference page for the systest.signals.segments function.

The following is an example workflow of editing existing test cases. In this case we load the test case, add a signal to it, then save the test case.

  1. Load the test cases contained in the test myTest.test.

    testCases = stLoadTestCases ('myTest.test');
  2. Create a ramp segment with an Offset of 2 and a FinalValue of 6.

     segment = systest.signals.segments.Ramp('Offset', 2, 'FinalValue', 6)
  3. Update the first test case's signal MySignal to use the new segment.

     testCases(1).MySignal.Segments = segment;
  4. After you have worked with the test case(s), you can save them back to the test.

    stSaveTestCases('myTest.test', testCases);

Create Signals

You can create signals with default properties or create them and specify properties. You can create the following signal/segment types:

  • Constant – A segment with a constant value.

  • Custom – A segment with user-specified time and data vectors.

    Properties include:

  • Pulse – A segment with a pulse value.

  • Ramp – A segment with a linearly changing value.

  • Sine – A periodic sine wave.

  • Square – A periodic series of pulses.

  • Step – A segment that transitions from a one value to another.

For a list of the properties for each segment type, see the reference page for the systest.signals.segments package.

If you add a segment and do not specify any properties, it is created with default properties. Default properties of the signals are defined in Signal Types. To add properties, follow the syntax shown in the examples below.

Creating Signals with Default Values

Create a signal with one segment using default values, in this case a constant.

systest.signals.Signal('Constant')

Create a Signal with two segments using default values, in this case a constant segment followed by a step.

systest.signals.Signal('Constant', 'Step')

Creating Signals with Properties

Create a segment with one property, in this case a Constant segment with a Value of 5 .

 segment = systest.signals.segments.Constant('Value', 5)

Create a segment with multiple properties, in this case a ramp segment with an Offset of 2 and a FinalValue of 10.

 segment = systest.signals.segments.Ramp('Offset', 2, 'FinalValue', 10)

Appending Segments to Signals

If you create segments, you need to append them to signals. The following is an example of creating a signal, creating segments, then adding the segments to the signal.

Create a signal with one segment.

 signal = systest.signals.Signal('Step');

Create two stand-alone segments.

 ramp = systest.signals.segments.Ramp();
 pulse = systest.signals.segments.Pulse();

Add the two segments to the end of the signal's Segments property, which is an array of segment objects.

 signal.Segments = [signal.Segments ramp pulse]

Import from External Source to Test Case

You can use the programmatic interface to import test cases from external sources, such as an Excel® file, a Simulink Signal Builder harness, or a Simulink Design Verifier data file.

The following is an example of the basic high-level workflow of importing data from an external source. To see the details of this example, see the example "Importing Test Cases from Excel into a Test Harness" by opening the SystemTest Help, then Examples > Programmatic Interface > Importing Test Cases from Excel into a Harness.

  1. Start with a model. In the case of this example, the model contains an Inport block with a bus that contains four signals.

  2. The example imports a test case from a single worksheet in an Excel file using the function xlsread. It also assigns the data in the columns to signals in the test case.

  3. Create a test case using the systest.TestCase function.

  4. Create signals from the data in the spreadsheet columns using the systest.signals.Signal function.

  5. Create a SystemTest test file using the systest.createHarness function.

  6. Then append the test case to the newly created test using the stLoadTestCases and stSaveTestCases functions.

To see the specific commands for these steps, see the above referenced example in the SystemTest Help.

Was this topic helpful?