1

Good morning, I have the following situation:

  • I have a library middleware.so that provide a wrapper for a external library boughtLib.so
  • makefile of middleware.so link dynamic library boughtLib.so and cannot be modified
  • I need to write a test case to be sure that middleware.so uses the functions in boughtLib.so (in order to be sure no one replaced the optimized implementation of boughtLib.so with a low performancecustom one).

I approached the issue as follow:

  • in my GTEST I defined the wrap implementation of boughtLib.so library function (i.e.

    void __wrap_firstBoughtLib()
    {
      //Some action to be trapped by gtest testcase
    }
    

) and I modified the make file of my gtest based test suite using

-Wl,--wrap=firstBoughtLib()

Now when I invoke the firstBoughtLib() directly from the testcase, the invoked function is __wrap_firstBoughtLib(), not the original one in boughtLib.so . However, each call to firstBoughtLib() performed in middleware.so still uses the functions in boughtLib.so. I tried removing from LD_LOAD_LIBRARY the folder containing the boughtLib.so, so that middleware.so didn't find it, but then at start time the SW complain about missing library.

If you have some suggestion about how to approach the issue, I would really appreciate.

1 Answer 1

0

I finally found out to avoid such an issue. Instead of modifying the middleware.so makefile, I modified the makefile of tje unit test adding that option:

-Wl,-defsym,firstBoughtLib=__wrap_firstBoughtLib

By this way any call to the symbol firstBoughtLib performed even in middleware.so will be replaced by my custom __wrap_firstBoughtLib. Hope this help someone facing similar issues

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.