Initialize Tizen 2.3
[framework/system/deviced.git] / src / auto-test / storage.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_STORAGE      "getstorage"
21 #define METHOD_MEM_TRIM "MemTrim"
22
23 static void mem_trim(void *data, DBusMessage *msg, DBusError *tmp)
24 {
25         DBusError err;
26         int ret, result;
27
28         if (!msg)
29                 return;
30
31         dbus_error_init(&err);
32         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
33         if (!ret) {
34                 _E("no message [%s:%s]", err.name, err.message);
35                 dbus_error_free(&err);
36                 return;
37         }
38         _D("succeed mem trim : %d", result);
39 }
40
41 static int request_mem_trim(void)
42 {
43         int ret;
44
45         ret = dbus_method_async_with_reply(DEVICED_BUS_NAME,
46                 DEVICED_PATH_STORAGE, DEVICED_INTERFACE_STORAGE,
47                 METHOD_MEM_TRIM, NULL, NULL, mem_trim, -1, NULL);
48         if (ret == 0)
49                 _D("request mem trim");
50         return ret;
51 }
52
53 static int test_storage(void)
54 {
55         DBusError err;
56         DBusMessage *msg;
57         int ret;
58         double dAvail;
59         double dTotal;
60
61         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
62                         DEVICED_PATH_STORAGE,
63                         DEVICED_INTERFACE_STORAGE,
64                         METHOD_GET_STORAGE, NULL, NULL);
65         if (!msg) {
66                 _E("fail : %s %s %s %s",
67                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
68                         METHOD_GET_STORAGE);
69                 return -EBADMSG;
70         }
71
72         dbus_error_init(&err);
73
74         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT64, &dTotal, DBUS_TYPE_INT64, &dAvail, DBUS_TYPE_INVALID);;
75         if (!ret) {
76                 _E("no message : [%s:%s]", err.name, err.message);
77         }
78         _I("total : %4.4lf avail %4.4lf", dTotal, dAvail);
79         dbus_message_unref(msg);
80         dbus_error_free(&err);
81         sleep(TEST_WAIT_TIME_INTERVAL);
82         return ret;
83 }
84
85 static void storage_init(void *data)
86 {
87         _I("start test");
88         test_storage();
89 }
90
91 static void storage_exit(void *data)
92 {
93         _I("end test");
94 }
95
96 static int storage_unit(int argc, char **argv)
97 {
98         int status;
99
100         if (argv[1] == NULL)
101                 return -EINVAL;
102         test_storage();
103         request_mem_trim();
104         ecore_main_loop_begin();
105 out:
106         return 0;
107 }
108
109 static const struct test_ops storage_test_ops = {
110         .priority = TEST_PRIORITY_NORMAL,
111         .name     = "storage",
112         .init     = storage_init,
113         .exit    = storage_exit,
114         .unit    = storage_unit,
115 };
116
117 TEST_OPS_REGISTER(&storage_test_ops)