From bf7fdcf95b0cbb3517e874292f788a6c40cd1f7b Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 11 May 2018 17:50:33 +0900 Subject: [PATCH 01/16] packaging: Remove unneeded package's dependency Change-Id: I7a641708123de7f02c68aa36685e8cb1fa1aed3c Signed-off-by: Chanwoo Choi --- packaging/pass.spec | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packaging/pass.spec b/packaging/pass.spec index f274516..8f64774 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -14,19 +14,12 @@ Source1: %{name}.manifest Source2: %{hal_name}.manifest BuildRequires: cmake -BuildRequires: libattr-devel -BuildRequires: gettext-devel -BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(device-node) -BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(eventsystem) BuildRequires: pkgconfig(libudev) -BuildRequires: pkgconfig(libtzplatform-config) %description PASS (Power-Aware System Service) -- 2.7.4 From 7623f121b200e02949e1a73dacc87e2f20f61d14 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 1 Jun 2018 10:25:46 +0900 Subject: [PATCH 02/16] core: Remove unused helper functions Change-Id: I70c130c7715dab70f11294547889022a44ff93ce Signed-off-by: Chanwoo Choi --- include/pass/common.h | 57 ---------------------------- src/core/common.c | 102 -------------------------------------------------- 2 files changed, 159 deletions(-) diff --git a/include/pass/common.h b/include/pass/common.h index 9de28a3..b11571d 100644 --- a/include/pass/common.h +++ b/include/pass/common.h @@ -77,16 +77,6 @@ typedef unsigned long long uint64; }) #endif -#ifndef clamp -#define clamp(x, low, high) \ - __extension__ ({ \ - typeof(x) _x = (x); \ - typeof(low) _low = (low); \ - typeof(high) _high = (high); \ - ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ - }) -#endif - #ifndef SEC_TO_MSEC #define SEC_TO_MSEC(x) ((x)*1000) #endif @@ -100,54 +90,7 @@ typedef unsigned long long uint64; #define USEC_TO_MSEC(x) ((double)x/1000) #endif -#define NANO_SECOND_MULTIPLIER 1000000 /* 1ms = 1,000,000 nsec */ - -#ifndef safe_free -#define safe_free(x) safe_free_memory((void**)&(x)) -#endif - -static inline void safe_free_memory(void** mem) -{ - if (mem && *mem) { - free(*mem); - *mem = NULL; - } -} - -#define ret_value_if(expr, val) do { \ - if (expr) { \ - _E("(%s)", #expr); \ - return (val); \ - } \ -} while (0) - -#define ret_value_msg_if(expr, val, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - return val; \ - } \ -} while (0) - -#define ret_msg_if(expr, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - return; \ - } \ -} while (0) - -FILE * open_proc_oom_score_adj_file(int pid, const char *mode); -int get_exec_pid(const char *execpath); -int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); -int is_vip(int pid); -int remove_dir(const char *path, int del_dir); -int sys_check_node(char *path); int sys_get_int(char *fname, int *val); -int sys_set_int(char *fname, int val); int sys_get_str(char *fname, char *str); -int sys_set_str(char *fname, char *val); -int terminate_process(const char *partition, bool force); -int mount_check(const char* path); -void print_time(const char *prefix); -int get_privilege(pid_t pid, char *name, size_t len); #endif /* __CORE_COMMON_H__ */ diff --git a/src/core/common.c b/src/core/common.c index a0ee779..6e2150a 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -39,64 +39,6 @@ #define BUFF_MAX 255 -int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) -{ - int fd, ret; - char buf[PATH_MAX + 1]; - char *filename; - - if (!cmdline_size) - return -1; - - snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); - fd = open(buf, O_RDONLY); - if (fd < 0) { - errno = ESRCH; - return -1; - } - - ret = read(fd, buf, PATH_MAX); - close(fd); - if ((ret >= 0) && (ret <= PATH_MAX)) { - buf[ret] = '\0'; - } else { - errno = EIO; - return -1; - } - - filename = strrchr(buf, '/'); - if (filename == NULL) - filename = buf; - else - filename = filename + 1; - - if ((cmdline_size - 1) < strlen(filename)) { - errno = EOVERFLOW; - return -1; - } - - strncpy(cmdline, filename, cmdline_size - 1); - cmdline[cmdline_size - 1] = '\0'; - return 0; -} - -/* - * Helper function - * - Read from sysfs entry - * - Write to sysfs entry - */ -int sys_check_node(char *path) -{ - int fd; - - fd = open(path, O_RDONLY); - if (fd == -1) - return -1; - - close(fd); - return 0; -} - static int sys_read_buf(char *file, char *buf) { int fd; @@ -118,25 +60,6 @@ static int sys_read_buf(char *file, char *buf) return ret; } -static int sys_write_buf(char *file, char *buf) -{ - int fd; - int r; - int ret = 0; - - fd = open(file, O_WRONLY); - if (fd == -1) - return -ENOENT; - - r = write(fd, buf, strlen(buf)); - if (r < 0) - ret = -EIO; - - close(fd); - - return ret; -} - int sys_get_int(char *fname, int *val) { char buf[BUFF_MAX]; @@ -152,19 +75,6 @@ int sys_get_int(char *fname, int *val) return ret; } -int sys_set_int(char *fname, int val) -{ - char buf[BUFF_MAX]; - int ret = 0; - - snprintf(buf, sizeof(buf), "%d", val); - - if (sys_write_buf(fname, buf) != 0) - ret = -EIO; - - return ret; -} - int sys_get_str(char *fname, char *str) { char buf[BUFF_MAX] = {0}; @@ -176,15 +86,3 @@ int sys_get_str(char *fname, char *str) return -1; } - -int sys_set_str(char *fname, char *val) -{ - int r = -1; - - if (val != NULL) { - if (sys_write_buf(fname, val) == 0) - r = 0; - } - - return r; -} -- 2.7.4 From cc9043745b44afd3adf1296eb67f31ab34e56d81 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 17 Jul 2018 18:12:13 +0900 Subject: [PATCH 03/16] packaging: Remove unused libpass.manifest file Change-Id: I62564514c93b12f7211f37427207aa898e315092 Signed-off-by: Chanwoo Choi --- packaging/libpass.manifest | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 packaging/libpass.manifest diff --git a/packaging/libpass.manifest b/packaging/libpass.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/packaging/libpass.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - -- 2.7.4 From 8a975691f71eda3bbf59b334816156b687e9f3fa Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 17 May 2018 13:02:10 +0900 Subject: [PATCH 04/16] gdbus: Move dbus interface definition to one header file Move dbus interface definition to gdbus-util.h header file and clean-up code as following: - Rename dbus definition from PASS_DBUS_BUS_NAME to DBUS_CORE_BUS_NAME - Use ARRAY_SIZE() macro and then remove unnecessary following definitions: : DBUS_CORE_I_NUM_SIGNALS : DBUS_PMQOS_I_NUM_SIGNALS Change-Id: Ic3f78d84b353bfe382330366d10292711de8c5fa Signed-off-by: Chanwoo Choi --- include/pass/gdbus-util.h | 22 ++++++++++++++++++++++ src/core/main.c | 4 +--- src/pass/pass.c | 11 +++-------- src/pmqos/pmqos.c | 14 +++----------- src/thermal/thermal.c | 6 ------ 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/include/pass/gdbus-util.h b/include/pass/gdbus-util.h index eaa09ea..1eb349e 100644 --- a/include/pass/gdbus-util.h +++ b/include/pass/gdbus-util.h @@ -27,6 +27,28 @@ #include "pmqos/pmqos-dbus-stub.h" #include "thermal/thermal-dbus-stub.h" +/* Dbus definition for PASS */ +#define DBUS_PASS_BUS_NAME "org.tizen.system.pass" + +#define DBUS_CORE_INTERFACE "org.tizen.system.pass.core" +#define DBUS_CORE_PATH "/Org/Tizen/System/Pass/Core" +#define DBUS_CORE_I_START_HANDLER "handle_start" +#define DBUS_CORE_I_STOP_HANDLER "handle_stop" + +#define DBUS_PMQOS_INTERFACE "org.tizen.system.pass.pmqos" +#define DBUS_PMQOS_PATH "/Org/Tizen/System/Pass/Pmqos" +#define DBUS_PMQOS_I_START_HANDLER "handle_start" +#define DBUS_PMQOS_I_STOP_HANDLER "handle_stop" +#define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch" +#define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving" + +#define DBUS_THERMAL_INTERFACE "org.tizen.system.pass.monitor.thermal" +#define DBUS_THERMAL_PATH "/Org/Tizen/System/Pass/Monitor/Thermal" +#define DBUS_THERMAL_I_START_HANDLER "handle_start" +#define DBUS_THERMAL_I_STOP_HANDLER "handle_stop" +#define DBUS_THERMAL_METHOD "thermal_scenario" + +/* Dbus definition for systemd */ #define SYSTEMD_DBUS_NAME "org.freedesktop.systemd1" #define SYSTEMD_DBUS_OBJECT_PATH "/org/freedesktop/systemd1" #define SYSTEMD_DBUS_IFACE_FOR_PROPS "org.freedesktop.DBus.Properties" diff --git a/src/core/main.c b/src/core/main.c index a3c2542..b86224d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -29,8 +29,6 @@ #include #include -#define PASS_DBUS_BUS_NAME "org.tizen.system.pass" - unsigned int g_startup_cb_id; GMainLoop *g_mainloop; @@ -97,7 +95,7 @@ static int late_init(void) signal(SIGTERM, sig_quit); signal(SIGUSR1, sig_usr1); - ret = pass_gdbus_get_name(PASS_DBUS_BUS_NAME); + ret = pass_gdbus_get_name(DBUS_PASS_BUS_NAME); if (ret < 0) return ret; diff --git a/src/pass/pass.c b/src/pass/pass.c index aa86b14..378ca9e 100644 --- a/src/pass/pass.c +++ b/src/pass/pass.c @@ -31,11 +31,6 @@ #include "pass-parser.h" #include "pass-hal.h" -#define DBUS_CORE_I_START_HANDLER "handle_start" -#define DBUS_CORE_I_STOP_HANDLER "handle_stop" -#define DBUS_CORE_I_NUM_SIGNALS 2 -#define DBUS_CORE_INTERFACE "org.tizen.system.pass.core" -#define DBUS_CORE_PATH "/Org/Tizen/System/Pass/Core" #define PASS_CONF_PATH "/etc/pass/pass.conf" static uint64 supported_module[] = { @@ -411,7 +406,7 @@ static void pass_exit(void *data) pass_init_done, NULL); pass_gdbus_disconnect_signal(g_gdbus_instance, - DBUS_CORE_I_NUM_SIGNALS, g_gdbus_signal_infos); + ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); pass_gdbus_put_instance_core(&g_gdbus_instance); pass_exit_done(); @@ -438,7 +433,7 @@ static int pass_probe(void *data) } ret = pass_gdbus_connect_signal(g_gdbus_instance, - DBUS_CORE_I_NUM_SIGNALS, g_gdbus_signal_infos); + ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); if (ret < 0) { _E("cannot register callbacks as the dbus method invocation " "handlers\n"); @@ -473,7 +468,7 @@ static int pass_probe(void *data) out_disconnect: pass_gdbus_disconnect_signal(g_gdbus_instance, - DBUS_CORE_I_NUM_SIGNALS, g_gdbus_signal_infos); + ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); out: pass_gdbus_put_instance_core(&g_gdbus_instance); diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 6a6a89c..0c8355b 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -34,14 +34,6 @@ #define MILLISECONDS(tv) ((tv.tv_sec)*1000 + (tv.tv_nsec)/1000000) #define DELTA(a, b) (MILLISECONDS(a) - MILLISECONDS(b)) -#define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch" -#define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving" -#define DBUS_PMQOS_I_START_HANDLER "handle_start" -#define DBUS_PMQOS_I_STOP_HANDLER "handle_stop" -#define DBUS_PMQOS_I_NUM_SIGNALS 4 -#define DBUS_PMQOS_INTERFACE "org.tizen.system.pass.pmqos" -#define DBUS_PMQOS_PATH "/Org/Tizen/System/Pass/Pmqos" - static SystemPassPmqos *g_gdbus_instance = NULL; static struct pmqos_scenario *g_pmqos = NULL; @@ -482,7 +474,7 @@ static void pmqos_exit(void *data) pmqos_init_done, NULL); pass_gdbus_disconnect_signal(g_gdbus_instance, - DBUS_PMQOS_I_NUM_SIGNALS, g_gdbus_signal_infos); + ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); pass_gdbus_put_instance_pmqos(&g_gdbus_instance); pmqos_free(); @@ -505,7 +497,7 @@ static int pmqos_probe(void *data) } ret = pass_gdbus_connect_signal(g_gdbus_instance, - DBUS_PMQOS_I_NUM_SIGNALS, g_gdbus_signal_infos); + ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); if (ret < 0) { _E("cannot register callbacks as the dbus method invocation " "handlers\n"); @@ -540,7 +532,7 @@ static int pmqos_probe(void *data) out_disconnect: pass_gdbus_disconnect_signal(g_gdbus_instance, - DBUS_PMQOS_I_NUM_SIGNALS, g_gdbus_signal_infos); + ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); out: pass_gdbus_put_instance_pmqos(&g_gdbus_instance); diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 274635f..8c80aef 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -31,12 +31,6 @@ #define THERMAL_CONF_PATH "/etc/pass/pass-thermal.conf" -#define DBUS_THERMAL_I_START_HANDLER "handle_start" -#define DBUS_THERMAL_I_STOP_HANDLER "handle_stop" -#define DBUS_THERMAL_INTERFACE "org.tizen.system.pass.monitor.thermal" -#define DBUS_THERMAL_PATH "/Org/Tizen/System/Pass/Monitor/Thermal" -#define DBUS_THERMAL_METHOD "thermal_scenario" - static SystemPassMonitorThermal *g_gdbus_instance = NULL; static struct thermal_scenario *g_thermal = NULL; -- 2.7.4 From 4bced0cb95f29453f72aa3bd05fda735f2064970 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 18 Jul 2018 14:42:04 +0900 Subject: [PATCH 05/16] Remove unused macro and definitions from CMakeLists.txt Change-Id: Ib69cb04851a28a646f9682eebae5587a361c00a0 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 70 ---------------------------------------------------------- 1 file changed, 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05a959b..6fe5f97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,62 +2,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(pass C) ######################################################## -# Build options: -######################################################## -IF("${ARCH}" STREQUAL "emulator") - OPTION(USE_EMULATOR "Use Emulator" ON) -ELSEIF("${ARCH}" STREQUAL "arm") - OPTION(USE_ARM "Use Arm" ON) -ENDIF() - -IF("${ARCH_BIT}" STREQUAL "32") - OPTION(USE_32BIT "Use 32bit architecture" ON) -ELSEIF("${ARCH_BIT}" STREQUAL "64") - OPTION(USE_64BIT "Use 64bit architecture" ON) -ENDIF() - -######################################################## -# PASS Macros -######################################################## - -MACRO(ADD_SOURCE DIR OUT) - FILE(GLOB ALL_SRCS "${DIR}/*.c") - FOREACH(SRC ${ALL_SRCS}) - IF(NOT ${SRC} MATCHES "ivi|mobile|wearable|tv|none") - SET(D_SRCS ${D_SRCS} ${SRC}) - ENDIF() - ENDFOREACH() - FILE(GLOB S_SRCS "${DIR}/*-${PROFILE}.c") - IF(DEFINED S_SRCS) - SET(D_SRCS ${D_SRCS} ${S_SRCS}) - ENDIF() - SET(${OUT} ${D_SRCS}) -ENDMACRO() - -MACRO(INSTALL_CONF DIR CONF) - SET(T_CONF ${DIR}/${CONF}-${PROFILE}.conf) - SET(E_CONF ${DIR}/${CONF}-emul-${PROFILE}.conf) - IF(USE_EMULATOR AND EXISTS ${E_CONF}) - SET(T_CONF ${E_CONF}) - ENDIF() - IF(NOT EXISTS ${T_CONF}) - SET(T_CONF ${DIR}/${CONF}.conf) - ENDIF() - IF(DEFINED T_CONF) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${T_CONF} - DESTINATION /etc/pass - RENAME ${CONF}.conf) - ENDIF() -ENDMACRO() - -######################################################## # PASS CMakeLists.txt ######################################################## SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}/bin") SET(INCLUDEDIR "${PREFIX}/include/${PROJECT_NAME}") -SET(DATADIR "${PREFIX}/share/${PROJECT_NAME}") -SET(CONFDIR "/etc/${PROJECT_NAME}") SET(VERSION 0.1.0) SET(PASS_HAL_NAME pass-hal-devel) @@ -120,25 +69,6 @@ SET(CMAKE_EXE_LINKER_FLAGS "-pie") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"") -ADD_DEFINITIONS("-DENABLE_PASS_DLOG") -ADD_DEFINITIONS("-DENABLE_LIBPASS_DLOG") -ADD_DEFINITIONS("-DENABLE_PM_LOG") -IF(ENGINEER_MODE STREQUAL on) -ADD_DEFINITIONS("-DENGINEER_MODE") -ENDIF(ENGINEER_MODE STREQUAL on) -IF(PROFILE STREQUAL tv) - ADD_DEFINITIONS("-DPROFILE_TV") -ENDIF() -IF(USE_ARM) - ADD_DEFINITIONS("-DTARGET") -ELSEIF(USE_EMULATOR) - ADD_DEFINITIONS("-DEMULATOR") -ENDIF() -IF(USE_32BIT) - ADD_DEFINITIONS("-DARCH_32BIT") -ELSEIF(USE_64BIT) - ADD_DEFINITIONS("-DARCH_64BIT") -ENDIF() ADD_CUSTOM_COMMAND( OUTPUT src/pass/pass-dbus-stub.c -- 2.7.4 From 8c2962a001fa9084014d56b23becc91656e3fa06 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 17 Jul 2018 18:38:21 +0900 Subject: [PATCH 06/16] hal: Move LOG_TAG definition to makefile to remove the duplicate Each log header file defines LOG_TAG. It defines LOG_TAG on Makefile in order to remove the duplicate definitions. Change-Id: I3b4b08008e259fe3a0c8257ffaad0f291666a0c4 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 1 + include/pass/log.h | 4 ---- src/hal/hal-log.h | 4 ---- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fe5f97..a16e74c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functi SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-pie") +ADD_DEFINITIONS("-DLOG_TAG=\"PASS\"") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"") diff --git a/include/pass/log.h b/include/pass/log.h index d170161..1edba9f 100644 --- a/include/pass/log.h +++ b/include/pass/log.h @@ -20,10 +20,6 @@ #define __LOG_H__ #include -#ifdef LOG_TAG -#undef LOG_TAG -#define LOG_TAG "PASS" -#endif /* LOG_TAG */ #define _D(fmt, arg...) do { SLOGD(fmt, ##arg); } while (0) #define _I(fmt, arg...) do { SLOGI(fmt, ##arg); } while (0) diff --git a/src/hal/hal-log.h b/src/hal/hal-log.h index 69a86d5..4b43f61 100644 --- a/src/hal/hal-log.h +++ b/src/hal/hal-log.h @@ -20,10 +20,6 @@ #define __HAL_LOG_H__ #include -#ifdef LOG_TAG -#undef LOG_TAG -#define LOG_TAG "PASS" -#endif /* LOG_TAG */ #define _D(fmt, arg...) do { SLOGD(fmt, ##arg); } while (0) #define _I(fmt, arg...) do { SLOGI(fmt, ##arg); } while (0) -- 2.7.4 From 0fac90d924a734f0ed99eba974f16e2355f3b5f4 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 20 Jul 2018 13:23:11 +0900 Subject: [PATCH 07/16] pass: hal: Fix error number from EINVAL to EPERM/ENODEV All HAL functions return '-EINVAL' error number when error happen. It is necessary to return more correct error value. Return -EPERM value if HAL(Hardware Abstract Layer) function is not supported according to h/w resource type and return -ENODEV value if HAL function is not implemented on HAL package. Change-Id: I0b0da7429f38aa0362293275849a713e6020a763 Signed-off-by: Chanwoo Choi --- src/pass/pass-hal.c | 92 ++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/pass/pass-hal.c b/src/pass/pass-hal.c index 3694326..1df1912 100644 --- a/src/pass/pass-hal.c +++ b/src/pass/pass-hal.c @@ -95,10 +95,10 @@ int pass_get_curr_governor(struct pass_resource *res, char *governor) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->get_curr_governor) - return -EINVAL; + return -ENODEV; return dvfs->get_curr_governor(res->config_data.res_name, governor); } @@ -112,10 +112,10 @@ int pass_set_curr_governor(struct pass_resource *res, char *governor) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->set_curr_governor) - return -EINVAL; + return -ENODEV; return dvfs->set_curr_governor(res->config_data.res_name, governor); } @@ -130,10 +130,10 @@ int pass_get_curr_freq(struct pass_resource *res) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->get_curr_freq) - return -EINVAL; + return -ENODEV; return dvfs->get_curr_freq(res->config_data.res_name); } @@ -148,10 +148,10 @@ int pass_get_min_freq(struct pass_resource *res) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->get_min_freq) - return -EINVAL; + return -ENODEV; return dvfs->get_min_freq(res->config_data.res_name); } @@ -165,10 +165,10 @@ int pass_set_min_freq(struct pass_resource *res, int freq) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->set_min_freq) - return -EINVAL; + return -ENODEV; return dvfs->set_min_freq(res->config_data.res_name, freq); } @@ -182,10 +182,10 @@ int pass_get_max_freq(struct pass_resource *res) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->get_max_freq) - return -EINVAL; + return -ENODEV; return dvfs->get_max_freq(res->config_data.res_name); } @@ -199,10 +199,10 @@ int pass_set_max_freq(struct pass_resource *res, int freq) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->set_max_freq) - return -EINVAL; + return -ENODEV; return dvfs->set_max_freq(res->config_data.res_name, freq); } @@ -217,10 +217,10 @@ int pass_get_available_min_freq(struct pass_resource *res) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->get_available_min_freq) - return -EINVAL; + return -ENODEV; return dvfs->get_available_min_freq(res->config_data.res_name); } @@ -234,10 +234,10 @@ int pass_get_available_max_freq(struct pass_resource *res) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->get_available_max_freq) - return -EINVAL; + return -ENODEV; return dvfs->get_available_max_freq(res->config_data.res_name); } @@ -252,10 +252,10 @@ int pass_get_up_threshold(struct pass_resource *res) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->get_up_threshold) - return -EINVAL; + return -ENODEV; return dvfs->get_up_threshold(res->config_data.res_name); } @@ -269,10 +269,10 @@ int pass_set_up_threshold(struct pass_resource *res, int up_threshold) dvfs = get_dvfs(res, res->config_data.res_type); if (!dvfs) - return -EINVAL; + return -EPERM; if (!dvfs->set_up_threshold) - return -EINVAL; + return -ENODEV; return dvfs->set_up_threshold(res->config_data.res_name, up_threshold); } @@ -287,10 +287,10 @@ int pass_get_online_state(struct pass_resource *res, int cpu) hotplug = get_hotplug(res, res->config_data.res_type); if (!hotplug) - return -EINVAL; + return -EPERM; if (!hotplug->get_online_state) - return -EINVAL; + return -ENODEV; return hotplug->get_online_state(res->config_data.res_name, cpu); } @@ -304,10 +304,10 @@ int pass_set_online_state(struct pass_resource *res, int cpu, int on) hotplug = get_hotplug(res, res->config_data.res_type); if (!hotplug) - return -EINVAL; + return -EPERM; if (!hotplug->set_online_state) - return -EINVAL; + return -ENODEV; return hotplug->set_online_state(res->config_data.res_name, cpu, on); } @@ -321,10 +321,10 @@ int pass_get_online_min_num(struct pass_resource *res) hotplug = get_hotplug(res, res->config_data.res_type); if (!hotplug) - return -EINVAL; + return -EPERM; if (!hotplug->get_online_min_num) - return -EINVAL; + return -ENODEV; return hotplug->get_online_min_num(res->config_data.res_name); } @@ -338,10 +338,10 @@ int pass_set_online_min_num(struct pass_resource *res, int num) hotplug = get_hotplug(res, res->config_data.res_type); if (!hotplug) - return -EINVAL; + return -EPERM; if (!hotplug->set_online_min_num) - return -EINVAL; + return -ENODEV; return hotplug->set_online_min_num(res->config_data.res_name, num); } @@ -355,10 +355,10 @@ int pass_get_online_max_num(struct pass_resource *res) hotplug = get_hotplug(res, res->config_data.res_type); if (!hotplug) - return -EINVAL; + return -EPERM; if (!hotplug->get_online_max_num) - return -EINVAL; + return -ENODEV; return hotplug->get_online_max_num(res->config_data.res_name); } @@ -372,10 +372,10 @@ int pass_set_online_max_num(struct pass_resource *res, int num) hotplug = get_hotplug(res, res->config_data.res_type); if (!hotplug) - return -EINVAL; + return -EPERM; if (!hotplug->set_online_max_num) - return -EINVAL; + return -ENODEV; return hotplug->set_online_max_num(res->config_data.res_name, num); } @@ -390,10 +390,10 @@ int pass_get_temp(struct pass_resource *res) tmu = get_tmu(res, res->config_data.res_type); if (!tmu) - return -EINVAL; + return -EPERM; if (!tmu->get_temp) - return -EINVAL; + return -ENODEV; /* * In the case of the HAL TMU ops, res_thermal_name is used @@ -411,10 +411,10 @@ int pass_get_tmu_policy(struct pass_resource *res, char *policy) tmu = get_tmu(res, res->config_data.res_type); if (!tmu) - return -EINVAL; + return -EPERM; if (!tmu->get_policy) - return -EINVAL; + return -ENODEV; /* * In the case of the HAL TMU ops, res_thermal_name is used @@ -436,11 +436,11 @@ int pass_set_fault_around_bytes(struct pass_resource *res, memory = res->hal.memory; break; default: - return -EINVAL; + return -EPERM; } if (!memory->set_fault_around_bytes) - return -EINVAL; + return -ENODEV; return memory->set_fault_around_bytes(res->config_data.res_name, fault_around_bytes); } @@ -457,11 +457,11 @@ int pass_get_fault_around_bytes(struct pass_resource *res) memory = res->hal.memory; break; default: - return -EINVAL; + return -EPERM; } if (!memory->get_fault_around_bytes) - return -EINVAL; + return -ENODEV; return memory->get_fault_around_bytes(res->config_data.res_name); } @@ -470,7 +470,7 @@ int pass_set_pmqos_data(struct pass_resource *res, void *data) { struct pass_resource_nonstandard *nonstandard = NULL; - if (!res) + if (!res || !data) return -EINVAL; switch (res->config_data.res_type) { @@ -478,11 +478,11 @@ int pass_set_pmqos_data(struct pass_resource *res, void *data) nonstandard = (res->hal.nonstandard); break; default: - return -EINVAL; + return -EPERM; } - if (!nonstandard->set_pmqos_data || !data) - return -EINVAL; + if (!nonstandard->set_pmqos_data) + return -ENODEV; return nonstandard->set_pmqos_data(res->config_data.res_name, data); } -- 2.7.4 From b466751f6e98426404cb054f4619aaba03e3ea0f Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 18 Jul 2018 20:11:56 +0900 Subject: [PATCH 08/16] unittest: Add testcase to verify PASS HAL interface PASS provides HAL(Hardware Abstract Layer) interface for CPU/GPU/Bus/memory h/w resources and so on. Add testcase to verify PASS HAL interface. Change-Id: I2c229b13e303f46007e32cc39f559fb29d8e1b78 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 1 + unittest/CMakeLists.txt | 34 +++ unittest/pass_hal_gtest.cpp | 552 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 587 insertions(+) create mode 100644 unittest/CMakeLists.txt create mode 100644 unittest/pass_hal_gtest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a16e74c..a7521d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,3 +111,4 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/s ) ADD_SUBDIRECTORY(src/hal) +ADD_SUBDIRECTORY(unittest) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt new file mode 100644 index 0000000..99c5bdc --- /dev/null +++ b/unittest/CMakeLists.txt @@ -0,0 +1,34 @@ +PROJECT(pass C CXX) + +SET(SRCS ${CMAKE_SOURCE_DIR}/src/hal/hal.c + ${CMAKE_SOURCE_DIR}/src/pass/pass-hal.c + ${CMAKE_SOURCE_DIR}/src/pass/pass-parser.c + ${CMAKE_SOURCE_DIR}/src/core/common.c + ${CMAKE_SOURCE_DIR}/src/core/config-parser.c +) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/pass) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(gtest_pkgs REQUIRED glib-2.0 gio-2.0 gmock dlog) + +FOREACH(flag ${gtest_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE -fPIC") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + ADD_EXECUTABLE(${src_name} ${SRCS} ${src}) + TARGET_LINK_LIBRARIES(${src_name} ${gtest_LDFLAGS} ${gtest_pkgs_LDFLAGS} -ldl) + INSTALL(TARGETS ${src_name} DESTINATION bin) +ENDFOREACH() diff --git a/unittest/pass_hal_gtest.cpp b/unittest/pass_hal_gtest.cpp new file mode 100644 index 0000000..8f229d9 --- /dev/null +++ b/unittest/pass_hal_gtest.cpp @@ -0,0 +1,552 @@ +/* + * Copyright (C) 2018 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 + +extern "C" { +#include "pass-hal.h" +#include "pass-parser.h" +} + +using namespace std; + +class PassHalTest : public testing::Test { + public: + virtual void SetUp() {} + virtual void TearDown() {} +}; + +static struct pass g_pass; + +static int haltest_is_failed(struct pass_resource *res, int ret) +{ + char *res_name = res->config_data.res_name; + /* + * If -EPERM, function is not supported according to h/w resource type. + * And if -ENODEV, function is not implemented on hal package. + * It means that this funcion is not necessary on two error case + * when calling the HAL functions. + */ + if (ret < 0) { + if (ret == -EPERM || ret == -ENODEV) + return 0; + + cout << "Failed to test HAL of '" << res_name << "'" << endl; + return 1; + } + return 0; +} + +TEST_F(PassHalTest, GetResourceConfig) +{ + int ret = 0; + unsigned int i; + char path[] = "/etc/pass/pass.conf"; + + /* Stop PASS daemon before HAL testing */ + ret = system("systemctl stop pass.service"); + ASSERT_EQ(ret, 0) << "PassServieStop Faield"; + + ret = pass_get_resource_config(&g_pass, path); + if (ret < 0) + return; + + ASSERT_EQ(ret, 0) << "GetResourceConfig Failed"; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_resource(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetResourceConfig Failed"; + return; + } + } +} + +TEST_F(PassHalTest, GetCurrGovernor) +{ + int ret = 0; + unsigned int i; + char governor[BUFF_MAX]; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_curr_governor(res, governor); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetCurrGovernor Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetCurrGovernor) +{ + int ret = 0; + unsigned int i; + char governor[BUFF_MAX]; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_curr_governor(res, governor); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetCurrGovernor Failed"; + return; + } + + ret = pass_set_curr_governor(res, governor); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetCurrGovernor Failed"; + return; + } + } +} + +TEST_F(PassHalTest, GetCurrFreq) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_curr_freq(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetCurrFreq Failed"; + return; + } + } +} + +TEST_F(PassHalTest, GetMinFreq) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_min_freq(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetMinFreq Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetMinFreq) +{ + int ret = 0; + int min_freq = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + min_freq = pass_get_available_min_freq(res); + if (haltest_is_failed(res, min_freq)) { + ASSERT_EQ(min_freq, 0) << "GetAvailableMinFreq Failed"; + return; + } + + if (min_freq >= 0) { + ret = pass_set_min_freq(res, min_freq); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetMinFreq Failed"; + return; + } + } + } +} + +TEST_F(PassHalTest, GetMaxFreq) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_max_freq(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetMaxFreq Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetMaxFreq) +{ + int ret = 0; + int max_freq = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + max_freq = pass_get_available_max_freq(res); + if (haltest_is_failed(res, max_freq)) { + ASSERT_EQ(max_freq, 0) << "GetAvailableMaxFreq Failed"; + return; + } + + if (max_freq >= 0) { + ret = pass_set_max_freq(res, max_freq); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetMaxFreq Failed"; + return; + } + } + } +} + +TEST_F(PassHalTest, GetAvailableMinFreq) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_available_min_freq(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetAvailableMinFreq Failed"; + return; + } + } +} + +TEST_F(PassHalTest, GetAvailableMaxFreq) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_available_max_freq(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetAvailableMaxFreq Failed"; + return; + } + } +} + + +TEST_F(PassHalTest, GetUpThreshold) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_up_threshold(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetUpThreshold Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetUpThreshold) +{ + int ret = 0; + int up_threshold = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + up_threshold = pass_get_up_threshold(res); + if (haltest_is_failed(res, up_threshold)) { + ASSERT_EQ(up_threshold, 0) << "GetUpThreshold Failed"; + return; + } + + if (up_threshold >= 0) { + ret = pass_set_up_threshold(res, up_threshold); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetUpThreshold Failed"; + return; + } + } + } +} + +TEST_F(PassHalTest, GetTemperature) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_temp(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetTemperature Failed"; + return; + } + } +} + +TEST_F(PassHalTest, GetTmuPolicy) +{ + int ret = 0; + unsigned int i; + char policy[BUFF_MAX]; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_tmu_policy(res, policy); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetTmuPolicy Failed"; + return; + } + } +} + +TEST_F(PassHalTest, GetOnlineState) +{ + int ret = 0; + unsigned int i, j; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + for (j = 0; j < res->config_data.num_cpus; j++) { + ret = pass_get_online_state(res, j); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetOnlineState Failed"; + return; + } + } + + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetOnlineState Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetOnlineState) +{ + int ret = 0; + int online_state = 0; + unsigned int i, j; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + for (j = 0; j < res->config_data.num_cpus; j++) { + online_state = pass_get_online_state(res, j); + if (haltest_is_failed(res, online_state)) { + ASSERT_EQ(online_state, 0) << "GetOnlineState Failed"; + return; + } + + if (online_state >= 0) { + ret = pass_set_online_state(res, j, online_state); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetOnlineState Failed"; + return; + } + } + } + } +} + + +TEST_F(PassHalTest, GetOnlineMinNum) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_online_min_num(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetOnlineMinNum Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetOnlineMinNum) +{ + int ret = 0; + int online_min_num = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + online_min_num = pass_get_online_min_num(res); + if (haltest_is_failed(res, online_min_num)) { + ASSERT_EQ(online_min_num, 0) << "GetOnlineMinNum Failed"; + return; + } + + if (online_min_num >= 0) { + ret = pass_set_online_min_num(res, online_min_num); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetOnlineMinNum Failed"; + return; + } + } + } +} + +TEST_F(PassHalTest, GetOnlineMaxNum) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_online_max_num(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetOnlineMaxNum Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetOnlineMaxNum) +{ + int ret = 0; + int online_max_num = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + online_max_num = pass_get_online_max_num(res); + if (haltest_is_failed(res, online_max_num)) { + ASSERT_EQ(online_max_num, 0) << "GetOnlineMaxNum Failed"; + return; + } + + if (online_max_num >= 0) { + ret = pass_set_online_max_num(res, online_max_num); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetOnlineMaxNum Failed"; + return; + } + } + } +} + +TEST_F(PassHalTest, GetFaultAroundBytes) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_get_fault_around_bytes(res); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "GetFaultAroundBytes Failed"; + return; + } + } +} + +TEST_F(PassHalTest, SetFaultAroundBytes) +{ + int ret = 0; + int fault_around_bytes = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + fault_around_bytes = pass_get_fault_around_bytes(res); + if (haltest_is_failed(res, fault_around_bytes)) { + ASSERT_EQ(fault_around_bytes, 0) << "GetFaultAroundBytes Failed"; + return; + } + + if (fault_around_bytes >= 0) { + ret = pass_set_fault_around_bytes(res, fault_around_bytes); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetFaultAroundBytes Failed"; + return; + } + } + } +} + +TEST_F(PassHalTest, SetPmqosData) +{ + int ret = 0; + unsigned int i; + char applaunch_scenario[] = "AppLaunch"; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_set_pmqos_data(res, applaunch_scenario); + if (haltest_is_failed(res, ret)) { + ASSERT_EQ(ret, 0) << "SetPmqosData Failed"; + return; + } + } +} + +TEST_F(PassHalTest, PutResourceConfig) +{ + int ret = 0; + unsigned int i; + + for (i = 0; i < g_pass.num_resources; i++) { + struct pass_resource *res = &g_pass.res[i]; + + ret = pass_put_resource(res); + if (ret < 0) { + pass_put_resource_config(&g_pass); + ASSERT_EQ(ret, 0) << "PutResourceConfig Failed"; + return; + } + } + + /* Restart PASS daemon before HAL testing */ + ret = system("systemctl start pass.service"); + ASSERT_EQ(ret, 0) << "PassServiceStart Faield"; +} + +int main(int argc, char *argv[]) +{ + int ret; + + try { + testing::InitGoogleTest(&argc, argv); + ret = RUN_ALL_TESTS(); + } catch (...) { + ret = EXIT_FAILURE; + } + + return ret; +} -- 2.7.4 From 3e630f95d84727db2dad5236e5b1ce19730764e4 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 23 Jul 2018 18:36:58 +0900 Subject: [PATCH 09/16] unittest: Add testcase to verify pass daemon This patch adds unittest based on gtest test suite. Change-Id: I72a346720b32eb5941b1af9e4afb46533356bd24 Signed-off-by: Dongwoo Lee Signed-off-by: Chanwoo Choi --- unittest/pass_gtest.cpp | 241 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 unittest/pass_gtest.cpp diff --git a/unittest/pass_gtest.cpp b/unittest/pass_gtest.cpp new file mode 100644 index 0000000..7cd0317 --- /dev/null +++ b/unittest/pass_gtest.cpp @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2018 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 + +#define PASS_DBUS_NAME "org.tizen.system.pass" +#define PASS_DBUS_PATH "/Org/Tizen/System/Pass/" +#define PASS_DBUS_INTF "org.tizen.system.pass." + +class PassTest : public testing::Test { +public: + static void SetUpTestCase() { + int ret = 0; + ASSERT_EQ(ret, 0); + } + static void TearDownTestCase() { + int ret = 0; + ASSERT_EQ(ret, 0); + } + void TearDown() override { + } +}; + +static gint32 pass_test_method_call(const gchar *path, const gchar *intf, + const gchar *method, GVariant *body) +{ + const gchar *type; + GVariant *ret; + GError *err = NULL; + GDBusMessage *msg, *reply; + GDBusConnection *conn; + gint32 r; + + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (err) + return -1; + + msg = g_dbus_message_new_method_call(PASS_DBUS_NAME, path, + intf, method); + if (!msg) + return -1; + + if (body) + g_dbus_message_set_body(msg, body); + + reply = g_dbus_connection_send_message_with_reply_sync(conn, msg, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + G_MAXINT, NULL, NULL, &err); + if (err) { + g_object_unref(msg); + g_clear_error(&err); + return -1; + } + + ret = g_variant_get_child_value(g_dbus_message_get_body(reply), 0); + type = g_variant_get_type_string(ret); + if (type[0] == 'i') + r = g_variant_get_int32(ret); + else + r = -1; + + g_variant_unref(ret); + + g_dbus_connection_flush(conn, NULL, NULL, NULL); + g_object_unref(msg); + g_object_unref(reply); + g_clear_error(&err); + + return r; +} + +TEST_F(PassTest, AppLaunch) +{ + gint32 ret; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "AppLaunch", + g_variant_new("(i)", 3000)); + ASSERT_EQ(ret, 0) << "AppLaunch Failed"; + + +} + +TEST_F(PassTest, MultipleAppLaunch) +{ + gint32 ret; + int i; + + for (i = 0; i < 3; i++) { + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "AppLaunch", + g_variant_new("(i)", 3000)); + ASSERT_EQ(ret, 0) << "MultipleAppLaunch Failed"; + } +} + +TEST_F(PassTest, AppLaunch_and_UltraPowerSaving) +{ + gint32 ret; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "AppLaunch", + g_variant_new("(i)", 3000)); + ASSERT_EQ(ret, 0) << "AppLaunch Failed"; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "UltraPowerSaving", + g_variant_new("(i)", 3000)); + ASSERT_EQ(ret, 0) << "UltraPowerSaving Failed"; +} + +TEST_F(PassTest, HandleErrorCase) +{ + gint32 ret; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "stop", + NULL); + ASSERT_EQ(ret, 0) << "PmQosStop Faield"; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "AppLaunch", + g_variant_new("(i)", 3000)); + + ASSERT_EQ(ret, -1) << "AppLaunch Faield"; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "start", + NULL); + ASSERT_EQ(ret, 0) << "PmQosStart Faield"; + +} + +TEST_F(PassTest, PmQosRestart) +{ + gint32 ret; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "stop", + NULL); + ASSERT_EQ(ret, 0) << "PmQosStop Faield"; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "start", + NULL); + ASSERT_EQ(ret, 0) << "PmQosStart Faield"; + + ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", + PASS_DBUS_INTF"pmqos", + "AppLaunch", + g_variant_new("(i)", 3000)); + + ASSERT_EQ(ret, 0) << "PmQosStop Faield"; +} + +TEST_F(PassTest, ThermalMonitorRestart) +{ + gint32 ret; + + ret = pass_test_method_call(PASS_DBUS_PATH"Monitor/Thermal", + PASS_DBUS_INTF"monitor.thermal", + "stop", + NULL); + ASSERT_EQ(ret, 0) << "ThermalMonitorStop Faield"; + + ret = pass_test_method_call(PASS_DBUS_PATH"Monitor/Thermal", + PASS_DBUS_INTF"monitor.thermal", + "start", + NULL); + + ASSERT_EQ(ret, 0) << "ThermalMonitorStart Faield"; +} + +TEST_F(PassTest, PassCoreRestart) +{ + gint32 ret; + + ret = pass_test_method_call(PASS_DBUS_PATH"Core", + PASS_DBUS_INTF"core", + "stop", + NULL); + ASSERT_EQ(ret, 0) << "PassCoreStop Faield"; + + ret = pass_test_method_call(PASS_DBUS_PATH"Core", + PASS_DBUS_INTF"core", + "start", + NULL); + + ASSERT_EQ(ret, 0) << "PassCoreStart Faield"; +} + +TEST_F(PassTest, PassServiceReStart) +{ + gint32 ret; + + ret = system("systemctl stop pass.service"); + ASSERT_EQ(ret, 0) << "PassServieStop Faield"; + + ret = system("systemctl start pass.service"); + ASSERT_EQ(ret, 0) << "PassServiceStart Faield"; +} + +int main(int argc, char *argv[]) +{ + int ret; + + try { + testing::InitGoogleTest(&argc, argv); + ret = RUN_ALL_TESTS(); + } catch (...) { + ret = EXIT_FAILURE; + } + + return ret; +} -- 2.7.4 From 1c0f72a99d29c21aab1b79fd787c2de372bf7df0 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 23 Jul 2018 10:46:26 +0900 Subject: [PATCH 10/16] packaging: Add pass-haltests package Add pass-haltests-* package contains 'pass_hal_gtest' command binary which tests the HAL(Hardware Abstract Layer) interface. Change-Id: I29687b0021c8a6cfd1d1b97560a25fbb3be70e89 Signed-off-by: Chanwoo Choi --- packaging/pass.spec | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packaging/pass.spec b/packaging/pass.spec index 8f64774..56c78d2 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -2,6 +2,7 @@ %define _unpackaged_files_terminate_build 0 %define daemon_name pass %define hal_name pass-hal-devel +%define haltest_name pass-haltests Name: %{daemon_name} Summary: Power Aware System Service @@ -19,6 +20,7 @@ BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(libudev) %description @@ -39,6 +41,14 @@ Requires: pass = %{version}-%{release} %description -n %{hal_name} Header files required to build pass-hal packages for specific boards. +%package -n %{haltest_name} +Summary: PASS HAL test package with gtest +Group: Development/Tools +Requires: pass = %{version}-%{release} + +%description -n %{haltest_name} +PASS HAL test package with gtest + %prep %setup -q @@ -90,3 +100,7 @@ systemctl daemon-reload %{_includedir}/%{daemon_name}/hal.h %{_includedir}/%{daemon_name}/hal-log.h %{_libdir}/pkgconfig/%{hal_name}.pc + +%files -n %{haltest_name} +%defattr(-,root,root,-) +%{_bindir}/pass_hal_gtest -- 2.7.4 From a4bdfc59038eef3ec202e9bb6c172a9270dbf736 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 23 Jul 2018 18:38:39 +0900 Subject: [PATCH 11/16] packaging: Add pass-unittest package Add pass-unittest-* package contains 'pass_gtest' command binary which tests the external d-bus interface. Change-Id: Ic3a022a63fb5ab1001c1e14544a261f45613a7ec Signed-off-by: Chanwoo Choi --- packaging/pass.spec | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packaging/pass.spec b/packaging/pass.spec index 56c78d2..c36ad3e 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -3,6 +3,7 @@ %define daemon_name pass %define hal_name pass-hal-devel %define haltest_name pass-haltests +%define unittest_name pass-unittest Name: %{daemon_name} Summary: Power Aware System Service @@ -49,6 +50,14 @@ Requires: pass = %{version}-%{release} %description -n %{haltest_name} PASS HAL test package with gtest +%package -n %{unittest_name} +Summary: PASS unit test package with gtest +Group: Development/Tools +Requires: pass = %{version}-%{release} + +%description -n %{unittest_name} +PASS unit test package with gtest + %prep %setup -q @@ -104,3 +113,7 @@ systemctl daemon-reload %files -n %{haltest_name} %defattr(-,root,root,-) %{_bindir}/pass_hal_gtest + +%files -n %{unittest_name} +%defattr(-,root,root,-) +%{_bindir}/pass_gtest -- 2.7.4 From 8345ee327c87319e64f267e30bd1f61507c887cc Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 2 Aug 2018 16:17:51 +0900 Subject: [PATCH 12/16] gdbus: Separate gdubs-definition.h from gdbus-util.h gdbus-util.h contains the gdbus helper function and dbus path/interface definitions. Some PASS modules only require the dbus path/interface definitions with gdbus helper function. So, separate gdubs-definition.h from gdbus-util.h. Change-Id: I587c728d3d594adc65778e77bf7933a17acde4c1 Signed-off-by: Chanwoo Choi --- include/pass/gdbus-definition.h | 53 +++++++++++++++++++++++++++++++++++++++++ include/pass/gdbus-util.h | 30 +---------------------- 2 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 include/pass/gdbus-definition.h diff --git a/include/pass/gdbus-definition.h b/include/pass/gdbus-definition.h new file mode 100644 index 0000000..cca8b3f --- /dev/null +++ b/include/pass/gdbus-definition.h @@ -0,0 +1,53 @@ +/* + * PASS (Power Aware System Service) + * + * Copyright (c) 2018 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. + */ + +#ifndef __GDBUS_DEFINITION_H__ +#define __GDBUS_DEFINITION_H__ + +/* Dbus definition for PASS */ +#define DBUS_PASS_BUS_NAME "org.tizen.system.pass" +#define DBUS_PASS_PATH "/Org/Tizen/System/Pass" + +#define DBUS_CORE_INTERFACE "org.tizen.system.pass.core" +#define DBUS_CORE_PATH "/Org/Tizen/System/Pass/Core" +#define DBUS_CORE_I_START_HANDLER "handle_start" +#define DBUS_CORE_I_STOP_HANDLER "handle_stop" + +#define DBUS_PMQOS_INTERFACE "org.tizen.system.pass.pmqos" +#define DBUS_PMQOS_PATH "/Org/Tizen/System/Pass/Pmqos" +#define DBUS_PMQOS_I_START_HANDLER "handle_start" +#define DBUS_PMQOS_I_STOP_HANDLER "handle_stop" +#define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch" +#define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving" + +#define DBUS_THERMAL_INTERFACE "org.tizen.system.pass.monitor.thermal" +#define DBUS_THERMAL_PATH "/Org/Tizen/System/Pass/Monitor/Thermal" +#define DBUS_THERMAL_I_START_HANDLER "handle_start" +#define DBUS_THERMAL_I_STOP_HANDLER "handle_stop" +#define DBUS_THERMAL_METHOD "thermal_scenario" + +/* Dbus definition for systemd */ +#define SYSTEMD_DBUS_NAME "org.freedesktop.systemd1" +#define SYSTEMD_DBUS_OBJECT_PATH "/org/freedesktop/systemd1" +#define SYSTEMD_DBUS_IFACE_FOR_PROPS "org.freedesktop.DBus.Properties" +#define SYSTEMD_DBUS_METHOD_GET_PROP "Get" +#define SYSTEMD_DBUS_METHOD_GET_PROP_ARG_TYPE "(ss)" +#define SYSTEMD_DBUS_METHOD_GET_PROP_RET_TYPE "(v)" +#define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_NAME ".Manager" + +#endif /* __GDBUS_DEFINITION_H__ */ diff --git a/include/pass/gdbus-util.h b/include/pass/gdbus-util.h index 1eb349e..130e237 100644 --- a/include/pass/gdbus-util.h +++ b/include/pass/gdbus-util.h @@ -27,35 +27,7 @@ #include "pmqos/pmqos-dbus-stub.h" #include "thermal/thermal-dbus-stub.h" -/* Dbus definition for PASS */ -#define DBUS_PASS_BUS_NAME "org.tizen.system.pass" - -#define DBUS_CORE_INTERFACE "org.tizen.system.pass.core" -#define DBUS_CORE_PATH "/Org/Tizen/System/Pass/Core" -#define DBUS_CORE_I_START_HANDLER "handle_start" -#define DBUS_CORE_I_STOP_HANDLER "handle_stop" - -#define DBUS_PMQOS_INTERFACE "org.tizen.system.pass.pmqos" -#define DBUS_PMQOS_PATH "/Org/Tizen/System/Pass/Pmqos" -#define DBUS_PMQOS_I_START_HANDLER "handle_start" -#define DBUS_PMQOS_I_STOP_HANDLER "handle_stop" -#define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch" -#define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving" - -#define DBUS_THERMAL_INTERFACE "org.tizen.system.pass.monitor.thermal" -#define DBUS_THERMAL_PATH "/Org/Tizen/System/Pass/Monitor/Thermal" -#define DBUS_THERMAL_I_START_HANDLER "handle_start" -#define DBUS_THERMAL_I_STOP_HANDLER "handle_stop" -#define DBUS_THERMAL_METHOD "thermal_scenario" - -/* Dbus definition for systemd */ -#define SYSTEMD_DBUS_NAME "org.freedesktop.systemd1" -#define SYSTEMD_DBUS_OBJECT_PATH "/org/freedesktop/systemd1" -#define SYSTEMD_DBUS_IFACE_FOR_PROPS "org.freedesktop.DBus.Properties" -#define SYSTEMD_DBUS_METHOD_GET_PROP "Get" -#define SYSTEMD_DBUS_METHOD_GET_PROP_ARG_TYPE "(ss)" -#define SYSTEMD_DBUS_METHOD_GET_PROP_RET_TYPE "(v)" -#define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_NAME ".Manager" +#include "gdbus-definition.h" struct pass_gdbus_signal_info { const gchar *handler; -- 2.7.4 From 4b00d8c0461b1cefdc87896fe2b1524798f527bb Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 2 Aug 2018 16:23:00 +0900 Subject: [PATCH 13/16] unittest: pass_gtest: Use gdbus-definition.h to remove local definition Remove local dbus definition and then use gdbus-definition.h which contains dbus path/interface definition. And changes the path of systemctl command. Change-Id: Ic5ec5b36b5c36f9580be93fdc38a53cb15894102 Signed-off-by: Chanwoo Choi --- unittest/pass_gtest.cpp | 66 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/unittest/pass_gtest.cpp b/unittest/pass_gtest.cpp index 7cd0317..60f78af 100644 --- a/unittest/pass_gtest.cpp +++ b/unittest/pass_gtest.cpp @@ -20,9 +20,7 @@ #include #include -#define PASS_DBUS_NAME "org.tizen.system.pass" -#define PASS_DBUS_PATH "/Org/Tizen/System/Pass/" -#define PASS_DBUS_INTF "org.tizen.system.pass." +#include class PassTest : public testing::Test { public: @@ -52,7 +50,7 @@ static gint32 pass_test_method_call(const gchar *path, const gchar *intf, if (err) return -1; - msg = g_dbus_message_new_method_call(PASS_DBUS_NAME, path, + msg = g_dbus_message_new_method_call(DBUS_PASS_BUS_NAME, path, intf, method); if (!msg) return -1; @@ -90,8 +88,8 @@ TEST_F(PassTest, AppLaunch) { gint32 ret; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "AppLaunch", g_variant_new("(i)", 3000)); ASSERT_EQ(ret, 0) << "AppLaunch Failed"; @@ -105,8 +103,8 @@ TEST_F(PassTest, MultipleAppLaunch) int i; for (i = 0; i < 3; i++) { - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "AppLaunch", g_variant_new("(i)", 3000)); ASSERT_EQ(ret, 0) << "MultipleAppLaunch Failed"; @@ -117,14 +115,14 @@ TEST_F(PassTest, AppLaunch_and_UltraPowerSaving) { gint32 ret; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "AppLaunch", g_variant_new("(i)", 3000)); ASSERT_EQ(ret, 0) << "AppLaunch Failed"; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "UltraPowerSaving", g_variant_new("(i)", 3000)); ASSERT_EQ(ret, 0) << "UltraPowerSaving Failed"; @@ -134,21 +132,21 @@ TEST_F(PassTest, HandleErrorCase) { gint32 ret; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "stop", NULL); ASSERT_EQ(ret, 0) << "PmQosStop Faield"; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "AppLaunch", g_variant_new("(i)", 3000)); ASSERT_EQ(ret, -1) << "AppLaunch Faield"; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "start", NULL); ASSERT_EQ(ret, 0) << "PmQosStart Faield"; @@ -159,20 +157,20 @@ TEST_F(PassTest, PmQosRestart) { gint32 ret; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "stop", NULL); ASSERT_EQ(ret, 0) << "PmQosStop Faield"; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "start", NULL); ASSERT_EQ(ret, 0) << "PmQosStart Faield"; - ret = pass_test_method_call(PASS_DBUS_PATH"Pmqos", - PASS_DBUS_INTF"pmqos", + ret = pass_test_method_call(DBUS_PASS_PATH"/Pmqos", + DBUS_PASS_BUS_NAME".pmqos", "AppLaunch", g_variant_new("(i)", 3000)); @@ -183,14 +181,14 @@ TEST_F(PassTest, ThermalMonitorRestart) { gint32 ret; - ret = pass_test_method_call(PASS_DBUS_PATH"Monitor/Thermal", - PASS_DBUS_INTF"monitor.thermal", + ret = pass_test_method_call(DBUS_PASS_PATH"/Monitor/Thermal", + DBUS_PASS_BUS_NAME".monitor.thermal", "stop", NULL); ASSERT_EQ(ret, 0) << "ThermalMonitorStop Faield"; - ret = pass_test_method_call(PASS_DBUS_PATH"Monitor/Thermal", - PASS_DBUS_INTF"monitor.thermal", + ret = pass_test_method_call(DBUS_PASS_PATH"/Monitor/Thermal", + DBUS_PASS_BUS_NAME".monitor.thermal", "start", NULL); @@ -201,14 +199,14 @@ TEST_F(PassTest, PassCoreRestart) { gint32 ret; - ret = pass_test_method_call(PASS_DBUS_PATH"Core", - PASS_DBUS_INTF"core", + ret = pass_test_method_call(DBUS_PASS_PATH"/Core", + DBUS_PASS_BUS_NAME".core", "stop", NULL); ASSERT_EQ(ret, 0) << "PassCoreStop Faield"; - ret = pass_test_method_call(PASS_DBUS_PATH"Core", - PASS_DBUS_INTF"core", + ret = pass_test_method_call(DBUS_PASS_PATH"/Core", + DBUS_PASS_BUS_NAME".core", "start", NULL); @@ -219,10 +217,10 @@ TEST_F(PassTest, PassServiceReStart) { gint32 ret; - ret = system("systemctl stop pass.service"); + ret = system("/bin/systemctl stop pass.service"); ASSERT_EQ(ret, 0) << "PassServieStop Faield"; - ret = system("systemctl start pass.service"); + ret = system("/bin/systemctl start pass.service"); ASSERT_EQ(ret, 0) << "PassServiceStart Faield"; } -- 2.7.4 From ed7fc936af1d04c35b47031ca2748fd688f7ff7e Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 2 Aug 2018 16:40:51 +0900 Subject: [PATCH 14/16] pass: rescon: Fix issue of init_level setting and remove unneeded pass_hotplug RESCON (Resource Controller) module changes the value h/w resource according to 'init_level' property getting from each h/w resource configuration. Even if RESCON always is initialized before CPUHP init, RESCON depends on CPUHP in order to get the limited number of online CPU. Fix issue of init_level setting during init step by getting limited_min_cpu value without CPUHP module. And remove unneeded pass_hotplug. Change-Id: If7f13a7197fe93b41c23688d49370631d6d76e5e Signed-off-by: Chanwoo Choi --- src/pass/pass-cpuhp-radiation.c | 6 ++-- src/pass/pass-cpuhp.c | 63 ----------------------------------------- src/pass/pass-rescon.c | 50 +++++++------------------------- src/pass/pass.h | 12 -------- 4 files changed, 14 insertions(+), 117 deletions(-) diff --git a/src/pass/pass-cpuhp-radiation.c b/src/pass/pass-cpuhp-radiation.c index 8010c39..362c0b3 100644 --- a/src/pass/pass-cpuhp-radiation.c +++ b/src/pass/pass-cpuhp-radiation.c @@ -177,12 +177,12 @@ int pass_cpuhp_radiation_governor(struct pass_resource *res, void *result) return level; if (up_count * 100 >= num_pass_gov * up_threshold) { - level += cpuhp->hotplug->num_cpus; + level += res->config_data.num_cpus; if (level > res->rescon.max_level) - level -= cpuhp->hotplug->num_cpus; + level -= res->config_data.num_cpus; } else if (down_count * 100 >= num_pass_gov * down_threshold) { - level -= cpuhp->hotplug->num_cpus; + level -= res->config_data.num_cpus; } if (right_count * 100 >= num_pass_gov * up_threshold) { diff --git a/src/pass/pass-cpuhp.c b/src/pass/pass-cpuhp.c index 5d55091..a74b321 100644 --- a/src/pass/pass-cpuhp.c +++ b/src/pass/pass-cpuhp.c @@ -55,53 +55,6 @@ static bool is_enabled(struct pass_cpuhp *cpuhp) return true; } -static void cpuhp_hotplug_stop(struct pass_resource *res) -{ - struct pass_level *levels = res->config_data.levels; - int level = res->rescon.max_level; - - if (!res->cpuhp.hotplug || !levels) - return; - - res->cpuhp.hotplug->online = levels[level].limit_min_cpu; -} - -static int cpuhp_hotplug_dummy_governor(struct pass_resource *res) -{ - int level = res->rescon.curr_level; - - return res->config_data.levels[level].limit_min_cpu; -} - -static struct pass_hotplug* cpuhp_get_hotplug(struct pass_resource *res, - enum pass_gov_type type) -{ - struct pass_hotplug *hotplug; - - switch (type) { - case PASS_GOV_DUMMY: - case PASS_GOV_BASIC: - /* Don't use Hotplug interface */ - return NULL; - case PASS_GOV_HOTPLUG_ONLY: - case PASS_GOV_STEP: - case PASS_GOV_RADIATION: - /* Use Hotplug interface */ - hotplug = calloc(1, sizeof(struct pass_hotplug)); - if (!hotplug) { - _E("cannot allocate the memory of struct pass_hotplug"); - return NULL; - } - hotplug->governor = cpuhp_hotplug_dummy_governor; - return hotplug; - default: - _E("Unknown hotplug type"); - break; - }; - - return NULL; -} - static void cpuhp_calculate_busy_cpu(struct pass_resource *res, void *result) { struct pass_cpuhp *cpuhp = &res->cpuhp; @@ -260,8 +213,6 @@ static void cpuhp_governor_stop(struct pass_resource *res) return; } - cpuhp_hotplug_stop(res); - /* Unregister the resource-monitor for CPUHP module */ pass_resmon_unregister_timer(res, RESMON_SRC_CPUHP); @@ -298,9 +249,6 @@ static int cpuhp_governor_exit(struct pass_resource *res) */ cpuhp_governor_update(res, PASS_OFF); - if (cpuhp->hotplug) - free(cpuhp->hotplug->sequence); - /* Set pass_cpuhp structure as default value */ cpuhp->pass_cpu_threshold = 0; cpuhp->up_threshold = 0; @@ -431,17 +379,6 @@ int pass_cpuhp_init(struct pass_resource *res) max_freq = res->config_data.levels[i].limit_max_freq; cpuhp->max_freq = max_freq; - /* Get the instance of CPU Hotplug's policy */ - cpuhp->hotplug = cpuhp_get_hotplug(res, res->config_data.gov_type); - if (cpuhp->hotplug) { - cpuhp->hotplug->sequence = calloc(res->config_data.num_cpus, - sizeof(int)); - for (i = 0; i < res->config_data.num_cpus; i++) - cpuhp->hotplug->sequence[i] = i + res->config_data.cpu; - - cpuhp->hotplug->num_cpus = res->config_data.num_cpus; - } - /* Get the instance of CPUHP governor */ cpuhp->governor = cpuhp_get_governor(res, res->config_data.gov_type); if (!cpuhp->governor) { diff --git a/src/pass/pass-rescon.c b/src/pass/pass-rescon.c index f5b0e56..2ea800b 100644 --- a/src/pass/pass-rescon.c +++ b/src/pass/pass-rescon.c @@ -23,63 +23,35 @@ #include "pass.h" #include "pass-hal.h" -static void hotplug_set_online(struct pass_resource *res, - unsigned int min_num) -{ - struct pass_hotplug *hotplug = res->cpuhp.hotplug; - int i; - - if (!hotplug || min_num == hotplug->online) - return; - - if (min_num > hotplug->num_cpus) - min_num = hotplug->num_cpus; - - pass_set_online_min_num(res, min_num); - - for (i = 0 ; i < hotplug->num_cpus; i++) { - if (i < min_num) - pass_set_online_state(res, hotplug->sequence[i], 1); - else - pass_set_online_state(res, hotplug->sequence[i], 0); - } - - /* - _I("- CPU %4s '%d->%d'Core\n", - (hotplug->online > min_num ? "DOWN" : "UP"), - hotplug->online, min_num); - */ - - hotplug->online = min_num; -} - static int rescon_set_level(struct pass_resource *res, int new_level) { struct pass_level *levels = res->config_data.levels;; - struct pass_cpuhp *cpuhp = &res->cpuhp; int curr_level = res->rescon.curr_level; int limit_max_freq; int limit_min_freq; int limit_min_cpu; int fault_around_bytes; - int ret; + int ret, i; /* Get the detailed resource value according to PASS level */ limit_max_freq = levels[new_level].limit_max_freq; limit_min_freq = levels[new_level].limit_min_freq; + limit_min_cpu = levels[new_level].limit_min_cpu; fault_around_bytes = levels[new_level].fault_around_bytes; res->rescon.prev_level = curr_level; res->rescon.curr_level = new_level; - /* Turn on/off CPUs according the maximum number of online CPU */ - if (cpuhp->hotplug) { - if (cpuhp->hotplug->governor) - limit_min_cpu = cpuhp->hotplug->governor(res); - else - limit_min_cpu = 1; + /* Turn on/off CPUs according required number of online CPU */ + if (limit_min_cpu >= 0) { + if (limit_min_cpu > res->config_data.num_cpus) + limit_min_cpu = res->config_data.num_cpus; + + pass_set_online_min_num(res, limit_min_cpu); - hotplug_set_online(res, limit_min_cpu); + for (i = 0; i < res->config_data.num_cpus; i++) + pass_set_online_state(res, res->config_data.cpu + i, + (i < limit_min_cpu) ? 1 : 0); } /* Set maximum frequency */ diff --git a/src/pass/pass.h b/src/pass/pass.h index 8a07cf8..b77ffb7 100644 --- a/src/pass/pass.h +++ b/src/pass/pass.h @@ -84,14 +84,6 @@ enum pass_state { PASS_ON = 1, }; -struct pass_hotplug { - char name[BUFF_MAX]; - unsigned int num_cpus; - unsigned int online; - unsigned int *sequence; - int (*governor)(struct pass_resource *res); -}; - struct pass_level_condition { int freq; int nr_running; @@ -274,8 +266,6 @@ struct pass_pmqos { * @governor: the instance of CPUHP Policy governor. * @max_freq: the maximum frequency among levels * - * @hotplug: the instance of CPU Hotplug governor (will be deprecated). - * * CPUHP may be o enabled or disabled according to configuration file setting. */ struct pass_cpuhp { @@ -290,8 +280,6 @@ struct pass_cpuhp { struct pass_cpuhp_governor *governor; unsigned int max_freq; - - struct pass_hotplug *hotplug; }; /* -- 2.7.4 From 2e2878fe676d79ef50eb19e73492b640f04e7a41 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 3 Aug 2018 10:54:22 +0900 Subject: [PATCH 15/16] unittest: pass_hal_gtest: Modify path of systemctl command To prevent malicious binary by changing path of systemctl, modify path of systemctl command with absolute path. Change-Id: I6a7bc842d43f954ac3ac9a1a43684d4de7167155 Signed-off-by: Chanwoo Choi --- unittest/pass_hal_gtest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/pass_hal_gtest.cpp b/unittest/pass_hal_gtest.cpp index 8f229d9..0b3b450 100644 --- a/unittest/pass_hal_gtest.cpp +++ b/unittest/pass_hal_gtest.cpp @@ -60,7 +60,7 @@ TEST_F(PassHalTest, GetResourceConfig) char path[] = "/etc/pass/pass.conf"; /* Stop PASS daemon before HAL testing */ - ret = system("systemctl stop pass.service"); + ret = system("/bin/systemctl stop pass.service"); ASSERT_EQ(ret, 0) << "PassServieStop Faield"; ret = pass_get_resource_config(&g_pass, path); @@ -533,7 +533,7 @@ TEST_F(PassHalTest, PutResourceConfig) } /* Restart PASS daemon before HAL testing */ - ret = system("systemctl start pass.service"); + ret = system("/bin/systemctl start pass.service"); ASSERT_EQ(ret, 0) << "PassServiceStart Faield"; } -- 2.7.4 From f59071aaacb811e0cd57929c073c2a854c82345e Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 14 Aug 2018 13:23:10 +0900 Subject: [PATCH 16/16] unittest: Rename haltest binary from pass_hal_gtest to pass_haltests Change-Id: I1b22c4d34c09dfe21ebcd83d111d09f3bb571154 Signed-off-by: Chanwoo Choi --- packaging/pass.spec | 2 +- unittest/{pass_hal_gtest.cpp => pass_haltests.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename unittest/{pass_hal_gtest.cpp => pass_haltests.cpp} (100%) diff --git a/packaging/pass.spec b/packaging/pass.spec index c36ad3e..7ea81b1 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -112,7 +112,7 @@ systemctl daemon-reload %files -n %{haltest_name} %defattr(-,root,root,-) -%{_bindir}/pass_hal_gtest +%{_bindir}/pass_haltests %files -n %{unittest_name} %defattr(-,root,root,-) diff --git a/unittest/pass_hal_gtest.cpp b/unittest/pass_haltests.cpp similarity index 100% rename from unittest/pass_hal_gtest.cpp rename to unittest/pass_haltests.cpp -- 2.7.4