Search code examples
c++ubuntugooglemock

SegFault when using gmock


I am using gmock 1.6 framework to code unit test. the unit tests exit and work fine on windows.

The goal is to run them on linux.

on Linux dev env:

  • when I used eclipse CDT, the test work fine.

  • but when I use command line command (cmake .. && make), I get a segmentation fault while the execution.

Software versions:

  • GNU Make 4.1
  • gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
  • cmake 3.10.2
class mockClass : puclic baseClass
{
   .....
   MOCK_METHOD1(function, void(const std::shared_ptr<mmmm>));
   .....

}

TEST(testSerie1, test1)
{
   mockClass attrb;
   ......
   EXPECT_CALL(attrb, function(_)).Times(AnyNumber()); // here code crahes
    ...
}

ERROR:

Thread 2 "m_thread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread  (LWP 20104)]
0x0123 in testing::internal::FunctionMocker<void (std::shared_ptr<mmmmmmm>)>::Invoke(std::shared_ptr<mmmmmmm>) ()
(gdb) 
(gdb) 
(gdb) backtrace 
#0  ... in testing::internal::FunctionMocker<void (std::shared_ptr<mmmmmmm>)>::Invoke(std::shared_ptr<mmmmmmm>) ()
#1  ... in MockIClass::function(std::shared_ptr<mmmmmmm>) ()
.....
.....
.....
#6  0x00007ffff72bb66f in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007ffff758e6db in start_thread (arg=0x7ffff664e700) at pthread_create.c:463
#8  0x00007ffff6d1688f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) 


Any idea please to avoid this segmentation fault ?


Solution

  • The problem is solved when I upgraded the googlemock library version to 1.8.1.