Change dbus function name
[platform/core/system/feedbackd.git] / src / auto-test / test.h
1 /*
2  * feedbackd auto-test
3  *
4  * Copyright (c) 2018 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 FEEDBACKD__TEST_H__
21 #define FEEDBACKD__TEST_H__
22 #include <stdio.h>
23 #include <errno.h>
24 #include <libsyscommon/libgdbus.h>
25
26 #include "shared/log.h"
27 #include "shared/common.h"
28
29 #ifdef ENABLE_TEST_DLOG
30 #define ENABLE_DLOG
31 #endif
32
33 //#define LOG_TAG "AUTO_TEST"
34
35 enum test_priority {
36         TEST_PRIORITY_NORMAL = 0,
37         TEST_PRIORITY_HIGH,
38 };
39
40 struct test_ops {
41         enum test_priority priority;
42         char *name;
43         void (*init) (void *data);
44         void (*exit) (void *data);
45         int (*start) (void);
46         int (*stop) (void);
47         int (*status) (void);
48         int (*unit) (int argc, char **argv);
49 };
50
51 enum test_ops_status {
52         TEST_OPS_STATUS_UNINIT,
53         TEST_OPS_STATUS_START,
54         TEST_OPS_STATUS_STOP,
55         TEST_OPS_STATUS_MAX,
56 };
57
58 void test_init(void *data);
59 void test_exit(void *data);
60
61 static inline int test_start(const struct test_ops *c)
62 {
63         if (c && c->start)
64                 return c->start();
65
66         return -EINVAL;
67 }
68
69 static inline int test_stop(const struct test_ops *c)
70 {
71         if (c && c->stop)
72                 return c->stop();
73
74         return -EINVAL;
75 }
76
77 static inline int test_get_status(const struct test_ops *c)
78 {
79         if (c && c->status)
80                 return c->status();
81
82         return -EINVAL;
83 }
84
85 #define TEST_OPS_REGISTER(c)    \
86 static void __CONSTRUCTOR__ module_init(void)   \
87 {       \
88         add_test(c);    \
89 }       \
90 static void __DESTRUCTOR__ module_exit(void)    \
91 {       \
92         remove_test(c); \
93 }
94 void add_test(const struct test_ops *c);
95 void remove_test(const struct test_ops *c);
96 const struct test_ops *find_test(const char *name);
97 void _R(const char *format, ...);
98 #endif