Test for battery monitor framework 22/212722/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 26 Aug 2019 08:44:24 +0000 (17:44 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 26 Aug 2019 08:44:41 +0000 (17:44 +0900)
Change-Id: Ide1e6c63fea1490a33186e07da6d01114c271d08
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
test/CMakeLists.txt
test/battery.c [new file with mode: 0755]
test/battery.h [new file with mode: 0755]
test/stc_test.c

index 0a231d16b474b84d9a018b97b5a5b54421a6f5c7..79ea9f67bc0a3f5bb3dfb39713634237fcfb2b8e 100755 (executable)
@@ -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 (executable)
index 0000000..1ef838f
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <assert.h>
+#include <dlfcn.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <stc.h>
+#include <stc_internal.h>
+
+#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;
+\r} 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;
+\r} 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 (executable)
index 0000000..1d8c717
--- /dev/null
@@ -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__ */
index 2712b202e7792a8d532829e9c57ba1b6e509fc18..3ecdeb2b6a4f9afc7a7c9fd1fb3cd737dd4b40f1 100755 (executable)
@@ -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);