tests: Fix hooking to be done via wrapper provided by linker 31/309731/3
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 16 Apr 2024 06:08:38 +0000 (15:08 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 16 Apr 2024 06:40:46 +0000 (15:40 +0900)
For MCD(Module Circular Dependency) score, remove direct reference
from hal-api-common to hal-api-common-hook.c.

Change-Id: I1095243186f270cc1fb8d1ed30f7c8e954deb16d
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
tests/unittest/CMakeLists.txt
tests/unittest/hal-api-common-hook.c

index f7789f31ad3d2804f468e48093cf53d1cff61541..c887682383c012d890ba3bca305409a9660cf81b 100644 (file)
@@ -21,7 +21,7 @@ ENDFOREACH(flag)
 
 TARGET_LINK_LIBRARIES(${HAL_API_COMMON_UNITTEST} ${hal_api_common_unittest_pkgs_LDFLAGS} ${PROJECT_NAME})
 SET_TARGET_PROPERTIES(${HAL_API_COMMON_UNITTEST} PROPERTIES COMPILE_FLAGS "-fPIE -fvisibility=default")
-SET_TARGET_PROPERTIES(${HAL_API_COMMON_UNITTEST} PROPERTIES LINK_FLAGS "-pie")
+SET_TARGET_PROPERTIES(${HAL_API_COMMON_UNITTEST} PROPERTIES LINK_FLAGS "-pie -Wl,--wrap=dlopen -Wl,--wrap=dlclose -Wl,--wrap=dlsym -Wl,--wrap=access")
 
 ADD_TEST(
        NAME ${HAL_API_COMMON_UNITTEST}
index 3e3797885c97becbd2ed6eb798c9916b44b216f7..e86fe936fb66a4d95acbcf4974e53eab944e28f1 100644 (file)
@@ -45,19 +45,19 @@ hal_backend hal_backend_module_data = {
  * dlopen/dlsym/dlclose/access for hooking.By implementing the hooking functions,
  * be able to verify the internal logic of hal-api-common functions.
  */
-void *dlopen(const char *filename, int flags) {
+void *__wrap_dlopen(const char *filename, int flags) {
        return calloc(1, sizeof(void *));
 }
 
-int dlclose(void *handle) {
+int __wrap_dlclose(void *handle) {
        free(handle);
        return 0;
 }
 
-void *dlsym(void *handle, const char *symbol) {
+void *__wrap_dlsym(void *handle, const char *symbol) {
        return (void *)&hal_backend_module_data;
 }
 
-int access(const char *pathname, int mode) {
+int __wrap_access(const char *pathname, int mode) {
        return 0;
 }