test: Fix mock function to call the real one 35/301835/1 accepted/tizen_unified_riscv accepted/tizen/unified/20231128.175118 accepted/tizen/unified/riscv/20231211.234104
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 24 Nov 2023 07:11:37 +0000 (16:11 +0900)
committeryoungjae cho <y0.cho@samsung.com>
Fri, 24 Nov 2023 08:31:55 +0000 (08:31 +0000)
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>
tests/CMakeLists.txt
tests/test-mock.c

index c20c070..ae480bf 100644 (file)
@@ -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}")
index 58eb80b..5dffc7c 100644 (file)
@@ -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)