From patchwork Fri Dec 20 04:45:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 182204 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp57975ilf; Thu, 19 Dec 2019 20:46:46 -0800 (PST) X-Google-Smtp-Source: APXvYqzXO+nFoLDeL7hWCrdQHWtotlIvvKtwJ4AeRiIrBLUPLbK3zbfrOuRVDwBdWYu1ExyRTJCO X-Received: by 2002:a17:906:9395:: with SMTP id l21mr13763872ejx.284.1576817206559; Thu, 19 Dec 2019 20:46:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576817206; cv=none; d=google.com; s=arc-20160816; b=niXHWuJOSafHurKLbyghPiMUnChf2y+ndm77I10SJqFquYPZOV2BazTUCoS/Qt/Frn zidWyhIrUsUnBja8g9VB+dEZiDpPpkg0gKquOM2XQw9mVyhB5P2fREMaOLMP04D22O1d xvwebwXyhFWGtiHWHqMRssdlMEHTcaKmXsZYhUlpi/aPUMQjcnzo8LDWZ729gXjYskXG nZtWKNemJ2s7Y1hCDmGrdODRKTmVd/mEWIwmQHYEh9H4ohWNeeHKbgTNEmMAEpDmqZYK fBZYZ1R9H6tMtCl9OPg6LS+vb5+8Eou5b2U+RZhW3mZDFQNoZMwKgBvuXLyXHDf0//aL wDvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=kP3axUOLDKq892UdnR0bJ+KGllkADPqVqDTK63xKeNc=; b=E4Ki1A4dqi2n/Y46DV/tDI/CmtJF8rIn5WIuZYagz4f6Er7eoq4kdGonMLa8WtmGqi mDUHybhvUPvdoQvYi7pB0h0lzIyEhQrKvdMsot68LP0+pi0sCWkUcGnHVYnLXtMCydkA soPI7iImNKpqGv55eMbaYAnPp7aE2NCGQWaj5UPGrG5tPPbdOlgnclRk3iM53iIy5q3B uZTAGHAS79XWb03K0FQcFV2SlaGbQS5pZjMeeUp9DxGGqsnUdXmxI+vleG99iuqH6afm oaSXVekeUsS1DAxYktl+ysuvEvvTjku23Vw6wjSvUMzZw7VAFwbX+bSodqYqsFq745h8 t3/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id bo24si6158090edb.331.2019.12.19.20.46.46; Thu, 19 Dec 2019 20:46:46 -0800 (PST) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AC3741BF91; Fri, 20 Dec 2019 05:46:11 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id A14561BE8E for ; Fri, 20 Dec 2019 05:45:58 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4D5AC12FC; Thu, 19 Dec 2019 20:45:57 -0800 (PST) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.14.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 37F363F86C; Thu, 19 Dec 2019 20:45:57 -0800 (PST) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, sthemmin@microsoft.com, jerinj@marvell.com, bruce.richardson@intel.com, david.marchand@redhat.com, pbhagavatula@marvell.com, konstantin.ananyev@intel.com, honnappa.nagarahalli@arm.com Cc: dev@dpdk.org, dharmik.thakkar@arm.com, ruifeng.wang@arm.com, gavin.hu@arm.com, nd@arm.com Date: Thu, 19 Dec 2019 22:45:14 -0600 Message-Id: <20191220044524.32910-8-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191220044524.32910-1-honnappa.nagarahalli@arm.com> References: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> <20191220044524.32910-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v7 07/17] test/ring: negative test cases for rte_ring_xxx_elem APIs 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" All the negative test cases are consolidated into a single function. This provides the ability to add test cases for rte_ring_xxx_elem APIs easily. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- app/test/test_ring.c | 176 ++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 85 deletions(-) -- 2.17.1 diff --git a/app/test/test_ring.c b/app/test/test_ring.c index 294e3ee10..552e8b53a 100644 --- a/app/test/test_ring.c +++ b/app/test/test_ring.c @@ -113,6 +113,93 @@ test_ring_print_test_string(const char *istr, unsigned int api_type, int esize) printf("burst\n"); } +/* + * Various negative test cases. + */ +static int +test_ring_negative_tests(void) +{ + struct rte_ring *rp = NULL; + struct rte_ring *rt = NULL; + unsigned int i; + + /* Test with esize not a multiple of 4 */ + TEST_RING_CREATE("test_bad_element_size", 23, + RING_SIZE + 1, SOCKET_ID_ANY, 0, rp); + if (rp != NULL) { + printf("Test failed to detect invalid element size\n"); + goto test_fail; + } + + + for (i = 0; i < RTE_DIM(esize); i++) { + /* Test if ring size is not power of 2 */ + TEST_RING_CREATE("test_bad_ring_size", esize[i], + RING_SIZE + 1, SOCKET_ID_ANY, 0, rp); + if (rp != NULL) { + printf("Test failed to detect odd count\n"); + goto test_fail; + } + + /* Test if ring size is exceeding the limit */ + TEST_RING_CREATE("test_bad_ring_size", esize[i], + RTE_RING_SZ_MASK + 1, SOCKET_ID_ANY, + 0, rp); + if (rp != NULL) { + printf("Test failed to detect limits\n"); + goto test_fail; + } + + /* Tests if lookup returns NULL on non-existing ring */ + rp = rte_ring_lookup("ring_not_found"); + if (rp != NULL && rte_errno != ENOENT) { + printf("Test failed to detect NULL ring lookup\n"); + goto test_fail; + } + + /* Test to if a non-power of 2 count causes the create + * function to fail correctly + */ + TEST_RING_CREATE("test_ring_count", esize[i], 4097, + SOCKET_ID_ANY, 0, rp); + if (rp != NULL) + goto test_fail; + + TEST_RING_CREATE("test_ring_negative", esize[i], RING_SIZE, + SOCKET_ID_ANY, + RING_F_SP_ENQ | RING_F_SC_DEQ, rp); + if (rp == NULL) { + printf("test_ring_negative fail to create ring\n"); + goto test_fail; + } + + if (rte_ring_lookup("test_ring_negative") != rp) + goto test_fail; + + if (rte_ring_empty(rp) != 1) { + printf("test_ring_nagative ring is not empty but it should be\n"); + goto test_fail; + } + + /* Tests if it would always fail to create ring with an used + * ring name. + */ + TEST_RING_CREATE("test_ring_negative", esize[i], RING_SIZE, + SOCKET_ID_ANY, 0, rt); + if (rt != NULL) + goto test_fail; + + rte_ring_free(rp); + } + + return 0; + +test_fail: + + rte_ring_free(rp); + return -1; +} + static int test_ring_basic(struct rte_ring *r) { @@ -555,70 +642,6 @@ test_ring_burst_bulk_tests(unsigned int api_type) return -1; } -/* - * it will always fail to create ring with a wrong ring size number in this function - */ -static int -test_ring_creation_with_wrong_size(void) -{ - struct rte_ring * rp = NULL; - - /* Test if ring size is not power of 2 */ - rp = rte_ring_create("test_bad_ring_size", RING_SIZE + 1, SOCKET_ID_ANY, 0); - if (NULL != rp) { - return -1; - } - - /* Test if ring size is exceeding the limit */ - rp = rte_ring_create("test_bad_ring_size", (RTE_RING_SZ_MASK + 1), SOCKET_ID_ANY, 0); - if (NULL != rp) { - return -1; - } - return 0; -} - -/* - * it tests if it would always fail to create ring with an used ring name - */ -static int -test_ring_creation_with_an_used_name(void) -{ - struct rte_ring * rp; - - rp = rte_ring_create("test", RING_SIZE, SOCKET_ID_ANY, 0); - if (NULL != rp) - return -1; - - return 0; -} - -/* - * Test to if a non-power of 2 count causes the create - * function to fail correctly - */ -static int -test_create_count_odd(void) -{ - struct rte_ring *r = rte_ring_create("test_ring_count", - 4097, SOCKET_ID_ANY, 0 ); - if(r != NULL){ - return -1; - } - return 0; -} - -static int -test_lookup_null(void) -{ - struct rte_ring *rlp = rte_ring_lookup("ring_not_found"); - if (rlp ==NULL) - if (rte_errno != ENOENT){ - printf( "test failed to returnn error on null pointer\n"); - return -1; - } - return 0; -} - /* * Test default, single element, bulk and burst APIs */ @@ -835,6 +858,10 @@ test_ring(void) unsigned int i, j; struct rte_ring *r = NULL; + /* Negative test cases */ + if (test_ring_negative_tests() < 0) + goto test_fail; + /* some more basic operations */ if (test_ring_basic_ex() < 0) goto test_fail; @@ -861,27 +888,6 @@ test_ring(void) 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"); - goto test_fail; - } else - printf("Test detected odd count\n"); - - if ( test_lookup_null() < 0){ - 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) - goto test_fail; - - /* test of creation ring with an used name */ - if (test_ring_creation_with_an_used_name() < 0) - goto test_fail; - if (test_ring_with_exact_size() < 0) goto test_fail;