tizen 2.3 release
[framework/system/deviced.git] / src / auto-test / hdmi.c
1 /*
2  * test
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #include "test.h"
19
20 #define METHOD_GET_HDMI         "GetHDMI"
21 #define METHOD_GET_HDCP         "GetHDCP"
22 #define METHOD_GET_HDMI_AUDIO   "GetHDMIAudio"
23
24 static const struct device_change_type {
25         char *name;
26         char *status;
27 } device_change_types [] = {
28         {"hdmi",        "1"},
29         {"hdmi",        "0"},
30 };
31
32 static int test_hdmi(void)
33 {
34         DBusError err;
35         DBusMessage *msg;
36         int ret, val;
37
38         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
39                         DEVICED_PATH_SYSNOTI,
40                         DEVICED_INTERFACE_SYSNOTI,
41                         METHOD_GET_HDMI, NULL, NULL);
42         if (!msg) {
43                 _E("fail : %s %s %s %s",
44                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
45                         METHOD_GET_HDMI);
46                 return -EBADMSG;
47         }
48
49         dbus_error_init(&err);
50
51         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val,
52                         DBUS_TYPE_INVALID);
53         if (!ret) {
54                 _E("no message : [%s:%s]", err.name, err.message);
55                 val = -1;
56         }
57         _I("%d", val);
58         if (val < 0)
59                 _R("[NG] ---- %s", __func__);
60         else
61                 _R("[OK] ---- %s        : V(%d)", __func__, val);
62         dbus_message_unref(msg);
63         dbus_error_free(&err);
64         sleep(TEST_WAIT_TIME_INTERVAL);
65         return val;
66 }
67
68 static int test_hdcp(void)
69 {
70         DBusError err;
71         DBusMessage *msg;
72         int ret, val;
73
74         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
75                         DEVICED_PATH_SYSNOTI,
76                         DEVICED_INTERFACE_SYSNOTI,
77                         METHOD_GET_HDCP, NULL, NULL);
78         if (!msg) {
79                 _E("fail : %s %s %s %s",
80                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
81                         METHOD_GET_HDCP);
82                 return -EBADMSG;
83         }
84
85         dbus_error_init(&err);
86
87         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val,
88                         DBUS_TYPE_INVALID);
89         if (!ret) {
90                 _E("no message : [%s:%s]", err.name, err.message);
91                 val = -1;
92         }
93         _I("%d", val);
94         if (val < 0)
95                 _R("[NG] ---- %s", __func__);
96         else
97                 _R("[OK] ---- %s        : V(%d)", __func__, val);
98         dbus_message_unref(msg);
99         dbus_error_free(&err);
100         sleep(TEST_WAIT_TIME_INTERVAL);
101         return val;
102 }
103
104 static int test_hdmi_audio(void)
105 {
106         DBusError err;
107         DBusMessage *msg;
108         int ret, val;
109
110         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
111                         DEVICED_PATH_SYSNOTI,
112                         DEVICED_INTERFACE_SYSNOTI,
113                         METHOD_GET_HDMI_AUDIO, NULL, NULL);
114         if (!msg) {
115                 _E("fail : %s %s %s %s",
116                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
117                         METHOD_GET_HDMI_AUDIO);
118                 return -EBADMSG;
119         }
120
121         dbus_error_init(&err);
122
123         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val,
124                         DBUS_TYPE_INVALID);
125         if (!ret) {
126                 _E("no message : [%s:%s]", err.name, err.message);
127                 val = -1;
128         }
129         _I("%d", val);
130         if (val < 0)
131                 _R("[NG] ---- %s", __func__);
132         else
133                 _R("[OK] ---- %s  : V(%d)", __func__, val);
134         dbus_message_unref(msg);
135         dbus_error_free(&err);
136         sleep(TEST_WAIT_TIME_INTERVAL);
137         return val;
138 }
139
140 static int hdmi(int index)
141 {
142         DBusError err;
143         DBusMessage *msg;
144         int ret, val;
145         char *param[4];
146
147         param[0] = METHOD_SET_DEVICE;
148         param[1] = "2";
149         param[2] = device_change_types[index].name;
150         param[3] = device_change_types[index].status;
151
152         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
153                         DEVICED_PATH_SYSNOTI,
154                         DEVICED_INTERFACE_SYSNOTI,
155                         METHOD_SET_DEVICE, "siss", param);
156         if (!msg) {
157                 _E("fail : %s %s %s %s",
158                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
159                         METHOD_SET_DEVICE);
160                 return -EBADMSG;
161         }
162
163         dbus_error_init(&err);
164
165         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
166         if (ret == 0) {
167                 _E("no message : [%s:%s]", err.name, err.message);
168                 dbus_error_free(&err);
169                 val = -EBADMSG;
170         }
171         _I("%s %s", device_change_types[index].name, device_change_types[index].status);
172         if (val < 0)
173                 _R("[NG] ---- %s", __func__);
174         else
175                 _R("[OK] ---- %s             : V(%s %s)",
176                 __func__, device_change_types[index].name, device_change_types[index].status);
177         dbus_message_unref(msg);
178         dbus_error_free(&err);
179         sleep(TEST_WAIT_TIME_INTERVAL);
180         return val;
181 }
182
183 static void unit(char *unit, char *status)
184 {
185         int index;
186
187         for (index = 0; index < ARRAY_SIZE(device_change_types); index++) {
188                 if (strcmp(unit, device_change_types[index].name) != 0 ||
189                     strcmp(status, device_change_types[index].status) != 0)
190                         continue;
191                 hdmi(index);
192         }
193 }
194
195 static void hdmi_init(void *data)
196 {
197         int index;
198
199         _I("start test");
200         for (index = 0; index < ARRAY_SIZE(device_change_types); index++) {
201                 hdmi(index);
202                 test_hdmi();
203                 test_hdcp();
204                 test_hdmi_audio();
205         }
206 }
207
208 static void hdmi_exit(void *data)
209 {
210         _I("end test");
211 }
212
213 static int hdmi_unit(int argc, char **argv)
214 {
215         int status;
216
217         if (argv[1] == NULL)
218                 return -EINVAL;
219         if (argc != 3)
220                 return -EAGAIN;
221
222         unit(argv[1], argv[2]);
223 out:
224         return 0;
225 }
226
227 static const struct test_ops hdmi_test_ops = {
228         .priority = TEST_PRIORITY_NORMAL,
229         .name     = "hdmi",
230         .init     = hdmi_init,
231         .exit    = hdmi_exit,
232         .unit    = hdmi_unit,
233 };
234
235 TEST_OPS_REGISTER(&hdmi_test_ops)