]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/test/test/test_event_ring.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
7 #include <rte_event_ring.h>
15 * Test some basic ops for the event rings.
16 * Does not fully test everything, since most code is reused from rte_ring
17 * library and tested as part of the normal ring autotests.
20 #define RING_SIZE 4096
23 static struct rte_event_ring
*r
;
26 * ensure failure to create ring with a bad ring size
29 test_event_ring_creation_with_wrong_size(void)
31 struct rte_event_ring
*rp
= NULL
;
33 /* Test if ring size is not power of 2 */
34 rp
= rte_event_ring_create("test_bad_ring_size", RING_SIZE
+ 1,
39 /* Test if ring size is exceeding the limit */
40 rp
= rte_event_ring_create("test_bad_ring_size", (RTE_RING_SZ_MASK
+ 1),
48 * Test to check if a non-power-of-2 count causes the create
49 * function to fail correctly
52 test_create_count_odd(void)
54 struct rte_event_ring
*r
= rte_event_ring_create("test_event_ring_count",
55 4097, SOCKET_ID_ANY
, 0);
62 test_lookup_null(void)
64 struct rte_event_ring
*rlp
= rte_event_ring_lookup("ring_not_found");
65 if (rlp
== NULL
&& rte_errno
!= ENOENT
) {
66 printf("test failed to return error on null pointer\n");
73 test_basic_event_enqueue_dequeue(void)
75 struct rte_event_ring
*sr
= NULL
;
76 struct rte_event evs
[16];
77 uint16_t ret
, free_count
, used_count
;
79 memset(evs
, 0, sizeof(evs
));
80 sr
= rte_event_ring_create("spsc_ring", 32, rte_socket_id(),
81 RING_F_SP_ENQ
| RING_F_SC_DEQ
);
83 printf("Failed to create sp/sc ring\n");
86 if (rte_event_ring_get_capacity(sr
) != 31) {
87 printf("Error, invalid capacity\n");
92 if (rte_event_ring_count(sr
) != 0) {
93 printf("Error, ring not empty as expected\n");
96 if (rte_event_ring_free_count(sr
) != rte_event_ring_get_capacity(sr
)) {
97 printf("Error, ring free count not as expected\n");
101 ret
= rte_event_ring_enqueue_burst(sr
, evs
, RTE_DIM(evs
), &free_count
);
102 if (ret
!= RTE_DIM(evs
) ||
103 free_count
!= rte_event_ring_get_capacity(sr
) - ret
) {
104 printf("Error, status after enqueue is unexpected\n");
108 ret
= rte_event_ring_enqueue_burst(sr
, evs
, RTE_DIM(evs
), &free_count
);
109 if (ret
!= RTE_DIM(evs
) - 1 ||
111 printf("Error, status after enqueue is unexpected\n");
115 ret
= rte_event_ring_dequeue_burst(sr
, evs
, RTE_DIM(evs
), &used_count
);
116 if (ret
!= RTE_DIM(evs
) ||
117 used_count
!= rte_event_ring_get_capacity(sr
) - ret
) {
118 printf("Error, status after enqueue is unexpected\n");
121 ret
= rte_event_ring_dequeue_burst(sr
, evs
, RTE_DIM(evs
), &used_count
);
122 if (ret
!= RTE_DIM(evs
) - 1 ||
124 printf("Error, status after enqueue is unexpected\n");
128 rte_event_ring_free(sr
);
131 rte_event_ring_free(sr
);
136 test_event_ring_with_exact_size(void)
138 struct rte_event_ring
*std_ring
, *exact_sz_ring
;
139 struct rte_event ev
= { .mbuf
= NULL
};
140 struct rte_event ev_array
[16];
141 static const unsigned int ring_sz
= RTE_DIM(ev_array
);
144 std_ring
= rte_event_ring_create("std", ring_sz
, rte_socket_id(),
145 RING_F_SP_ENQ
| RING_F_SC_DEQ
);
146 if (std_ring
== NULL
) {
147 printf("%s: error, can't create std ring\n", __func__
);
150 exact_sz_ring
= rte_event_ring_create("exact sz",
151 ring_sz
, rte_socket_id(),
152 RING_F_SP_ENQ
| RING_F_SC_DEQ
| RING_F_EXACT_SZ
);
153 if (exact_sz_ring
== NULL
) {
154 printf("%s: error, can't create exact size ring\n", __func__
);
159 * Check that the exact size ring is bigger than the standard ring
161 if (rte_event_ring_get_size(std_ring
) >=
162 rte_event_ring_get_size(exact_sz_ring
)) {
163 printf("%s: error, std ring (size: %u) is not smaller than exact size one (size %u)\n",
165 rte_event_ring_get_size(std_ring
),
166 rte_event_ring_get_size(exact_sz_ring
));
170 * check that the exact_sz_ring can hold one more element than the
171 * standard ring. (16 vs 15 elements)
173 for (i
= 0; i
< ring_sz
- 1; i
++) {
174 rte_event_ring_enqueue_burst(std_ring
, &ev
, 1, NULL
);
175 rte_event_ring_enqueue_burst(exact_sz_ring
, &ev
, 1, NULL
);
177 if (rte_event_ring_enqueue_burst(std_ring
, &ev
, 1, NULL
) != 0) {
178 printf("%s: error, unexpected successful enqueue\n", __func__
);
181 if (rte_event_ring_enqueue_burst(exact_sz_ring
, &ev
, 1, NULL
) != 1) {
182 printf("%s: error, enqueue failed\n", __func__
);
186 /* check that dequeue returns the expected number of elements */
187 if (rte_event_ring_dequeue_burst(exact_sz_ring
, ev_array
,
188 RTE_DIM(ev_array
), NULL
) != ring_sz
) {
189 printf("%s: error, failed to dequeue expected nb of elements\n",
194 /* check that the capacity function returns expected value */
195 if (rte_event_ring_get_capacity(exact_sz_ring
) != ring_sz
) {
196 printf("%s: error, incorrect ring capacity reported\n",
201 rte_event_ring_free(std_ring
);
202 rte_event_ring_free(exact_sz_ring
);
207 test_event_ring(void)
210 r
= rte_event_ring_create("ev_test", RING_SIZE
,
215 /* retrieve the ring from its name */
216 if (rte_event_ring_lookup("ev_test") != r
) {
217 printf("Cannot lookup ring from its name\n");
221 /* basic operations */
222 if (test_create_count_odd() < 0) {
223 printf("Test failed to detect odd count\n");
226 printf("Test detected odd count\n");
228 if (test_lookup_null() < 0) {
229 printf("Test failed to detect NULL ring lookup\n");
232 printf("Test detected NULL ring lookup\n");
234 /* test of creating ring with wrong size */
235 if (test_event_ring_creation_with_wrong_size() < 0)
238 if (test_basic_event_enqueue_dequeue() < 0)
241 if (test_event_ring_with_exact_size() < 0)
247 REGISTER_TEST_COMMAND(event_ring_autotest
, test_event_ring
);