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