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