From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by dpdk.org (Postfix) with ESMTP id 3BBFA37A0 for ; Fri, 30 Jun 2017 11:42:53 +0200 (CEST) Received: by mail-wm0-f44.google.com with SMTP id 62so105036893wmw.1 for ; Fri, 30 Jun 2017 02:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8UIZgVru5Y9BzQpOAt8koEg7lIT0YTKaBXlspJ6tP5c=; b=Qq8eWl9z1+Ts73tnArfLPeVSaw447TaqqIjQFXa816xFZUNvPwd0PONVQnPca0xAph 0Aj2L+bndyOlhsajET5t7tJYkTjkDtFfoeDEuIsQ1e5jC3J5AC6aJ2tLpTUJXLHSftt/ f8/TAYMCH88AK3e21qs/diHXxykY5crMapJ2euifqGbNIwjMeT3BcX0pz23+rqxXxH8m OWJ/ftZevpn8HIcLuF+2txtAhZLNHAuGrsI0xekEye1IF7gcTp8qm4W3jYXwcZKDqDK9 m3gvemPU/EmHX1LhNOB43rf2j+uDQKbIo+dA3UKxXL0fVqXyEVQHd0IWhj4T+X6u6rWw 3+eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8UIZgVru5Y9BzQpOAt8koEg7lIT0YTKaBXlspJ6tP5c=; b=tHTTz40ybPTDlF+Gu3AYTSw0/a4nWfejitvgSB9EUA5uvdIXf5euXsTjFnRccWQp+h tqqQKWZLbX5htfb4lfY6OI5O3sHzkQ253gyWgwBT31cDv5JK/09CptRRdgsFyWDni0l6 EXuXMtVSNIU3p5O4Q2SO/C7g1iTOC9PciAoWvDdsFTzEAknzNS49o8NbE0b9D4GlIaT5 rHtQYQ0ZO4e0DN8XpFMyZ7CXUgW0gwIwwhgGO1FGsPj+u18MhHCHBTquYzM5VwH3gSFq cUbOlntq1hWMeLuY83+pWlG1wfIYFWnDkk3BK+Ky7cuQWFadqdKtdntuI9kZ8rzpj7m3 Z3Sw== X-Gm-Message-State: AKS2vOzxkB0HpzInbSylUN4+cAYqJ7FV5pDkFrnquNWLsm7sVtv/qw9n X2f/K0YKRzvl0v1y X-Received: by 10.28.68.66 with SMTP id r63mr5006415wma.120.1498815772745; Fri, 30 Jun 2017 02:42:52 -0700 (PDT) Received: from platinum (2a01cb0c03c651000226b0fffeed02fc.ipv6.abo.wanadoo.fr. [2a01:cb0c:3c6:5100:226:b0ff:feed:2fc]) by smtp.gmail.com with ESMTPSA id f8sm3272669wme.26.2017.06.30.02.42.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2017 02:42:52 -0700 (PDT) Date: Fri, 30 Jun 2017 11:42:50 +0200 From: Olivier Matz To: Bruce Richardson Cc: dev@dpdk.org, jerin.jacob@caviumnetworks.com Message-ID: <20170630114250.46efbb47@platinum> In-Reply-To: <20170607133620.275801-3-bruce.richardson@intel.com> References: <20170607133620.275801-1-bruce.richardson@intel.com> <20170607133620.275801-3-bruce.richardson@intel.com> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [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: Fri, 30 Jun 2017 09:42:53 -0000 Hi Bruce, On Wed, 7 Jun 2017 14:36:17 +0100, Bruce Richardson wrote: > 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; > + } I think you should use a "goto fail" to free the ring in error cases. > + > + /* > + * 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); >