Test Case Input Data Files

You can use Test Manager to create MAT-file and Microsoft® Excel® data files to use as inputs to test cases. You generate a template that contains the signal names and the times, and then enter the data.

Creating a data file also adds the file to the list of available input files for the test case. After you add input data, you can then select the file to use in your test case.

You can create files for input data only for tests that run in the current release. To select the release, in the test case, use the Select releases for simulation list.

You can edit input files. After you create the template, select the file from the list of input files and click Edit. MAT-files open in the signal editor. Excel files open in Excel.

Selecting the Add an iteration that runs this input check box adds an iteration to the test case under Table Iterations and assigns the input file to it. After you create the input file, continue to specify the iteration. For more information on iterations, see Test Iterations.

Generate an Excel Template

You can generate a template test spreadsheet from a model or harness (system under test [SUT]). You can then complete the spreadsheet with external data and import it into Simulink® Test™ as a test case.

The Create Test from Spreadsheet wizard parses the SUT for test attributes and automatically generates a template spreadsheet and a test case:

  • Inputs — Inputs are characterized by root input ports

  • Parameters — Named parameters in the model

  • Comparison signals — Logged signals and output ports

The wizard allows you to filter and edit the attributes needed for testing. The resulting spreadsheet has separate column sets for inputs, parameters, and comparison signals. If multiple iterations are required, a separate sheet in the same file is generated for each scenario. You can expand the spreadsheet to add time-based signal data, tolerances, and parameter overrides. See Format Test Case Data in Excel for the full description of the format readable by Simulink Test.

You can use the model coordinate_transform_test as an example for the process. The model must be on the MATLAB® path.

  1. Open the test manager. On the Apps tab, under Model Verification, Validation, and Test, click Simulink Test. Then, on the Tests tab, click Simulink Test Manager.

  2. Open the wizard. From Simulink Test Manager, select New > Test from Spreadsheet. Select Create a test template file for specifying data and follow the prompts.

  3. In the Attributes page, select which attribute categories are to be included in the spreadsheet. For example, if parameter overrides are not necessary for the tests, clear Parameters. The attribute categories shown on the page are derived from the SUT. Comparison signals are always shown.

  4. If the test requires all attributes in a category as is, select Yes, include all attributes in the spreadsheet and click Next. If not, select No, I want to filter and edit the attributes. This shows a page with a tab for each attribute category.

  5. If you are filtering the attributes, in the Parameters and Comparison tabs, clear the attributes that are not needed. For example, you can remove a logged signal from this list if it is not to be used for comparison in the tests.

  6. Optionally change tolerances in the Comparison page. The tolerance settings apply to all signals in the list. To specify different tolerances for each signal, edit the spreadsheet after it is generated.

    If you change the SUT during the selection process, click Refresh to synchronize the attribute lists with the SUT. Once selection is complete, click Next and keep following the prompts.

  7. In the Scenarios page, specify the number of test scenarios and a base name for the sheets in the spreadsheet.

If comparison signals are selected, the wizard runs the model to capture the baseline. Make sure that the model does not run indefinitely by setting a finite stop time. The wizard creates two files:

  • Excel spreadsheet — The spreadsheet includes columns for inputs, parameters, and comparison signals. Inputs and comparisons have different time bases. An identical sheet for each test scenario is generated. Complete the spreadsheet outside MATLAB to uniquely define each scenario.

  • Test file — The test case imports the Excel spreadsheet. The fields defined in the spreadsheet are locked to the spreadsheet, and cannot be edited in the Test Manager.

    To change the locked fields, edit the spreadsheet outside MATLAB.If you change a parameter, you must capture the baseline again by clicking the Capture button.

Format Test Case Data in Excel

You can specify signal data in a Microsoft Excel file to use as input to your test case or as baseline criteria (outputs). The Excel file includes time and signal data. To support a range of models and configurations, you can specify signal data of most data types. For exceptions, see Limitations. You can indicate whether signals are scalar, multidimensional, or complex. You can optionally specify the data type, block path and port index, units, interpolation type, and function-call execution times.

