Tuesday, August 21, 2012

pthread_mutex_lock(&mutex_)failed with error 22!!

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
I got the above error two times while I was writing UT test cases. See the two scenarios below.  
  1. 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.  
  2. 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.


Henry said...

thank you! helped me solve my issue

Chanduthedev p said...

Hi Henry,

Thanks for your comments.


Kamil said...

Thanks, man. That comment directed me to where look for errors. Cheers

Anonymous said...

Thanks dude. It helps a lot.

Unknown said...

Thanks, it worked for me

Popular Posts