Initialize Tizen 2.3
[framework/system/deviced.git] / src / auto-test / udev.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 static const struct device_change_type {
21         char *name;
22         char *status;
23 } device_change_types [] = {
24         {"udev",                "start"},
25         {"udev",                "stop"},
26 };
27
28 static int test(int index)
29 {
30         DBusError err;
31         DBusMessage *msg;
32         int ret, ret_val;
33         char *param[3];
34
35         param[0] = UDEV;
36         param[1] = "1";
37         param[2] = device_change_types[index].status;
38
39         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
40                         DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
41                         UDEV, "sis", param);
42         if (!msg) {
43                 _E("fail : %s %s %s %s",
44                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
45                         UDEV);
46                 return -EBADMSG;
47         }
48
49         dbus_error_init(&err);
50
51         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
52         if (!ret) {
53                 _E("no message : [%s:%s]", err.name, err.message);
54                 ret_val = -EBADMSG;
55         }
56         _I("START");
57         dbus_message_unref(msg);
58         dbus_error_free(&err);
59         sleep(TEST_WAIT_TIME_INTERVAL);
60         return ret_val;
61 }
62
63 static void unit(char *unit, char *status)
64 {
65         int index;
66
67         for (index = 0; index < ARRAY_SIZE(device_change_types); index++) {
68                 if (strcmp(unit, device_change_types[index].name) != 0 ||
69                     strcmp(status, device_change_types[index].status) != 0)
70                         continue;
71                 test(index);
72         }
73 }
74
75 static void udev_init(void *data)
76 {
77         int index;
78
79         _I("start test");
80         for (index = 0; index < ARRAY_SIZE(device_change_types); index++)
81                 test(index);
82 }
83
84 static void udev_exit(void *data)
85 {
86         _I("end test");
87 }
88
89 static int udev_unit(int argc, char **argv)
90 {
91         int status;
92
93         if (argv[1] == NULL)
94                 return -EINVAL;
95         if (argc != 3)
96                 return -EAGAIN;
97
98         unit(argv[1], argv[2]);
99 out:
100         return 0;
101 }
102
103 static const struct test_ops udev_test_ops = {
104         .priority = TEST_PRIORITY_HIGH,
105         .name     = "udev",
106         .init     = udev_init,
107         .exit    = udev_exit,
108         .unit    = udev_unit,
109 };
110
111 TEST_OPS_REGISTER(&udev_test_ops)