net/virtio: fix mbuf data offset for simple Rx
[dpdk.git] / test / test / test_ring.c
index 112433b..aaf1e70 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
  */
 
 #include <string.h>
@@ -43,7 +14,6 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_memory.h>
-#include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_cycles.h>
 #include <rte_eal.h>
@@ -54,7 +24,6 @@
 #include <rte_malloc.h>
 #include <rte_ring.h>
 #include <rte_random.h>
-#include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_hexdump.h>
 
@@ -88,8 +57,6 @@
 
 static rte_atomic32_t synchro;
 
-static struct rte_ring *r;
-
 #define        TEST_RING_VERIFY(exp)                                           \
        if (!(exp)) {                                                   \
                printf("error at %s:%d\tcondition " #exp " failed\n",   \
@@ -104,7 +71,7 @@ static struct rte_ring *r;
  * helper routine for test_ring_basic
  */
 static int
-test_ring_basic_full_empty(void * const src[], void *dst[])
+test_ring_basic_full_empty(struct rte_ring *r, void * const src[], void *dst[])
 {
        unsigned i, rand;
        const unsigned rsz = RING_SIZE - 1;
@@ -117,18 +84,21 @@ test_ring_basic_full_empty(void * const src[], void *dst[])
                rand = RTE_MAX(rte_rand() % RING_SIZE, 1UL);
                printf("%s: iteration %u, random shift: %u;\n",
                    __func__, i, rand);
-               TEST_RING_VERIFY(rte_ring_enqueue_bulk(r, src, rand) != 0);
-               TEST_RING_VERIFY(rte_ring_dequeue_bulk(r, dst, rand) == rand);
+               TEST_RING_VERIFY(rte_ring_enqueue_bulk(r, src, rand,
+                               NULL) != 0);
+               TEST_RING_VERIFY(rte_ring_dequeue_bulk(r, dst, rand,
+                               NULL) == rand);
 
                /* fill the ring */
-               TEST_RING_VERIFY(rte_ring_enqueue_bulk(r, src, rsz) != 0);
+               TEST_RING_VERIFY(rte_ring_enqueue_bulk(r, src, rsz, NULL) != 0);
                TEST_RING_VERIFY(0 == rte_ring_free_count(r));
                TEST_RING_VERIFY(rsz == rte_ring_count(r));
                TEST_RING_VERIFY(rte_ring_full(r));
                TEST_RING_VERIFY(0 == rte_ring_empty(r));
 
                /* empty the ring */
-               TEST_RING_VERIFY(rte_ring_dequeue_bulk(r, dst, rsz) == rsz);
+               TEST_RING_VERIFY(rte_ring_dequeue_bulk(r, dst, rsz,
+                               NULL) == rsz);
                TEST_RING_VERIFY(rsz == rte_ring_free_count(r));
                TEST_RING_VERIFY(0 == rte_ring_count(r));
                TEST_RING_VERIFY(0 == rte_ring_full(r));
@@ -142,7 +112,7 @@ test_ring_basic_full_empty(void * const src[], void *dst[])
 }
 
 static int
-test_ring_basic(void)
+test_ring_basic(struct rte_ring *r)
 {
        void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
        int ret;
@@ -167,37 +137,37 @@ test_ring_basic(void)
        cur_dst = dst;
 
        printf("enqueue 1 obj\n");
-       ret = rte_ring_sp_enqueue_bulk(r, cur_src, 1);
+       ret = rte_ring_sp_enqueue_bulk(r, cur_src, 1, NULL);
        cur_src += 1;
        if (ret == 0)
                goto fail;
 
        printf("enqueue 2 objs\n");
-       ret = rte_ring_sp_enqueue_bulk(r, cur_src, 2);
+       ret = rte_ring_sp_enqueue_bulk(r, cur_src, 2, NULL);
        cur_src += 2;
        if (ret == 0)
                goto fail;
 
        printf("enqueue MAX_BULK objs\n");
-       ret = rte_ring_sp_enqueue_bulk(r, cur_src, MAX_BULK);
+       ret = rte_ring_sp_enqueue_bulk(r, cur_src, MAX_BULK, NULL);
        cur_src += MAX_BULK;
        if (ret == 0)
                goto fail;
 
        printf("dequeue 1 obj\n");
-       ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 1);
+       ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 1, NULL);
        cur_dst += 1;
        if (ret == 0)
                goto fail;
 
        printf("dequeue 2 objs\n");
-       ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 2);
+       ret = rte_ring_sc_dequeue_bulk(r, cur_dst, 2, NULL);
        cur_dst += 2;
        if (ret == 0)
                goto fail;
 
        printf("dequeue MAX_BULK objs\n");