Basic Excel File Format

The figure shows the basic format of the Excel file. This example uses scalar signals and the default data type, double, for all signals.

  • When specifying time and signal data (and not function-call execution times), the time column is the first column. Time values must increase in value, and every cell must contain a value. .

  • Include one column for each input signal in the first row. In each column, include the signal data for each time point. Signal names are case-sensitive.

  • If dataset elements have different time vectors, the spreadsheet can have more than one time column. In this case, the columns to the right of each time column, up to the next time column, define signals along that time vector. The signal columns must have the same number of rows as the time column they define values for. The figure shows an example that has a time column for each time vector.

When you import data, you specify the mapping mode. To map using signal or block names, add the block or signal names and qualifiers in the first row. If you are mapping using block path and name, also specify them in the optional rows (see Block Path and Port Index). If you are mapping using port numbers, signal columns map to the model ports in order during import, ignoring the block or signal names.

Input and Output Data

You can save inputs and outputs in the same Excel file in the same sheet. Specify whether the signals are for inputs or outputs in one of the optional rows, using Source:Input or Source:Output as the label. Keep all the inputs together and all the outputs together.

To import the file as input data, use the Inputs section of the test case, described in Run Tests Using External Data. To use the Excel file as expected outputs, select it to add as baseline data, in the Baseline Criteria section of the test case, described in Baseline Criteria.

When you capture inputs and expected outputs in Test Manager, you can save inputs and outputs to the same Excel file. Both sets of data are saved to the same sheet unless you specify a different sheet. Saving the inputs or expected outputs adds the file to the test. See Capture Baseline Criteria.

Parameters

You can save parameter override values in the same Excel file in the same sheet. Specify the name of the parameter in the Parameter: column and the override value in the Value: column. Each row corresponds to a parameter. Enter vector and matrix parameters as you would in MATLAB. You can also use MATLAB expressions for parameter values. Values are read as strings and are evaluated at runtime. Signal data and parameter data start on the same row.

The Parameter column must precede the Value column and both columns are required. For a parameter in a masked subsystem, add a third column MaskBlockPath and enter the path to the block.

Signal Tolerances

You can specify tolerances for comparison signals in the Excel file. It is possible to define one or more tolerance types for each signal, in any order. Prefix the tolerance value with one of: AbsTol:, RelTol:, LeadingTol:, LaggingTol:. The format is <ToleranceType>:<ToleranceValue>.

Tolerances are interpreted as floating-point doubles. Each tolerance type should be in a dedicated row. Once a row is declared to be a certain type of tolerance, all columns in that row must be of that type. An empty cell is treated as tolerance of zero. For more information on tolerances, see Compare Model Output To Baseline Data.

Simulation for Equivalence Tests

When you perform equivalence tests in Test Manager, you compare the results of two simulations. If your Excel input file is for an equivalence test, you can specify the inputs for each simulation. Specify the simulation in one of the optional rows, using Simulation:1 or Simulation: 2 as the label. Keep the inputs for each simulation together.

Scalar, Multidimensional, Complex, and Bus Signals

In addition to scalar signal names, you can indicate multidimensional, complex, and bus signals, or a combination of these. The figure shows some examples.

Specify block paths, and optionally, port index in one of the optional rows. See Block Path and Port Index.

Base Name.  Names are case-sensitive.

Multidimensional Signals.  Use parentheses with the signal dimension after the signal name. For example:

  • mySignal(1,3)

Dimensions on the signal that you do not specify default to zeros of the same data type and complexity as the dimensions that you specify.

Complex Signals.  For complex signals, use (real) or (imag) with the signal name. For example:

  • mySignal (real)

  • mySignal (imag)

  • mySignal(1,3) (imag)

