diff options
author | Yunmi Ha <yunmi.ha@samsung.com> | 2017-06-30 13:59:12 +0900 |
---|---|---|
committer | Yunmi Ha <yunmi.ha@samsung.com> | 2017-06-30 16:08:07 +0900 |
commit | 8eb81bd1835f83c0763d7ed1b356026c1bf8c65a (patch) | |
tree | 936bb34b39ea8718e052da9f9ae26439ea1e9ee8 | |
parent | 6191fb8c8fcd4d493adbc88d5b749ec69a27a07e (diff) | |
download | deviced-8eb81bd1835f83c0763d7ed1b356026c1bf8c65a.tar.gz deviced-8eb81bd1835f83c0763d7ed1b356026c1bf8c65a.tar.bz2 deviced-8eb81bd1835f83c0763d7ed1b356026c1bf8c65a.zip |
auto-test: support ir dbus test
Change-Id: I73dd2d414cbc046cb0c8ab26a4819a46fda4ed09
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
-rw-r--r-- | src/auto-test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/auto-test/auto-test.conf | 5 | ||||
-rwxr-xr-x | src/auto-test/ir.c | 185 | ||||
-rwxr-xr-x | src/auto-test/led.c | 13 |
4 files changed, 191 insertions, 13 deletions
diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index e57e5332..d4f4b3cf 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -28,6 +28,7 @@ SET(SRCS power.c proc.c extcon.c + ir.c ) # extcon test diff --git a/src/auto-test/auto-test.conf b/src/auto-test/auto-test.conf index 23c3a1b3..077beae4 100644 --- a/src/auto-test/auto-test.conf +++ b/src/auto-test/auto-test.conf @@ -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 index 00000000..49ed9c79 --- /dev/null +++ b/src/auto-test/ir.c @@ -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) diff --git a/src/auto-test/led.c b/src/auto-test/led.c index 3353d257..ab9bc4aa 100755 --- a/src/auto-test/led.c +++ b/src/auto-test/led.c @@ -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!!!"); } |