Initialize Tizen 2.3
[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, level;
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, &level,
52                         DBUS_TYPE_INVALID);
53         if (!ret) {
54                 _E("no message : [%s:%s]", err.name, err.message);
55                 level = -1;
56         }
57         _I("%d", level);
58         dbus_message_unref(msg);
59         dbus_error_free(&err);
60         sleep(TEST_WAIT_TIME_INTERVAL);
61         return level;
62 }
63
64 static int test_hdcp(void)
65 {
66         DBusError err;
67         DBusMessage *msg;
68         int ret, level;
69
70         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
71                         DEVICED_PATH_SYSNOTI,
72                         DEVICED_INTERFACE_SYSNOTI,
73                         METHOD_GET_HDCP, NULL, NULL);
74         if (!msg) {
75                 _E("fail : %s %s %s %s",
76                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
77                         METHOD_GET_HDCP);
78                 return -EBADMSG;
79         }
80
81         dbus_error_init(&err);
82
83         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level,
84                         DBUS_TYPE_INVALID);
85         if (!ret) {
86                 _E("no message : [%s:%s]", err.name, err.message);
87                 level = -1;
88         }
89         _I("%d", level);
90         dbus_message_unref(msg);
91         dbus_error_free(&err);
92         sleep(TEST_WAIT_TIME_INTERVAL);
93         return level;
94 }
95
96 static int test_hdmi_audio(void)
97 {
98         DBusError err;
99         DBusMessage *msg;
100         int ret, level;
101
102         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
103                         DEVICED_PATH_SYSNOTI,
104                         DEVICED_INTERFACE_SYSNOTI,
105                         METHOD_GET_HDMI_AUDIO, NULL, NULL);
106         if (!msg) {
107                 _E("fail : %s %s %s %s",
108                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
109                         METHOD_GET_HDMI_AUDIO);
110                 return -EBADMSG;
111         }
112
113         dbus_error_init(&err);
114
115         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level,
116                         DBUS_TYPE_INVALID);
117         if (!ret) {
118                 _E("no message : [%s:%s]", err.name, err.message);
119                 level = -1;
120         }
121         _I("%d", level);
122         dbus_message_unref(msg);
123         dbus_error_free(&err);
124         sleep(TEST_WAIT_TIME_INTERVAL);
125         return level;
126 }
127
128 static int test(int index)
129 {
130         DBusError err;
131         DBusMessage *msg;
132         int ret, ret_val;
133         char *param[4];
134
135         param[0] = METHOD_SET_DEVICE;
136         param[1] = "2";
137         param[2] = device_change_types[index].name;
138         param[3] = device_change_types[index].status;
139
140         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
141                         DEVICED_PATH_SYSNOTI,
142                         DEVICED_INTERFACE_SYSNOTI,
143                         METHOD_SET_DEVICE, "siss", param);
144         if (!msg) {
145                 _E("fail : %s %s %s %s",
146                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
147                         METHOD_SET_DEVICE);
148                 return -EBADMSG;
149         }
150
151         dbus_error_init(&err);
152
153         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
154         if (ret == 0) {
155                 _E("no message : [%s:%s]", err.name, err.message);
156                 dbus_error_free(&err);
157                 ret_val = -EBADMSG;
158         }
159         _I("%s %s", device_change_types[index].name, device_change_types[index].status);
160         dbus_message_unref(msg);
161         dbus_error_free(&err);
162         sleep(TEST_WAIT_TIME_INTERVAL);
163         return ret_val;
164 }
165
166 static void unit(char *unit, char *status)
167 {
168         int index;
169
170         for (index = 0; index < ARRAY_SIZE(device_change_types); index++) {
171                 if (strcmp(unit, device_change_types[index].name) != 0 ||
172                     strcmp(status, device_change_types[index].status) != 0)
173                         continue;
174                 test(index);
175         }
176 }
177
178 static void hdmi_init(void *data)
179 {
180         int index;
181
182         _I("start test");
183         for (index = 0; index < ARRAY_SIZE(device_change_types); index++) {
184                 test(index);
185                 test_hdmi();
186                 test_hdcp();
187                 test_hdmi_audio();
188         }
189 }
190
191 static void hdmi_exit(void *data)
192 {
193         _I("end test");
194 }
195
196 static int hdmi_unit(int argc, char **argv)
197 {
198         int status;
199
200         if (argv[1] == NULL)
201                 return -EINVAL;
202         if (argc != 3)
203                 return -EAGAIN;
204
205         unit(argv[1], argv[2]);
206 out:
207         return 0;
208 }
209
210 static const struct test_ops hdmi_test_ops = {
211         .priority = TEST_PRIORITY_NORMAL,
212         .name     = "hdmi",
213         .init     = hdmi_init,
214         .exit    = hdmi_exit,
215         .unit    = hdmi_unit,
216 };
217
218 TEST_OPS_REGISTER(&hdmi_test_ops)