auto-test: support battery dbus test 02/132702/5 accepted/tizen/unified/20170612.170904 submit/tizen/20170612.061649
authorYunmi Ha <yunmi.ha@samsung.com>
Wed, 7 Jun 2017 07:38:34 +0000 (16:38 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Thu, 8 Jun 2017 09:47:07 +0000 (18:47 +0900)
deviced-auto-test package was added.
Now it supports battery dbus method test only.
(other module will be updated.)

This is optional package.
If you want to use this, install device-auto-test package manually
and run below command. Then you can see detail usage for this tool.
$/usr/bin/deviced-auto-test

usage: deviced-auto-test [PROFILE] [MODULE] [UNIT-METHOD] [OPTS]

Change-Id: Id8824459e88286d8f0074b05b2e1f93690a6e4d2
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
CMakeLists.txt
packaging/deviced.spec
src/auto-test/CMakeLists.txt [new file with mode: 0644]
src/auto-test/auto-test.conf [new file with mode: 0644]
src/auto-test/battery.c [new file with mode: 0644]
src/auto-test/config.c [new file with mode: 0644]
src/auto-test/config.h [new file with mode: 0644]
src/auto-test/main.c [new file with mode: 0644]
src/auto-test/result.c [new file with mode: 0644]
src/auto-test/test.c [new file with mode: 0644]
src/auto-test/test.h [new file with mode: 0644]

index 0d32ba4..86e554e 100755 (executable)
@@ -293,3 +293,4 @@ ADD_SUBDIRECTORY(src/devicectl)
 IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on)
        ADD_SUBDIRECTORY(src/usb-host-ffs-test-daemon)
 ENDIF()
+ADD_SUBDIRECTORY(src/auto-test)
index a5c83b7..c994406 100755 (executable)
@@ -134,6 +134,14 @@ Deviced library for device control (devel).
 Because this is internal interface, every profile MUST have the same
 devel package.
 
+%package auto-test
+Summary:  Deviced auto test tool
+Group:    System/Utilities
+
+%description auto-test
+Deviced helper programs.
+This package can be installed optional for auto dbus test.
+
 %prep
 %setup -q
 
