From patchwork Fri Jun 26 15:29:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Gonzalez Monroy X-Patchwork-Id: 5854 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 346B6C9CE; Fri, 26 Jun 2015 17:29:52 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 68E40C96A for ; Fri, 26 Jun 2015 17:29:43 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 26 Jun 2015 08:29:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,685,1427785200"; d="scan'208";a="735284387" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 26 Jun 2015 08:29:40 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5QFTdX8011014 for ; Fri, 26 Jun 2015 16:29:39 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t5QFTdh7028503 for ; Fri, 26 Jun 2015 16:29:39 +0100 Received: (from smonroy@localhost) by sivswdev02.ir.intel.com with id t5QFTdIc028499 for dev@dpdk.org; Fri, 26 Jun 2015 16:29:39 +0100 From: Sergio Gonzalez Monroy To: dev@dpdk.org Date: Fri, 26 Jun 2015 16:29:36 +0100 Message-Id: <1435332578-28415-8-git-send-email-sergio.gonzalez.monroy@intel.com> X-Mailer: git-send-email 1.8.5.4 In-Reply-To: <1435332578-28415-1-git-send-email-sergio.gonzalez.monroy@intel.com> References: <1433586732-28217-1-git-send-email-sergio.gonzalez.monroy@intel.com> <1435332578-28415-1-git-send-email-sergio.gonzalez.monroy@intel.com> Subject: [dpdk-dev] [PATCH v6 7/9] app/test: rte_memzone_free unit test X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add new unit test for rte_memzone_free API. Signed-off-by: Sergio Gonzalez Monroy --- app/test/test_memzone.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/app/test/test_memzone.c b/app/test/test_memzone.c index 6934eee..c37f950 100644 --- a/app/test/test_memzone.c +++ b/app/test/test_memzone.c @@ -432,7 +432,6 @@ test_memzone_reserve_max(void) printf("Expected size = %zu, actual size = %zu\n", maxlen, mz->len); rte_dump_physmem_layout(stdout); rte_memzone_dump(stdout); - return -1; } return 0; @@ -472,7 +471,6 @@ test_memzone_reserve_max_aligned(void) maxlen, mz->len); rte_dump_physmem_layout(stdout); rte_memzone_dump(stdout); - return -1; } return 0; @@ -684,6 +682,82 @@ test_memzone_bounded(void) } static int +test_memzone_free(void) +{ + const struct rte_memzone *mz[RTE_MAX_MEMZONE]; + int i; + char name[20]; + + mz[0] = rte_memzone_reserve("tempzone0", 2000, SOCKET_ID_ANY, 0); + mz[1] = rte_memzone_reserve("tempzone1", 4000, SOCKET_ID_ANY, 0); + + if (mz[0] > mz[1]) + return -1; + if (!rte_memzone_lookup("tempzone0")) + return -1; + if (!rte_memzone_lookup("tempzone1")) + return -1; + + if (rte_memzone_free(mz[0])) { + printf("Fail memzone free - tempzone0\n"); + return -1; + } + if (rte_memzone_lookup("tempzone0")) { + printf("Found previously free memzone - tempzone0\n"); + return -1; + } + mz[2] = rte_memzone_reserve("tempzone2", 2000, SOCKET_ID_ANY, 0); + + if (mz[2] > mz[1]) { + printf("tempzone2 should have gotten the free entry from tempzone0\n"); + return -1; + } + if (rte_memzone_free(mz[2])) { + printf("Fail memzone free - tempzone2\n"); + return -1; + } + if (rte_memzone_lookup("tempzone2")) { + printf("Found previously free memzone - tempzone2\n"); + return -1; + } + if (rte_memzone_free(mz[1])) { + printf("Fail memzone free - tempzone1\n"); + return -1; + } + if (rte_memzone_lookup("tempzone1")) { + printf("Found previously free memzone - tempzone1\n"); + return -1; + } + + i = 0; + do { + snprintf(name, sizeof(name), "tempzone%u", i); + mz[i] = rte_memzone_reserve(name, 1, SOCKET_ID_ANY, 0); + } while (mz[i++] != NULL); + + if (rte_memzone_free(mz[0])) { + printf("Fail memzone free - tempzone0\n"); + return -1; + } + mz[0] = rte_memzone_reserve("tempzone0new", 0, SOCKET_ID_ANY, 0); + + if (mz[0] == NULL) { + printf("Fail to create memzone - tempzone0new - when MAX memzones were " + "created and one was free\n"); + return -1; + } + + for (i = i - 2; i >= 0; i--) { + if (rte_memzone_free(mz[i])) { + printf("Fail memzone free - tempzone%d\n", i); + return -1; + } + } + + return 0; +} + +static int test_memzone(void) { const struct rte_memzone *memzone1; @@ -763,6 +837,10 @@ test_memzone(void) if (mz != NULL) return -1; + printf("test free memzone\n"); + if (test_memzone_free() < 0) + return -1; + printf("test reserving memzone with bigger size than the maximum\n"); if (test_memzone_reserving_zone_size_bigger_than_the_maximum() < 0) return -1;