From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id D50083251 for ; Wed, 7 Jun 2017 16:05:35 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP; 07 Jun 2017 07:05:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,311,1493708400"; d="scan'208";a="1157667613" Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.223.223]) by fmsmga001.fm.intel.com with ESMTP; 07 Jun 2017 07:05:34 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: olivier.matz@6wind.com, jerin.jacob@caviumnetworks.com, Bruce Richardson Date: Wed, 7 Jun 2017 14:36:17 +0100 Message-Id: <20170607133620.275801-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607133620.275801-1-bruce.richardson@intel.com> References: <20170607133620.275801-1-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH 2/5] test/test: add unit tests for exact size rings X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jun 2017 14:05:36 -0000 Signed-off-by: Bruce Richardson --- test/test/test_ring.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/test/test/test_ring.c b/test/test/test_ring.c index 858ebc1..7f3b00d 100644 --- a/test/test/test_ring.c +++ b/test/test/test_ring.c @@ -770,6 +770,74 @@ test_ring_basic_ex(void) } static int +test_ring_with_exact_size(void) +{ + struct rte_ring *std_ring, *exact_sz_ring; + void *ptr_array[16]; + static const unsigned int ring_sz = RTE_DIM(ptr_array); + unsigned int i; + + 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__); + return -1; + } + 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__); + return -1; + } + + /* + * 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)); + return -1; + } + /* + * 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__); + return -1; + } + if (rte_ring_enqueue(exact_sz_ring, NULL) == -ENOBUFS) { + printf("%s: error, enqueue failed\n", __func__); + return -1; + } + + /* 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__); + return -1; + } + + /* 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__); + return -1; + } + + rte_ring_free(std_ring); + rte_ring_free(exact_sz_ring); + return 0; +} + +static int test_ring(void) { /* some more basic operations */ @@ -820,6 +888,9 @@ test_ring(void) if (test_ring_creation_with_an_used_name() < 0) return -1; + if (test_ring_with_exact_size() < 0) + return -1; + /* dump the ring status */ rte_ring_list_dump(stdout); -- 2.9.4