From: Dewal Agarwal Date: Thu, 28 May 2020 07:10:04 +0000 (+0530) Subject: For Automated App Usage X-Git-Tag: submit/tizen/20200602.140952^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e6922534a270a3f65fc292e9a10569ac409c78c;p=platform%2Fcore%2Fapi%2Fbatterymonitor.git For Automated App Usage Change-Id: Iecdc2bcf3ce3fc262253ff74097aacad8ef66e6e Signed-off-by: Dewal Agarwal --- diff --git a/test/test_cli_app/src/bmt_usage.c b/test/test_cli_app/src/bmt_usage.c index ceb66d9..c5db3ea 100644 --- a/test/test_cli_app/src/bmt_usage.c +++ b/test/test_cli_app/src/bmt_usage.c @@ -28,12 +28,29 @@ /* internal header */ #include "bmt_utility.h" #include -#include +#include +#include #include #include #include "battery_monitor.h" #include "battery_monitor_util.h" +time_t s_t = 0, e_t = 0; +const int tmin = 604800; /* Time interval for 7 days in seconds */ +static int count = 20; + +static void get_custom_time_values(void) +{ + time_t crr_time; + time(&crr_time); + if (crr_time == -1) + return; + s_t = 0; e_t = 0; + s_t = (crr_time - tmin/2); e_t = (crr_time - 1); + + return; +} + static gboolean bmt_testapp_get_total_power_usage_by_app_id_for_ci() { /* @@ -481,6 +498,77 @@ static gboolean bmt_testapp_get_power_usage_for_all_app_id_per_resource() return FALSE; } +bool bmt_testapp_get_power_usage_automated() +{ + time_t start_time = 0, end_time = 0; + + testapp_time_s *user_data = (testapp_time_s *)calloc(1, sizeof(testapp_time_s)); + if (user_data == NULL) { + testapp_print("time_s memory allocation failed"); + return FALSE; + } + int i = 0; unsigned int wait_time = 5, next_iteration = 180; + double battery_usage = -1; + while(i < count) { + get_custom_time_values(); + if (s_t != 0 && e_t != 0) { + start_time = s_t; + end_time = e_t; + } + else + return FALSE; + + testapp_print("\n Start Time: %ld \n", start_time); + testapp_print("\n End Time: %ld \n", end_time); + user_data->from = start_time; user_data->to = end_time; + + int error_code = APP_MANAGER_ERROR_NONE; + error_code = app_manager_foreach_app_info(get_app_id_all_resource_cb, (void *)user_data); + if (error_code != APP_MANAGER_ERROR_NONE) + testapp_print("app manager fails"); + + sleep(wait_time); //Before using the next API + + for (int id = BATTERY_MONITOR_RESOURCE_ID_BLE; id < BATTERY_MONITOR_RESOURCE_ID_MAX; id++) { + battery_usage = -1; + error_code = battery_monitor_get_power_usage_by_resource(id, start_time, end_time, &battery_usage); + if (error_code != BATTERY_MONITOR_ERROR_NONE) { + if (error_code == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND) + testapp_print ("This resource is not available \n"); + continue; + } + + switch (id) { + case BATTERY_MONITOR_RESOURCE_ID_BLE: + testapp_print ("Resource ID : BT Usage Value = [%lf] \n", battery_usage); + break; + case BATTERY_MONITOR_RESOURCE_ID_WIFI: + testapp_print ("Resource ID : WIFI Usage Value = [%lf] \n", battery_usage); + break; + case BATTERY_MONITOR_RESOURCE_ID_CPU: + testapp_print ("Resource ID : CPU Usage Value = [%lf] \n", battery_usage); + break; + case BATTERY_MONITOR_RESOURCE_ID_DISPLAY: + testapp_print ("Resource ID : DISPLAY Usage Value = [%lf] \n", battery_usage); + break; + case BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK: + testapp_print ("Resource ID : DEVICE NETWORK Usage Value = [%lf] \n", battery_usage); + break; + case BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR: + testapp_print ("Resource ID : GPS Usage Value = [%lf] \n", battery_usage); + break; + default: + testapp_print ("Default Case \n"); + break; + } + } + i++; + sleep(next_iteration); + } + free(user_data); + return FALSE; +} + static gboolean testapp_test_interpret_command(int selected_number) { gboolean go_to_loop = TRUE; @@ -507,6 +595,11 @@ static gboolean testapp_test_interpret_command(int selected_number) case 7: bmt_testapp_get_power_usage_for_all_app_id_per_resource(); break; + case 8: + break; + case 9: + bmt_testapp_get_power_usage_automated(); + break; case 0: go_to_loop = FALSE; break; diff --git a/test/test_cli_app/src/bmt_utility.c b/test/test_cli_app/src/bmt_utility.c index 91efd12..09269a3 100644 --- a/test/test_cli_app/src/bmt_utility.c +++ b/test/test_cli_app/src/bmt_utility.c @@ -64,6 +64,7 @@ void testapp_show_menu(battery_monitor_menu_e menu) testapp_print(" 6. Get Total Usage for each Resource ID for CI\n"); testapp_print(" 7. Get Each Resource Usage for each App ID for CI\n"); testapp_print(" 8. Dummy menu entry (Don't Use)\n"); + testapp_print(" 9. Auto-Test Menu\n"); testapp_print(" 0. Go to Main Menu\n"); testapp_print("------------------------------------------\n\n");