Stub memory usage

Component Testing for C

For each STUB, the test allocates memory to:

  • Store the expected value of the input parameters during the test

  • Store the obtained value of the input parameters during the test when error is detected

  • Store the values assigned to output parameters before the test

A stub can be called several times during the execution of a test.

The test allocates memory for expected and returned values in accordance with the maximum number of STUB calls used in the tests.

In the following example, the script allocates storage space for expected and returned values for 4 ranges for read_file and 3 ranges for write_file:

TEST 1

STUB read_file 1..10(3,"line")1,11..20(1,"line")2, 21..100(1,"line")3, 101=>(3,"")0

STUB write_file 1..5=>(4,"line")1,others=>(4,"")1

...

END TEST

.....

TEST 2

STUB read_file 1..100(3,"line")1, 101=>(3,"")0

STUB write_file 1..2=>(4,"line")1,3=>(4,"line")4,others=>(4,"")1

...

END TEST

By default, when you define a STUB, the test allocates space for obtained values for the 10 first call in error.

In the following example, the script allocates storage space for the first 17 call errors to the stub:

DEFINE STUB file 17

#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 close_file(int fd);

END DEFINE

In this case, only the first 17 errors are shown in the report. Any more errors are not recorded.

You can also reduce the stub allocation value to a lower value when running tests on a target platform that is short on memory resources.