Stub Simulation

Component Testing for C

Stub simulation is based on the idea certain functions are to be simulated and are therefore replaced with other functions which are generated in the test driver. These generated functions, or stubs, have the same interface as the simulated functions, but the body of the functions is replaced.

These stubs have the following roles:

To be able to generate these stubs, the Test Script Compiler needs to know:

When using the Component Testing Wizard, you specify the functions that you want to stub. This automatically adds the corresponding code to the .ptu test script. On execution of the test, Component Testing for C generates the stub in the test driver, which includes:

Function Prototypes

When generating a stub for a function, Test RealTime considers the first prototype of the function that is encountered, which can be:

This means that the declaration of the function contained in the DEFINE STUB statement is ignored if the function was previously declared in a header file.

If an existing body of stubbed function is encountered, Test RealTime renames the existing body to atl_stub_<function-name> and the stubbed version of the function is used in the test driver.

Passing Parameters

Passing parameters by pointer can lead to problems of ambiguity regarding the data actually passed to the function. For example, a parameter that is described in a prototype by int *x can be passed in the following way:

int *x as input ==> f(x)

int x as output or input/output ==> f(&x)

int x[10] as input ==> f(x)

int x[10] as output or input/output ==> f(x)

 

Therefore, to describe the stubs, you should specify the following:

Example

An example project called Stub C is available from the Examples section of the Start page. This example demonstrates the use of stubs in Component Testing for C. See Example projects for more information.

Related Topics

Stub Definition in CStub Usage in CSizing StubsReplacing StubsAdvanced StubsExample projects