From: hyunuk.tak Date: Mon, 26 Aug 2019 08:44:24 +0000 (+0900) Subject: Test for battery monitor framework X-Git-Tag: submit/tizen/20191014.135557~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c35bd5112a5e096cafb996bd6690abb65eaee15a;p=platform%2Fcore%2Fapi%2Fsmart-traffic-control.git Test for battery monitor framework Change-Id: Ide1e6c63fea1490a33186e07da6d01114c271d08 Signed-off-by: hyunuk.tak --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0a231d1..79ea9f6 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,6 +20,7 @@ SET(stc_test firewall.c pcap.c manager.c + battery.c stc_menu.c stc_test.c ) diff --git a/test/battery.c b/test/battery.c new file mode 100755 index 0000000..1ef838f --- /dev/null +++ b/test/battery.c @@ -0,0 +1,257 @@ +/* + * Smart Traffic Control (STC) + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + * + */ + +/** + * This file declares definitions, macros and structures. + * + * @file pcap.c + * @author Tak hyunuk (hyunuk.tak@samsung.com) + * @version 0.1 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "stc_test.h" +#include "stc_menu.h" + +typedef struct { + char *app_id; + uint time; + uint rx; + uint tx; +} battery_app_data_s; + +typedef struct { + uint time_level_0; + uint time_level_1; + uint time_level_2; + uint time_level_3; + uint time_level_4; + uint time_level_5; + uint time_level_6; + GSList *atm_list; + GSList *data_list; + } battery_dn_data_s; + +typedef struct { + uint time_level_0; + uint time_level_1; + uint time_level_2; + uint time_level_3; + uint time_level_4; + time_t start_time; + time_t end_time; + uint scan_time; + GSList *atm_list; + GSList *data_list; + } battery_wifi_data_s; + +typedef void *bm_data_h; +typedef enum { + BM_DATA_TYPE_BLE, + BM_DATA_TYPE_WIFI, + BM_DATA_TYPE_CPU, + BM_DATA_TYPE_DISPLAY, + BM_DATA_TYPE_DEVICE_NETWORK, + BM_DATA_TYPE_GPS_SENSOR, + BM_DATA_TYPE_HRM_SENSOR, + BM_DATA_TYPE_BATTERY, + BM_DATA_TYPE_MAX, +} bm_plugin_data_type_e; + +typedef struct { + int (*init) (void); + int (*deinit) (void); + int (*get_feature_data) (bm_data_h *, bm_plugin_data_type_e); +} netconfig_bm_plugin_s; + +#define NETCONFIG_PLUGIN_DN_FILEPATH "/usr/lib/net-config-plugin-bm-dn.so" +#define NETCONFIG_PLUGIN_WIFI_FILEPATH "/usr/lib/net-config-plugin-bm-wifi.so" + +static void *handle_plugin_dn; +static void *handle_plugin_wifi; + +static netconfig_bm_plugin_s *netconfig_plugin_dn; +static netconfig_bm_plugin_s *netconfig_plugin_wifi; + +static gboolean netconfig_plugin_dn_enabled = FALSE; +static gboolean netconfig_plugin_wifi_enabled = FALSE; + +static int __test_stc_battery_dn_get_data(MManager *mm, struct menu_data *menu) +{ + bm_data_h data; + + if (!netconfig_plugin_dn_enabled) + return STC_ERROR_NOT_INITIALIZED; + + netconfig_plugin_dn->get_feature_data(&data, 0); + + battery_dn_data_s *dn_data = (battery_dn_data_s *)data; + + msg(HR_SINGLE); + + while (dn_data != NULL) { + GSList *atm_list = NULL; + GSList *data_list = NULL; + + msg("[DN] rssi[%d/%d/%d/%d/%d/%d/%d]", + dn_data->time_level_0, dn_data->time_level_1, dn_data->time_level_2, + dn_data->time_level_3, dn_data->time_level_4, dn_data->time_level_5, + dn_data->time_level_6); + + for (atm_list = dn_data->atm_list; atm_list != NULL; atm_list = atm_list->next) { + battery_app_data_s *app_data = (battery_app_data_s *)atm_list->data; + msg("[DN] app_id[%s] rx[%d] tx[%d]", app_data->app_id, app_data->rx, app_data->tx); + } + + msg(HR_SINGLE); + + if (dn_data->data_list == NULL) + break; + + data_list = dn_data->data_list; + dn_data = (battery_dn_data_s *)data_list->data; + } + + return STC_ERROR_NONE; +} + +static int __test_stc_battery_wifi_get_data(MManager *mm, struct menu_data *menu) +{ + bm_data_h data; + + if (!netconfig_plugin_wifi_enabled) + return STC_ERROR_NOT_INITIALIZED; + + netconfig_plugin_wifi->get_feature_data(&data, 0); + + battery_wifi_data_s *wifi_data = (battery_wifi_data_s *)data; + + msg(HR_SINGLE); + + while (wifi_data != NULL) { + GSList *atm_list = NULL; + GSList *data_list = NULL; + + msg("[Wi-Fi] start[%ld] end[%ld] scan[%d] rssi[%d/%d/%d/%d/%d]", + wifi_data->start_time, wifi_data->end_time, wifi_data->scan_time, + wifi_data->time_level_0, wifi_data->time_level_1, wifi_data->time_level_2, + wifi_data->time_level_3, wifi_data->time_level_4); + + for (atm_list = wifi_data->atm_list; atm_list != NULL; atm_list = atm_list->next) { + battery_app_data_s *app_data = (battery_app_data_s *)atm_list->data; + msg("[Wi-Fi] app_id[%s] rx[%d] tx[%d]", app_data->app_id, app_data->rx, app_data->tx); + } + + msg(HR_SINGLE); + + if (wifi_data->data_list == NULL) + break; + + data_list = wifi_data->data_list; + wifi_data = (battery_wifi_data_s *)data_list->data; + } + + return STC_ERROR_NONE; +} + +int test_stc_battery_dn_init(void) +{ + handle_plugin_dn = dlopen(NETCONFIG_PLUGIN_DN_FILEPATH, RTLD_NOW); + if (!handle_plugin_dn) { + msg("Can't load %s: %s", NETCONFIG_PLUGIN_DN_FILEPATH, dlerror()); + return STC_ERROR_NOT_INITIALIZED; + } + + netconfig_plugin_dn = dlsym(handle_plugin_dn, "netconfig_bm_dn_plugin"); + if (!netconfig_plugin_dn) { + msg("Can't load symbol: %s", dlerror()); + dlclose(handle_plugin_dn); + return STC_ERROR_NOT_INITIALIZED; + } + + netconfig_plugin_dn->init(); + netconfig_plugin_dn_enabled = TRUE; + + return STC_ERROR_NONE; +} + +int test_stc_battery_dn_deinit(void) +{ + if (!netconfig_plugin_dn_enabled) + return STC_ERROR_NOT_INITIALIZED; + + netconfig_plugin_dn->deinit(); + netconfig_plugin_dn_enabled = FALSE; + dlclose(netconfig_plugin_dn); + + return STC_ERROR_NONE; +} + +int test_stc_battery_wifi_init(void) +{ + handle_plugin_wifi = dlopen(NETCONFIG_PLUGIN_WIFI_FILEPATH, RTLD_NOW); + if (!handle_plugin_wifi) { + msg("Can't load %s: %s", NETCONFIG_PLUGIN_WIFI_FILEPATH, dlerror()); + return STC_ERROR_NOT_INITIALIZED; + } + + netconfig_plugin_wifi = dlsym(handle_plugin_wifi, "netconfig_bm_wifi_plugin"); + if (!netconfig_plugin_wifi) { + msg("Can't load symbol: %s", dlerror()); + dlclose(handle_plugin_wifi); + return STC_ERROR_NOT_INITIALIZED; + } + + netconfig_plugin_wifi->init(); + netconfig_plugin_wifi_enabled = TRUE; + + return STC_ERROR_NONE; +} + +int test_stc_battery_wifi_deinit(void) +{ + if (!netconfig_plugin_wifi_enabled) + return STC_ERROR_NOT_INITIALIZED; + + netconfig_plugin_wifi->deinit(); + netconfig_plugin_wifi_enabled = FALSE; + dlclose(netconfig_plugin_wifi); + + return STC_ERROR_NONE; +} + +struct menu_data menu_battery[] = { + { "1", LOG_LIGHTBLUE "[Get]" LOG_END " DN", NULL, __test_stc_battery_dn_get_data, NULL}, + { "2", LOG_LIGHTBLUE "[Get]" LOG_END " Wi-Fi", NULL, __test_stc_battery_wifi_get_data, NULL}, + { NULL, NULL, }, +}; diff --git a/test/battery.h b/test/battery.h new file mode 100755 index 0000000..1d8c717 --- /dev/null +++ b/test/battery.h @@ -0,0 +1,41 @@ +/* + * Smart Traffic Control (STC) + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + * + */ + +/** + * This file declares definitions, macros and structures. + * + * @file battery.h + * @author Tak hyunuk (hyunuk.tak@samsung.com) + * @version 0.1 + */ + +#ifndef __TEST_STC_BATTERY_H__ +#define __TEST_STC_BATTERY_H__ + +/***************************************************************************** + * Local Functions Definition + *****************************************************************************/ + +int test_stc_battery_dn_init(void); +int test_stc_battery_dn_deinit(void); + +int test_stc_battery_wifi_init(void); +int test_stc_battery_wifi_deinit(void); + +#endif /** __TEST_STC_BATTERY_H__ */ diff --git a/test/stc_test.c b/test/stc_test.c index 2712b20..3ecdeb2 100755 --- a/test/stc_test.c +++ b/test/stc_test.c @@ -42,6 +42,7 @@ #include "restriction.h" #include "firewall.h" #include "pcap.h" +#include "battery.h" #include "manager.h" #define STC_APP_ID_LEN 128 @@ -55,6 +56,7 @@ extern struct menu_data menu_statistics[]; extern struct menu_data menu_restriction[]; extern struct menu_data menu_firewall[]; extern struct menu_data menu_pcap[]; +extern struct menu_data menu_battery[]; extern struct menu_data menu_iptables[]; stc_h g_stc = NULL; @@ -390,6 +392,7 @@ static struct menu_data menu_main[] = { { "3", LOG_LIGHTMAGENTA "[Firewall]" LOG_END, menu_firewall, NULL, NULL}, { "4", LOG_LIGHTMAGENTA "[Iptables]" LOG_END, menu_iptables, NULL, NULL}, { "5", LOG_LIGHTMAGENTA "[Pcap]" LOG_END, menu_pcap, NULL, NULL}, + { "6", LOG_LIGHTMAGENTA "[Battery]" LOG_END, menu_battery, NULL, NULL}, { NULL, NULL, }, }; @@ -431,6 +434,8 @@ static int __test_stc_initialize(MManager *mm, struct menu_data *menu) test_stc_restriction_list_create(); test_stc_restriction_register_cb(); test_stc_pcap_create(); + test_stc_battery_dn_init(); + test_stc_battery_wifi_init(); menu_manager_set_user_data(mm, g_stc); @@ -447,6 +452,8 @@ static int __test_stc_deinitialize(void) test_stc_restriction_list_destroy(); test_stc_restriction_unregister_cb(); test_stc_pcap_destroy(); + test_stc_battery_dn_deinit(); + test_stc_battery_wifi_deinit(); if (g_stc) { ret = stc_deinitialize(g_stc);