auto-test: support extcon dbus test 06/136406/1
authorYunmi Ha <yunmi.ha@samsung.com>
Thu, 29 Jun 2017 09:45:32 +0000 (18:45 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Thu, 29 Jun 2017 09:45:32 +0000 (18:45 +0900)
Change-Id: I33885c7a81b10367f2364f4c5f0e8fdca1464da5
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/auto-test/CMakeLists.txt
src/auto-test/auto-test.conf
src/auto-test/extcon.c [new file with mode: 0755]

index da6da42..e57e533 100644 (file)
@@ -27,6 +27,7 @@ SET(SRCS
        led.c
        power.c
        proc.c
+       extcon.c
 )
 
 # extcon test
index 2e3dde8..23c3a1b 100644 (file)
@@ -4,6 +4,7 @@ display=1
 led=1
 power=1
 proc=1
+extcon=1
 
 [wearable]
 battery=1
@@ -11,6 +12,7 @@ display=1
 led=0
 power=1
 proc=1
+extcon=1
 
 [tv]
 battery=0
@@ -18,6 +20,7 @@ display=1
 led=0
 power=1
 proc=1
+extcon=1
 
 [ivi]
 battery=0
@@ -25,6 +28,7 @@ display=1
 led=0
 power=1
 proc=1
+extcon=1
 
 [common]
 battery=0
@@ -32,3 +36,4 @@ display=1
 led=0
 power=1
 proc=1
+extcon=1
diff --git a/src/auto-test/extcon.c b/src/auto-test/extcon.c
new file mode 100755 (executable)
index 0000000..493d547
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * 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"
+
+#define METHOD_EXTCON_GETSTATUS                "GetStatus"
+#define METHOD_EXTCON_ENABLE           "enable"
+#define METHOD_EXTCON_DISABLE          "disable"
+
+static bool request_extcon_method(const char *method, char *sig, char *param[])
+{
+       DBusMessage *msg;
+       int val;
+       bool ret = FALSE;
+
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_EXTCON,
+                       DEVICED_INTERFACE_EXTCON,
+                       method, sig, param);
+       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 == -ENOTSUP) || (val == -ENOSYS)) {
+                       _I("Not supported feature! (%s): %d", method, val);
+                       ret = TRUE;
+               } else if (val < 0) {
+                       _E("fail (%s): returned fail (%d)", method, val);
+               } else {
+                       _I("success (%s): %d", method, val);
+                       ret = TRUE;
+               }
+       }
+
+       dbus_message_unref(msg);
+       return ret;
+}
+
+static bool get_extcon_status(char *device_name)
+{
+       DBusMessage *msg;
+       int val;
+       bool ret = FALSE;
+       char *param[1];
+
+       param[0] = device_name;
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_EXTCON,
+                       DEVICED_INTERFACE_EXTCON,
+                       METHOD_EXTCON_GETSTATUS, "s", 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");
+       else {
+               if ((val == -ENOTSUP) || (val == -ENOSYS)) {
+                       _I("Not supported feature! : %d", val);
+                       ret = TRUE;
+               } else if ((val == -EINVAL) || (val == -ENOENT)) {
+                       _E("fail : returned fail (%d)", val);
+               } else {
+                       _I("success : %d", val);
+                       ret = TRUE;
+               }
+       }
+
+       dbus_message_unref(msg);
+       return ret;
+}
+
+static bool set_extcon_enable(char *device_name)
+{
+       char *param[1];
+
+       param[0] = device_name;
+       return request_extcon_method(METHOD_EXTCON_ENABLE, "s", param);
+}
+
+static bool set_extcon_disable(char *device_name)
+{
+       char *param[1];
+
+       param[0] = device_name;
+       return request_extcon_method(METHOD_EXTCON_DISABLE, "s", param);
+}
+
+
+void extcon_test_all(int *success, int *fail)
+{
+       int s = 0;
+       int f = 0;
+
+       (set_extcon_enable("Headphone"))                ? s++ : f++;
+       (get_extcon_status("Headphone"))                ? s++ : f++;
+       (set_extcon_disable("Headphone"))               ? s++ : f++;
+
+       if (NULL != success)    *success = s;
+       if (NULL != fail)       *fail = f;
+}
+
+static void extcon_init(void *data)
+{
+       int success = 0;
+       int fail = 0;
+
+       _I("start test");
+
+       extcon_test_all(&success, &fail);
+
+       _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+}
+
+static void extcon_exit(void *data)
+{
+       _I("end test");
+}
+
+static int extcon_unit(int argc, char **argv)
+{
+       if (argc < 4) {
+               int success = 0;
+               int fail = 0;
+
+               _I("start test");
+               extcon_test_all(&success, &fail);
+               _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+       } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_GETSTATUS)) {
+               get_extcon_status(argv[4]);
+       } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_ENABLE)) {
+               set_extcon_enable(argv[4]);
+       } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_DISABLE)) {
+               set_extcon_disable(argv[4]);
+       } else {
+               _E("Unknown test case!!!");
+       }
+
+       return 0;
+}
+
+static const struct test_ops extcon_test_ops = {
+       .priority = TEST_PRIORITY_NORMAL,
+       .name     = "extcon",
+       .init     = extcon_init,
+       .exit    = extcon_exit,
+       .unit    = extcon_unit,
+};
+
+TEST_OPS_REGISTER(&extcon_test_ops)