@@ -532,3 +540,9 @@ mv %{_bindir}/deviced %{_bindir}/deviced.ivi
 %{_includedir}/deviced/*.h
 %{_libdir}/libdeviced.so
 %{_libdir}/pkgconfig/deviced.pc
+
+%files auto-test
+%manifest deviced.manifest
+%license LICENSE
+%{_bindir}/deviced-auto-test
+%config %{_sysconfdir}/deviced/auto-test.conf
diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6ca20db
--- /dev/null
@@ -0,0 +1,62 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(deviced-auto-test C)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
+
+IF("${PROFILE}" STREQUAL "wearable")
+       SET(PROFILE wearable)
+ELSEIF("${PROFILE}" STREQUAL "tv")
+       SET(PROFILE tv)
+ELSE()
+       SET(PROFILE mobile)
+ENDIF()
+
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_ENGINEER_MODE")
+    OPTION(USE_ENGINEER_MODE "Use Engineer mode" ON)
+ENDIF()
+
+SET(SRCS
+       test.c
+       main.c
+       result.c
+       ../core/config-parser.c
+       config.c
+
+       battery.c
+)
+
+# extcon test
+#SET(SRCS ${SRCS}
+#      storage.c
+#      usb.c
+#      hdmi.c
+#      earjack.c
+#)
+
+#IF(NOT PROFILE STREQUAL wearable)
+#SET(SRCS ${SRCS}
+#      cradle.c
+#      keyboard.c
+#      tvout.c
+#)
+#ENDIF(NOT PROFILE STREQUAL wearable)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED edbus)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed -pie")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DENABLE_TEST_DLOG")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} shared)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-test.conf DESTINATION /etc/deviced)
diff --git a/src/auto-test/auto-test.conf b/src/auto-test/auto-test.conf
new file mode 100644 (file)
index 0000000..f4fe9c7
--- /dev/null
@@ -0,0 +1,14 @@
+[mobile]
+battery=1
+
+[wearable]
+battery=1
+
+[tv]
+battery=0
+
+[ivi]
+battery=0
+
+[common]
+battery=0
diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c
new file mode 100644 (file)
index 0000000..8271b49
--- /dev/null
@@ -0,0 +1,498 @@
+/*
+ * test
+ *
+ * Copyright (c) 2016 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 <stdio.h>
+#include "test.h"
+
+#define METHOD_BATTERY_TIMETOFULL       "TimeToFull"
+#define METHOD_BATTERY_TIMETOEMPTY      "TimeToEmpty"
+#define METHOD_BATTERY_SETLOWBATLEVEL   "SetLowbatLevel"
+#define METHOD_BATTERY_GETLOWBATLEVEL   "GetLowbatLevel"
+#define METHOD_BATTERY_CHARGERSTATUS    "ChargerStatus"
+#define METHOD_BATTERY_CHARGENOW        "ChargeNow"
+#define METHOD_BATTERY_STATUSLOW        "BatteryStatusLow"
+#define METHOD_BATTERY_GETPERCENT       "GetPercent"
+#define METHOD_BATTERY_GETPERCENTRAW    "GetPercentRaw"
+#define METHOD_BATTERY_ISFULL           "IsFull"
+#define METHOD_BATTERY_HEALTH           "GetHealth"
+#define METHOD_BATTERY_GETINFO          "GetBatteryInfo"
+#define METHOD_BATTERY_POWERSUPPLY      "power_supply"
+
+#define CHARGEFULL_NAME     "Full"
+#define CHARGENOW_NAME      "Charging"
+#define DISCHARGE_NAME      "Discharging"
+#define NOTCHARGE_NAME      "Not charging"
+
+#define GOOD_NAME           "Good"
+#define OVERHEAT_NAME       "Overheat"
+#define TEMPCOLD_NAME       "Cold"
+#define OVERVOLT_NAME       "Over voltage"
+
+#define POWER_SUPPLY_TYPE_BATTERY   "1"
+#define POWER_SUPPLY_TYPE_UPS       "2"
+
+#define PRESENT_ABNORMAL    "0"
+#define PRESENT_NORMAL      "1"
+
+#define DEFAULT_LOWBATLEVEL 15
+
+#define S_ENTER        1
+#define S_LEAVE        0
+
+static struct power_supply_type {
+       char *scenario;
+       int status;
+       char *capacity;
+       char *charge_status;
+       char *health;
+       char *online;
+       char *present;
+       char *name;
+} power_supply_types[] = {
+       {"norm", S_ENTER, "100",    CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "CHARGE"},
+       {"norm", S_ENTER, "100",    DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "DISCHARGE"},
+       {"norm", S_LEAVE, "100",    DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL}, /* init */
+
+       {"heat1", S_ENTER, "100",   DISCHARGE_NAME, OVERHEAT_NAME,  POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL},
+       {"heat1", S_ENTER, "100",   NOTCHARGE_NAME, OVERHEAT_NAME,  POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "HEALTH(H) BEFORE CHARGE"},
+       {"heat1", S_LEAVE, "100",   DISCHARGE_NAME, OVERHEAT_NAME,  POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "DISCHARGE"},
+       {"heat1", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL}, /* init */
+
+       {"heat2", S_ENTER, "100",   CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, NULL},
+       {"heat2", S_ENTER, "100",   NOTCHARGE_NAME, OVERHEAT_NAME,  POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "HEALTH(H) AFTER CHARGE"},
+       {"heat2", S_LEAVE, "100",   DISCHARGE_NAME, OVERHEAT_NAME,  POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "DISCHARGE"},
+       {"heat2", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL}, /* init */
+
+       {"cold1", S_ENTER, "100",   DISCHARGE_NAME, TEMPCOLD_NAME,  POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL},
+       {"cold1", S_ENTER, "100",   NOTCHARGE_NAME, TEMPCOLD_NAME,  POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "HEALTH(L) BEFORE CHARGE"},
+       {"cold1", S_LEAVE, "100",   DISCHARGE_NAME, TEMPCOLD_NAME,  POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "DISCHARGE"},
+       {"cold1", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL}, /* init */
+
+       {"cold2", S_ENTER, "100",   CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, NULL},
+       {"cold2", S_ENTER, "100",   NOTCHARGE_NAME, TEMPCOLD_NAME,  POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "HEALTH(L) AFTER CHARGE"},
+       {"cold2", S_LEAVE, "100",   DISCHARGE_NAME, TEMPCOLD_NAME,  POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "DISCHARGE"},
+       {"cold2", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL}, /* init */
+
+       {"ovp", S_ENTER, "100",    DISCHARGE_NAME, OVERVOLT_NAME,  POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "OVP"},
+       {"ovp", S_LEAVE, "100",    DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL}, /* init */
+
+       {"pres1", S_ENTER, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_ABNORMAL, NULL},
+       {"pres1", S_ENTER, "100",   NOTCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_ABNORMAL, "PRESENT BEFORE CHARGE"},
+       {"pres1", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_ABNORMAL, "DISCHARGE"},
+       {"pres1", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL,   NULL}, /* init */
+
+       {"pres2", S_ENTER, "100",   CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, NULL},
+       {"pres2", S_ENTER, "100",   NOTCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_ABNORMAL, "PRESENT AFTER CHARGE"},
+       {"pres2", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_ABNORMAL, "DISCHARGE"},
+       {"pres2", S_LEAVE, "100",   DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, NULL}, /* init */
+
+       {"bat15", S_ENTER, "15",    DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "LOWBAT 15%"}, /* lowbat 15% */
+       {"bat15", S_LEAVE, "15",    CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "LOWBAT 15%"},
+       {"bat5", S_ENTER, "5",      DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "LOWBAT 5%"},  /* lowbat 5% */
+       {"bat5", S_LEAVE, "5",      CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "LOWBAT 5%"},
+       {"bat3", S_ENTER, "3",      DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "LOWBAT 3%"},  /* lowbat 3% */
+       {"bat3", S_LEAVE, "3",      CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "LOWBAT 3%"},
+       {"bat1", S_ENTER, "1",      DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "LOWBAT 1%"},  /* lowbat 1% */
+       {"bat1", S_LEAVE, "1",      CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "LOWBAT 1%"},
+
+       {"ta",   S_ENTER, "100",    CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "CHARGE"},   /* charging */
+       {"ta",  S_LEAVE, "100",         DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "DISCHARGE"},/* discharging */
+
+       {"full", S_ENTER, "100",    CHARGEFULL_NAME, GOOD_NAME,     POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "CHARGE"},   /* full */
+       {"full", S_LEAVE, "100",    DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "DISCHARGE"},/* discharging */
+
+       {"capa", S_ENTER, "100",    DISCHARGE_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_BATTERY,  PRESENT_NORMAL, "CAPACITY"},/* discharging */
+       {"capa", S_LEAVE, "100",    CHARGENOW_NAME, GOOD_NAME,      POWER_SUPPLY_TYPE_UPS,      PRESENT_NORMAL, "CAPACITY"},/* charging */
+};
+
+
+static bool get_battery_method(const char *method, int *value)
+{
+       DBusMessage *msg;
+       int val;
+       bool ret = FALSE;
+
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_BATTERY,
+                       DEVICED_INTERFACE_BATTERY,
+                       method, NULL, NULL);
+       if (!msg) {
+               _E("fail (%s): no reply", method);
+               return ret;
+       }
+
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID) == 0)
+               _E("fail (%s): no message", method);
+       else {
+               _I("success (%s): %d", method, val);
+               ret = TRUE;
+               if (NULL != value)
+                       *value = val;
+       }
+
+       dbus_message_unref(msg);
+       return ret;
+}
+
+static bool get_battery_method_vconf(const char *method)
+{
+       DBusMessage *msg;
+       int val;
+       bool ret = FALSE;
+
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_BATTERY,
+                       DEVICED_INTERFACE_BATTERY,
+                       method, NULL, NULL);
+       if (!msg) {
+               _E("fail (%s): no reply", method);
+               return ret;
+       }
+
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID) == 0)
+               _E("fail (%s): no message", method);
+       else {
+               if (val == -EIO) {
+                       _E("fail (%s): return fail", method);
+               } else {
+                       _I("success (%s): %d", method, val);
+                       ret = TRUE;
+               }
+       }
+
+       dbus_message_unref(msg);
+       return ret;
+}
+
+static bool get_battery_time_to_full(void)
+{
+       return get_battery_method(METHOD_BATTERY_TIMETOFULL, NULL);
+}
+
+static bool get_battery_time_to_empty(void)
+{
+       return get_battery_method(METHOD_BATTERY_TIMETOEMPTY, NULL);
+}
+
+static bool get_battery_low_level(int *value)
+{
+       return get_battery_method(METHOD_BATTERY_GETLOWBATLEVEL, value);
+}
+
+static bool set_battery_low_level(int newlevel)
+{
+       DBusMessage *msg;
+       int getlevel = -1;
+       int val = -1;
+       char *param[1];
+       char str_mode[10];
+       bool ret = FALSE;
+
+       snprintf(str_mode, sizeof(str_mode), "%d", newlevel);
+       param[0] = str_mode;
+
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_BATTERY,
+                       DEVICED_INTERFACE_BATTERY,
+                       METHOD_BATTERY_SETLOWBATLEVEL, "i", param);
+
+       if (!msg) {
+               _E("fail : no reply");
+               return ret;
+       }
+
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID) == 0) {
+               _E("fail : no message");
+               goto out;
+       } else {
+               if (newlevel <= DEFAULT_LOWBATLEVEL) {
+                       if (0 != val) {
+                               _I("success : can't set low level (%d) smaller than default (%d)", newlevel, DEFAULT_LOWBATLEVEL);
+                               ret = TRUE;
+                       } else {
+                               _E("fail : can't set low level (%d) smaller than default (%d), but returned success", newlevel, DEFAULT_LOWBATLEVEL);
+                       }
+                       goto out;
+               } else {
+                       if (0 != val) {
+                               _E("fail : return fail");
+                               goto out;
+                       }
+               }
+       }
+
+       if (!get_battery_low_level(&getlevel))   {
+               _E("fail : can't get battery low level");
+       } else {
+               if (getlevel == newlevel) {
+                       _I("success : %d", newlevel);
+                       ret = TRUE;
+               } else {
+                       _E("fail : set low level %d, but current low level %d", newlevel, getlevel);
+               }
+       }
+out:
+       dbus_message_unref(msg);
+       return ret;
+}
+
+static bool get_battery_charger_status()
+{
+       return get_battery_method_vconf(METHOD_BATTERY_CHARGERSTATUS);
+}
+
+static bool get_battery_charge_now()
+{
+       return get_battery_method(METHOD_BATTERY_CHARGENOW, NULL);
+}
+
+static bool get_battery_status_low()
+{
+       return get_battery_method_vconf(METHOD_BATTERY_STATUSLOW);
+}
+
+static bool get_battery_percent()
+{
+       return get_battery_method(METHOD_BATTERY_GETPERCENT, NULL);
+}
+
+static bool get_battery_percent_raw()
+{
+       return get_battery_method(METHOD_BATTERY_GETPERCENTRAW, NULL);
+}
+
+static bool get_battery_is_full()
+{
+       return get_battery_method(METHOD_BATTERY_ISFULL, NULL);
+}
+
+static bool get_battery_health()
+{
+       return get_battery_method(METHOD_BATTERY_HEALTH, NULL);
+}
+
+static bool get_battery_info()
+{
+       DBusMessage *msg;
+       int val[6];
+       bool ret = FALSE;
+       char *argv[3];
+
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_BATTERY,
+                       DEVICED_INTERFACE_BATTERY,
+                       METHOD_BATTERY_GETINFO, NULL, NULL);
+       if (!msg) {
+               _E("fail: no reply");
+               return ret;
+       }
+
+       if (dbus_message_get_args(msg, NULL,
+                               DBUS_TYPE_INT32, &val[0],   //return value
+                               DBUS_TYPE_STRING, &argv[0], //status
+                               DBUS_TYPE_STRING, &argv[1], //health
+                               DBUS_TYPE_STRING, &argv[2], //power source
+                               DBUS_TYPE_INT32, &val[1],   //online
+                               DBUS_TYPE_INT32, &val[2],   //present
+                               DBUS_TYPE_INT32, &val[3],   //capacity
+                               DBUS_TYPE_INT32, &val[4],   //current_now
+                               DBUS_TYPE_INT32, &val[5],   //current_average
+                               DBUS_TYPE_INVALID) == 0)
+               _E("fail: no message");
+       else {
+               if (val[0] < 0) {
+                       _E("fail: return fail");
+               } else {
+                       _I("success: %s %s %s %d %d %d %d %d", argv[0], argv[1], argv[2], val[1], val[2], val[3], val[4], val[5]);
+                       ret = TRUE;
+               }
+       }
+
+       dbus_message_unref(msg);
+       return ret;
+}
+
+static bool set_battery_power_supply(int index)
+{
+       DBusError err;
+       DBusMessage *msg;
+       int val;
+       bool ret = FALSE;
+       char *param[7];
+
+       param[0] = POWER_SUBSYSTEM;
+       param[1] = "5";
+       param[2] = power_supply_types[index].capacity;
+       param[3] = power_supply_types[index].charge_status;
+       param[4] = power_supply_types[index].health;
+       param[5] = power_supply_types[index].online;
+       param[6] = power_supply_types[index].present;
+
+       _I("C(%s , %s) P(%s) STATUS(%s) HEALTH(%s)",
+                                               power_supply_types[index].capacity,
+                                               power_supply_types[index].online,
+                                               power_supply_types[index].present,
+                                               power_supply_types[index].charge_status,
+                                               power_supply_types[index].health);
+
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_BATTERY,
+                       DEVICED_INTERFACE_BATTERY,
+                       POWER_SUBSYSTEM, "sisssss", param);
+       if (!msg) {
+               _E("fail: no reply");
+               return ret;
+       }
+
+       dbus_error_init(&err);
+
+       if (dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID) == 0) {
+               _E("fail: no message : [%s:%s]", err.name, err.message);
+               val = -EBADMSG;
+       } else {
+               if (val < 0) {
+                       _E("fail: return fail");
+               } else {
+                       _I("success: %d", val);
+                       ret = TRUE;
+               }
+       }
+
+       /*
+       if (power_supply_types[index].name != NULL)
+               _I("++++++++++[START] %s ++++++++++", power_supply_types[index].name);
+               _I("C(%s , %s) P(%s) STATUS(%s) HEALTH(%s)",
+                       power_supply_types[index].capacity,
+                       power_supply_types[index].online,
+                       power_supply_types[index].present,
+                       power_supply_types[index].charge_status,
+                       power_supply_types[index].health);
+       if (power_supply_types[index].name != NULL)
+               _I("++++++++++[END] %s ++++++++++", power_supply_types[index].name);
+       if (val < 0)
+               _R("[NG] ---- %s", __func__);
+       else
+               _R("[OK] ---- %s     : C(%s , %s) P(%s) S(%s) H(%s)",
+                               __func__,
+                               power_supply_types[index].capacity,
+                               power_supply_types[index].online,
+                               power_supply_types[index].present,
+                               power_supply_types[index].charge_status,
+                               power_supply_types[index].health);
+       */
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+       sleep(TEST_WAIT_TIME_INTERVAL);
+
+       return ret;
+}
+
+void battery_test_all(int *success, int *fail)
+{
+       int s = 0;
+       int f = 0;
+
+       (get_battery_time_to_full())    ? s++ : f++;
+       (get_battery_time_to_empty())   ? s++ : f++;
+       (get_battery_low_level(NULL))   ? s++ : f++;
+       (set_battery_low_level(10))     ? s++ : f++;
+       (set_battery_low_level(50))     ? s++ : f++;
+       (get_battery_charger_status())  ? s++ : f++;
+       (get_battery_charge_now())      ? s++ : f++;
+       (get_battery_status_low())      ? s++ : f++;
+       (get_battery_percent())         ? s++ : f++;
+       (get_battery_percent_raw())     ? s++ : f++;
+       (get_battery_is_full())         ? s++ : f++;
+       (get_battery_health())          ? s++ : f++;
+       (get_battery_info())            ? s++ : f++;
+
+       for (int index = 0; index < ARRAY_SIZE(power_supply_types); index++)
+               (set_battery_power_supply(index)) ? s++ : f++;
+
+       if (NULL != success)    *success = s;
+       if (NULL != fail)       *fail = f;
+}
+
+static void battery_init(void *data)
+{
+       int success = 0;
+       int fail = 0;
+
+       _I("start test");
+
+       battery_test_all(&success, &fail);
+
+       _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+}
+
+static void battery_exit(void *data)
+{
+       _I("end test");
+
+}
+
+static int battery_unit(int argc, char **argv)
+{
+       if (argc < 4) {
+               int success = 0;
+               int fail = 0;
+               _I("start test");
+               battery_test_all(&success, &fail);
+               _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_TIMETOFULL)) {
+               get_battery_time_to_full();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_TIMETOEMPTY)) {
+               get_battery_time_to_empty();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_GETLOWBATLEVEL)) {
+               get_battery_low_level(NULL);
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_SETLOWBATLEVEL)) {
+               set_battery_low_level(atoi(argv[4]));
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_CHARGERSTATUS)) {
+               get_battery_charger_status();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_CHARGENOW)) {
+               get_battery_charge_now();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_STATUSLOW)) {
+               get_battery_status_low();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_GETPERCENT)) {
+               get_battery_percent();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_GETPERCENTRAW)) {
+               get_battery_percent_raw();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_ISFULL)) {
+               get_battery_is_full();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_HEALTH)) {
+               get_battery_health();
+       } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_GETINFO)) {
+               get_battery_info();
+       } 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 {
+               _E("Unknown test case!!!");
+       }
+
+       return 0;
+}
+
+static const struct test_ops battery_test_ops = {
+       .priority = TEST_PRIORITY_NORMAL,
+       .name     = "battery",
+       .init     = battery_init,
+       .exit    = battery_exit,
+       .unit    = battery_unit,
+};
+
+TEST_OPS_REGISTER(&battery_test_ops)
diff --git a/src/auto-test/config.c b/src/auto-test/config.c
new file mode 100644 (file)
index 0000000..fb2acd8
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2014 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 <glib.h>
+#include <string.h>
+
+#include "core/config-parser.h"
+
+#include "test.h"
+#include "config.h"
+
+#define CONF_FILE              "/etc/deviced/auto-test.conf"
+#define DEF_PROFILE            "mobile"
+
+static char section[256] = {'\0',};
+static GHashTable *config_hash = NULL;
+
+static int load_config(struct parse_result *result, void *user_data)
+{
+       int value = 0;
+
+       if (!MATCH(result->section, section))
+               return 0;
+
+       _D("%s,%s,%s", result->section, result->name, result->value);
+
+       value = atoi(result->value);
+       if ((value == 1) && !g_hash_table_contains(config_hash, result->name))
+               g_hash_table_add(config_hash, g_strdup(result->name));
+
+       return 0;
+}
+
+void test_config_load(const char *profile)
+{
+       int len = 0;
+       int ret = 0;
+
+       if (NULL != profile)    len = strlen(profile);
+       if ((0 >= len) || (255 < len))
+               strncpy(section, DEF_PROFILE, 255);
+       else
+               strncpy(section, profile, 255);
+
+
+       if (NULL != config_hash)
+               test_config_unload();
+
+       config_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+       if (NULL == config_hash) {
+               _E("Failed to create config hash table!");
+               return ;
+       }
+
+       ret = config_parse(CONF_FILE, load_config, NULL);
+
+       if (ret < 0) {
+               _E("Failed to load %s, %d Use default value!", CONF_FILE, ret);
+               test_config_unload();
+       }
+}
+
+void test_config_unload()
+{
+       if (NULL != config_hash) {
+               g_hash_table_unref(config_hash);
+               config_hash = NULL;
+       }
+}
+
+bool test_config_is_supported(const char *module)
+{
+       // if fail to load config file, all modules are supported as default.
+       //if ((NULL == module) || (NULL == config_hash) || (0 == g_hash_table_size(config_hash)))
+       if ((NULL == module) || (NULL == config_hash))
+               return TRUE;
+
+       return g_hash_table_contains(config_hash, module);
+}
diff --git a/src/auto-test/config.h b/src/auto-test/config.h
new file mode 100644 (file)
index 0000000..f541dd7
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2014 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 __AUTOTEST_CONFIG_H__
+#define __AUTOTEST_CONFIG_H__
+
+#include <stdbool.h>
+
+void test_config_load(const char *profile);
+void test_config_unload();
+bool test_config_is_supported(const char *module);
+
+
+#endif /* __AUTOTEST_CONFIG_H__ */
diff --git a/src/auto-test/main.c b/src/auto-test/main.c
new file mode 100644 (file)
index 0000000..a3c8df7
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * test
+ *
+ * Copyright (c) 2013 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"
+#include "config.h"
+
+static void test_main(int argc, char **argv)
+{
+       _I("auto test all");
+       test_init((void *)NULL);
+       test_exit((void *)NULL);
+}
+
+static void unit_test(int argc, char **argv)
+{
+       const struct test_ops *ops;
+
+       ops = find_test(argv[2]);
+       if (!ops) {
+               _E("there is no test ops : %s", argv[2]);
+               return;
+       }
+       ops->unit(argc, argv);
+}
+
+void show_usage()
+{
+       printf("Usage: deviced-auto-test [PROFILE] [MODULE] [UNIT-METHOD] [OPTS]\n\n");
+       printf("Mandatory arguments\n");
+       printf("[PROFILE] :\n");
+       printf("\tmobile\n\twearable\n\ttv\n\tivi\n\tcommon\n\n");
+       printf("Optional arguments\nIf you don't give any optional arguments, all supported modules will be tested.\n");
+       printf("All module list is as below.\nAs per profile, supported modules are different.\n");
+       printf("[MODULE]:\n");
+       printf("\tbattery\n");
+       printf("[UNIT-METHOD], [OPTS]:\n");
+       printf("\tThis is refered to module information.\n");
+       printf("\tThis can not be used without [MODULE] argument.\n\n");
+}
+
+int main(int argc, char **argv)
+{
+       if (argc < 2) {
+               show_usage();
+               return 0;
+       }
+
+       test_config_load(argv[1]);
+       config_test();
+
+       if (argc >= 3)
+               unit_test(argc, argv);
+       else
+               test_main(argc, argv);
+
+       test_config_unload();
+
+       return 0;
+}
+
diff --git a/src/auto-test/result.c b/src/auto-test/result.c
new file mode 100644 (file)
index 0000000..4476e2d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * test
+ *
+ * Copyright (c) 2014 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 <stdio.h>
+#include <errno.h>
+#include <E_DBus.h>
+
+#include "core/list.h"
+#include "core/common.h"
+
+#ifdef ENABLE_TEST_DLOG
+#define ENABLE_DLOG
+#endif
+
+#define LOG_TAG "ATR" /* AUTO_TESTE_RESULT */
+#include "shared/log-macro.h"
+
+#define BUF_MAX 256
+
+void _R(const char *format, ...)
+{
+       va_list args;
+       char buf[BUF_MAX];
+
+       va_start(args, format);
+       vsnprintf(buf, BUF_MAX, format, args);
+       va_end(args);
+
+       _D("%s", buf);
+}
diff --git a/src/auto-test/test.c b/src/auto-test/test.c
new file mode 100644 (file)
index 0000000..40b950f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * test
+ *
+ * Copyright (c) 2013 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"
+#include "config.h"
+
+static dd_list *dd_head;
+
+void add_test(const struct test_ops *d)
+{
+       if (d->priority == TEST_PRIORITY_HIGH)
+               DD_LIST_PREPEND(dd_head, d);
+       else
+               DD_LIST_APPEND(dd_head, d);
+}
+
+void remove_test(const struct test_ops *d)
+{
+       DD_LIST_REMOVE(dd_head, d);
+}
+
+const struct test_ops *find_test(const char *name)
+{
+       dd_list *elem;
+       const struct test_ops *d;
+
+       DD_LIST_FOREACH(dd_head, elem, d) {
+               if (!strcasecmp(d->name, name))
+                       return d;
+       }
+       return NULL;
+}
+
+void config_test()
+{
+       dd_list *elem;
+       const struct test_ops *d;
+
+       DD_LIST_FOREACH(dd_head, elem, d) {
+               if (!test_config_is_supported(d->name))
+                       DD_LIST_REMOVE(dd_head, d);
+       }
+}
+
+void test_init(void *data)
+{
+       dd_list *elem;
+       const struct test_ops *d;
+
+       _D("test module count(%d)", DD_LIST_LENGTH(dd_head));
+       DD_LIST_FOREACH(dd_head, elem, d) {
+               _D("[%s] initialize", d->name);
+               if (d->init)
+                       d->init(data);
+       }
+}
+
+void test_exit(void *data)
+{
+       dd_list *elem;
+       const struct test_ops *d;
+
+       DD_LIST_FOREACH(dd_head, elem, d) {
+               _D("[%s] deinitialize", d->name);
+               if (d->exit)
+                       d->exit(data);
+       }
+}
diff --git a/src/auto-test/test.h b/src/auto-test/test.h
new file mode 100644 (file)
index 0000000..33108ab
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * test
+ *
+ * Copyright (c) 2013 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 __TEST_H__
+#define __TEST_H__
+#include <stdio.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <E_DBus.h>
+
+#include "core/list.h"
+#include "core/common.h"
+#include "core/udev.h"
+#include "shared/dbus.h"
+
+#ifdef ENABLE_TEST_DLOG
+#define ENABLE_DLOG
+#endif
+
+#define LOG_TAG "AUTO_TEST"
+#include "shared/log-macro.h"
+
+#define TEST_WAIT_TIME_INTERVAL        2
+#define METHOD_SET_DEVICE      "device_changed"
+
+enum test_priority {
+       TEST_PRIORITY_NORMAL = 0,
+       TEST_PRIORITY_HIGH,
+};
+
+struct test_ops {
+       enum test_priority priority;
+       char *name;
+       void (*init) (void *data);
+       void (*exit) (void *data);
+       int (*start) (void);
+       int (*stop) (void);
+       int (*status) (void);
+       int (*unit) (int argc, char **argv);
+};
+
+enum test_ops_status {
+       TEST_OPS_STATUS_UNINIT,
+       TEST_OPS_STATUS_START,
+       TEST_OPS_STATUS_STOP,
+       TEST_OPS_STATUS_MAX,
+};
+
+void test_init(void *data);
+void test_exit(void *data);
+
+static inline int test_start(const struct test_ops *c)
+{
+       if (c && c->start)
+               return c->start();
+
+       return -EINVAL;
+}
+
+static inline int test_stop(const struct test_ops *c)
+{
+       if (c && c->stop)
+               return c->stop();
+
+       return -EINVAL;
+}
+
+static inline int test_get_status(const struct test_ops *c)
+{
+       if (c && c->status)
+               return c->status();
+
+       return -EINVAL;
+}
+
+#define TEST_OPS_REGISTER(c)   \
+static void __CONSTRUCTOR__ module_init(void)  \
+{      \
+       add_test(c);    \
+}      \
+static void __DESTRUCTOR__ module_exit(void)   \
+{      \
+       remove_test(c); \
+}
+DBusMessage *deviced_dbus_method_sync_with_reply(const char *dest, const char *path,
+               const char *interface, const char *method,
+               const char *sig, char *param[]);
+void add_test(const struct test_ops *c);
+void remove_test(const struct test_ops *c);
+const struct test_ops *find_test(const char *name);
+void config_test();
+void _R (const char *format, ...);
+#endif