chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

I'm having an issue when mocking some template classes in linux (in windows with Visual Studio 2019 this is working properly). The production code is more complex, but I've reproduced the problem with the next code snippet. It seems that the Mixin classes pattern is causing problems with the simbol generation in gcc (using gcc version 7.5.0)


template<typename T>
class CResMgr
{
public:
  // INFO: removing the virtual specifier doesn't reproduce the problem,
  // but in the production code this can't be modified
  virtual bool Release(T* _resource) { delete _resource; return true; }
};

// Mixin class template
template<typename C>
class T3DBasicResMgr : public C {};

using CTextureMgr = T3DBasicResMgr<CResMgr<int>>;

// INFO: inheriting directly CResMgr<int> instead of using Mixin classes
//  doesn't reproduce the problem, but in the production code this can't be done
//class CTextureMgr : public CResMgr<int> {};

class TDriver
{
public:
  CTextureMgr* m_pTextureMgr = nullptr;
  CTextureMgr* getTextureMgr() const { return m_pTextureMgr; }
};

TEST_CASE("Test Isolator++ in linux with Mixin classes", "[Isolator++]")
{
  SECTION("LINUX TEST")
  {
    auto usingTexMgr = CTextureMgr();	// Ensure the class is being used
    // Here is the runtime error trying to mock CTextureMgr
    auto texMgr = FAKE<CTextureMgr>(ISOLATOR_FORCE_SYMBOL, FakeOptions::Recursive);
    auto driver = FAKE<TDriver>();
    WHEN_CALLED(driver->getTextureMgr()).ReturnFake();
    driver->getTextureMgr()->Release(nullptr);
  }

  ISOLATOR_CLEANUP();
}

This is the error shown in the console:

********* Typemock Isolator++ Assert Exception *********

 - The class 'T3DBasicResMgr<CResMgr<int> >' information cannot be found by Isolator++. 

1) Isolator++ uses DEBUG info to identify types and fake them. Make sure that DEBUG info is generated by compiler (-g3).

2) Isolator++ may fail to fake objects that aren't used anywhere in your test project as the compiler optimizes these. Using of FAKE<T3DBasicResMgr<CResMgr<int> >>(ISOLATOR_FORCE_SYMBOL) may help (for static methods please use FAKE_STATICS(T3DBasicResMgr<CResMgr<int> >)).

To verify that DEBUG info is generated, please use -g3 option while compiling.

Also make sure that optimization is switched off (-O0 compilation flag)

I can confirm that I'm generating Debug symbols and compiling with -g3 -O0 -fPIC _GLIBCXX_USE_CXX11_ABI=0, linking with LD_FLAGS=-no-pie and environment variable LD_BIND_NOW=1

Does anyone knows how to make gcc generate symbols for T3DBasicResMgr<CResMgr<int> >? Or any other way to avoid this problem?

Thanks

asked by benjamin-golden-race (1.1k points)
I am facing a similar behavior, although the class is used and all flags are set properly.

1 Answer

0 votes

Hi Benjamin,

Thank you for reaching out.

Can you please tell me what testing framework are you using?

Cheers,

Alon Sapozhnikov.

Support Specialist

answered by Alon_TypeMock (8.9k points)
I'm using Catch2

Hi Benjamin,

Sorry for the delayed response.

Can you please share with us the logs of the run.
To enable the logs you can check this link:
https://www.typemock.com/docs/?book=Ipp&page=suppressing_additional_message.htm

please keep me posted.

Cheers,

Alon Sapozhnikov.
Support Specialist.

...