tizen 2.3 release
[framework/system/deviced.git] / src / auto-test / test.h
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
19
20 #ifndef __TEST_H__
21 #define __TEST_H__
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <errno.h>
25 #include <E_DBus.h>
26
27 #include "core/list.h"
28 #include "core/common.h"
29 #include "core/udev.h"
30 #include "shared/dbus.h"
31
32 #ifdef ENABLE_TEST_DLOG
33 #define ENABLE_DLOG
34 #endif
35
36 #define LOG_TAG "AUTO_TEST"
37 #include "shared/log-macro.h"
38
39 #define TEST_WAIT_TIME_INTERVAL 5
40 #define METHOD_SET_DEVICE       "device_changed"
41
42 enum test_priority {
43         TEST_PRIORITY_NORMAL = 0,
44         TEST_PRIORITY_HIGH,
45 };
46
47 struct test_ops {
48         enum test_priority priority;
49         char *name;
50         void (*init) (void *data);
51         void (*exit) (void *data);
52         int (*start) (void);
53         int (*stop) (void);
54         int (*status) (void);
55         int (*unit) (int argc, char **argv);
56 };
57
58 enum test_ops_status {
59         TEST_OPS_STATUS_UNINIT,
60         TEST_OPS_STATUS_START,
61         TEST_OPS_STATUS_STOP,
62         TEST_OPS_STATUS_MAX,
63 };
64
65 void test_init(void *data);
66 void test_exit(void *data);
67
68 static inline int test_start(const struct test_ops *c)
69 {
70         if (c && c->start)
71                 return c->start();
72
73         return -EINVAL;
74 }
75
76 static inline int test_stop(const struct test_ops *c)
77 {
78         if (c && c->stop)
79                 return c->stop();
80
81         return -EINVAL;
82 }
83
84 static inline int test_get_status(const struct test_ops *c)
85 {
86         if (c && c->status)
87                 return c->status();
88
89         return -EINVAL;
90 }
91
92 #define TEST_OPS_REGISTER(c)    \
93 static void __CONSTRUCTOR__ module_init(void)   \
94 {       \
95         add_test(c);    \
96 }       \
97 static void __DESTRUCTOR__ module_exit(void)    \
98 {       \
99         remove_test(c); \
100 }
101 DBusMessage *deviced_dbus_method_sync_with_reply(const char *dest, const char *path,
102                 const char *interface, const char *method,
103                 const char *sig, char *param[]);
104 void add_test(const struct test_ops *c);
105 void remove_test(const struct test_ops *c);
106 const struct test_ops *find_test(const char *name);
107 void _R (const char *format, ...);
108 #endif