-       ret = rte_ring_sc_dequeue_bulk(r, cur_dst, MAX_BULK);
+       ret = rte_ring_sc_dequeue_bulk(r, cur_dst, MAX_BULK, NULL);
        cur_dst += MAX_BULK;
        if (ret == 0)
                goto fail;
@@ -213,37 +183,37 @@ test_ring_basic(void)
        cur_dst = dst;
 
        printf("enqueue 1 obj\n");
-       ret = rte_ring_mp_enqueue_bulk(r, cur_src, 1);
+       ret = rte_ring_mp_enqueue_bulk(r, cur_src, 1, NULL);
        cur_src += 1;
        if (ret == 0)
                goto fail;
 
        printf("enqueue 2 objs\n");
-       ret = rte_ring_mp_enqueue_bulk(r, cur_src, 2);
+       ret = rte_ring_mp_enqueue_bulk(r, cur_src, 2, NULL);
        cur_src += 2;
        if (ret == 0)
                goto fail;
 
        printf("enqueue MAX_BULK objs\n");
-       ret = rte_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK);
+       ret = rte_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK, NULL);
        cur_src += MAX_BULK;
        if (ret == 0)
                goto fail;
 
        printf("dequeue 1 obj\n");
-       ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 1);
+       ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 1, NULL);
        cur_dst += 1;
        if (ret == 0)
                goto fail;
 
        printf("dequeue 2 objs\n");
-       ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 2);
+       ret = rte_ring_mc_dequeue_bulk(r, cur_dst, 2, NULL);
        cur_dst += 2;
        if (ret == 0)
                goto fail;
 
        printf("dequeue MAX_BULK objs\n");
-       ret = rte_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK);
+       ret = rte_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK, NULL);
        cur_dst += MAX_BULK;
        if (ret == 0)
                goto fail;
@@ -260,11 +230,11 @@ test_ring_basic(void)
 
        printf("fill and empty the ring\n");
        for (i = 0; i<RING_SIZE/MAX_BULK; i++) {
-               ret = rte_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK);
+               ret = rte_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK, NULL);
                cur_src += MAX_BULK;
                if (ret == 0)
                        goto fail;
-               ret = rte_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK);
+               ret = rte_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK, NULL);
                cur_dst += MAX_BULK;
                if (ret == 0)
                        goto fail;
@@ -278,7 +248,7 @@ test_ring_basic(void)
                goto fail;
        }
 
-       if (test_ring_basic_full_empty(src, dst) != 0)
+       if (test_ring_basic_full_empty(r, src, dst) != 0)
                goto fail;
 
        cur_src = src;
@@ -290,25 +260,25 @@ test_ring_basic(void)
        cur_src = src;
        cur_dst = dst;
 
-       ret = rte_ring_enqueue_bulk(r, cur_src, num_elems);
+       ret = rte_ring_enqueue_bulk(r, cur_src, num_elems, NULL);
        cur_src += num_elems;
        if (ret == 0) {
                printf("Cannot enqueue\n");
                goto fail;
        }
-       ret = rte_ring_enqueue_bulk(r, cur_src, num_elems);
+       ret = rte_ring_enqueue_bulk(r, cur_src, num_elems, NULL);
        cur_src += num_elems;
        if (ret == 0) {
                printf("Cannot enqueue\n");
                goto fail;
        }
