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