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