From: Chanwoo Choi Date: Thu, 16 Jun 2022 05:36:55 +0000 (+0900) Subject: tests: unittest: Add hook function for handle hal backend library X-Git-Tag: accepted/tizen/7.0/unified/20221110.060157~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F66%2F276566%2F2;p=platform%2Fhal%2Fapi%2Fcommon.git tests: unittest: Add hook function for handle hal backend library The hal-api-common uses the dlopen/dlsym/dlclose to load/unload the shared library of hal backend and find symbol from hal backend library. For testing hal-api-common functions when building time, re-implement dlopen/dlsym/dlclose for hooking.By implementing the hooking functions, be able to verify the internal logic of hal-api-common functions. Following fucntions are re-implemented for hooking: - void *dlopen(const char *filename, int flags) - int dlclose(void *handle) - void *dlsym(void *handle, const char *symbol) - int access(const char *pathname, int mode) And hal-backend-[module] (e.g., tbm/tdm/audio/camera/devcie/power etc) have to contain the their own hal_backend structure to implement the h/w device-dependent hal backend. Instead of adding the each hal_backend structure for all hal modules, use the common 'hal_backend_module_data' regardless of hal module name. Change-Id: Icbcba49a654f9ed1a287233c9cc0e3efcca508df Signed-off-by: Chanwoo Choi --- diff --git a/tests/unittest/hal-api-common-hook.c b/tests/unittest/hal-api-common-hook.c new file mode 100644 index 0000000..c55b1cc --- /dev/null +++ b/tests/unittest/hal-api-common-hook.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "hal-common-interface.h" + +/* + * All hal-backend-[module] (e.g., tbm/tdm/audio/camera/devcie/power etc) + * have to contain the their own hal_backend structure to implement + * the h/w device-dependent hal backend. Instead of adding the each hal_backend + * structure for all hal modules, use the common hal_backend_module_data + * regardless of hal module name. Below dlsym hooking function doesn't + * check the symbol name and then return the common hal_backend_module_data. + * */ +static int hal_backend_init(void **data) { return 0; } +static int hal_backend_exit(void *data) { return 0; } + +hal_backend hal_backend_module_data = { + .name = "hal-backend-module", + .vendor = "hal-backend-vendor", + .abi_version = HAL_ABI_VERSION_TIZEN_7_0, + .init = hal_backend_init, + .exit = hal_backend_exit, +}; + +/* + * hal-api-common uses the dlopen/dlsym/dlclose/access to load/unload + * the shared library of hal backend and find symbol from hal backend library. + * For testing hal-api-common functions when building time, re-implement + * 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) { + return calloc(1, sizeof(void *)); +} + +int dlclose(void *handle) { + free(handle); + return 0; +} + +void *dlsym(void *handle, const char *symbol) { + return (void *)&hal_backend_module_data; +} + +int access(const char *pathname, int mode) { + return 0; +}