From: Youngjae Cho Date: Fri, 24 Nov 2023 07:11:37 +0000 (+0900) Subject: test: Fix mock function to call the real one X-Git-Tag: accepted/tizen/unified/20231128.175118^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3a95d38c32297b5ffb20927485288b26e8f40d8;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git test: Fix mock function to call the real one 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 --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c20c070..ae480bf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,6 +27,8 @@ PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED 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}") diff --git a/tests/test-mock.c b/tests/test-mock.c index 58eb80b..5dffc7c 100644 --- a/tests/test-mock.c +++ b/tests/test-mock.c @@ -21,7 +21,7 @@ int __wrap_open(const char *pathname, int flags) 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)