From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id ECCA01BD41 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 orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2018 03:09:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,381,1539673200"; d="scan'208";a="100475690" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga007.jf.intel.com with ESMTP; 21 Dec 2018 03:09:21 -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 wBLB9Kmu019017; Fri, 21 Dec 2018 11:09:20 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBLB9K4w028354; Fri, 21 Dec 2018 11:09:20 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBLB9K8N028350; Fri, 21 Dec 2018 11:09:20 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, stephen@networkplumber.org Date: Fri, 21 Dec 2018 11:09:15 +0000 Message-Id: <740fcadac150c128f62cc2761dfe00fd10c90990.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 4/4] test/extmem: extend test to cover non-heap API 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, 21 Dec 2018 11:09:23 -0000 Currently, extmem autotest only covers the external malloc heap API. Extend it to also cover the non-heap, register/unregister external memory API. Signed-off-by: Anatoly Burakov --- test/test/test_external_mem.c | 146 ++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/test/test/test_external_mem.c b/test/test/test_external_mem.c index 5557f6e3f..e1abce104 100644 --- a/test/test/test_external_mem.c +++ b/test/test/test_external_mem.c @@ -393,6 +393,144 @@ test_malloc_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, return -1; } +static int +test_extmem_invalid_param(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, + int n_pages) +{ + /* these calls may fail for other reasons, so check errno */ + if (rte_extmem_unregister(addr, len) >= 0 || + rte_errno != ENOENT) { + printf("%s():%i: Unregistered non-existent memory\n", + __func__, __LINE__); + return -1; + } + + if (rte_extmem_attach(addr, len) >= 0 || + rte_errno != ENOENT) { + printf("%s():%i: Attached to non-existent memory\n", + __func__, __LINE__); + return -1; + } + if (rte_extmem_attach(addr, len) >= 0 || + rte_errno != ENOENT) { + printf("%s():%i: Detached from non-existent memory\n", + __func__, __LINE__); + return -1; + } + + /* zero length */ + if (rte_extmem_register(addr, 0, NULL, 0, pgsz) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Registered memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + + if (rte_extmem_unregister(addr, 0) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Unregistered memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + + if (rte_extmem_attach(addr, 0) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Attached memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + if (rte_extmem_attach(addr, 0) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Detached memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + + /* zero address */ + if (rte_extmem_register(NULL, len, NULL, 0, pgsz) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Registered memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + + if (rte_extmem_unregister(NULL, len) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Unregistered memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + + if (rte_extmem_attach(NULL, len) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Attached memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + if (rte_extmem_attach(NULL, len) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Detached memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + + /* the following tests are only valid if IOVA table is not NULL */ + if (iova != NULL) { + /* wrong page count */ + if (rte_extmem_register(addr, len, + iova, 0, pgsz) >= 0 || rte_errno != EINVAL) { + printf("%s():%i: Registered memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + if (rte_extmem_register(addr, len, + iova, n_pages - 1, pgsz) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Registered memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + if (rte_extmem_register(addr, len, + iova, n_pages + 1, pgsz) >= 0 || + rte_errno != EINVAL) { + printf("%s():%i: Registered memory with invalid parameters\n", + __func__, __LINE__); + return -1; + } + } + + return 0; +} + +static int +test_extmem_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, + int n_pages) +{ + /* register memory */ + if (rte_extmem_register(addr, len, iova, n_pages, pgsz) != 0) { + printf("%s():%i: Failed to register memory\n", + __func__, __LINE__); + goto fail; + } + + /* check if memory is accessible from EAL */ + if (check_mem(addr, iova, pgsz, n_pages) < 0) + goto fail; + + if (rte_extmem_unregister(addr, len) != 0) { + printf("%s():%i: Removing memory from heap failed\n", + __func__, __LINE__); + goto fail; + } + + return 0; +fail: + /* even if something failed, attempt to clean up */ + rte_extmem_unregister(addr, len); + + return -1; +} + /* we need to test attach/detach in secondary processes. */ static int test_external_mem(void) @@ -419,12 +557,20 @@ test_external_mem(void) iova[i] = tmp; } + /* test external heap memory */ 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); + /* test non-heap memory */ + ret |= test_extmem_invalid_param(addr, len, pgsz, iova, n_pages); + ret |= test_extmem_basic(addr, len, pgsz, iova, n_pages); + /* when iova table is NULL, everything should still work */ + ret |= test_extmem_invalid_param(addr, len, pgsz, NULL, n_pages); + ret |= test_extmem_basic(addr, len, pgsz, NULL, n_pages); + munmap(addr, len); return ret; -- 2.17.1