Recently I came across below problem while I was writing the gmock test for our source code. gmock is a unit test framework for C++. gmock is short form of Google Mocking.
gtest/internal/gtest-port.h:1151:: pthread_mutex_lock(&mutex_)failed with error 22
Abort
I got the above error two times while I was writing UT test cases. See the two scenarios below.
After my analysis and contacting with our UT team, I came to know that the possible reason for this problem is that calling extra EXPECT_CALL for the unused functions.
gtest/internal/gtest-port.h:1151:: pthread_mutex_lock(&mutex_)failed with error 22
Abort
- Extra EXPECT_CALL : This could be one of the reasons for the above problem. In my test case I have lot of EXPECT_CALL's, because our function is calling lot of other functions, so I need to mock all the functions, in the process of mocking these functions, by mistake I mocked one function which is not been called by this function. That means I added one extra EXPECT_CALL. By taking stack trace using GDB I found the function and commented that expect call. And it was working fine.
- Used Once instead of Repeatedly: This may also causes for the above error message. With the experience of extra expect_call case, I have taken the stack trace or back trace using GDB, and I found that for one expect call I used WillOnce. So changed to WillRepeatedly. It got solved.
After my analysis and contacting with our UT team, I came to know that the possible reason for this problem is that calling extra EXPECT_CALL for the unused functions.
5 comments:
thank you! helped me solve my issue
Hi Henry,
Thanks for your comments.
CHandUtheDev
Thanks, man. That comment directed me to where look for errors. Cheers
Thanks dude. It helps a lot.
Thanks, it worked for me
Post a Comment