-       ret = rte_ring_dequeue_bulk(r, cur_dst, num_elems);
+       ret = rte_ring_dequeue_bulk(r, cur_dst, num_elems, NULL);
        cur_dst += num_elems;
        if (ret == 0) {
                printf("Cannot dequeue\n");
                goto fail;
        }
-       ret = rte_ring_dequeue_bulk(r, cur_dst, num_elems);
+       ret = rte_ring_dequeue_bulk(r, cur_dst, num_elems, NULL);
        cur_dst += num_elems;
        if (ret == 0) {
                printf("Cannot dequeue2\n");
@@ -345,7 +315,7 @@ test_ring_basic(void)
 }
 
 static int
-test_ring_burst_basic(void)
+test_ring_burst_basic(struct rte_ring *r)
 {
        void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL;
        int ret;
@@ -371,39 +341,39 @@ test_ring_burst_basic(void)
 
        printf("Test SP & SC basic functions \n");
        printf("enqueue 1 obj\n");
-       ret = rte_ring_sp_enqueue_burst(r, cur_src, 1);
+       ret = rte_ring_sp_enqueue_burst(r, cur_src, 1, NULL);
        cur_src += 1;
-       if ((ret & RTE_RING_SZ_MASK) != 1)
+       if (ret != 1)
                goto fail;
 
        printf("enqueue 2 objs\n");
-       ret = rte_ring_sp_enqueue_burst(r, cur_src, 2);
+       ret = rte_ring_sp_enqueue_burst(r, cur_src, 2, NULL);
        cur_src += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
        printf("enqueue MAX_BULK objs\n");
-       ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK;
+       ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
        cur_src += MAX_BULK;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+       if (ret != MAX_BULK)
                goto fail;
 
        printf("dequeue 1 obj\n");
-       ret = rte_ring_sc_dequeue_burst(r, cur_dst, 1;
+       ret = rte_ring_sc_dequeue_burst(r, cur_dst, 1, NULL);
        cur_dst += 1;
-       if ((ret & RTE_RING_SZ_MASK) != 1)
+       if (ret != 1)
                goto fail;
 
        printf("dequeue 2 objs\n");
-       ret = rte_ring_sc_dequeue_burst(r, cur_dst, 2);
+       ret = rte_ring_sc_dequeue_burst(r, cur_dst, 2, NULL);
        cur_dst += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
        printf("dequeue MAX_BULK objs\n");
-       ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
+       ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK, NULL);
        cur_dst += MAX_BULK;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+       if (ret != MAX_BULK)
                goto fail;
 
        /* check data */
@@ -419,24 +389,23 @@ test_ring_burst_basic(void)
 
        printf("Test enqueue without enough memory space \n");
        for (i = 0; i< (RING_SIZE/MAX_BULK - 1); i++) {
-               ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
+               ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
                cur_src += MAX_BULK;
-               if ((ret & RTE_RING_SZ_MASK) != MAX_BULK) {
+               if (ret != MAX_BULK)
                        goto fail;
-               }
        }
 
        printf("Enqueue 2 objects, free entries = MAX_BULK - 2  \n");
-       ret = rte_ring_sp_enqueue_burst(r, cur_src, 2);
+       ret = rte_ring_sp_enqueue_burst(r, cur_src, 2, NULL);
        cur_src += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
        printf("Enqueue the remaining entries = MAX_BULK - 2  \n");
        /* Always one free entry left */
-       ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
+       ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
        cur_src += MAX_BULK - 3;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
+       if (ret != MAX_BULK - 3)
                goto fail;
 
        printf("Test if ring is full  \n");
@@ -444,27 +413,27 @@ test_ring_burst_basic(void)
                goto fail;
 
        printf("Test enqueue for a full entry  \n");
-       ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
-       if ((ret & RTE_RING_SZ_MASK) != 0)
+       ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
+       if (ret != 0)
                goto fail;
 
        printf("Test dequeue without enough objects \n");
        for (i = 0; i<RING_SIZE/MAX_BULK - 1; i++) {
-               ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
+               ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK, NULL);
                cur_dst += MAX_BULK;
-               if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+               if (ret != MAX_BULK)
                        goto fail;
        }
 
        /* Available memory space for the exact MAX_BULK entries */
