Stub simulation

Component Testing for C

Stub simulation is based on the idea that 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 generate these stubs, the Test Script Compiler must have the following information:

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, OneTest Embedded considers both the original and the simulation version of the first prototype of the function that is encountered, which can be:

If the first declaration is not found OneTest Embedded considers that original is identical to the simulated function.

Both can differ when the original prototype does not declare explicitly how the application uses it. For example, a void * parameter can be used as char* or int *.

It is possible to stub a function that is located in the source file under test. In this case, the source file must be included in the .ptu test script. If an existing body of stubbed function is encountered in the source code under test, OneTest Embedded renames the existing body to _atu_stub_<function-name> and the stubbed version of the function is used in the test driver.

An example is provided in the StubInUseFunc test node of the Stub C example project.

Note: To comply with the DO178B standard, the source code under test must be compiled separately from the .ptu. If you choose to include the source file in the .ptu script, then you will need to justify this with the DO178B authority.

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:


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