28dfa4c966553f6d33ee46675a78d8aeda19e909
[platform/core/system/deviced.git] / src / auto-test / proc.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_SYSNOTI_GETREVISION      "GetRevision"
21
22
23 static bool get_sysnoti_revision()
24 {
25         GVariant *msg;
26         int val, err;
27         bool ret = FALSE;
28
29         err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
30                                         DEVICED_PATH_SYSNOTI,
31                                         DEVICED_INTERFACE_SYSNOTI,
32                                         METHOD_SYSNOTI_GETREVISION, NULL, &msg);
33         if (err < 0) {
34                 _E("fail : no reply");
35                 return ret;
36         }
37
38         if (!g_variant_get_safe(msg, "(i)", &val))
39                 _E("fail : no message");
40         else {
41                 if ((val == -ENOTSUP) || (val == -ENOSYS)) {
42                         _I("Not supported feature! : %d", val);
43                         ret = TRUE;
44                 } else if (val < 0) {
45                         _E("fail : returned fail (%d)", val);
46                 } else {
47                         _I("success : %d", val);
48                         ret = TRUE;
49                 }
50         }
51
52         g_variant_unref(msg);
53         return ret;
54 }
55
56 void proc_test_all(int *success, int *fail)
57 {
58         int s = 0;
59         int f = 0;
60
61         (get_sysnoti_revision())        ? s++ : f++;
62
63         if (NULL != success)    *success = s;
64         if (NULL != fail)       *fail = f;
65 }
66
67 static void proc_init(void *data)
68 {
69         int success = 0;
70         int fail = 0;
71
72         _I("start test");
73
74         proc_test_all(&success, &fail);
75
76         _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
77 }
78
79 static void proc_exit(void *data)
80 {
81         _I("end test");
82 }
83
84 static int proc_unit(int argc, char **argv)
85 {
86         if (argc < 4) {
87                 int success = 0;
88                 int fail = 0;
89
90                 _I("start test");
91                 proc_test_all(&success, &fail);
92                 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
93         } else if (0 == strcmp(argv[3], METHOD_SYSNOTI_GETREVISION)) {
94                 get_sysnoti_revision();
95         } else {
96                 _E("Unknown test case!!!");
97         }
98
99         return 0;
100 }
101
102 static const struct test_ops proc_test_ops = {
103         .priority = TEST_PRIORITY_NORMAL,
104         .name     = "proc",
105         .init     = proc_init,
106         .exit    = proc_exit,
107         .unit    = proc_unit,
108 };
109
110 TEST_OPS_REGISTER(&proc_test_ops)