I ended up changing the testing approach slightly and the pthread error has gone away, but something different has popped up. If the new problem seems legit I can open a fresh thread. The original test dynamically loaded a DLL at run time, linked an init function from that DLL that setup function pointers and returned an object with those function pointers in place. Those functions are the focus of the test. The normal code runs in a DLL, but after looking closer it turns out I do NOT need to test that way. The new test is able to simply compile in the functions calls we are testing without the use of a DLL. This eliminated the pthread crash.
Another strange issue has come up that is not making sense at the moment. Some of the stuff I am working on is proprietary, so I cannot put a direct copy/paste of files and the build setup and so on. I will try to provide as much information as I can.
After changing the test to NOT load any DLLs all seemed well. But now I am finding that using MOCK_CONST_METHOD appears to introduce random failures into the test when used with one specific function. I can literally run the test binary back-to-back and every run is a different result. I have a few other const methods that behave correctly. Sometimes the test passes completely and other times I get a random error message regarding the mocked constant method at different points in the test.
Simply defining this one mock method will cause the error. The other const methods are not causing problems:
Problematic mock definition:The method being mocked is in the public section of the class definition (ERROR_TYPE and STATE_TYPE are typedef enums):
virtual ERROR_TYPE GetState(
STATE_TYPE* pState) const;
Mock definition:
MOCK_CONST_METHOD1(GetState,
ERROR_TYPE(STATE_TYPE* pState));
Example of mock method that does not create problems:
Class definition:
virtual ERROR_TYPE GetParameter(
INDEX_TYPE nIndex,
PTR_TYPE pParameterStructure) const;
Mock definition:
MOCK_CONST_METHOD2(GetParameter,
ERROR_TYPE(INDEX_TYPE nIndex, PTR_TYPE pParameterStructure));
There are total of 24 methods mocked. Some const and some not.
Test Failure Example:
When it fails, it looks like this:
$ ./bin/Test_Entrypoint
[==========] Running 18 tests from 1 test case.
[----------] Global test environment set-up.
...
[ RUN ] Entrypoint.SendCommand
: Failure
Uninteresting mock function call - returning default value.
Function call: GetState(0xb77262b0)
The mock function has no default action set, and its return type has no default value set.
Aborted
I checked thoroughly and SendCommand NEVER calls GetState.
Or it can look like this:
$ ./bin/Test_Entrypoint
[==========] Running 18 tests from 1 test case.
[----------] Global test environment set-up.
...
[ RUN ]Entrypoint.SendCommand
[ OK ] Entrypoint.SendCommand (0 ms)
[ RUN ] Entrypoint.GetParameter
: Failure
Uninteresting mock function call - returning default value.
Function call: GetState(0xb76de2b0)
The mock function has no default action set, and its return type has no default value set.
[ FAILED ] Entrypoint.GetParameter (1 ms)
The build setup is nothing special. CMakeLists.txt adds gmock-1.6.0 to the build and in the test directory of the area being tested my test executable has:
Entrypoint.cpp contains the functions getting unit tested.add_executable(Test_Entrypoint
Test_Entrypoint.cpp
${ENTRYPOINT_DIR}/Entrypoint.cpp
<SOURCE FILES OF CLASS BEING MOCKED WITH DEPS TO MAKE LINKER HAPPY>
)
target_link_libraries(Test_Entrypoint
${GMOCK_LIBRARY}
${GTEST_LIBRARY}
${OS_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
I don't see anything different being done with the particular const method that keeps killing the test, but obviously something is causing it to get called internally in GMock. I put in a print at the ONLY place the method gets called in the entrypoint code and the print does NOT show up when this error occurs.
Entrypoint.cpp when GetState is called:
static ERROR_TYPE GetState(
HANDLE_TYPE hHandle,
STATE_TYPE* pState){
if ( hHandle == NULL) return ERROR_NULL;
printf("**********************static ERROR_TYPE GetState( called.\n");
return GetInstance(hHandle)->GetState( pState);
}
GetInstance(hHandle)->GetState <-- this is the method call being mocked and is ONLY called from this one Entrypoint function.
I am running gtest-1.6.0, Fedora 20, CMake 2.8.12.2, gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7). If you need more specific details let me know and I will sanitize and provide them to the extent possible. Thank you for taking a look at this. I am bit stumped on what I have done wrong to cause this problem. If needed, I can try to re-create the issue in something that I am able to share without modification. Attached is a copy of the flags.make and the link.txt generated from CMake (with IP sanitized) if those help at all.
Thank you.
Regards,
Brent