DEFINE STUB ... END DEFINE
C Test Script Language
Purpose
The DEFINE STUB and END DEFINE instructions delimit a simulation block consisting of stub definition functions, variables or procedure declarations.
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 call descriptions for a test scenario. By default, its value is 10.
Description
Defining stubs in a test script is optional.
Using the stub definitions, the C Test Script Compiler generates simulation variables and functions for which the interface is identical to that of 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 mode of passing. The mode of passing the parameter is specified by adding the following 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 parameters, you can add an optional _nocheck parameter before the _in or _inout parameter (see the Example paragraph). This allows the parameters to be sent to the stub without being checked.
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.
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