From patchwork Fri Dec 21 11:09:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 49228 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CB35A1BD73; Fri, 21 Dec 2018 12:09:26 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 386001BD41 for ; Fri, 21 Dec 2018 12:09:22 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2018 03:09:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,381,1539673200"; d="scan'208";a="304053540" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga006.fm.intel.com with ESMTP; 21 Dec 2018 03:09:20 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBLB9Jvl019011; Fri, 21 Dec 2018 11:09:19 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBLB9Jn5028340; Fri, 21 Dec 2018 11:09:19 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBLB9J19028336; Fri, 21 Dec 2018 11:09:19 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, stephen@networkplumber.org Date: Fri, 21 Dec 2018 11:09:13 +0000 Message-Id: <0521642ca0052bbfb1a8d21033582276c9782717.1545390524.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/4] test/extmem: extend autotest to test without IOVA table 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" Currently, only scenario with valid IOVA table is tested. Fix this by also testing without IOVA table - in these cases, EAL should always return RTE_BAD_IOVA for all memsegs. Signed-off-by: Anatoly Burakov --- test/test/test_external_mem.c | 68 +++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/test/test/test_external_mem.c b/test/test/test_external_mem.c index 6df42e3ae..845c625d6 100644 --- a/test/test/test_external_mem.c +++ b/test/test/test_external_mem.c @@ -42,7 +42,11 @@ check_mem(void *addr, rte_iova_t *iova, size_t pgsz, int n_pages) printf("%s():%i: VA mismatch\n", __func__, __LINE__); return -1; } - if (ms->iova != iova[i]) { + if (iova == NULL && ms->iova != RTE_BAD_IOVA) { + printf("%s():%i: IOVA is not invalid\n", __func__, + __LINE__); + return -1; + } else if (iova != NULL && ms->iova != iova[i]) { printf("%s():%i: IOVA mismatch\n", __func__, __LINE__); return -1; } @@ -218,24 +222,29 @@ test_malloc_invalid_param(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, goto fail; } - /* wrong page count */ - if (rte_malloc_heap_memory_add(valid_name, addr, len, - iova, 0, pgsz) >= 0 || rte_errno != EINVAL) { - printf("%s():%i: Added memory with invalid parameters\n", - __func__, __LINE__); - goto fail; - } - if (rte_malloc_heap_memory_add(valid_name, addr, len, - iova, n_pages - 1, pgsz) >= 0 || rte_errno != EINVAL) { - printf("%s():%i: Added memory with invalid parameters\n", - __func__, __LINE__); - goto fail; - } - if (rte_malloc_heap_memory_add(valid_name, addr, len, - iova, n_pages + 1, pgsz) >= 0 || rte_errno != EINVAL) { - printf("%s():%i: Added memory with invalid parameters\n", - __func__, __LINE__); - goto fail; + /* the following tests are only valid if IOVA table is not NULL */ + if (iova != NULL) { + /* wrong page count */ + if (rte_malloc_heap_memory_add(valid_name, addr, len, + iova, 0, pgsz) >= 0 || rte_errno != EINVAL) { + printf("%s():%i: Added memory with invalid parameters\n", + __func__, __LINE__); + goto fail; + } + if (rte_malloc_heap_memory_add(valid_name, addr, len, + iova, n_pages - 1, pgsz) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Added memory with invalid parameters\n", + __func__, __LINE__); + goto fail; + } + if (rte_malloc_heap_memory_add(valid_name, addr, len, + iova, n_pages + 1, pgsz) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Added memory with invalid parameters\n", + __func__, __LINE__); + goto fail; + } } /* tests passed, destroy heap */ @@ -257,7 +266,7 @@ test_malloc_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, const char *heap_name = "heap"; void *ptr = NULL; int socket_id; - const struct rte_memzone *mz = NULL; + const struct rte_memzone *mz = NULL, *contig_mz = NULL; /* create heap */ if (rte_malloc_heap_create(heap_name) != 0) { @@ -322,12 +331,19 @@ test_malloc_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, goto fail; } + /* try allocating a memzone */ + mz = rte_memzone_reserve("heap_test", pgsz * 2, socket_id, 0); + if (mz == NULL) { + printf("%s():%i: Failed to reserve memzone\n", + __func__, __LINE__); + goto fail; + } /* try allocating an IOVA-contiguous memzone - this should succeed - * because we've set up a contiguous IOVA table. + * if we've set up a contiguous IOVA table, and fail if we haven't. */ - mz = rte_memzone_reserve("heap_test", pgsz * 2, socket_id, + contig_mz = rte_memzone_reserve("heap_test_contig", pgsz * 2, socket_id, RTE_MEMZONE_IOVA_CONTIG); - if (mz == NULL) { + if (iova != NULL && contig_mz == NULL) { printf("%s():%i: Failed to reserve memzone\n", __func__, __LINE__); goto fail; @@ -342,6 +358,8 @@ test_malloc_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, rte_memzone_free(mz); mz = NULL; + rte_memzone_free(contig_mz); + contig_mz = NULL; if (rte_malloc_heap_memory_remove(heap_name, addr, len) != 0) { printf("%s():%i: Removing memory from heap failed\n", @@ -356,6 +374,7 @@ test_malloc_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, return 0; fail: + rte_memzone_free(contig_mz); rte_memzone_free(mz); rte_free(ptr); /* even if something failed, attempt to clean up */ @@ -393,6 +412,9 @@ test_external_mem(void) ret = test_malloc_invalid_param(addr, len, pgsz, iova, n_pages); ret |= test_malloc_basic(addr, len, pgsz, iova, n_pages); + /* when iova table is NULL, everything should still work */ + ret |= test_malloc_invalid_param(addr, len, pgsz, NULL, n_pages); + ret |= test_malloc_basic(addr, len, pgsz, NULL, n_pages); munmap(addr, len);