1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <sys/queue.h>
14 #include <rte_common.h>
16 #include <rte_memory.h>
17 #include <rte_launch.h>
18 #include <rte_cycles.h>
20 #include <rte_per_lcore.h>
21 #include <rte_lcore.h>
22 #include <rte_atomic.h>
23 #include <rte_branch_prediction.h>
24 #include <rte_malloc.h>
26 #include <rte_ring_elem.h>
27 #include <rte_random.h>
28 #include <rte_errno.h>
29 #include <rte_hexdump.h>
32 #include "test_ring.h"
38 * #. Functional tests. Tests single/bulk/burst, default/SPSC/MPMC,
39 * legacy/custom element size (4B, 8B, 16B, 20B) APIs.
40 * Some tests incorporate unaligned addresses for objects.
41 * The enqueued/dequeued data is validated for correctness.
43 * #. Performance tests are in test_ring_perf.c
46 #define RING_SIZE 4096
49 #define TEST_RING_VERIFY(exp) \
51 printf("error at %s:%d\tcondition " #exp " failed\n", \
52 __func__, __LINE__); \
53 rte_ring_dump(stdout, r); \
57 #define TEST_RING_FULL_EMTPY_ITER 8
59 static const int esize[] = {-1, 4, 8, 16, 20};
64 uint32_t create_flags;
66 unsigned int (*flegacy)(struct rte_ring *r,
67 void * const *obj_table, unsigned int n,
68 unsigned int *free_space);
69 unsigned int (*felem)(struct rte_ring *r, const void *obj_table,
70 unsigned int esize, unsigned int n,
71 unsigned int *free_space);
74 unsigned int (*flegacy)(struct rte_ring *r,
75 void **obj_table, unsigned int n,
76 unsigned int *available);
77 unsigned int (*felem)(struct rte_ring *r, void *obj_table,
78 unsigned int esize, unsigned int n,
79 unsigned int *available);
81 } test_enqdeq_impl[] = {
83 .desc = "MP/MC sync mode",
84 .api_type = TEST_RING_ELEM_BULK | TEST_RING_THREAD_DEF,
87 .flegacy = rte_ring_enqueue_bulk,
88 .felem = rte_ring_enqueue_bulk_elem,
91 .flegacy = rte_ring_dequeue_bulk,
92 .felem = rte_ring_dequeue_bulk_elem,
96 .desc = "SP/SC sync mode",
97 .api_type = TEST_RING_ELEM_BULK | TEST_RING_THREAD_SPSC,
98 .create_flags = RING_F_SP_ENQ | RING_F_SC_DEQ,
100 .flegacy = rte_ring_sp_enqueue_bulk,
101 .felem = rte_ring_sp_enqueue_bulk_elem,
104 .flegacy = rte_ring_sc_dequeue_bulk,
105 .felem = rte_ring_sc_dequeue_bulk_elem,
109 .desc = "MP/MC sync mode",
110 .api_type = TEST_RING_ELEM_BULK | TEST_RING_THREAD_MPMC,
113 .flegacy = rte_ring_mp_enqueue_bulk,
114 .felem = rte_ring_mp_enqueue_bulk_elem,
117 .flegacy = rte_ring_mc_dequeue_bulk,
118 .felem = rte_ring_mc_dequeue_bulk_elem,
122 .desc = "MP_RTS/MC_RTS sync mode",
123 .api_type = TEST_RING_ELEM_BULK | TEST_RING_THREAD_DEF,
124 .create_flags = RING_F_MP_RTS_ENQ | RING_F_MC_RTS_DEQ,
126 .flegacy = rte_ring_enqueue_bulk,
127 .felem = rte_ring_enqueue_bulk_elem,
130 .flegacy = rte_ring_dequeue_bulk,
131 .felem = rte_ring_dequeue_bulk_elem,
135 .desc = "MP_HTS/MC_HTS sync mode",
136 .api_type = TEST_RING_ELEM_BULK | TEST_RING_THREAD_DEF,
137 .create_flags = RING_F_MP_HTS_ENQ | RING_F_MC_HTS_DEQ,
139 .flegacy = rte_ring_enqueue_bulk,
140 .felem = rte_ring_enqueue_bulk_elem,
143 .flegacy = rte_ring_dequeue_bulk,
144 .felem = rte_ring_dequeue_bulk_elem,
148 .desc = "MP/MC sync mode",
149 .api_type = TEST_RING_ELEM_BURST | TEST_RING_THREAD_DEF,
152 .flegacy = rte_ring_enqueue_burst,
153 .felem = rte_ring_enqueue_burst_elem,
156 .flegacy = rte_ring_dequeue_burst,
157 .felem = rte_ring_dequeue_burst_elem,
161 .desc = "SP/SC sync mode",
162 .api_type = TEST_RING_ELEM_BURST | TEST_RING_THREAD_SPSC,
163 .create_flags = RING_F_SP_ENQ | RING_F_SC_DEQ,
165 .flegacy = rte_ring_sp_enqueue_burst,
166 .felem = rte_ring_sp_enqueue_burst_elem,
169 .flegacy = rte_ring_sc_dequeue_burst,
170 .felem = rte_ring_sc_dequeue_burst_elem,
174 .desc = "MP/MC sync mode",
175 .api_type = TEST_RING_ELEM_BURST | TEST_RING_THREAD_MPMC,
178 .flegacy = rte_ring_mp_enqueue_burst,
179 .felem = rte_ring_mp_enqueue_burst_elem,
182 .flegacy = rte_ring_mc_dequeue_burst,
183 .felem = rte_ring_mc_dequeue_burst_elem,
187 .desc = "MP_RTS/MC_RTS sync mode",
188 .api_type = TEST_RING_ELEM_BURST | TEST_RING_THREAD_DEF,
189 .create_flags = RING_F_MP_RTS_ENQ | RING_F_MC_RTS_DEQ,
191 .flegacy = rte_ring_enqueue_burst,
192 .felem = rte_ring_enqueue_burst_elem,
195 .flegacy = rte_ring_dequeue_burst,
196 .felem = rte_ring_dequeue_burst_elem,
200 .desc = "MP_HTS/MC_HTS sync mode",
201 .api_type = TEST_RING_ELEM_BURST | TEST_RING_THREAD_DEF,
202 .create_flags = RING_F_MP_HTS_ENQ | RING_F_MC_HTS_DEQ,
204 .flegacy = rte_ring_enqueue_burst,
205 .felem = rte_ring_enqueue_burst_elem,
208 .flegacy = rte_ring_dequeue_burst,
209 .felem = rte_ring_dequeue_burst_elem,
215 test_ring_enq_impl(struct rte_ring *r, void **obj, int esize, unsigned int n,
216 unsigned int test_idx)
219 return test_enqdeq_impl[test_idx].enq.flegacy(r, obj, n, NULL);
221 return test_enqdeq_impl[test_idx].enq.felem(r, obj, esize, n,
226 test_ring_deq_impl(struct rte_ring *r, void **obj, int esize, unsigned int n,
227 unsigned int test_idx)
230 return test_enqdeq_impl[test_idx].deq.flegacy(r, obj, n, NULL);
232 return test_enqdeq_impl[test_idx].deq.felem(r, obj, esize, n,
237 test_ring_inc_ptr(void **obj, int esize, unsigned int n)
239 /* Legacy queue APIs? */
241 return ((void **)obj) + n;
243 return (void **)(((uint32_t *)obj) +
244 (n * esize / sizeof(uint32_t)));
248 test_ring_mem_init(void *obj, unsigned int count, int esize)
252 /* Legacy queue APIs? */
254 for (i = 0; i < count; i++)
255 ((void **)obj)[i] = (void *)(unsigned long)i;
257 for (i = 0; i < (count * esize / sizeof(uint32_t)); i++)
258 ((uint32_t *)obj)[i] = i;
262 test_ring_mem_cmp(void *src, void *dst, unsigned int size)
266 ret = memcmp(src, dst, size);
268 rte_hexdump(stdout, "src", src, size);
269 rte_hexdump(stdout, "dst", dst, size);
270 printf("data after dequeue is not the same\n");
277 test_ring_print_test_string(const char *istr, unsigned int api_type, int esize)
279 printf("\n%s: ", istr);
282 printf("legacy APIs: ");
284 printf("elem APIs: element size %dB ", esize);
286 if (api_type == TEST_RING_IGNORE_API_TYPE)
289 if (api_type & TEST_RING_THREAD_DEF)
290 printf(": default enqueue/dequeue: ");
291 else if (api_type & TEST_RING_THREAD_SPSC)
293 else if (api_type & TEST_RING_THREAD_MPMC)
296 if (api_type & TEST_RING_ELEM_SINGLE)
298 else if (api_type & TEST_RING_ELEM_BULK)
300 else if (api_type & TEST_RING_ELEM_BURST)
305 * Various negative test cases.
308 test_ring_negative_tests(void)
310 struct rte_ring *rp = NULL;
311 struct rte_ring *rt = NULL;
314 /* Test with esize not a multiple of 4 */
315 rp = test_ring_create("test_bad_element_size", 23,
316 RING_SIZE + 1, SOCKET_ID_ANY, 0);
318 printf("Test failed to detect invalid element size\n");
323 for (i = 0; i < RTE_DIM(esize); i++) {
324 /* Test if ring size is not power of 2 */
325 rp = test_ring_create("test_bad_ring_size", esize[i],
326 RING_SIZE + 1, SOCKET_ID_ANY, 0);
328 printf("Test failed to detect odd count\n");
332 /* Test if ring size is exceeding the limit */
333 rp = test_ring_create("test_bad_ring_size", esize[i],
334 RTE_RING_SZ_MASK + 1, SOCKET_ID_ANY, 0);
336 printf("Test failed to detect limits\n");
340 /* Tests if lookup returns NULL on non-existing ring */
341 rp = rte_ring_lookup("ring_not_found");
342 if (rp != NULL && rte_errno != ENOENT) {
343 printf("Test failed to detect NULL ring lookup\n");
347 /* Test to if a non-power of 2 count causes the create
348 * function to fail correctly
350 rp = test_ring_create("test_ring_count", esize[i], 4097,
355 rp = test_ring_create("test_ring_negative", esize[i], RING_SIZE,
357 RING_F_SP_ENQ | RING_F_SC_DEQ);
359 printf("test_ring_negative fail to create ring\n");
363 if (rte_ring_lookup("test_ring_negative") != rp)
366 if (rte_ring_empty(rp) != 1) {
367 printf("test_ring_nagative ring is not empty but it should be\n");
371 /* Tests if it would always fail to create ring with an used
374 rt = test_ring_create("test_ring_negative", esize[i], RING_SIZE,
392 * Burst and bulk operations with sp/sc, mp/mc and default (during creation)
393 * Random number of elements are enqueued and dequeued.
396 test_ring_burst_bulk_tests1(unsigned int test_idx)
399 void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
401 unsigned int i, j, temp_sz;
403 const unsigned int rsz = RING_SIZE - 1;
405 for (i = 0; i < RTE_DIM(esize); i++) {
406 test_ring_print_test_string(test_enqdeq_impl[test_idx].desc,
407 test_enqdeq_impl[test_idx].api_type, esize[i]);
409 /* Create the ring */
410 r = test_ring_create("test_ring_burst_bulk_tests", esize[i],
411 RING_SIZE, SOCKET_ID_ANY,
412 test_enqdeq_impl[test_idx].create_flags);
414 /* alloc dummy object pointers */
415 src = test_ring_calloc(RING_SIZE * 2, esize[i]);
418 test_ring_mem_init(src, RING_SIZE * 2, esize[i]);
421 /* alloc some room for copied objects */
422 dst = test_ring_calloc(RING_SIZE * 2, esize[i]);
427 printf("Random full/empty test\n");
429 for (j = 0; j != TEST_RING_FULL_EMTPY_ITER; j++) {
430 /* random shift in the ring */
431 rand = RTE_MAX(rte_rand() % RING_SIZE, 1UL);
432 printf("%s: iteration %u, random shift: %u;\n",
434 ret = test_ring_enq_impl(r, cur_src, esize[i], rand,
436 TEST_RING_VERIFY(ret != 0);
438 ret = test_ring_deq_impl(r, cur_dst, esize[i], rand,
440 TEST_RING_VERIFY(ret == rand);
443 ret = test_ring_enq_impl(r, cur_src, esize[i], rsz,
445 TEST_RING_VERIFY(ret != 0);
447 TEST_RING_VERIFY(rte_ring_free_count(r) == 0);
448 TEST_RING_VERIFY(rsz == rte_ring_count(r));
449 TEST_RING_VERIFY(rte_ring_full(r));
450 TEST_RING_VERIFY(rte_ring_empty(r) == 0);
453 ret = test_ring_deq_impl(r, cur_dst, esize[i], rsz,
455 TEST_RING_VERIFY(ret == (int)rsz);
456 TEST_RING_VERIFY(rsz == rte_ring_free_count(r));
457 TEST_RING_VERIFY(rte_ring_count(r) == 0);
458 TEST_RING_VERIFY(rte_ring_full(r) == 0);
459 TEST_RING_VERIFY(rte_ring_empty(r));
462 temp_sz = rsz * sizeof(void *);
464 temp_sz = rsz * esize[i];
465 TEST_RING_VERIFY(test_ring_mem_cmp(src, dst,
469 /* Free memory before test completed */
487 * Burst and bulk operations with sp/sc, mp/mc and default (during creation)
488 * Sequence of simple enqueues/dequeues and validate the enqueued and
492 test_ring_burst_bulk_tests2(unsigned int test_idx)
495 void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
499 for (i = 0; i < RTE_DIM(esize); i++) {
500 test_ring_print_test_string(test_enqdeq_impl[test_idx].desc,
501 test_enqdeq_impl[test_idx].api_type, esize[i]);
503 /* Create the ring */
504 r = test_ring_create("test_ring_burst_bulk_tests", esize[i],
505 RING_SIZE, SOCKET_ID_ANY,
506 test_enqdeq_impl[test_idx].create_flags);
508 /* alloc dummy object pointers */
509 src = test_ring_calloc(RING_SIZE * 2, esize[i]);
512 test_ring_mem_init(src, RING_SIZE * 2, esize[i]);
515 /* alloc some room for copied objects */
516 dst = test_ring_calloc(RING_SIZE * 2, esize[i]);
521 printf("enqueue 1 obj\n");
522 ret = test_ring_enq_impl(r, cur_src, esize[i], 1, test_idx);
525 cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
527 printf("enqueue 2 objs\n");
528 ret = test_ring_enq_impl(r, cur_src, esize[i], 2, test_idx);
531 cur_src = test_ring_inc_ptr(cur_src, esize[i], 2);
533 printf("enqueue MAX_BULK objs\n");
534 ret = test_ring_enq_impl(r, cur_src, esize[i], MAX_BULK,
538 cur_src = test_ring_inc_ptr(cur_src, esize[i], MAX_BULK);
540 printf("dequeue 1 obj\n");
541 ret = test_ring_deq_impl(r, cur_dst, esize[i], 1, test_idx);
544 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 1);
546 printf("dequeue 2 objs\n");
547 ret = test_ring_deq_impl(r, cur_dst, esize[i], 2, test_idx);
550 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 2);
552 printf("dequeue MAX_BULK objs\n");
553 ret = test_ring_deq_impl(r, cur_dst, esize[i], MAX_BULK,
557 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], MAX_BULK);
560 if (test_ring_mem_cmp(src, dst, RTE_PTR_DIFF(cur_dst, dst)))
563 /* Free memory before test completed */
581 * Burst and bulk operations with sp/sc, mp/mc and default (during creation)
582 * Enqueue and dequeue to cover the entire ring length.
585 test_ring_burst_bulk_tests3(unsigned int test_idx)
588 void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
592 for (i = 0; i < RTE_DIM(esize); i++) {
593 test_ring_print_test_string(test_enqdeq_impl[test_idx].desc,
594 test_enqdeq_impl[test_idx].api_type, esize[i]);
596 /* Create the ring */
597 r = test_ring_create("test_ring_burst_bulk_tests", esize[i],
598 RING_SIZE, SOCKET_ID_ANY,
599 test_enqdeq_impl[test_idx].create_flags);
601 /* alloc dummy object pointers */
602 src = test_ring_calloc(RING_SIZE * 2, esize[i]);
605 test_ring_mem_init(src, RING_SIZE * 2, esize[i]);
608 /* alloc some room for copied objects */
609 dst = test_ring_calloc(RING_SIZE * 2, esize[i]);
614 printf("fill and empty the ring\n");
615 for (j = 0; j < RING_SIZE / MAX_BULK; j++) {
616 ret = test_ring_enq_impl(r, cur_src, esize[i], MAX_BULK,
620 cur_src = test_ring_inc_ptr(cur_src, esize[i],
623 ret = test_ring_deq_impl(r, cur_dst, esize[i], MAX_BULK,
627 cur_dst = test_ring_inc_ptr(cur_dst, esize[i],
632 if (test_ring_mem_cmp(src, dst, RTE_PTR_DIFF(cur_dst, dst)))
635 /* Free memory before test completed */
653 * Burst and bulk operations with sp/sc, mp/mc and default (during creation)
654 * Enqueue till the ring is full and dequeue till the ring becomes empty.
657 test_ring_burst_bulk_tests4(unsigned int test_idx)
660 void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
663 unsigned int api_type, num_elems;
665 api_type = test_enqdeq_impl[test_idx].api_type;
667 for (i = 0; i < RTE_DIM(esize); i++) {
668 test_ring_print_test_string(test_enqdeq_impl[test_idx].desc,
669 test_enqdeq_impl[test_idx].api_type, esize[i]);
671 /* Create the ring */
672 r = test_ring_create("test_ring_burst_bulk_tests", esize[i],
673 RING_SIZE, SOCKET_ID_ANY,
674 test_enqdeq_impl[test_idx].create_flags);
676 /* alloc dummy object pointers */
677 src = test_ring_calloc(RING_SIZE * 2, esize[i]);
680 test_ring_mem_init(src, RING_SIZE * 2, esize[i]);
683 /* alloc some room for copied objects */
684 dst = test_ring_calloc(RING_SIZE * 2, esize[i]);
689 printf("Test enqueue without enough memory space\n");
690 for (j = 0; j < (RING_SIZE/MAX_BULK - 1); j++) {
691 ret = test_ring_enq_impl(r, cur_src, esize[i], MAX_BULK,
695 cur_src = test_ring_inc_ptr(cur_src, esize[i],
699 printf("Enqueue 2 objects, free entries = MAX_BULK - 2\n");
700 ret = test_ring_enq_impl(r, cur_src, esize[i], 2, test_idx);
703 cur_src = test_ring_inc_ptr(cur_src, esize[i], 2);
705 printf("Enqueue the remaining entries = MAX_BULK - 3\n");
706 /* Bulk APIs enqueue exact number of elements */
707 if ((api_type & TEST_RING_ELEM_BULK) == TEST_RING_ELEM_BULK)
708 num_elems = MAX_BULK - 3;
710 num_elems = MAX_BULK;
711 /* Always one free entry left */
712 ret = test_ring_enq_impl(r, cur_src, esize[i], num_elems,
714 if (ret != MAX_BULK - 3)
716 cur_src = test_ring_inc_ptr(cur_src, esize[i], MAX_BULK - 3);
718 printf("Test if ring is full\n");
719 if (rte_ring_full(r) != 1)
722 printf("Test enqueue for a full entry\n");
723 ret = test_ring_enq_impl(r, cur_src, esize[i], MAX_BULK,
728 printf("Test dequeue without enough objects\n");
729 for (j = 0; j < RING_SIZE / MAX_BULK - 1; j++) {
730 ret = test_ring_deq_impl(r, cur_dst, esize[i], MAX_BULK,
734 cur_dst = test_ring_inc_ptr(cur_dst, esize[i],
738 /* Available memory space for the exact MAX_BULK entries */
739 ret = test_ring_deq_impl(r, cur_dst, esize[i], 2, test_idx);
742 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 2);
744 /* Bulk APIs enqueue exact number of elements */
745 if ((api_type & TEST_RING_ELEM_BULK) == TEST_RING_ELEM_BULK)
746 num_elems = MAX_BULK - 3;
748 num_elems = MAX_BULK;
749 ret = test_ring_deq_impl(r, cur_dst, esize[i], num_elems,
751 if (ret != MAX_BULK - 3)
753 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], MAX_BULK - 3);
755 printf("Test if ring is empty\n");
756 /* Check if ring is empty */
757 if (rte_ring_empty(r) != 1)
761 if (test_ring_mem_cmp(src, dst, RTE_PTR_DIFF(cur_dst, dst)))
764 /* Free memory before test completed */
782 * Test default, single element, bulk and burst APIs
785 test_ring_basic_ex(void)
789 struct rte_ring *rp = NULL;
790 void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
792 for (i = 0; i < RTE_DIM(esize); i++) {
793 rp = test_ring_create("test_ring_basic_ex", esize[i], RING_SIZE,
795 RING_F_SP_ENQ | RING_F_SC_DEQ);
797 printf("%s: failed to create ring\n", __func__);
801 /* alloc dummy object pointers */
802 src = test_ring_calloc(RING_SIZE, esize[i]);
804 printf("%s: failed to alloc src memory\n", __func__);
807 test_ring_mem_init(src, RING_SIZE, esize[i]);
810 /* alloc some room for copied objects */
811 dst = test_ring_calloc(RING_SIZE, esize[i]);
813 printf("%s: failed to alloc dst memory\n", __func__);
818 if (rte_ring_lookup("test_ring_basic_ex") != rp) {
819 printf("%s: failed to find ring\n", __func__);
823 if (rte_ring_empty(rp) != 1) {
824 printf("%s: ring is not empty but it should be\n",
829 printf("%u ring entries are now free\n",
830 rte_ring_free_count(rp));
832 for (j = 0; j < RING_SIZE - 1; j++) {
833 ret = test_ring_enqueue(rp, cur_src, esize[i], 1,
834 TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
836 printf("%s: rte_ring_enqueue fails\n",
840 cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
843 if (rte_ring_full(rp) != 1) {
844 printf("%s: ring is not full but it should be\n",
849 for (j = 0; j < RING_SIZE - 1; j++) {
850 ret = test_ring_dequeue(rp, cur_dst, esize[i], 1,
851 TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
853 printf("%s: rte_ring_dequeue fails\n",
857 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 1);
860 if (rte_ring_empty(rp) != 1) {
861 printf("%s: ring is not empty but it should be\n",
867 if (test_ring_mem_cmp(src, dst, RTE_PTR_DIFF(cur_dst, dst)))
870 /* Following tests use the configured flags to decide
873 /* reset memory of dst */
874 memset(dst, 0, RTE_PTR_DIFF(cur_dst, dst));
876 /* reset cur_src and cur_dst */
880 /* Covering the ring burst operation */
881 ret = test_ring_enqueue(rp, cur_src, esize[i], 2,
882 TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST);
884 printf("%s: rte_ring_enqueue_burst fails\n", __func__);
887 cur_src = test_ring_inc_ptr(cur_src, esize[i], 2);
889 ret = test_ring_dequeue(rp, cur_dst, esize[i], 2,
890 TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST);
892 printf("%s: rte_ring_dequeue_burst fails\n", __func__);
895 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 2);
897 /* Covering the ring bulk operation */
898 ret = test_ring_enqueue(rp, cur_src, esize[i], 2,
899 TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK);
901 printf("%s: rte_ring_enqueue_bulk fails\n", __func__);
904 cur_src = test_ring_inc_ptr(cur_src, esize[i], 2);
906 ret = test_ring_dequeue(rp, cur_dst, esize[i], 2,
907 TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK);
909 printf("%s: rte_ring_dequeue_bulk fails\n", __func__);
912 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 2);
915 if (test_ring_mem_cmp(src, dst, RTE_PTR_DIFF(cur_dst, dst)))
936 * Basic test cases with exact size ring.
939 test_ring_with_exact_size(void)
941 struct rte_ring *std_r = NULL, *exact_sz_r = NULL;
942 void **src_orig = NULL, **dst_orig = NULL;
943 void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
944 const unsigned int ring_sz = 16;
948 for (i = 0; i < RTE_DIM(esize); i++) {
949 test_ring_print_test_string("Test exact size ring",
950 TEST_RING_IGNORE_API_TYPE,
953 std_r = test_ring_create("std", esize[i], ring_sz,
955 RING_F_SP_ENQ | RING_F_SC_DEQ);
957 printf("%s: error, can't create std ring\n", __func__);
960 exact_sz_r = test_ring_create("exact sz", esize[i], ring_sz,
962 RING_F_SP_ENQ | RING_F_SC_DEQ |
964 if (exact_sz_r == NULL) {
965 printf("%s: error, can't create exact size ring\n",
970 /* alloc object pointers. Allocate one extra object
971 * and create an unaligned address.
973 src_orig = test_ring_calloc(17, esize[i]);
974 if (src_orig == NULL)
976 test_ring_mem_init(src_orig, 17, esize[i]);
977 src = (void **)((uintptr_t)src_orig + 1);
980 dst_orig = test_ring_calloc(17, esize[i]);
981 if (dst_orig == NULL)
983 dst = (void **)((uintptr_t)dst_orig + 1);
987 * Check that the exact size ring is bigger than the
990 if (rte_ring_get_size(std_r) >= rte_ring_get_size(exact_sz_r)) {
991 printf("%s: error, std ring (size: %u) is not smaller than exact size one (size %u)\n",
993 rte_ring_get_size(std_r),
994 rte_ring_get_size(exact_sz_r));
998 * check that the exact_sz_ring can hold one more element
999 * than the standard ring. (16 vs 15 elements)
1001 for (j = 0; j < ring_sz - 1; j++) {
1002 ret = test_ring_enqueue(std_r, cur_src, esize[i], 1,
1003 TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
1005 printf("%s: error, enqueue failed\n", __func__);
1008 ret = test_ring_enqueue(exact_sz_r, cur_src, esize[i], 1,
1009 TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
1011 printf("%s: error, enqueue failed\n", __func__);
1014 cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
1016 ret = test_ring_enqueue(std_r, cur_src, esize[i], 1,
1017 TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
1018 if (ret != -ENOBUFS) {
1019 printf("%s: error, unexpected successful enqueue\n",
1023 ret = test_ring_enqueue(exact_sz_r, cur_src, esize[i], 1,
1024 TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
1025 if (ret == -ENOBUFS) {
1026 printf("%s: error, enqueue failed\n", __func__);
1029 cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
1031 /* check that dequeue returns the expected number of elements */
1032 ret = test_ring_dequeue(exact_sz_r, cur_dst, esize[i], ring_sz,
1033 TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST);
1034 if (ret != (int)ring_sz) {
1035 printf("%s: error, failed to dequeue expected nb of elements\n",
1039 cur_dst = test_ring_inc_ptr(cur_dst, esize[i], ring_sz);
1041 /* check that the capacity function returns expected value */
1042 if (rte_ring_get_capacity(exact_sz_r) != ring_sz) {
1043 printf("%s: error, incorrect ring capacity reported\n",
1049 if (test_ring_mem_cmp(src, dst, RTE_PTR_DIFF(cur_dst, dst)))
1054 rte_ring_free(std_r);
1055 rte_ring_free(exact_sz_r);
1067 rte_ring_free(std_r);
1068 rte_ring_free(exact_sz_r);
1078 /* Negative test cases */
1079 if (test_ring_negative_tests() < 0)
1082 /* Some basic operations */
1083 if (test_ring_basic_ex() < 0)
1086 if (test_ring_with_exact_size() < 0)
1089 /* Burst and bulk operations with sp/sc, mp/mc and default.
1090 * The test cases are split into smaller test cases to
1091 * help clang compile faster.
1093 for (i = 0; i != RTE_DIM(test_enqdeq_impl); i++) {
1096 rc = test_ring_burst_bulk_tests1(i);
1100 rc = test_ring_burst_bulk_tests2(i);
1104 rc = test_ring_burst_bulk_tests3(i);
1108 rc = test_ring_burst_bulk_tests4(i);
1113 /* dump the ring status */
1114 rte_ring_list_dump(stdout);
1123 REGISTER_TEST_COMMAND(ring_autotest, test_ring);