Segmentation fault when trying simple google_test example

4,143 views
Skip to first unread message

Giaco777

unread,
Feb 13, 2012, 8:23:21 AM2/13/12
to Google C++ Mocking Framework
Hi,

I wanted to enter the google test and mocking world with a very simple
example mostly copied together from the ForDummies document. I run
google mock on Windows XP with cygwin 1.7.10-1. Compiling and linking
the code below with gcc 4.5.3 runs well, but when running it, I get an
Segmentation Fault. This is the gdb output for that:

Program received signal SIGSEGV, Segmentation fault.
0x00432ae2 in join (ptr=0x611d7cd4, this=0x6fa6a4)
at ./gtest/include/gtest/internal/gtest-linked_ptr.h:113
113 while (p->next_ != ptr) p = p->next_;

What's wrong here?

I've send this request already two weeks ago to "moderators", but did
not receive any response so far.

Kind Regards


#include "gmock/gmock.h"
#include "gtest/gtest.h"



class Turtle {
public:
virtual ~Turtle() {}
virtual void PenUp() = 0;
virtual void PenDown() = 0;
virtual void Forward(int distance) = 0;
virtual void Turn(int degrees) = 0;
virtual void GoTo(int x, int y) = 0;
virtual int GetX() const = 0;
virtual int GetY() const = 0;
};


class MockTurtle : public Turtle {
public:
MOCK_METHOD0(PenUp, void());
MOCK_METHOD0(PenDown, void());
MOCK_METHOD1(Forward, void(int distance));
MOCK_METHOD1(Turn, void(int degrees));
MOCK_METHOD2(GoTo, void(int x, int y));
MOCK_CONST_METHOD0(GetX, int());
MOCK_CONST_METHOD0(GetY, int());
};

using ::testing::AtLeast; // #1

TEST(PainterTest, CanDrawSomething) {
MockTurtle turtle; // #2
EXPECT_CALL(turtle, PenDown()) // #3
.Times(AtLeast(1));
} // #5

int main(int argc, char *argv[]) {
// The following line must be executed to initialize Google Mock
// (and Google Test) before running the tests.
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}

Greg Miller

unread,
Feb 13, 2012, 2:09:53 PM2/13/12
to Giaco777, Google C++ Mocking Framework
Hi.

Sorry you didn't get a response. I'm unable to reproduce this problem on Win XP, cygwin 1.7.10(0.259/5/3), gcc 4.5.3, and the current gmock/gtest packages that are available for download from the website. I created a small test like you suggested (though I only included two methods to mock), and I modified the Makefile at gmock/make/Makefile to compile my test. It worked as expected and did not segv.

If you can provide more details about how to reproduce the problem we might be able to help.

Thanks.

Greg

(Note that the test will not PASS as written because the PenDown() expectation will not be satisfied.)

Tyler

unread,
Mar 2, 2012, 9:27:42 AM3/2/12
to Google C++ Mocking Framework
Hi,

I've ran into the same issue on Cygwin. I just found a workaround by
trial and error. I had to compile the code with the option
'gtest_disable_pthreads' OFF. I hope this helps.

Tyler
Reply all
Reply to author
Forward
0 new messages