test: Fix mock function to call the real one 33/301833/2 accepted/tizen/8.0/unified/20231128.175440
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 07:45:31 +0000 (16:45 +0900)
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 c20c0705b89f4ee14f0eb9b2b07745c606cb43c0..ae480bf5d8cf5ea3018d24c1cc1b7cc64f1cbb8d 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 58eb80ba98a1c3a8a33abf7d158ad1b0f307050b..5dffc7cecd051d2ad3195f1f31c48bc7b9f9d481 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)