-       ret = rte_ring_sc_dequeue_burst(r, cur_dst, 2);
+       ret = rte_ring_sc_dequeue_burst(r, cur_dst, 2, NULL);
        cur_dst += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
-       ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
+       ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK, NULL);
        cur_dst += MAX_BULK - 3;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
+       if (ret != MAX_BULK - 3)
                goto fail;
 
        printf("Test if ring is empty \n");
@@ -486,39 +455,39 @@ test_ring_burst_basic(void)
        printf("Test MP & MC basic functions \n");
 
        printf("enqueue 1 obj\n");
-       ret = rte_ring_mp_enqueue_burst(r, cur_src, 1);
+       ret = rte_ring_mp_enqueue_burst(r, cur_src, 1, NULL);
        cur_src += 1;
-       if ((ret & RTE_RING_SZ_MASK) != 1)
+       if (ret != 1)
                goto fail;
 
        printf("enqueue 2 objs\n");
-       ret = rte_ring_mp_enqueue_burst(r, cur_src, 2);
+       ret = rte_ring_mp_enqueue_burst(r, cur_src, 2, NULL);
        cur_src += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
        printf("enqueue MAX_BULK objs\n");
-       ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
+       ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
        cur_src += MAX_BULK;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+       if (ret != MAX_BULK)
                goto fail;
 
        printf("dequeue 1 obj\n");
-       ret = rte_ring_mc_dequeue_burst(r, cur_dst, 1);
+       ret = rte_ring_mc_dequeue_burst(r, cur_dst, 1, NULL);
        cur_dst += 1;
-       if ((ret & RTE_RING_SZ_MASK) != 1)
+       if (ret != 1)
                goto fail;
 
        printf("dequeue 2 objs\n");
-       ret = rte_ring_mc_dequeue_burst(r, cur_dst, 2);
+       ret = rte_ring_mc_dequeue_burst(r, cur_dst, 2, NULL);
        cur_dst += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
        printf("dequeue MAX_BULK objs\n");
-       ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
+       ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK, NULL);
        cur_dst += MAX_BULK;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+       if (ret != MAX_BULK)
                goto fail;
 
        /* check data */
@@ -534,13 +503,13 @@ test_ring_burst_basic(void)
 
        printf("fill and empty the ring\n");
        for (i = 0; i<RING_SIZE/MAX_BULK; i++) {
-               ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
+               ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
                cur_src += MAX_BULK;
-               if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+               if (ret != MAX_BULK)
                        goto fail;
-               ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
+               ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK, NULL);
                cur_dst += MAX_BULK;
-               if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+               if (ret != MAX_BULK)
                        goto fail;
        }
 
@@ -557,41 +526,41 @@ test_ring_burst_basic(void)
 
        printf("Test enqueue without enough memory space \n");
        for (i = 0; i<RING_SIZE/MAX_BULK - 1; i++) {
-               ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
+               ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
                cur_src += MAX_BULK;
-               if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+               if (ret != MAX_BULK)
                        goto fail;
        }
 
        /* Available memory space for the exact MAX_BULK objects */
-       ret = rte_ring_mp_enqueue_burst(r, cur_src, 2);
+       ret = rte_ring_mp_enqueue_burst(r, cur_src, 2, NULL);
        cur_src += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
-       ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK);
+       ret = rte_ring_mp_enqueue_burst(r, cur_src, MAX_BULK, NULL);
        cur_src += MAX_BULK - 3;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
+       if (ret != MAX_BULK - 3)
                goto fail;
 
 
        printf("Test dequeue without enough objects \n");
        for (i = 0; i<RING_SIZE/MAX_BULK - 1; i++) {
-               ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
+               ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK, NULL);
                cur_dst += MAX_BULK;
