1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
9 #ifdef RTE_EXEC_ENV_WINDOWS
13 printf("event_ring not supported on Windows, skipping test\n");
19 #include <rte_event_ring.h>
25 * Test some basic ops for the event rings.
26 * Does not fully test everything, since most code is reused from rte_ring
27 * library and tested as part of the normal ring autotests.
30 #define RING_SIZE 4096
33 static struct rte_event_ring *r;
36 * ensure failure to create ring with a bad ring size
39 test_event_ring_creation_with_wrong_size(void)
41 struct rte_event_ring *rp = NULL;
43 /* Test if ring size is not power of 2 */
44 rp = rte_event_ring_create("test_bad_ring_size", RING_SIZE + 1,
49 /* Test if ring size is exceeding the limit */
50 rp = rte_event_ring_create("test_bad_ring_size", (RTE_RING_SZ_MASK + 1),
58 * Test to check if a non-power-of-2 count causes the create
59 * function to fail correctly
62 test_create_count_odd(void)
64 struct rte_event_ring *r = rte_event_ring_create("test_event_ring_count",
65 4097, SOCKET_ID_ANY, 0);
72 test_lookup_null(void)
74 struct rte_event_ring *rlp = rte_event_ring_lookup("ring_not_found");
75 if (rlp == NULL && rte_errno != ENOENT) {
76 printf("test failed to return error on null pointer\n");
83 test_basic_event_enqueue_dequeue(void)
85 struct rte_event_ring *sr = NULL;
86 struct rte_event evs[16];
87 uint16_t ret, free_count, used_count;
89 memset(evs, 0, sizeof(evs));
90 sr = rte_event_ring_create("spsc_ring", 32, rte_socket_id(),
91 RING_F_SP_ENQ | RING_F_SC_DEQ);
93 printf("Failed to create sp/sc ring\n");
96 if (rte_event_ring_get_capacity(sr) != 31) {
97 printf("Error, invalid capacity\n");
101 /* test sp/sc ring */
102 if (rte_event_ring_count(sr) != 0) {
103 printf("Error, ring not empty as expected\n");
106 if (rte_event_ring_free_count(sr) != rte_event_ring_get_capacity(sr)) {
107 printf("Error, ring free count not as expected\n");
111 ret = rte_event_ring_enqueue_burst(sr, evs, RTE_DIM(evs), &free_count);
112 if (ret != RTE_DIM(evs) ||
113 free_count != rte_event_ring_get_capacity(sr) - ret) {
114 printf("Error, status after enqueue is unexpected\n");
118 ret = rte_event_ring_enqueue_burst(sr, evs, RTE_DIM(evs), &free_count);
119 if (ret != RTE_DIM(evs) - 1 ||
121 printf("Error, status after enqueue is unexpected\n");
125 ret = rte_event_ring_dequeue_burst(sr, evs, RTE_DIM(evs), &used_count);
126 if (ret != RTE_DIM(evs) ||
127 used_count != rte_event_ring_get_capacity(sr) - ret) {
128 printf("Error, status after enqueue is unexpected\n");
131 ret = rte_event_ring_dequeue_burst(sr, evs, RTE_DIM(evs), &used_count);
132 if (ret != RTE_DIM(evs) - 1 ||
134 printf("Error, status after enqueue is unexpected\n");
138 rte_event_ring_free(sr);
141 rte_event_ring_free(sr);
146 test_event_ring_with_exact_size(void)
148 struct rte_event_ring *std_ring, *exact_sz_ring;
149 struct rte_event ev = { .mbuf = NULL };
150 struct rte_event ev_array[16];
151 static const unsigned int ring_sz = RTE_DIM(ev_array);
154 std_ring = rte_event_ring_create("std", ring_sz, rte_socket_id(),
155 RING_F_SP_ENQ | RING_F_SC_DEQ);
156 if (std_ring == NULL) {
157 printf("%s: error, can't create std ring\n", __func__);
160 exact_sz_ring = rte_event_ring_create("exact sz",
161 ring_sz, rte_socket_id(),
162 RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ);
163 if (exact_sz_ring == NULL) {
164 printf("%s: error, can't create exact size ring\n", __func__);
169 * Check that the exact size ring is bigger than the standard ring
171 if (rte_event_ring_get_size(std_ring) >=
172 rte_event_ring_get_size(exact_sz_ring)) {
173 printf("%s: error, std ring (size: %u) is not smaller than exact size one (size %u)\n",
175 rte_event_ring_get_size(std_ring),
176 rte_event_ring_get_size(exact_sz_ring));
180 * check that the exact_sz_ring can hold one more element than the
181 * standard ring. (16 vs 15 elements)
183 for (i = 0; i < ring_sz - 1; i++) {
184 rte_event_ring_enqueue_burst(std_ring, &ev, 1, NULL);
185 rte_event_ring_enqueue_burst(exact_sz_ring, &ev, 1, NULL);
187 if (rte_event_ring_enqueue_burst(std_ring, &ev, 1, NULL) != 0) {
188 printf("%s: error, unexpected successful enqueue\n", __func__);
191 if (rte_event_ring_enqueue_burst(exact_sz_ring, &ev, 1, NULL) != 1) {
192 printf("%s: error, enqueue failed\n", __func__);
196 /* check that dequeue returns the expected number of elements */
197 if (rte_event_ring_dequeue_burst(exact_sz_ring, ev_array,
198 RTE_DIM(ev_array), NULL) != ring_sz) {
199 printf("%s: error, failed to dequeue expected nb of elements\n",
204 /* check that the capacity function returns expected value */
205 if (rte_event_ring_get_capacity(exact_sz_ring) != ring_sz) {
206 printf("%s: error, incorrect ring capacity reported\n",
211 rte_event_ring_free(std_ring);
212 rte_event_ring_free(exact_sz_ring);
217 test_event_ring(void)
220 r = rte_event_ring_create("ev_test", RING_SIZE,
225 /* retrieve the ring from its name */
226 if (rte_event_ring_lookup("ev_test") != r) {
227 printf("Cannot lookup ring from its name\n");
231 /* basic operations */
232 if (test_create_count_odd() < 0) {
233 printf("Test failed to detect odd count\n");
236 printf("Test detected odd count\n");
238 if (test_lookup_null() < 0) {
239 printf("Test failed to detect NULL ring lookup\n");
242 printf("Test detected NULL ring lookup\n");
244 /* test of creating ring with wrong size */
245 if (test_event_ring_creation_with_wrong_size() < 0)
248 if (test_basic_event_enqueue_dequeue() < 0)
251 if (test_event_ring_with_exact_size() < 0)
257 #endif /* !RTE_EXEC_ENV_WINDOWS */
259 REGISTER_TEST_COMMAND(event_ring_autotest, test_event_ring);