I get a segmentation error when I try to run gtest, mocking a method that takes a pointer to an object as an argument. I have defined the layout of a method that creates problems.
class NvmControllerMockApp : NvmController_API { public: MOCK_METHOD1(registerAccessor, bool(NVM_Accessor *accessor)); MOCK_METHOD0(update, void()); }
This is o / p created with gtest:
Running main() from gmock_main.cc [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from MeterTamperAppTest [ RUN ] MeterTamperAppTest.NeutralDisturbanceCheck Segmentation fault (core dumped)
MOCK_METHOD1 is what creates the segmentation error. If this method is excluded from the file to be tested, everything works fine. As a warning, the NVM_Accessor class deals with some pointers. I tried to debug the error using GDB, and the following backtrace message at the segmentation error point:
Program received signal SIGSEGV, Segmentation fault. 0x00000000004168d3 in testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith (this=0x67f188, untyped_args=0x7fffffffdca0) at ../src/gmock-spec-builders.cc:363 363 this->UntypedDescribeUninterestingCall(untyped_args, &ss); (gdb) backtrace #0 0x00000000004168d3 in testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith (this=0x67f188, untyped_args=0x7fffffffdca0) at ../src/gmock-spec-builders.cc:363 #1 0x0000000000410fc9 in testing::internal::FunctionMockerBase<bool (NVM_Accessor*)>::InvokeWith(std::tr1::tuple<NVM_Accessor*> const&) ( this=0x67f188, args=...) at /home/sudeep/GramPower/gmock-1.7.0/include/gmock/gmock-spec-builders.h:1530 #2 0x0000000000410c56 in testing::internal::FunctionMocker<bool (NVM_Accessor*)>::Invoke(NVM_Accessor*) (this=0x67f188, a1=0x67f148) at /home/sudeep/GramPower/gmock-1.7.0/include/gmock/gmock-generated-function-mockers.h:97 #3 0x000000000041076f in NvmControllerMockApp::registerAccessor (this=0x67f180, gmock_a1=0x67f148) at /home/sudeep/GramPower/gpos_fw/gpos/apps/nvm_controller/mocks/nvm_controller_mock_app.h:26 #4 0x0000000000413470 in MeterTamperApp::MeterTamperApp (this=0x67f128, env_=0x67ee90) at apps/meter_tamper/meter_tamper_app.cpp:31 #5 0x0000000000410989 in MeterTamperAppMockEnvironment::MeterTamperAppMockEnvironment (this=0x67ee90) at apps/meter_tamper/tests/../mocks/meter_tamper_app_mock_environment.h:23 #6 0x0000000000410a3e in MeterTamperAppTest::MeterTamperAppTest (this=0x67ee80) at apps/meter_tamper/tests/meter_tamper_app_dtest.cpp:30 #7 0x0000000000410b10 in MeterTamperAppTest_NeutralDisturbanceCheck_Test::MeterTamperAppTest_NeutralDisturbanceCheck_Test (this=0x67ee80) at apps/meter_tamper/tests/meter_tamper_app_dtest.cpp:36
source share