Technically, to call the real symbol open() associated with the
linker flag --wrap=open, it should be invoked via __real_open().
It is matter in some build environment. Without it, the mock function
__wrap_open() calls open(), which is call for __wrap_open() itself
recursively.
ASAN build blames it:
[ RUN ] test_sys_get_str_p1
[ ERROR ] --- No entries for symbol __wrap_open.
/home/abuild/rpmbuild/BUILD/libsyscommon-5.0.0/tests/test-mock.c:16:
error: Could not get value to mock function __wrap_open
/home/abuild/rpmbuild/BUILD/libsyscommon-5.0.0/tests/test-mock.c:35:
note: Previously returned mock value was declared here
In this case, the __wrap_open() is recursively called. Within the
recursive call, there is no more reserved value to get as it has
already been consumed up by the previous __wrap_open(), which is test
failure. Fixed open() to __real_open() in order not to recursively
call the __wrap_open() but to call the real open().
Change-Id: Ib53f13ed68f335929569ad8755e86a711a08e274
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
ADD_EXECUTABLE(${TEST_DRIVER} ${SRCS})
TARGET_LINK_LIBRARIES(${TEST_DRIVER} ${REQUIRED_PKGS_LDFLAGS})
+# Suppress implicit declaration warning for __real functions.
+SET_TARGET_PROPERTIES(${TEST_DRIVER} PROPERTIES COMPILE_FLAGS "-Wno-implicit-function-declaration")
SET_TARGET_PROPERTIES(${TEST_DRIVER} PROPERTIES LINK_FLAGS "${WRAP_FLAGS} -Wl,--export-dynamic")
ADD_CUSTOM_TARGET(run-test ALL "./${TEST_DRIVER}")
mock_flags = mock_type(int);
- return open(mock_pathname, mock_flags);
+ return __real_open(mock_pathname, mock_flags);
}
int __wrap_open64(const char *pathname, int flags)