DEFINE STUB ... END DEFINE

The DEFINE STUB and END DEFINE instructions delimit a simulation block consisting of stub definition functions, variables or procedure declarations.

This instruction applies to C Test Script Language.

Syntax

DEFINE STUB <stub_name> [ <stub_dim> ]
END DEFINE

<stub_name> is the mandatory name of a simulation block.

<stub_dim> is an optional maximum number of stub calls errors that will be displayed in the report.

Description

Defining stubs in a test script is optional.

By using the stub definitions, the C Test Script Compiler generates simulation variables and functions with the same interface for the stubbed variables and functions.

The purpose of these simulation variables and functions is to store and test input parameters, assign values to output parameters, and if necessary, return appropriate values.

Definitions of functions must be in the form of ANSI prototypes for C.

Stub parameters describe both the type of item used by the calling function and the passing mode. The parameter passing mode is specified by adding the following parameters before the parameter name:

  • _in for input parameters
  • _out for output parameters
  • _inout for input/output parameters
  • _no for parameters that you do not want to test

Additionally, when using the _in or _inout parameter, you can add an optional _nocheck parameter before the _in or _inout parameter (see the Example). This allows the parameters to be sent to the stub without being checked.

You can also add _atcc_const before the _in or _inout parameter when the parameter is declared as a const type. By default the const type modifier is ignored to allow better use of the parameters during the test, but this can lead to compilation issues. If you use _atcc_const, the parameter will be considered as a const type.

The parameter mode is optional. If no parameter mode is specified, the _in mode is assumed by default.

A return parameter is always deemed to be an output parameter.

Global variables defined in DEFINE STUB blocks replace the real global variables.

By default, only the first 10 errors are shown in the report. Additional errors are not recorded. The number of calls should be customized if necessary by using the <stub_dim> parameter.

DEFINE STUB / END DEFINE blocks must be located after the BEGIN instruction and outside any SERVICE block.

Example

An example of the use of stubs is available in the StubC example project installed with the application.

BEGIN
DEFINE STUB Example
 #int open_file(char _in f[100]);
 #int create_file(char _in f[100]);
 #int read_file(int _in fd, char _out l[100]);
 #int write_file(int fd, char _in l[100]);
 #int write(int fd, char _nocheck _in l[100]);
 #int close_file(int fd);
END DEFINE
DEFINE STUB Example
#int foo1 (int _in param1)
#{
# {int foo1_b ;
# foo1_b = 10 ;}
#}
END DEFINE

Related Topics

STUB instruction