-               if ((ret & RTE_RING_SZ_MASK) != MAX_BULK)
+               if (ret != MAX_BULK)
                        goto fail;
        }
 
        /* Available objects - the exact MAX_BULK */
-       ret = rte_ring_mc_dequeue_burst(r, cur_dst, 2);
+       ret = rte_ring_mc_dequeue_burst(r, cur_dst, 2, NULL);
        cur_dst += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
-       ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK);
+       ret = rte_ring_mc_dequeue_burst(r, cur_dst, MAX_BULK, NULL);
        cur_dst += MAX_BULK - 3;
-       if ((ret & RTE_RING_SZ_MASK) != MAX_BULK - 3)
+       if (ret != MAX_BULK - 3)
                goto fail;
 
        /* check data */
@@ -607,12 +576,12 @@ test_ring_burst_basic(void)
 
        printf("Covering rte_ring_enqueue_burst functions \n");
 
-       ret = rte_ring_enqueue_burst(r, cur_src, 2);
+       ret = rte_ring_enqueue_burst(r, cur_src, 2, NULL);
        cur_src += 2;
-       if ((ret & RTE_RING_SZ_MASK) != 2)
+       if (ret != 2)
                goto fail;
 
-       ret = rte_ring_dequeue_burst(r, cur_dst, 2);
+       ret = rte_ring_dequeue_burst(r, cur_dst, 2, NULL);
        cur_dst += 2;
        if (ret != 2)
                goto fail;
@@ -700,7 +669,7 @@ test_ring_basic_ex(void)
 {
        int ret = -1;
        unsigned i;
-       struct rte_ring * rp;
+       struct rte_ring *rp = NULL;
        void **obj = NULL;
 
        obj = rte_calloc("test_ring_basic_ex_malloc", RING_SIZE, sizeof(void *), 0);
@@ -746,13 +715,13 @@ test_ring_basic_ex(void)
        }
 
        /* Covering the ring burst operation */
