Function Stubbing and Linking

This is a discussion on Function Stubbing and Linking within the C Programming forums, part of the General Programming Boards category; Hi all the C experts, We are developing the Test Engine for an avionics application. The library API a.h: contains ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    2

    Lightbulb Function Stubbing and Linking

    Hi all the C experts,

    We are developing the Test Engine for an avionics application.

    The library API a.h: contains external definition of function A().
    The application app.c: include "a.h", calls function A()
    The Test Engine test.c: include "a.h", also calls function A()

    We want the application to run on our Test environment, so we want to stub function A() of the library and replace it with our version A() in stub.c. So now both app.c and test.c are calling our re-defined A(). It works ok.
    stub.c: include "a.h", defines A().

    However, now we just realize we still want test.c to call the original A() of the library, and app.c still calls the stubbed A().
    app.c: include "a.h", calls function A() of the stub.c.
    test.c: include "a.h", calls function A() of the library.
    stub.c: include "a.h", defines A().

    Note that app.c is the application to be tested so we cannot make any change to it. We are free to change test.c. What can we change to test.c, or what can we do to the makefile so that the A() in test.c can link to the library?
    We really appreciate your help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    If you're using Linux/GCC, there is a linker option (-y IIRC) which allows you to do some fancy renaming of library functions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    53
    If you are doing unit testing of app.c then you need not concern about the code in the fucntion A(). You have to make ensure whether the function is getting called or not which you are doing it by stub.c.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    2
    Thanks for your responses.
    Your ideas all make sense. It turns out that the makefile in the application is much more complicated than I thought. All the c files are compiled to *.o file, then linked to an executable. This will then be linked to the library to become an image to load in to the hardware target.
    I guess this is not possible.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21