From 10e5620ea9ffc2643dbc7dbe301653b58fc0c767 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 3 Jun 2020 13:50:45 +0900 Subject: [PATCH] Add udev related code in auto test for battery tests udev events should not be delivered for battery tests. So, add udev related code to start and stop it. In addition, add battery full and temperature test functions. Change-Id: I3624b2c8238b08b36a89eacc9c6674458ffab452 Signed-off-by: lokilee73 (cherry picked from commit fa309a75edd44811da1bc1cbc9ec4f2a6daa1680) --- conf/org.tizen.system.deviced.conf | 3 +- src/auto-test/CMakeLists.txt | 1 + src/auto-test/auto-test.conf | 4 ++ src/auto-test/battery.c | 75 +++++++++++++++++++++- src/auto-test/udev.c | 126 +++++++++++++++++++++++++++++++++++++ src/battery/power-supply.c | 12 ++-- 6 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 src/auto-test/udev.c diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 4f26e05..6ade2fa 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -17,6 +17,7 @@ + @@ -56,7 +57,6 @@ - @@ -65,6 +65,7 @@ + diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index de6e43e..e840808 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -23,6 +23,7 @@ SET(SRCS time.c test_dbus_interface.c battery-monitor-test.c + udev.c ) FOREACH(flag ${pkgs_CFLAGS}) diff --git a/src/auto-test/auto-test.conf b/src/auto-test/auto-test.conf index 445175b..1b4f78e 100644 --- a/src/auto-test/auto-test.conf +++ b/src/auto-test/auto-test.conf @@ -8,6 +8,7 @@ proc=1 extcon=1 ir=1 time=1 +udev=1 [wearable] battery-monitor=1 @@ -19,6 +20,7 @@ proc=1 extcon=1 ir=0 time=1 +udev=1 [tv] battery-monitor=0 @@ -30,6 +32,7 @@ proc=1 extcon=1 ir=0 time=1 +udev=1 [common] battery-monitor=0 @@ -41,3 +44,4 @@ proc=1 extcon=1 ir=0 time=1 +udev=1 diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c index a399755..c688d4d 100644 --- a/src/auto-test/battery.c +++ b/src/auto-test/battery.c @@ -133,7 +133,6 @@ static struct power_supply_type { {"freq", S_LEAVE, "100", DISCHARGE_NAME, GOOD_NAME, POWER_SUPPLY_TYPE_BATTERY, PRESENT_NORMAL, MISC_NORMAL, FREQ_STRENGTH_LEVEL_0, "DISCHARGE"}, /* init */ }; - static bool get_battery_method(const char *method, int *value) { GVariant *msg = NULL; @@ -430,6 +429,72 @@ static bool set_battery_power_supply(int index) return ret; } +static void full_scenario(char *unit, char *capacity, int status) +{ + int index; + int len; + + if (!unit || !capacity) + return; + + len = strlen(unit); + + for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) { + if (len != strlen(power_supply_types[index].scenario)) + continue; + if (strncmp(unit, power_supply_types[index].scenario, len) != 0 || + power_supply_types[index].status != status) + continue; + power_supply_types[index].capacity = capacity; + _D("%s", power_supply_types[index].capacity); + set_battery_power_supply(index); + } +} + +static void battery_scenario(char *unit, int status) +{ + int index; + int found = 0; + int unit_len; + char *scenario = NULL; + + if (!unit) + return; + + unit_len = strlen(unit); + + for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) { + if (unit_len != strlen(power_supply_types[index].scenario)) + continue; + scenario = power_supply_types[index].scenario; + if (strncmp(unit, scenario, unit_len) != 0 || + power_supply_types[index].status != status) + continue; + found = 1; + set_battery_power_supply(index); + } + + if (found) + return; + + index = strlen(unit); + if (index < 0 || index > 3) + return; + + index = strtol(unit, NULL, 10); + if (index < 0 || index > 100) + return; + + for (index = 0; index < ARRAY_SIZE(power_supply_types); index++){ + if (strncmp("capa", power_supply_types[index].scenario, 4) != 0 || + power_supply_types[index].status != status) + continue; + power_supply_types[index].capacity = unit; + _D("%s", power_supply_types[index].capacity); + set_battery_power_supply(index); + } +} + void battery_test_all(int *success, int *fail) { int s = 0; @@ -509,6 +574,14 @@ static int battery_unit(int argc, char **argv) } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_POWERSUPPLY)) { for (int index = 0; index < ARRAY_SIZE(power_supply_types); index++) set_battery_power_supply(index); + } else if (argc > 4 && argv[4] && !strncmp("enter", argv[4], 5)) { + battery_scenario(argv[3], S_ENTER); + } else if (argc > 4 && argv[4] && !strncmp("leave", argv[4], 5)) { + battery_scenario(argv[3], S_LEAVE); + } else if (argc >5 && argv[5] && !strncmp("enter", argv[5], 5)) { + full_scenario(argv[3], argv[4], S_ENTER); + } else if (argc >5 && argv[5] && !strncmp("leave", argv[5], 5)) { + full_scenario(argv[3], argv[5], S_LEAVE); } else { _E("Unknown test case."); } diff --git a/src/auto-test/udev.c b/src/auto-test/udev.c new file mode 100644 index 0000000..86076b0 --- /dev/null +++ b/src/auto-test/udev.c @@ -0,0 +1,126 @@ +/* + * test + * + * Copyright (c) 2020 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 "test.h" + +static const struct device_change_type { + char *name; + char *status; +} device_change_types[] = { + {"udev", "start"}, + {"udev", "stop"}, +}; + +static int udev(int index) +{ + GVariant *msg; + int ret, val; + + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, + "udev", + g_variant_new("(sis)", "udev", 1, device_change_types[index].status)); + if (!msg) { + _E("fail : %s %s %s %s", + DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + "udev"); + return -EBADMSG; + } + + if (!dh_get_param_from_var(msg, "(i)", &val)) + _E("fail : no message"); + else { + if ((val == -ENOTSUP) || (val == -ENOSYS)) { + _I("Not supported feature! : %d", val); + ret = TRUE; + } else if (val < 0) { + _E("fail : returned fail (%d)", val); + } else { + _I("success : %d", val); + ret = TRUE; + } + } + + _I("%s", device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s : %s", + __func__, device_change_types[index].status); + else + _R("[OK] ---- %s : %s", + __func__, device_change_types[index].status); + + g_variant_unref(msg); + sleep(TEST_WAIT_TIME_INTERVAL); + return ret; +} + +static void unit(char *unit, char *status) +{ + int index; + int unit_len; + int status_len; + + if (!unit || !status) + return; + + unit_len = strlen(unit); + status_len = strlen(status); + + for (index = 0; index < ARRAY_SIZE(device_change_types); index++) { + if (unit_len != strlen(device_change_types[index].name) || + status_len != strlen(device_change_types[index].status)) + continue; + if (strncmp(unit, device_change_types[index].name, unit_len) != 0 || + strncmp(status, device_change_types[index].status, status_len) != 0) + continue; + udev(index); + } +} + +static void udev_init(void *data) +{ + int index; + + _I("start test"); + for (index = 0; index < ARRAY_SIZE(device_change_types); index++) + udev(index); +} + +static void udev_exit(void *data) +{ + _I("end test"); +} + +static int udev_unit(int argc, char **argv) +{ + if (argc != 4) + return -EINVAL; + + unit(argv[2], argv[3]); + return 0; +} + +static const struct test_ops udev_test_ops = { + .priority = TEST_PRIORITY_HIGH, + .name = "udev", + .init = udev_init, + .exit = udev_exit, + .unit = udev_unit, +}; + +TEST_OPS_REGISTER(&udev_test_ops) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 5fb0224..ffc6d6a 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -98,6 +98,7 @@ static int online_status; static int abnormal_health_popup_timer; static guint power_timer; +static device_notifier_state_e old_state = -1; bool battery_do_not_disturb(void); static int battery_pm_change_internal(int pid, int s_bits); @@ -1314,10 +1315,13 @@ static GVariant *dbus_get_battery_info(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { - int ret, val; + int ret = 0, val; const char *str; struct battery_info info = {0, }; + if (old_state == DEVICE_NOTIFIER_STATE_STOP) + goto out; + if (battery_dev && battery_dev->get_current_state) { ret = battery_dev->get_current_state(battery_get_info, &info); if (ret < 0) @@ -1343,6 +1347,7 @@ static GVariant *dbus_get_battery_info(GDBusConnection *conn, ret = 0; } +out: return g_variant_new("(isssiiiiiiii)", ret, battery.status_s, battery.health_s, @@ -1601,13 +1606,12 @@ static void remove_power_supply_handler(void) static int event_handler_state_changed(void *data) { - static device_notifier_state_e old = DEVICE_NOTIFIER_STATE_STOP; device_notifier_state_e state = *(device_notifier_state_e *)data; - if (old == state) + if (old_state == state) return 0; - old = state; + old_state = state; if (state == DEVICE_NOTIFIER_STATE_START) add_power_supply_handler(); -- 2.7.4