auto-test: support ir dbus test 06/136506/5
authorYunmi Ha <yunmi.ha@samsung.com>
Fri, 30 Jun 2017 04:59:12 +0000 (13:59 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Fri, 30 Jun 2017 07:08:07 +0000 (16:08 +0900)
Change-Id: I73dd2d414cbc046cb0c8ab26a4819a46fda4ed09
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/auto-test/CMakeLists.txt
src/auto-test/auto-test.conf
src/auto-test/ir.c [new file with mode: 0755]
src/auto-test/led.c

index e57e533..d4f4b3c 100644 (file)
@@ -28,6 +28,7 @@ SET(SRCS
        power.c
        proc.c
        extcon.c
+       ir.c
 )
 
 # extcon test
index 23c3a1b..077beae 100644 (file)
@@ -5,6 +5,7 @@ led=1
 power=1
 proc=1
 extcon=1
+ir=1
 
 [wearable]
 battery=1
@@ -13,6 +14,7 @@ led=0
 power=1
 proc=1
 extcon=1
+ir=0
 
 [tv]
 battery=0
@@ -21,6 +23,7 @@ led=0
 power=1
 proc=1
 extcon=1
+ir=0
 
 [ivi]
 battery=0
@@ -29,6 +32,7 @@ led=0
 power=1
 proc=1
 extcon=1
+ir=0
 
 [common]
 battery=0
@@ -37,3 +41,4 @@ led=0
 power=1
 proc=1
 extcon=1
+ir=0
diff --git a/src/auto-test/ir.c b/src/auto-test/ir.c
new file mode 100755 (executable)
index 0000000..49ed9c7
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * 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_IR_ISAVAILABLE          "IRIsAvailable"
+#define METHOD_IR_TRANSMIT                     "TransmitIR"
+#define METHOD_IR_SETIRCOMMAND         "SetIrCommand"
+
+struct dbus_int {
+       int *list;
+       int size;
+};
+
+static bool request_ir_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_IR,
+                       DEVICED_INTERFACE_IR,
+                       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 == -ENODEV) {
+                       _E("fail (%s): device open fail (%d)", method, val);
+               } 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_ir_isavailable()
+{
+       return request_ir_method(METHOD_IR_ISAVAILABLE, NULL, NULL);
+}
+
+static bool set_ir_transmit(int carrier_frequency, int *pattern, int size)
+{
+       char *param[1];
+       int freq_pattern[size + 1];
+       struct dbus_int pattern_list;
+
+       freq_pattern[0] = carrier_frequency;
+       for (int i = 1; i <= size; i++)
+               freq_pattern[i] = pattern[i-1];
+
+       pattern_list.list = freq_pattern;
+       pattern_list.size = size + 1;
+
+       param[0] = (char *)&pattern_list;
+       return request_ir_method(METHOD_IR_TRANSMIT, "ai", param);
+}
+
+/*legacy command*/
+static bool set_ir_command(char *command)
+{
+       DBusMessage *msg;
+       int val;
+       char *param[1];
+       bool ret = FALSE;
+
+       param[0] = command;
+       msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+                       DEVICED_PATH_LED,
+                       DEVICED_INTERFACE_LED,
+                       METHOD_IR_SETIRCOMMAND, "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 < 0) {
+                       _E("fail : returned fail (%d)", val);
+               } else {
+                       _I("success : %d", val);
+                       ret = TRUE;
+               }
+       }
+
+       dbus_message_unref(msg);
+       return ret;
+}
+
+void ir_test_all(int *success, int *fail)
+{
+       int s = 0;
+       int f = 0;
+
+       int pattern[5] = {100, 200, 300, 400, 500};
+
+       (get_ir_isavailable())                                  ? s++ : f++;
+       (set_ir_transmit(38000, pattern, 5))    ? s++ : f++;
+       (set_ir_command("N/A"))                                 ? s++ : f++;
+
+
+       if (NULL != success)    *success = s;
+       if (NULL != fail)       *fail = f;
+}
+
+static void ir_init(void *data)
+{
+       int success = 0;
+       int fail = 0;
+
+       _I("start test");
+
+       ir_test_all(&success, &fail);
+
+       _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+}
+
+static void ir_exit(void *data)
+{
+       _I("end test");
+}
+
+static int ir_unit(int argc, char **argv)
+{
+       if (argc < 4) {
+               int success = 0;
+               int fail = 0;
+
+               _I("start test");
+               ir_test_all(&success, &fail);
+               _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+       } else if (0 == strcasecmp(argv[3], METHOD_IR_ISAVAILABLE)) {
+               get_ir_isavailable();
+       //} else if (0 == strcasecmp(argv[3], METHOD_IR_TRANSMIT)) {
+       //      set_ir_transmit();
+       } else if (0 == strcasecmp(argv[3], METHOD_IR_SETIRCOMMAND)) {
+               set_ir_command(argv[4]);
+       } else {
+               _E("Unknown test case!!!");
+       }
+
+       return 0;
+}
+
+static const struct test_ops ir_test_ops = {
+       .priority = TEST_PRIORITY_NORMAL,
+       .name     = "ir",
+       .init     = ir_init,
+       .exit    = ir_exit,
+       .unit    = ir_unit,
+};
+
+TEST_OPS_REGISTER(&ir_test_ops)
index 3353d25..ab9bc4a 100755 (executable)
@@ -20,7 +20,6 @@
 #include "test.h"
 #include <stdio.h>
 
-#define METHOD_LED_SETIRCOMMAND                                "SetIrCommand"
 #define METHOD_LED_PLAYCUSTOM                          "playcustom"
 #define METHOD_LED_STOPCUSTOM                          "stopcustom"
 //#define METHOD_LED_GETBRIGHTNESS_FORCAMERA   "GetBrightnessForCamera"
@@ -141,15 +140,6 @@ static bool set_led_stopcustom()
        return set_led_method(METHOD_LED_STOPCUSTOM, NULL, NULL);
 }
 
-static bool set_led_ircommand(char *command)
-{
-       char *param[1];
-
-       param[0] = command;
-
-       return set_led_method(METHOD_LED_SETIRCOMMAND, "s", param);
-}
-
 void led_test_all(int *success, int *fail)
 {
        int s = 0;
@@ -161,7 +151,6 @@ void led_test_all(int *success, int *fail)
        (get_led_brightness())                  ? s++ : f++;
        (set_led_playcustom(1, 0, RED, DEFAULT_FLAG))   ? s++ : f++;
        (set_led_stopcustom())                  ? s++ : f++;
-       (set_led_ircommand("N/A"))              ? s++ : f++;
 
        if (NULL != success)    *success = s;
        if (NULL != fail)       *fail = f;
@@ -202,8 +191,6 @@ static int led_unit(int argc, char **argv)
                set_led_playcustom(atoi(argv[4]), atoi(argv[5]), strtoul(argv[6], NULL, 16), DEFAULT_FLAG);
        } else if (0 == strcasecmp(argv[3], METHOD_LED_STOPCUSTOM)) {
                set_led_stopcustom();
-       } else if (0 == strcasecmp(argv[3], METHOD_LED_SETIRCOMMAND)) {
-               set_led_ircommand(argv[3]);
        } else {
                _E("Unknown test case!!!");
        }