17bdd16502e3d1e0acac1f670e1d7f691ce182ea
[deb_dpdk.git] / app / test-eventdev / evt_test.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _EVT_TEST_
34 #define _EVT_TEST_
35
36 #include <string.h>
37 #include <stdbool.h>
38 #include <sys/queue.h>
39
40 #include <rte_eal.h>
41
42 enum evt_test_result {
43         EVT_TEST_SUCCESS,
44         EVT_TEST_FAILED,
45         EVT_TEST_UNSUPPORTED,
46 };
47
48 struct evt_test;
49 struct evt_options;
50
51 typedef bool (*evt_test_capability_check_t)(struct evt_options *opt);
52 typedef int (*evt_test_options_check_t)(struct evt_options *opt);
53 typedef void (*evt_test_options_dump_t)(struct evt_options *opt);
54 typedef int (*evt_test_setup_t)
55                 (struct evt_test *test, struct evt_options *opt);
56 typedef int (*evt_test_mempool_setup_t)
57                 (struct evt_test *test, struct evt_options *opt);
58 typedef int (*evt_test_ethdev_setup_t)
59                 (struct evt_test *test, struct evt_options *opt);
60 typedef int (*evt_test_eventdev_setup_t)
61                 (struct evt_test *test, struct evt_options *opt);
62 typedef int (*evt_test_launch_lcores_t)
63                 (struct evt_test *test, struct evt_options *opt);
64 typedef int (*evt_test_result_t)
65                 (struct evt_test *test, struct evt_options *opt);
66 typedef void (*evt_test_eventdev_destroy_t)
67                 (struct evt_test *test, struct evt_options *opt);
68 typedef void (*evt_test_ethdev_destroy_t)
69                 (struct evt_test *test, struct evt_options *opt);
70 typedef void (*evt_test_mempool_destroy_t)
71                 (struct evt_test *test, struct evt_options *opt);
72 typedef void (*evt_test_destroy_t)
73                 (struct evt_test *test, struct evt_options *opt);
74
75 struct evt_test_ops {
76         evt_test_capability_check_t cap_check;
77         evt_test_options_check_t opt_check;
78         evt_test_options_dump_t opt_dump;
79         evt_test_setup_t test_setup;
80         evt_test_mempool_setup_t mempool_setup;
81         evt_test_ethdev_setup_t ethdev_setup;
82         evt_test_eventdev_setup_t eventdev_setup;
83         evt_test_launch_lcores_t launch_lcores;
84         evt_test_result_t test_result;
85         evt_test_eventdev_destroy_t eventdev_destroy;
86         evt_test_ethdev_destroy_t ethdev_destroy;
87         evt_test_mempool_destroy_t mempool_destroy;
88         evt_test_destroy_t test_destroy;
89 };
90
91 struct evt_test {
92         const char *name;
93         void *test_priv;
94         struct evt_test_ops ops;
95 };
96
97 struct evt_test_entry {
98         struct evt_test test;
99
100         STAILQ_ENTRY(evt_test_entry) next;
101 };
102
103 void evt_test_register(struct evt_test_entry *test);
104 void evt_test_dump_names(void);
105
106 #define EVT_TEST_REGISTER(nm)                         \
107 static struct evt_test_entry _evt_test_entry_ ##nm;   \
108 RTE_INIT(evt_test_ ##nm);                             \
109 static void evt_test_ ##nm(void)                      \
110 {                                                     \
111         _evt_test_entry_ ##nm.test.name = RTE_STR(nm);\
112         memcpy(&_evt_test_entry_ ##nm.test.ops, &nm,  \
113                         sizeof(struct evt_test_ops)); \
114         evt_test_register(&_evt_test_entry_ ##nm);    \
115 }
116
117 struct evt_test *evt_test_get(const char *name);
118
119 static inline void *
120 evt_test_priv(struct evt_test *test)
121 {
122         return test->test_priv;
123 }
124
125 #endif /*  _EVT_TEST_ */