Documentation Center

  • Trials
  • Product Updates

Importing test cases from a Simulink® Signal Builder harness model into SystemTest

This example shows how to import test case data from a Signal Builder harness model into a SystemTest™ TEST-File from the MATLAB command line.

This example requires the following products to run:

  • Simulink

  • Stateflow®

Simulink Model Overview

The Simulink model is a modified version of the fuel rate controller with one root-level Inport block using a bus object, where each signal in the bus represents:

  • Throttle angle

  • Speed

  • Exhaust gas (EGO)

  • Manifold absolute pressure (MAP)

demosystest_fuelctrl_bus_model

Harness Model Overview

We would like to use the data from a Signal Builder block to test our Simulink model in SystemTest. In the current configuration, the signals of the Signal Builder block are put into a bus using a Bus Creator block, and then are fed to the test model using model reference. We import the test case data and create a SystemTest TEST-file based on the Signal Builder harness model.

st_fuelctrl_control_logic_bus_harness_model

Step 1: Read data from a Simulink® Signal Builder block

The Signal Builder block contains 5 groups (test cases) with 4 signals each. For simplicity, we only import data from the 'Driving Scenario' group. The signal names in this test case are:

  • input_bus.throttle

  • input_bus.engineSpeed

  • input_bus.EGO

  • input_bus.MAP

signalBuilderBlock = 'st_fuelctrl_control_logic_bus_harness_model/Test Cases';
[allTime allData allSignalNames allGroupNames] = signalbuilder(signalBuilderBlock);

% Get time and signals of driving scenario group (@ the 5th index)
groupData = allData(:,5);
groupTime = allTime(:,5);
groupName = allGroupNames{5};

Step 2: Create SystemTest test case object

Next we create a test case object and provide a name for the test case. This name is useful for identifying the test case in the Test Case Editor, the test results object, and in the test execution report.

testCaseName = sprintf( 'SignalBuilder Group "%s"', groupName);
signalBuilderTestCase = systest.TestCase(testCaseName);

% Update the Test Case Description
signalBuilderTestCase.Properties.Description = sprintf(['This Test Case was imported from a signal builder block.\n '...
    'BlockPath: %s\n Group: %s'], signalBuilderBlock, groupName);
Let's look at the test case object.
signalBuilderTestCase
signalBuilderTestCase = 

  systest.TestCase 

   Properties:
               Name: 'SignalBuilder Group "Driving Scenario"'
           Duration: 0 seconds
       DurationMode: 'LongestSignal'

   Signal Names:   

   Description: 

    This Test Case was imported from a signal builder block.
     BlockPath: st_fuelctrl_control_logic_bus_harness_model/Test Cases
     Group: Driving Scenario

  <a href="matlab:methods('systest.TestCase')">Methods</a>

Step 3: Create a signal object for each signal in the Signal Builder block and add it to a test case object

Next we create a signal object for each one of the test signals in the Driving Scenario group of the Signal Builder block. Each signal object is then added to a test case object.

for signalIdx = 1 : length(allSignalNames)

    % Extract the time and data for each signal
    timeValues = groupTime{signalIdx};
    dataValues = groupData{signalIdx};

    % Create a signal with custom segment
    signal = systest.signals.Signal('Custom', {'Time', timeValues, 'Data', dataValues});

    % Get the signal name
    signalFullName = allSignalNames{signalIdx};

    % Assign the bus signal to the test case
    signalBuilderTestCase.(signalFullName) = signal;
end
Looking at the test case object, we now see that "input_bus" has been
assigned to the test case object and appears under Parameter Name.
signalBuilderTestCase
signalBuilderTestCase = 

  systest.TestCase 

   Properties:
               Name: 'SignalBuilder Group "Driving Scenario"'
           Duration: 100 seconds
       DurationMode: 'LongestSignal'

   Signal Names:   
      input_bus: [1x1 struct]

   Description: 

    This Test Case was imported from a signal builder block.
     BlockPath: st_fuelctrl_control_logic_bus_harness_model/Test Cases
     Group: Driving Scenario

  <a href="matlab:methods('systest.TestCase')">Methods</a>

Step 4: Create a SystemTest TEST-File and add the test case to it

We can automatically generate a preconfigured SystemTest TEST-File for our model from the MATLAB command line. For more information, see the example Creating test harness for a model using buses at the root-level inports

testFileName = 'demosystest_fuelctrl_harness.test';
modelName = 'demosystest_fuelctrl_bus_model.mdl';
systest.createHarness(testFileName, modelName);

Now we are ready to append the test case to the TEST-file.

% Load existing test cases from the TEST-file
testCases = stLoadTestCases(testFileName);

% Append the signal builder test case
testCases = [testCases signalBuilderTestCase];

% Save the test cases to the TEST-file
stSaveTestCases(testFileName,testCases);
The appended test cases will be run in the second iteration of the test.
testCases
testCases = 

    A [1x2 systest.TestCase] array 

    SignalNames: input_bus.throttle, input_bus.engineSpeed, input_bus.EGO, input_bus.MAP

    Name                                        Duration      DurationMode       
    -----------------------------------------------------------------------------
    TestCase1                                   10            LongestSignal      
    SignalBuilder Group "Driving Scenario"      100           LongestSignal      
Was this topic helpful?