tailq: remove unneeded inclusions
[dpdk.git] / app / test / test_ring.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <string.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdint.h>
39 #include <inttypes.h>
40 #include <errno.h>
41 #include <sys/queue.h>
42
43 #include <rte_common.h>
44 #include <rte_log.h>
45 #include <rte_memory.h>
46 #include <rte_memzone.h>
47 #include <rte_launch.h>
48 #include <rte_cycles.h>
49 #include <rte_eal.h>
50 #include <rte_per_lcore.h>
51 #include <rte_lcore.h>
52 #include <rte_atomic.h>
53 #include <rte_branch_prediction.h>
54 #include <rte_malloc.h>
55 #include <rte_ring.h>
56 #include <rte_random.h>
57 #include <rte_common.h>
58 #include <rte_errno.h>
59 #include <rte_hexdump.h>
60
61 #include "test.h"
62
63 /*
64  * Ring
65  * ====
66  *
67  * #. Basic tests: done on one core:
68  *
69  *    - Using single producer/single consumer functions:
70  *
71  *      - Enqueue one object, two objects, MAX_BULK objects
72  *      - Dequeue one object, two objects, MAX_BULK objects
73  *      - Check that dequeued pointers are correct
74  *
75  *    - Using multi producers/multi consumers functions:
76  *
77  *      - Enqueue one object, two objects, MAX_BULK objects
78  *      - Dequeue one object, two objects, MAX_BULK objects
79  *      - Check that dequeued pointers are correct
80  *
81  *    - Test watermark and default bulk enqueue/dequeue:
82  *
83  *      - Set watermark
84  *      - Set default bulk value
85  *      - Enqueue objects, check that -EDQUOT is returned when
86  *        watermark is exceeded
87  *      - Check that dequeued pointers are correct
88  *
89  * #. Check live watermark change
90  *
91  *    - Start a loop on another lcore that will enqueue and dequeue
92  *      objects in a ring. It will monitor the value of watermark.
93  *    - At the same time, change the watermark on the master lcore.
94  *    - The slave lcore will check that watermark changes from 16 to 32.
95  *
96  * #. Performance tests.
97  *
98  * Tests done in test_ring_perf.c
99  */
100
101 #define RING_SIZE 4096
102 #define MAX_BULK 32
103 #define N 65536
104 #define TIME_S 5
105
106 static rte_atomic32_t synchro;
107
108 static struct rte_ring *r;
109
110 #define TEST_RING_VERIFY(exp)                                           \
111         if (!(exp)) {                                                   \
112                 printf("error at %s:%d\tcondition " #exp " failed\n",   \
113                     __func__, __LINE__);                                \
114                 rte_ring_dump(stdout, r);                               \
115                 return (-1);                                            \
116         }
117
118 #define TEST_RING_FULL_EMTPY_ITER       8
119
120 static int
121 check_live_watermark_change(__attribute__((unused)) void *dummy)
122 {
123         uint64_t hz = rte_get_timer_hz();
124         void *obj_table[MAX_BULK];
125         unsigned watermark, watermark_old = 16;
126         uint64_t cur_time, end_time;
127         int64_t diff = 0;
128         int i, ret;
129         unsigned count = 4;
130
131         /* init the object table */
132         memset(obj_table, 0, sizeof(obj_table));
133         end_time = rte_get_timer_cycles() + (hz * 2);
134
135         /* check that bulk and watermark are 4 and 32 (respectively) */
136         while (diff >= 0) {
137
138                 /* add in ring until we reach watermark */
139                 ret = 0;
140                 for (i = 0; i < 16; i ++) {
141                         if (ret != 0)
142                                 break;
143                         ret = rte_ring_enqueue_bulk(r, obj_table, count);
144                 }
145
146                 if (ret != -EDQUOT) {
147                         printf("Cannot enqueue objects, or watermark not "
148                                "reached (ret=%d)\n", ret);
149                         return -1;
150                 }
151
152                 /* read watermark, the only change allowed is from 16 to 32 */
153                 watermark = r->prod.watermark;
154                 if (watermark != watermark_old &&
155                     (watermark_old != 16 || watermark != 32)) {
156                         printf("Bad watermark change %u -> %u\n", watermark_old,
157                                watermark);
158                         return -1;
159                 }
160                 watermark_old = watermark;
161
162                 /* dequeue objects from ring */
163                 while (i--) {
164                         ret = rte_ring_dequeue_bulk(r, obj_table, count);
165                         if (ret != 0) {
166                                 printf("Cannot dequeue (ret=%d)\n", ret);
167                                 return -1;
168                         }
169                 }
170
171                 cur_time = rte_get_timer_cycles();
172                 diff = end_time - cur_time;
173         }
174
175         if (watermark_old != 32 ) {
176                 printf(" watermark was not updated (wm=%u)\n",
177                        watermark_old);
178                 return -1;
179         }
180
181         return 0;
182 }
183
184 static int
185 test_live_watermark_change(void)
186 {
187         unsigned lcore_id = rte_lcore_id();
188         unsigned lcore_id2 = rte_get_next_lcore(lcore_id, 0, 1);
189
190         printf("Test watermark live modification\n");
191         rte_ring_set_water_mark(r, 16);
192
193         /* launch a thread that will enqueue and dequeue, checking
194          * watermark and quota */
195         rte_eal_remote_launch(check_live_watermark_change, NULL, lcore_id2);
196
197         rte_delay_ms(1000);
198         rte_ring_set_water_mark(r, 32);
199         rte_delay_ms(1000);
200
201         if (rte_eal_wait_lcore(lcore_id2) < 0)
202                 return -1;
203
204         return 0;
205 }
206
207 /* Test for catch on invalid watermark values */
208 static int
209 test_set_watermark( void ){
210         unsigned count;
211         int setwm;
212
213         struct rte_ring *r = rte_ring_lookup("test_ring_basic_ex");
214         if(r == NULL){
215                 printf( " ring lookup failed\n" );
216                 goto error;
217         }
218         count = r->prod.size*2;
219         setwm = rte_ring_set_water_mark(r, count);
220         if (setwm != -EINVAL){
221                 printf("Test failed to detect invalid watermark count value\n");
222                 goto error;
223         }
224
225         count = 0;
226         rte_ring_set_water_mark(r, count);
227         if (r->prod.watermark != r->prod.size) {
228                 printf("Test failed to detect invalid watermark count value\n");
229                 goto error;
230         }
231         return 0;
232
233 error:
234         return -1;
235 }
236
237 /*
238  * helper routine for test_ring_basic
239  */
240 static int
241 test_ring_basic_full_empty(void * const src[], void *dst[])
242 {
243         unsigned i, rand;
244         const unsigned rsz = RING_SIZE - 1;
245
246         printf("Basic full/empty test\n");
247
248         for (i = 0; TEST_RING_FULL_EMTPY_ITER != i; i++) {
249
250                 /* random shift in the ring */
251                 rand = RTE_MAX(rte_rand() % RING_SIZE, 1UL);
252                 printf("%s: iteration %u, random shift: %u;\n",
253                     __func__, i, rand);
254                 TEST_RING_VERIFY(-ENOBUFS != rte_ring_enqueue_bulk(r, src,
255                     rand));
256                 TEST_RING_VERIFY(0 == rte_ring_dequeue_bulk(r, dst, rand));
257
258                 /* fill the ring */
259                 TEST_RING_VERIFY(-ENOBUFS != rte_ring_enqueue_bulk(r, src,
260                     rsz));
261                 TEST_RING_VERIFY(0 == rte_ring_free_count(r));
262                 TEST_RING_VERIFY(rsz == rte_ring_count(r));
263                 TEST_RING_VERIFY(rte_ring_full(r));
264                 TEST_RING_VERIFY(0 == rte_ring_empty(r));
265
266                 /* empty the ring */
267                 TEST_RING_VERIFY(0 == rte_ring_dequeue_bulk(r, dst, rsz));
268                 TEST_RING_VERIFY(rsz == rte_ring_free_count(r));
269                 TEST_RING_VERIFY(0 == rte_ring_count(r));
270                 TEST_RING_VERIFY(0 == rte_ring_full(r));
271                 TEST_RING_VERIFY(rte_ring_empty(r));
272
273                 /* check data */
274                 TEST_RING_VERIFY(0 == memcmp(src, dst, rsz));
275                 rte_ring_dump(stdout, r);
276         }
277         return (0);
278 }
279
280 static int
281 test_ring_basic(void)
282 {
283         void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
284         int ret;
285         unsigned i, num_elems;
286
287         /* alloc dummy object pointers */
288         src = malloc(RING_SIZE*2*sizeof(void *));
289         if (src == NULL)
290                 goto fail;
291
292         for (i = 0; i < RING_SIZE*2 ; i++) {
293                 src[i] = (void *)(unsigned long)i;
294         }
295         cur_src = src;
296
297         /* alloc some room for copied objects */
298         dst = malloc(RING_SIZE*2*sizeof(void *));
299         if (dst == NULL)
300                 goto fail;
301
302         memset(dst, 0, RING_SIZE*2*sizeof(void *));
303         cur_dst = dst;
304
305         printf("enqueue 1 obj\n");
306         ret = rte_ring_sp_enqueue_bulk(r, cur_src, 1);
307         cur_src += 1;
308         if (ret != 0)
309                 goto fail;
310
311         printf("enqueue 2 objs\n");
312         ret = rte_ring_sp_enqueue_bulk(r, cur_src, 2);
313         cur_src += 2;
314         if (ret != 0)
315                 goto fail;
316
317         printf("enqueue MAX_BULK objs\n");
318         ret = rte_ring_sp_enqueue_bulk(r, cur_src, MAX_BULK);
319         cur_src += MAX_BULK;
320         if (ret != 0)
321                 goto fail;
322
323         printf("dequeue 1 obj\n");
324         ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 1);
325         cur_dst += 1;
326         if (ret != 0)
327                 goto fail;
328
329         printf("dequeue 2 objs\n");
330         ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 2);
331         cur_dst += 2;
332         if (ret != 0)
333                 goto fail;
334
335         printf("dequeue MAX_BULK objs\n");
336         ret = rte_ring_sc_dequeue_bulk(r, cur_dst, MAX_BULK);
337         cur_dst += MAX_BULK;
338         if (ret != 0)
339                 goto fail;
340
341         /* check data */
342         if (memcmp(src, dst, cur_dst - dst)) {
343                 rte_hexdump(stdout, "src", src, cur_src - src);
344                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
345                 printf("data after dequeue is not the same\n");
346                 goto fail;
347         }
348         cur_src = src;
349         cur_dst = dst;
350
351         printf("enqueue 1 obj\n");
352         ret = rte_ring_mp_enqueue_bulk(r, cur_src, 1);
353         cur_src += 1;
354         if (ret != 0)
355                 goto fail;
356
357         printf("enqueue 2 objs\n");
358         ret = rte_ring_mp_enqueue_bulk(r, cur_src, 2);
359         cur_src += 2;
360         if (ret != 0)
361                 goto fail;
362
363         printf("enqueue MAX_BULK objs\n");
364         ret = rte_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK);
365         cur_src += MAX_BULK;
366         if (ret != 0)
367                 goto fail;
368
369         printf("dequeue 1 obj\n");
370         ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 1);
371         cur_dst += 1;
372         if (ret != 0)
373                 goto fail;
374
375         printf("dequeue 2 objs\n");
376         ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 2);
377         cur_dst += 2;
378         if (ret != 0)
379                 goto fail;
380
381         printf("dequeue MAX_BULK objs\n");
382         ret = rte_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK);
383         cur_dst += MAX_BULK;
384         if (ret != 0)
385                 goto fail;
386
387         /* check data */
388         if (memcmp(src, dst, cur_dst - dst)) {
389                 rte_hexdump(stdout, "src", src, cur_src - src);
390                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
391                 printf("data after dequeue is not the same\n");
392                 goto fail;
393         }
394         cur_src = src;
395         cur_dst = dst;
396
397         printf("fill and empty the ring\n");
398         for (i = 0; i<RING_SIZE/MAX_BULK; i++) {
399                 ret = rte_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK);
400                 cur_src += MAX_BULK;
401                 if (ret != 0)
402                         goto fail;
403                 ret = rte_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK);
404                 cur_dst += MAX_BULK;
405                 if (ret != 0)
406                         goto fail;
407         }
408
409         /* check data */
410         if (memcmp(src, dst, cur_dst - dst)) {
411                 rte_hexdump(stdout, "src", src, cur_src - src);
412                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
413                 printf("data after dequeue is not the same\n");
414                 goto fail;
415         }
416
417         if (test_ring_basic_full_empty(src, dst) != 0)
418                 goto fail;
419
420         cur_src = src;
421         cur_dst = dst;
422
423         printf("test watermark and default bulk enqueue / dequeue\n");
424         rte_ring_set_water_mark(r, 20);
425         num_elems = 16;
426
427         cur_src = src;
428         cur_dst = dst;
429
430         ret = rte_ring_enqueue_bulk(r, cur_src, num_elems);
431         cur_src += num_elems;
432         if (ret != 0) {
433                 printf("Cannot enqueue\n");
434                 goto fail;
435         }
436         ret = rte_ring_enqueue_bulk(r, cur_src, num_elems);
437         cur_src += num_elems;
438         if (ret != -EDQUOT) {
439                 printf("Watermark not exceeded\n");
440                 goto fail;
441         }
442         ret = rte_ring_dequeue_bulk(r, cur_dst, num_elems);
443         cur_dst += num_elems;
444         if (ret != 0) {
445                 printf("Cannot dequeue\n");
446                 goto fail;
447         }
448         ret = rte_ring_dequeue_bulk(r, cur_dst, num_elems);
449         cur_dst += num_elems;
450         if (ret != 0) {
451                 printf("Cannot dequeue2\n");
452                 goto fail;
453         }
454
455         /* check data */
456         if (memcmp(src, dst, cur_dst - dst)) {
457                 rte_hexdump(stdout, "src", src, cur_src - src);
458                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
459                 printf("data after dequeue is not the same\n");
460                 goto fail;
461         }
462
463         cur_src = src;
464         cur_dst = dst;
465
466         ret = rte_ring_mp_enqueue(r, cur_src);
467         if (ret != 0)
468                 goto fail;
469
470         ret = rte_ring_mc_dequeue(r, cur_dst);
471         if (ret != 0)
472                 goto fail;
473
474         if (src)
475                 free(src);
476         if (dst)
477                 free(dst);
478         return 0;
479
480  fail:
481         if (src)
482                 free(src);
483         if (dst)
484                 free(dst);
485         return -1;
486 }
487
488 static int
489 test_ring_burst_basic(void)
490 {
491         void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
492         int ret;
493         unsigned i;
494
495         /* alloc dummy object pointers */
496         src = malloc(RING_SIZE*2*sizeof(void *));
497         if (src == NULL)
498                 goto fail;
499
500         for (i = 0; i < RING_SIZE*2 ; i++) {
501                 src[i] = (void *)(unsigned long)i;
502         }
503         cur_src = src;
504
505         /* alloc some room for copied objects */
506         dst = malloc(RING_SIZE*2*sizeof(void *));
507         if (dst == NULL)
508                 goto fail;
509
510         memset(dst, 0, RING_SIZE*2*sizeof(void *));
511         cur_dst = dst;
512
513         printf("Test SP & SC basic functions \n");
514         printf("enqueue 1 obj\n");
515         ret = rte_ring_sp_enqueue_burst(r, cur_src, 1);
516         cur_src += 1;
517         if ((ret & RTE_RING_SZ_MASK) != 1)
518                 goto fail;
519
520         printf("enqueue 2 objs\n");
521         ret = rte_ring_sp_enqueue_burst(r, cur_src, 2);
522         cur_src += 2;
523         if ((ret & RTE_RING_SZ_MASK) != 2)
524                 goto fail;
525
526         printf("enqueue MAX_BULK objs\n");
527         ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK) ;
528         cur_src += MAX_BULK;
529         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
530                 goto fail;
531
532         printf("dequeue 1 obj\n");
533         ret = rte_ring_sc_dequeue_burst(r, cur_dst, 1) ;
534         cur_dst += 1;
535         if ((ret & RTE_RING_SZ_MASK) != 1)
536                 goto fail;
537
538         printf("dequeue 2 objs\n");
539         ret = rte_ring_sc_dequeue_burst(r, cur_dst, 2);
540         cur_dst += 2;
541         if ((ret & RTE_RING_SZ_MASK) != 2)
542                 goto fail;
543
544         printf("dequeue MAX_BULK objs\n");
545         ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
546         cur_dst += MAX_BULK;
547         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
548                 goto fail;
549
550         /* check data */
551         if (memcmp(src, dst, cur_dst - dst)) {
552                 rte_hexdump(stdout, "src", src, cur_src - src);
553                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
554                 printf("data after dequeue is not the same\n");
555                 goto fail;
556         }
557
558         cur_src = src;
559         cur_dst = dst;
560
561         printf("Test enqueue without enough memory space \n");
562         for (i = 0; i< (RING_SIZE/MAX_BULK - 1); i++) {
563                 ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
564                 cur_src += MAX_BULK;
565                 if ((ret & RTE_RING_SZ_MASK) != MAX_BULK) {
566                         goto fail;
567                 }
568         }
569
570         printf("Enqueue 2 objects, free entries = MAX_BULK - 2  \n");
571         ret = rte_ring_sp_enqueue_burst(r, cur_src, 2);
572         cur_src += 2;
573         if ((ret & RTE_RING_SZ_MASK) != 2)
574                 goto fail;
575
576         printf("Enqueue the remaining entries = MAX_BULK - 2  \n");
577         /* Always one free entry left */
578         ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
579         cur_src += MAX_BULK - 3;
580         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
581                 goto fail;
582
583         printf("Test if ring is full  \n");
584         if (rte_ring_full(r) != 1)
585                 goto fail;
586
587         printf("Test enqueue for a full entry  \n");
588         ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
589         if ((ret & RTE_RING_SZ_MASK) != 0)
590                 goto fail;
591
592         printf("Test dequeue without enough objects \n");
593         for (i = 0; i<RING_SIZE/MAX_BULK - 1; i++) {
594                 ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
595                 cur_dst += MAX_BULK;
596                 if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
597                         goto fail;
598         }
599
600         /* Available memory space for the exact MAX_BULK entries */
601         ret = rte_ring_sc_dequeue_burst(r, cur_dst, 2);
602         cur_dst += 2;
603         if ((ret & RTE_RING_SZ_MASK) != 2)
604                 goto fail;
605
606         ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
607         cur_dst += MAX_BULK - 3;
608         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
609                 goto fail;
610
611         printf("Test if ring is empty \n");
612         /* Check if ring is empty */
613         if (1 != rte_ring_empty(r))
614                 goto fail;
615
616         /* check data */
617         if (memcmp(src, dst, cur_dst - dst)) {
618                 rte_hexdump(stdout, "src", src, cur_src - src);
619                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
620                 printf("data after dequeue is not the same\n");
621                 goto fail;
622         }
623
624         cur_src = src;
625         cur_dst = dst;
626
627         printf("Test MP & MC basic functions \n");
628
629         printf("enqueue 1 obj\n");
630         ret = rte_ring_mp_enqueue_burst(r, cur_src, 1);
631         cur_src += 1;
632         if ((ret & RTE_RING_SZ_MASK) != 1)
633                 goto fail;
634
635         printf("enqueue 2 objs\n");
636         ret = rte_ring_mp_enqueue_burst(r, cur_src, 2);
637         cur_src += 2;
638         if ((ret & RTE_RING_SZ_MASK) != 2)
639                 goto fail;
640
641         printf("enqueue MAX_BULK objs\n");
642         ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
643         cur_src += MAX_BULK;
644         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
645                 goto fail;
646
647         printf("dequeue 1 obj\n");
648         ret = rte_ring_mc_dequeue_burst(r, cur_dst, 1);
649         cur_dst += 1;
650         if ((ret & RTE_RING_SZ_MASK) != 1)
651                 goto fail;
652
653         printf("dequeue 2 objs\n");
654         ret = rte_ring_mc_dequeue_burst(r, cur_dst, 2);
655         cur_dst += 2;
656         if ((ret & RTE_RING_SZ_MASK) != 2)
657                 goto fail;
658
659         printf("dequeue MAX_BULK objs\n");
660         ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
661         cur_dst += MAX_BULK;
662         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
663                 goto fail;
664
665         /* check data */
666         if (memcmp(src, dst, cur_dst - dst)) {
667                 rte_hexdump(stdout, "src", src, cur_src - src);
668                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
669                 printf("data after dequeue is not the same\n");
670                 goto fail;
671         }
672
673         cur_src = src;
674         cur_dst = dst;
675
676         printf("fill and empty the ring\n");
677         for (i = 0; i<RING_SIZE/MAX_BULK; i++) {
678                 ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
679                 cur_src += MAX_BULK;
680                 if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
681                         goto fail;
682                 ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
683                 cur_dst += MAX_BULK;
684                 if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
685                         goto fail;
686         }
687
688         /* check data */
689         if (memcmp(src, dst, cur_dst - dst)) {
690                 rte_hexdump(stdout, "src", src, cur_src - src);
691                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
692                 printf("data after dequeue is not the same\n");
693                 goto fail;
694         }
695
696         cur_src = src;
697         cur_dst = dst;
698
699         printf("Test enqueue without enough memory space \n");
700         for (i = 0; i<RING_SIZE/MAX_BULK - 1; i++) {
701                 ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
702                 cur_src += MAX_BULK;
703                 if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
704                         goto fail;
705         }
706
707         /* Available memory space for the exact MAX_BULK objects */
708         ret = rte_ring_mp_enqueue_burst(r, cur_src, 2);
709         cur_src += 2;
710         if ((ret & RTE_RING_SZ_MASK) != 2)
711                 goto fail;
712
713         ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
714         cur_src += MAX_BULK - 3;
715         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
716                 goto fail;
717
718
719         printf("Test dequeue without enough objects \n");
720         for (i = 0; i<RING_SIZE/MAX_BULK - 1; i++) {
721                 ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
722                 cur_dst += MAX_BULK;
723                 if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
724                         goto fail;
725         }
726
727         /* Available objects - the exact MAX_BULK */
728         ret = rte_ring_mc_dequeue_burst(r, cur_dst, 2);
729         cur_dst += 2;
730         if ((ret & RTE_RING_SZ_MASK) != 2)
731                 goto fail;
732
733         ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
734         cur_dst += MAX_BULK - 3;
735         if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
736                 goto fail;
737
738         /* check data */
739         if (memcmp(src, dst, cur_dst - dst)) {
740                 rte_hexdump(stdout, "src", src, cur_src - src);
741                 rte_hexdump(stdout, "dst", dst, cur_dst - dst);
742                 printf("data after dequeue is not the same\n");
743                 goto fail;
744         }
745
746         cur_src = src;
747         cur_dst = dst;
748
749         printf("Covering rte_ring_enqueue_burst functions \n");
750
751         ret = rte_ring_enqueue_burst(r, cur_src, 2);
752         cur_src += 2;
753         if ((ret & RTE_RING_SZ_MASK) != 2)
754                 goto fail;
755
756         ret = rte_ring_dequeue_burst(r, cur_dst, 2);
757         cur_dst += 2;
758         if (ret != 2)
759                 goto fail;
760
761         /* Free memory before test completed */
762         if (src)
763                 free(src);
764         if (dst)
765                 free(dst);
766         return 0;
767
768  fail:
769         if (src)
770                 free(src);
771         if (dst)
772                 free(dst);
773         return -1;
774 }
775
776 static int
777 test_ring_stats(void)
778 {
779
780 #ifndef RTE_LIBRTE_RING_DEBUG
781         printf("Enable RTE_LIBRTE_RING_DEBUG to test ring stats.\n");
782         return 0;
783 #else
784         void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
785         int ret;
786         unsigned i;
787         unsigned num_items            = 0;
788         unsigned failed_enqueue_ops   = 0;
789         unsigned failed_enqueue_items = 0;
790         unsigned failed_dequeue_ops   = 0;
791         unsigned failed_dequeue_items = 0;
792         unsigned last_enqueue_ops     = 0;
793         unsigned last_enqueue_items   = 0;
794         unsigned last_quota_ops       = 0;
795         unsigned last_quota_items     = 0;
796         unsigned lcore_id = rte_lcore_id();
797         struct rte_ring_debug_stats *ring_stats = &r->stats[lcore_id];
798
799         printf("Test the ring stats.\n");
800
801         /* Reset the watermark in case it was set in another test. */
802         rte_ring_set_water_mark(r, 0);
803
804         /* Reset the ring stats. */
805         memset(&r->stats[lcore_id], 0, sizeof(r->stats[lcore_id]));
806
807         /* Allocate some dummy object pointers. */
808         src = malloc(RING_SIZE*2*sizeof(void *));
809         if (src == NULL)
810                 goto fail;
811
812         for (i = 0; i < RING_SIZE*2 ; i++) {
813                 src[i] = (void *)(unsigned long)i;
814         }
815
816         /* Allocate some memory for copied objects. */
817         dst = malloc(RING_SIZE*2*sizeof(void *));
818         if (dst == NULL)
819                 goto fail;
820
821         memset(dst, 0, RING_SIZE*2*sizeof(void *));
822
823         /* Set the head and tail pointers. */
824         cur_src = src;
825         cur_dst = dst;
826
827         /* Do Enqueue tests. */
828         printf("Test the dequeue stats.\n");
829
830         /* Fill the ring up to RING_SIZE -1. */
831         printf("Fill the ring.\n");
832         for (i = 0; i< (RING_SIZE/MAX_BULK); i++) {
833                 rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
834                 cur_src += MAX_BULK;
835         }
836
837         /* Adjust for final enqueue = MAX_BULK -1. */
838         cur_src--;
839
840         printf("Verify that the ring is full.\n");
841         if (rte_ring_full(r) != 1)
842                 goto fail;
843
844
845         printf("Verify the enqueue success stats.\n");
846         /* Stats should match above enqueue operations to fill the ring. */
847         if (ring_stats->enq_success_bulk != (RING_SIZE/MAX_BULK))
848                 goto fail;
849
850         /* Current max objects is RING_SIZE -1. */
851         if (ring_stats->enq_success_objs != RING_SIZE -1)
852                 goto fail;
853
854         /* Shouldn't have any failures yet. */
855         if (ring_stats->enq_fail_bulk != 0)
856                 goto fail;
857         if (ring_stats->enq_fail_objs != 0)
858                 goto fail;
859
860
861         printf("Test stats for SP burst enqueue to a full ring.\n");
862         num_items = 2;
863         ret = rte_ring_sp_enqueue_burst(r, cur_src, num_items);
864         if ((ret & RTE_RING_SZ_MASK) != 0)
865                 goto fail;
866
867         failed_enqueue_ops   += 1;
868         failed_enqueue_items += num_items;
869
870         /* The enqueue should have failed. */
871         if (ring_stats->enq_fail_bulk != failed_enqueue_ops)
872                 goto fail;
873         if (ring_stats->enq_fail_objs != failed_enqueue_items)
874                 goto fail;
875
876
877         printf("Test stats for SP bulk enqueue to a full ring.\n");
878         num_items = 4;
879         ret = rte_ring_sp_enqueue_bulk(r, cur_src, num_items);
880         if (ret != -ENOBUFS)
881                 goto fail;
882
883         failed_enqueue_ops   += 1;
884         failed_enqueue_items += num_items;
885
886         /* The enqueue should have failed. */
887         if (ring_stats->enq_fail_bulk != failed_enqueue_ops)
888                 goto fail;
889         if (ring_stats->enq_fail_objs != failed_enqueue_items)
890                 goto fail;
891
892
893         printf("Test stats for MP burst enqueue to a full ring.\n");
894         num_items = 8;
895         ret = rte_ring_mp_enqueue_burst(r, cur_src, num_items);
896         if ((ret & RTE_RING_SZ_MASK) != 0)
897                 goto fail;
898
899         failed_enqueue_ops   += 1;
900         failed_enqueue_items += num_items;
901
902         /* The enqueue should have failed. */
903         if (ring_stats->enq_fail_bulk != failed_enqueue_ops)
904                 goto fail;
905         if (ring_stats->enq_fail_objs != failed_enqueue_items)
906                 goto fail;
907
908
909         printf("Test stats for MP bulk enqueue to a full ring.\n");
910         num_items = 16;
911         ret = rte_ring_mp_enqueue_bulk(r, cur_src, num_items);
912         if (ret != -ENOBUFS)
913                 goto fail;
914
915         failed_enqueue_ops   += 1;
916         failed_enqueue_items += num_items;
917
918         /* The enqueue should have failed. */
919         if (ring_stats->enq_fail_bulk != failed_enqueue_ops)
920                 goto fail;
921         if (ring_stats->enq_fail_objs != failed_enqueue_items)
922                 goto fail;
923
924
925         /* Do Dequeue tests. */
926         printf("Test the dequeue stats.\n");
927
928         printf("Empty the ring.\n");
929         for (i = 0; i<RING_SIZE/MAX_BULK; i++) {
930                 rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
931                 cur_dst += MAX_BULK;
932         }
933
934         /* There was only RING_SIZE -1 objects to dequeue. */
935         cur_dst++;
936
937         printf("Verify ring is empty.\n");
938         if (1 != rte_ring_empty(r))
939                 goto fail;
940
941         printf("Verify the dequeue success stats.\n");
942         /* Stats should match above dequeue operations. */
943         if (ring_stats->deq_success_bulk != (RING_SIZE/MAX_BULK))
944                 goto fail;
945
946         /* Objects dequeued is RING_SIZE -1. */
947         if (ring_stats->deq_success_objs != RING_SIZE -1)
948                 goto fail;
949
950         /* Shouldn't have any dequeue failure stats yet. */
951         if (ring_stats->deq_fail_bulk != 0)
952                 goto fail;
953
954         printf("Test stats for SC burst dequeue with an empty ring.\n");
955         num_items = 2;
956         ret = rte_ring_sc_dequeue_burst(r, cur_dst, num_items);
957         if ((ret & RTE_RING_SZ_MASK) != 0)
958                 goto fail;
959
960         failed_dequeue_ops   += 1;
961         failed_dequeue_items += num_items;
962
963         /* The dequeue should have failed. */
964         if (ring_stats->deq_fail_bulk != failed_dequeue_ops)
965                 goto fail;
966         if (ring_stats->deq_fail_objs != failed_dequeue_items)
967                 goto fail;
968
969
970         printf("Test stats for SC bulk dequeue with an empty ring.\n");
971         num_items = 4;
972         ret = rte_ring_sc_dequeue_bulk(r, cur_dst, num_items);
973         if (ret != -ENOENT)
974                 goto fail;
975
976         failed_dequeue_ops   += 1;
977         failed_dequeue_items += num_items;
978
979         /* The dequeue should have failed. */
980         if (ring_stats->deq_fail_bulk != failed_dequeue_ops)
981                 goto fail;
982         if (ring_stats->deq_fail_objs != failed_dequeue_items)
983                 goto fail;
984
985
986         printf("Test stats for MC burst dequeue with an empty ring.\n");
987         num_items = 8;
988         ret = rte_ring_mc_dequeue_burst(r, cur_dst, num_items);
989         if ((ret & RTE_RING_SZ_MASK) != 0)
990                 goto fail;
991         failed_dequeue_ops   += 1;
992         failed_dequeue_items += num_items;
993
994         /* The dequeue should have failed. */
995         if (ring_stats->deq_fail_bulk != failed_dequeue_ops)
996                 goto fail;
997         if (ring_stats->deq_fail_objs != failed_dequeue_items)
998                 goto fail;
999
1000
1001         printf("Test stats for MC bulk dequeue with an empty ring.\n");
1002         num_items = 16;
1003         ret = rte_ring_mc_dequeue_bulk(r, cur_dst, num_items);
1004         if (ret != -ENOENT)
1005                 goto fail;
1006
1007         failed_dequeue_ops   += 1;
1008         failed_dequeue_items += num_items;
1009
1010         /* The dequeue should have failed. */
1011         if (ring_stats->deq_fail_bulk != failed_dequeue_ops)
1012                 goto fail;
1013         if (ring_stats->deq_fail_objs != failed_dequeue_items)
1014                 goto fail;
1015
1016
1017         printf("Test total enqueue/dequeue stats.\n");
1018         /* At this point the enqueue and dequeue stats should be the same. */
1019         if (ring_stats->enq_success_bulk != ring_stats->deq_success_bulk)
1020                 goto fail;
1021         if (ring_stats->enq_success_objs != ring_stats->deq_success_objs)
1022                 goto fail;
1023         if (ring_stats->enq_fail_bulk    != ring_stats->deq_fail_bulk)
1024                 goto fail;
1025         if (ring_stats->enq_fail_objs    != ring_stats->deq_fail_objs)
1026                 goto fail;
1027
1028
1029         /* Watermark Tests. */
1030         printf("Test the watermark/quota stats.\n");
1031
1032         printf("Verify the initial watermark stats.\n");
1033         /* Watermark stats should be 0 since there is no watermark. */
1034         if (ring_stats->enq_quota_bulk != 0)
1035                 goto fail;
1036         if (ring_stats->enq_quota_objs != 0)
1037                 goto fail;
1038
1039         /* Set a watermark. */
1040         rte_ring_set_water_mark(r, 16);
1041
1042         /* Reset pointers. */
1043         cur_src = src;
1044         cur_dst = dst;
1045
1046         last_enqueue_ops   = ring_stats->enq_success_bulk;
1047         last_enqueue_items = ring_stats->enq_success_objs;
1048
1049
1050         printf("Test stats for SP burst enqueue below watermark.\n");
1051         num_items = 8;
1052         ret = rte_ring_sp_enqueue_burst(r, cur_src, num_items);
1053         if ((ret & RTE_RING_SZ_MASK) != num_items)
1054                 goto fail;
1055
1056         /* Watermark stats should still be 0. */
1057         if (ring_stats->enq_quota_bulk != 0)
1058                 goto fail;
1059         if (ring_stats->enq_quota_objs != 0)
1060                 goto fail;
1061
1062         /* Success stats should have increased. */
1063         if (ring_stats->enq_success_bulk != last_enqueue_ops + 1)
1064                 goto fail;
1065         if (ring_stats->enq_success_objs != last_enqueue_items + num_items)
1066                 goto fail;
1067
1068         last_enqueue_ops   = ring_stats->enq_success_bulk;
1069         last_enqueue_items = ring_stats->enq_success_objs;
1070
1071
1072         printf("Test stats for SP burst enqueue at watermark.\n");
1073         num_items = 8;
1074         ret = rte_ring_sp_enqueue_burst(r, cur_src, num_items);
1075         if ((ret & RTE_RING_SZ_MASK) != num_items)
1076                 goto fail;
1077
1078         /* Watermark stats should have changed. */
1079         if (ring_stats->enq_quota_bulk != 1)
1080                 goto fail;
1081         if (ring_stats->enq_quota_objs != num_items)
1082                 goto fail;
1083
1084         last_quota_ops   = ring_stats->enq_quota_bulk;
1085         last_quota_items = ring_stats->enq_quota_objs;
1086
1087
1088         printf("Test stats for SP burst enqueue above watermark.\n");
1089         num_items = 1;
1090         ret = rte_ring_sp_enqueue_burst(r, cur_src, num_items);
1091         if ((ret & RTE_RING_SZ_MASK) != num_items)
1092                 goto fail;
1093
1094         /* Watermark stats should have changed. */
1095         if (ring_stats->enq_quota_bulk != last_quota_ops +1)
1096                 goto fail;
1097         if (ring_stats->enq_quota_objs != last_quota_items + num_items)
1098                 goto fail;
1099
1100         last_quota_ops   = ring_stats->enq_quota_bulk;
1101         last_quota_items = ring_stats->enq_quota_objs;
1102
1103
1104         printf("Test stats for MP burst enqueue above watermark.\n");
1105         num_items = 2;
1106         ret = rte_ring_mp_enqueue_burst(r, cur_src, num_items);
1107         if ((ret & RTE_RING_SZ_MASK) != num_items)
1108                 goto fail;
1109
1110         /* Watermark stats should have changed. */
1111         if (ring_stats->enq_quota_bulk != last_quota_ops +1)
1112                 goto fail;
1113         if (ring_stats->enq_quota_objs != last_quota_items + num_items)
1114                 goto fail;
1115
1116         last_quota_ops   = ring_stats->enq_quota_bulk;
1117         last_quota_items = ring_stats->enq_quota_objs;
1118
1119
1120         printf("Test stats for SP bulk enqueue above watermark.\n");
1121         num_items = 4;
1122         ret = rte_ring_sp_enqueue_bulk(r, cur_src, num_items);
1123         if (ret != -EDQUOT)
1124                 goto fail;
1125
1126         /* Watermark stats should have changed. */
1127         if (ring_stats->enq_quota_bulk != last_quota_ops +1)
1128                 goto fail;
1129         if (ring_stats->enq_quota_objs != last_quota_items + num_items)
1130                 goto fail;
1131
1132         last_quota_ops   = ring_stats->enq_quota_bulk;
1133         last_quota_items = ring_stats->enq_quota_objs;
1134
1135
1136         printf("Test stats for MP bulk enqueue above watermark.\n");
1137         num_items = 8;
1138         ret = rte_ring_mp_enqueue_bulk(r, cur_src, num_items);
1139         if (ret != -EDQUOT)
1140                 goto fail;
1141
1142         /* Watermark stats should have changed. */
1143         if (ring_stats->enq_quota_bulk != last_quota_ops +1)
1144                 goto fail;
1145         if (ring_stats->enq_quota_objs != last_quota_items + num_items)
1146                 goto fail;
1147
1148         printf("Test watermark success stats.\n");
1149         /* Success stats should be same as last non-watermarked enqueue. */
1150         if (ring_stats->enq_success_bulk != last_enqueue_ops)
1151                 goto fail;
1152         if (ring_stats->enq_success_objs != last_enqueue_items)
1153                 goto fail;
1154
1155
1156         /* Cleanup. */
1157
1158         /* Empty the ring. */
1159         for (i = 0; i<RING_SIZE/MAX_BULK; i++) {
1160                 rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
1161                 cur_dst += MAX_BULK;
1162         }
1163
1164         /* Reset the watermark. */
1165         rte_ring_set_water_mark(r, 0);
1166
1167         /* Reset the ring stats. */
1168         memset(&r->stats[lcore_id], 0, sizeof(r->stats[lcore_id]));
1169
1170         /* Free memory before test completed */
1171         if (src)
1172                 free(src);
1173         if (dst)
1174                 free(dst);
1175         return 0;
1176
1177 fail:
1178         if (src)
1179                 free(src);
1180         if (dst)
1181                 free(dst);
1182         return -1;
1183 #endif
1184 }
1185
1186 /*
1187  * it will always fail to create ring with a wrong ring size number in this function
1188  */
1189 static int
1190 test_ring_creation_with_wrong_size(void)
1191 {
1192         struct rte_ring * rp = NULL;
1193
1194         /* Test if ring size is not power of 2 */
1195         rp = rte_ring_create("test_bad_ring_size", RING_SIZE + 1, SOCKET_ID_ANY, 0);
1196         if (NULL != rp) {
1197                 return -1;
1198         }
1199
1200         /* Test if ring size is exceeding the limit */
1201         rp = rte_ring_create("test_bad_ring_size", (RTE_RING_SZ_MASK + 1), SOCKET_ID_ANY, 0);
1202         if (NULL != rp) {
1203                 return -1;
1204         }
1205         return 0;
1206 }
1207
1208 /*
1209  * it tests if it would always fail to create ring with an used ring name
1210  */
1211 static int
1212 test_ring_creation_with_an_used_name(void)
1213 {
1214         struct rte_ring * rp;
1215
1216         rp = rte_ring_create("test", RING_SIZE, SOCKET_ID_ANY, 0);
1217         if (NULL != rp)
1218                 return -1;
1219
1220         return 0;
1221 }
1222
1223 /*
1224  * Test to if a non-power of 2 count causes the create
1225  * function to fail correctly
1226  */
1227 static int
1228 test_create_count_odd(void)
1229 {
1230         struct rte_ring *r = rte_ring_create("test_ring_count",
1231                         4097, SOCKET_ID_ANY, 0 );
1232         if(r != NULL){
1233                 return -1;
1234         }
1235         return 0;
1236 }
1237
1238 static int
1239 test_lookup_null(void)
1240 {
1241         struct rte_ring *rlp = rte_ring_lookup("ring_not_found");
1242         if (rlp ==NULL)
1243         if (rte_errno != ENOENT){
1244                 printf( "test failed to returnn error on null pointer\n");
1245                 return -1;
1246         }
1247         return 0;
1248 }
1249
1250 /*
1251  * it tests some more basic ring operations
1252  */
1253 static int
1254 test_ring_basic_ex(void)
1255 {
1256         int ret = -1;
1257         unsigned i;
1258         struct rte_ring * rp;
1259         void **obj = NULL;
1260
1261         obj = rte_calloc("test_ring_basic_ex_malloc", RING_SIZE, sizeof(void *), 0);
1262         if (obj == NULL) {
1263                 printf("test_ring_basic_ex fail to rte_malloc\n");
1264                 goto fail_test;
1265         }
1266
1267         rp = rte_ring_create("test_ring_basic_ex", RING_SIZE, SOCKET_ID_ANY,
1268                         RING_F_SP_ENQ | RING_F_SC_DEQ);
1269         if (rp == NULL) {
1270                 printf("test_ring_basic_ex fail to create ring\n");
1271                 goto fail_test;
1272         }
1273
1274         if (rte_ring_lookup("test_ring_basic_ex") != rp) {
1275                 goto fail_test;
1276         }
1277
1278         if (rte_ring_empty(rp) != 1) {
1279                 printf("test_ring_basic_ex ring is not empty but it should be\n");
1280                 goto fail_test;
1281         }
1282
1283         printf("%u ring entries are now free\n", rte_ring_free_count(rp));
1284
1285         for (i = 0; i < RING_SIZE; i ++) {
1286                 rte_ring_enqueue(rp, obj[i]);
1287         }
1288
1289         if (rte_ring_full(rp) != 1) {
1290                 printf("test_ring_basic_ex ring is not full but it should be\n");
1291                 goto fail_test;
1292         }
1293
1294         for (i = 0; i < RING_SIZE; i ++) {
1295                 rte_ring_dequeue(rp, &obj[i]);
1296         }
1297
1298         if (rte_ring_empty(rp) != 1) {
1299                 printf("test_ring_basic_ex ring is not empty but it should be\n");
1300                 goto fail_test;
1301         }
1302
1303         /* Covering the ring burst operation */
1304         ret = rte_ring_enqueue_burst(rp, obj, 2);
1305         if ((ret & RTE_RING_SZ_MASK) != 2) {
1306                 printf("test_ring_basic_ex: rte_ring_enqueue_burst fails \n");
1307                 goto fail_test;
1308         }
1309
1310         ret = rte_ring_dequeue_burst(rp, obj, 2);
1311         if (ret != 2) {
1312                 printf("test_ring_basic_ex: rte_ring_dequeue_burst fails \n");
1313                 goto fail_test;
1314         }
1315
1316         ret = 0;
1317 fail_test:
1318         if (obj != NULL)
1319                 rte_free(obj);
1320
1321         return ret;
1322 }
1323
1324 static int
1325 test_ring(void)
1326 {
1327         /* some more basic operations */
1328         if (test_ring_basic_ex() < 0)
1329                 return -1;
1330
1331         rte_atomic32_init(&synchro);
1332
1333         if (r == NULL)
1334                 r = rte_ring_create("test", RING_SIZE, SOCKET_ID_ANY, 0);
1335         if (r == NULL)
1336                 return -1;
1337
1338         /* retrieve the ring from its name */
1339         if (rte_ring_lookup("test") != r) {
1340                 printf("Cannot lookup ring from its name\n");
1341                 return -1;
1342         }
1343
1344         /* burst operations */
1345         if (test_ring_burst_basic() < 0)
1346                 return -1;
1347
1348         /* basic operations */
1349         if (test_ring_basic() < 0)
1350                 return -1;
1351
1352         /* ring stats */
1353         if (test_ring_stats() < 0)
1354                 return -1;
1355
1356         /* basic operations */
1357         if (test_live_watermark_change() < 0)
1358                 return -1;
1359
1360         if ( test_set_watermark() < 0){
1361                 printf ("Test failed to detect invalid parameter\n");
1362                 return -1;
1363         }
1364         else
1365                 printf ( "Test detected forced bad watermark values\n");
1366
1367         if ( test_create_count_odd() < 0){
1368                         printf ("Test failed to detect odd count\n");
1369                         return -1;
1370                 }
1371                 else
1372                         printf ( "Test detected odd count\n");
1373
1374         if ( test_lookup_null() < 0){
1375                                 printf ("Test failed to detect NULL ring lookup\n");
1376                                 return -1;
1377                         }
1378                         else
1379                                 printf ( "Test detected NULL ring lookup \n");
1380
1381         /* test of creating ring with wrong size */
1382         if (test_ring_creation_with_wrong_size() < 0)
1383                 return -1;
1384
1385         /* test of creation ring with an used name */
1386         if (test_ring_creation_with_an_used_name() < 0)
1387                 return -1;
1388
1389         /* dump the ring status */
1390         rte_ring_list_dump(stdout);
1391
1392         return 0;
1393 }
1394
1395 static struct test_command ring_cmd = {
1396         .command = "ring_autotest",
1397         .callback = test_ring,
1398 };
1399 REGISTER_TEST_COMMAND(ring_cmd);