From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id F113329C6 for ; Fri, 21 Dec 2018 12:09:21 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.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="109120415" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga007.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 wBLB9Jqu019006; 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 wBLB9JWY028333; Fri, 21 Dec 2018 11:09:19 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBLB9FPr028325; Fri, 21 Dec 2018 11:09:15 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, stephen@networkplumber.org Date: Fri, 21 Dec 2018 11:09:12 +0000 Message-Id: X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions 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:22 -0000 We will be adding a new extmem test that will behave roughly similar to already existing, so clarify function names to distinguish between these tests, as well as factor out the common parts. Signed-off-by: Anatoly Burakov --- test/test/test_external_mem.c | 62 +++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/test/test/test_external_mem.c b/test/test/test_external_mem.c index 998cafa68..6df42e3ae 100644 --- a/test/test/test_external_mem.c +++ b/test/test/test_external_mem.c @@ -23,7 +23,35 @@ #define EXTERNAL_MEM_SZ (RTE_PGSIZE_4K << 10) /* 4M of data */ static int -test_invalid_param(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, +check_mem(void *addr, rte_iova_t *iova, size_t pgsz, int n_pages) +{ + int i; + + /* check that we can get this memory from EAL now */ + for (i = 0; i < n_pages; i++) { + const struct rte_memseg *ms; + void *cur = RTE_PTR_ADD(addr, pgsz * i); + + ms = rte_mem_virt2memseg(cur, NULL); + if (ms == NULL) { + printf("%s():%i: Failed to retrieve memseg for external mem\n", + __func__, __LINE__); + return -1; + } + if (ms->addr != cur) { + printf("%s():%i: VA mismatch\n", __func__, __LINE__); + return -1; + } + if (ms->iova != iova[i]) { + printf("%s():%i: IOVA mismatch\n", __func__, __LINE__); + return -1; + } + } + return 0; +} + +static int +test_malloc_invalid_param(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, int n_pages) { static const char * const names[] = { @@ -223,11 +251,12 @@ test_invalid_param(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, } static int -test_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, int n_pages) +test_malloc_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, + int n_pages) { const char *heap_name = "heap"; void *ptr = NULL; - int socket_id, i; + int socket_id; const struct rte_memzone *mz = NULL; /* create heap */ @@ -261,26 +290,9 @@ test_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova, int n_pages) goto fail; } - /* check that we can get this memory from EAL now */ - for (i = 0; i < n_pages; i++) { - const struct rte_memseg *ms; - void *cur = RTE_PTR_ADD(addr, pgsz * i); - - ms = rte_mem_virt2memseg(cur, NULL); - if (ms == NULL) { - printf("%s():%i: Failed to retrieve memseg for external mem\n", - __func__, __LINE__); - goto fail; - } - if (ms->addr != cur) { - printf("%s():%i: VA mismatch\n", __func__, __LINE__); - goto fail; - } - if (ms->iova != iova[i]) { - printf("%s():%i: IOVA mismatch\n", __func__, __LINE__); - goto fail; - } - } + /* check if memory is accessible from EAL */ + if (check_mem(addr, iova, pgsz, n_pages) < 0) + goto fail; /* allocate - this now should succeed */ ptr = rte_malloc_socket("EXTMEM", 64, 0, socket_id); @@ -379,8 +391,8 @@ test_external_mem(void) iova[i] = tmp; } - ret = test_invalid_param(addr, len, pgsz, iova, n_pages); - ret |= test_basic(addr, len, pgsz, iova, n_pages); + ret = test_malloc_invalid_param(addr, len, pgsz, iova, n_pages); + ret |= test_malloc_basic(addr, len, pgsz, iova, n_pages); munmap(addr, len); -- 2.17.1