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