-       ret = rte_ring_enqueue_burst(rp, obj, 2);
-       if ((ret & RTE_RING_SZ_MASK) != 2) {
+       ret = rte_ring_enqueue_burst(rp, obj, 2, NULL);
+       if (ret != 2) {
                printf("test_ring_basic_ex: rte_ring_enqueue_burst fails \n");
                goto fail_test;
        }
 
-       ret = rte_ring_dequeue_burst(rp, obj, 2);
+       ret = rte_ring_dequeue_burst(rp, obj, 2, NULL);
        if (ret != 2) {
                printf("test_ring_basic_ex: rte_ring_dequeue_burst fails \n");
                goto fail_test;
@@ -760,67 +729,148 @@ test_ring_basic_ex(void)
 
        ret = 0;
 fail_test:
+       rte_ring_free(rp);
        if (obj != NULL)
                rte_free(obj);
 
        return ret;
 }
 
+static int
+test_ring_with_exact_size(void)
+{
+       struct rte_ring *std_ring = NULL, *exact_sz_ring = NULL;
+       void *ptr_array[16];
+       static const unsigned int ring_sz = RTE_DIM(ptr_array);
+       unsigned int i;
+       int ret = -1;
+
+       std_ring = rte_ring_create("std", ring_sz, rte_socket_id(),
+                       RING_F_SP_ENQ | RING_F_SC_DEQ);
+       if (std_ring == NULL) {
+               printf("%s: error, can't create std ring\n", __func__);
+               goto end;
+       }
+       exact_sz_ring = rte_ring_create("exact sz", ring_sz, rte_socket_id(),
+                       RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ);
+       if (exact_sz_ring == NULL) {
+               printf("%s: error, can't create exact size ring\n", __func__);
+               goto end;
+       }
+
+       /*
+        * Check that the exact size ring is bigger than the standard ring
+        */
+       if (rte_ring_get_size(std_ring) >= rte_ring_get_size(exact_sz_ring)) {
+               printf("%s: error, std ring (size: %u) is not smaller than exact size one (size %u)\n",
+                               __func__,
+                               rte_ring_get_size(std_ring),
+                               rte_ring_get_size(exact_sz_ring));
+               goto end;
+       }
+       /*
+        * check that the exact_sz_ring can hold one more element than the
+        * standard ring. (16 vs 15 elements)
+        */
+       for (i = 0; i < ring_sz - 1; i++) {
+               rte_ring_enqueue(std_ring, NULL);
+               rte_ring_enqueue(exact_sz_ring, NULL);
+       }
+       if (rte_ring_enqueue(std_ring, NULL) != -ENOBUFS) {
+               printf("%s: error, unexpected successful enqueue\n", __func__);
+               goto end;
+       }
+       if (rte_ring_enqueue(exact_sz_ring, NULL) == -ENOBUFS) {
+               printf("%s: error, enqueue failed\n", __func__);
+               goto end;
+       }
+
+       /* check that dequeue returns the expected number of elements */
+       if (rte_ring_dequeue_burst(exact_sz_ring, ptr_array,
+                       RTE_DIM(ptr_array), NULL) != ring_sz) {
+               printf("%s: error, failed to dequeue expected nb of elements\n",
+                               __func__);
+               goto end;
+       }
+
+       /* check that the capacity function returns expected value */
+       if (rte_ring_get_capacity(exact_sz_ring) != ring_sz) {
+               printf("%s: error, incorrect ring capacity reported\n",
+                               __func__);
+               goto end;
+       }
+
+       ret = 0; /* all ok if we get here */
+end:
+       rte_ring_free(std_ring);
+       rte_ring_free(exact_sz_ring);
+       return ret;
+}
+
 static int
 test_ring(void)
 {
+       struct rte_ring *r = NULL;
+
        /* some more basic operations */
        if (test_ring_basic_ex() < 0)
-               return -1;
+               goto test_fail;
 
        rte_atomic32_init(&synchro);
 
+       r = rte_ring_create("test", RING_SIZE, SOCKET_ID_ANY, 0);
        if (r == NULL)
-               r = rte_ring_create("test", RING_SIZE, SOCKET_ID_ANY, 0);
-       if (r == NULL)
-               return -1;
+               goto test_fail;
 
        /* retrieve the ring from its name */
        if (rte_ring_lookup("test") != r) {
                printf("Cannot lookup ring from its name\n");
-               return -1;
+               goto test_fail;
        }
 
        /* burst operations */
-       if (test_ring_burst_basic() < 0)
-               return -1;
+       if (test_ring_burst_basic(r) < 0)
+               goto test_fail;
 
        /* basic operations */
-       if (test_ring_basic() < 0)
-               return -1;
+       if (test_ring_basic(r) < 0)
+               goto test_fail;
 
        /* basic operations */
        if ( test_create_count_odd() < 0){
-                       printf ("Test failed to detect odd count\n");
-                       return -1;
-               }
-               else
-                       printf ( "Test detected odd count\n");
+               printf("Test failed to detect odd count\n");
+               goto test_fail;
+       } else
+               printf("Test detected odd count\n");
 
        if ( test_lookup_null() < 0){
-                               printf ("Test failed to detect NULL ring lookup\n");
-                               return -1;
-                       }
-                       else
-                               printf ( "Test detected NULL ring lookup \n");
+               printf("Test failed to detect NULL ring lookup\n");
+               goto test_fail;
+       } else
+               printf("Test detected NULL ring lookup\n");
 
        /* test of creating ring with wrong size */
        if (test_ring_creation_with_wrong_size() < 0)
-               return -1;
+               goto test_fail;
 
        /* test of creation ring with an used name */
        if (test_ring_creation_with_an_used_name() < 0)
-               return -1;
+               goto test_fail;
+
+       if (test_ring_with_exact_size() < 0)
+               goto test_fail;
 
        /* dump the ring status */
        rte_ring_list_dump(stdout);
 
+       rte_ring_free(r);
+
        return 0;
+
+test_fail:
+       rte_ring_free(r);
+
+       return -1;
 }
 
 REGISTER_TEST_COMMAND(ring_autotest, test_ring);