If you do not specify a real counterpart to an imaginary number, the real value defaults to zeros.

Bus Signals.  Specify bus signals in the form signalname.busElement.nestedElement for as many nested elements as the bus has. For example:

  • myBusSignal.x

  • busSignal2.x.z

Suppose the inport block myBus is a bus object with this structure:

In this case, specify the signal as myBus.a.w.

The figure shows an example of specifying bus signals with a bus data type (see Data Type). The BusObj data type also applies to the columns to the right because the base name for these signals is the same.

Block Path and Port Index.  If you want to specify the signal using the block path, enter it in one of the optional rows in the form BlockPath: path to block. When you specify a block path, you can also specify the block port index. The default port index is 1. Enter the port index in the row following the block path in the form PortIndex: port number. For example:

  • BlockPath: mymodel/myblock

  • PortIndex: 2

Data Type, Unit, Interpolation, and Block Path/Port Index

In the optional rows between the signal name and the time and signal data, you can include any combination of information about the signal:

Data Type.  Enter data types in the row after the signal name. The default data type is double.

You can mix data types in the same row, but you must use the same data type for all columns of a multidimensional or complex signal.

You can leave the columns to the right of the data type declaration empty if that data type applies to the signal data in those columns. For example, here the data type int16 applies to columns B and C because they are dimensions of the same signal.

Built-In MATLAB Data Types.  

Specify built-in MATLAB data types supported in Simulink in the form Type: data type. See Data Types Supported by Simulink (Simulink). For example:

  • Type: int16

  • Type: uint32

Enumerations.  

Specify an enumeration data type in the form Enum: class. For example:

  • Enum: school

The data in the cells correspond to enumerated values. For example:

Enum data type dimensions that do not have data default to the default enumeration value.

Fixed Point.  

Indicate a fixed-point data type using the prefix Fixdt:, followed by the data type in one of these forms:

  • A fixdt constructor, for example, Fixdt: fixdt(1,16).

  • A unique data type name string, for example, Fixdt: sfix16_B7. To learn about specifying data type names, see Fixed-Point Data Type and Scaling Notation (Fixed-Point Designer).

  • A numerictype object in the base workspace, for example, Fixdt: mytype.

Bus.  

Specify the bus object in the form Bus: bus object with a bus signal. For example:

  • Bus: BusObject1

To specify a bus signal, see Bus Signals.

Alias.  

Specify an alias data type in the form Alias: alias type. To learn about alias data types, see Simulink.AliasType.

Units.  Optionally, include a row for units. Specify units in the form Unit: units. You can specify units and physical quantity. For example:

  • Unit: g

  • Unit: kg@mass

Interpolation.  Optionally, include a row for interpolation. The default is linear. Specify interpolation as Interp: zoh or Interp: linear.

Synchronization.  Optionally, include a row for synchronization. The default is union. Specify synchronization as Sync: union or Sync: intersection.

Function-Call Execution Times

If the model contains control signals for function-call subsystems, add columns for each one before the first time column. Enter the control signal name in the column heading. Enter the points of time when you want to execute the function call in the column.

Function-call execution times that you specify are independent of the times in the time column. The figure shows how to format two function-call blocks that execute at various times. The time and signal data and data type information are independent of the function-call information.

Limitations

Arrays of buses as a data type are not supported.

Create a MAT-File for Input Data

  1. In the test case, under System Under Test, specify the model whose input data you want to create a MAT-file for.

  2. In the Inputs section of the test case, click Create.

  3. In the dialog box, set the file format to MAT-file. Specify the location for the MAT-file and click Create.

    The signal editor opens.

  4. In the Scenarios and Signals pane of the signal editor, expand the data node. Then select the signal whose data you want to add.

  5. Specify the signal data. Select the data type from the list, and enter the time and signal data for the signal.

  6. To update your signal data, click Apply.

  7. After adding the signal data, click Save.

See Also

|

Related Topics