DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions
@ 2018-12-21 11:09 Anatoly Burakov
  2018-12-21 11:09 ` [dpdk-dev] [PATCH 2/4] test/extmem: extend autotest to test without IOVA table Anatoly Burakov
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:09 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

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 <anatoly.burakov@intel.com>
---
 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH 2/4] test/extmem: extend autotest to test without IOVA table
  2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
@ 2018-12-21 11:09 ` Anatoly Burakov
  2018-12-21 11:09 ` [dpdk-dev] [PATCH 3/4] test/extmem: check if memseg list is external Anatoly Burakov
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:09 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

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 <anatoly.burakov@intel.com>
---
 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);
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH 3/4] test/extmem: check if memseg list is external
  2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
  2018-12-21 11:09 ` [dpdk-dev] [PATCH 2/4] test/extmem: extend autotest to test without IOVA table Anatoly Burakov
@ 2018-12-21 11:09 ` Anatoly Burakov
  2018-12-21 11:09 ` [dpdk-dev] [PATCH 4/4] test/extmem: extend test to cover non-heap API Anatoly Burakov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:09 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

Extend the extmem autotest to check whether the memseg lists for
externally allocated memory are always marked as external.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 test/test/test_external_mem.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/test/test/test_external_mem.c b/test/test/test_external_mem.c
index 845c625d6..5557f6e3f 100644
--- a/test/test/test_external_mem.c
+++ b/test/test/test_external_mem.c
@@ -13,6 +13,7 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_malloc.h>
 #include <rte_ring.h>
@@ -29,10 +30,18 @@ check_mem(void *addr, rte_iova_t *iova, size_t pgsz, int n_pages)
 
 	/* check that we can get this memory from EAL now */
 	for (i = 0; i < n_pages; i++) {
+		const struct rte_memseg_list *msl;
 		const struct rte_memseg *ms;
 		void *cur = RTE_PTR_ADD(addr, pgsz * i);
 
-		ms = rte_mem_virt2memseg(cur, NULL);
+		msl = rte_mem_virt2memseg_list(cur);
+		if (!msl->external) {
+			printf("%s():%i: Memseg list is not marked as external\n",
+				__func__, __LINE__);
+			return -1;
+		}
+
+		ms = rte_mem_virt2memseg(cur, msl);
 		if (ms == NULL) {
 			printf("%s():%i: Failed to retrieve memseg for external mem\n",
 				__func__, __LINE__);
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH 4/4] test/extmem: extend test to cover non-heap API
  2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
  2018-12-21 11:09 ` [dpdk-dev] [PATCH 2/4] test/extmem: extend autotest to test without IOVA table Anatoly Burakov
  2018-12-21 11:09 ` [dpdk-dev] [PATCH 3/4] test/extmem: check if memseg list is external Anatoly Burakov
@ 2018-12-21 11:09 ` Anatoly Burakov
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:09 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

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 <anatoly.burakov@intel.com>
---
 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v2 1/4] test/extmem: refactor and rename test functions
  2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
                   ` (2 preceding siblings ...)
  2018-12-21 11:09 ` [dpdk-dev] [PATCH 4/4] test/extmem: extend test to cover non-heap API Anatoly Burakov
@ 2018-12-21 11:29 ` Anatoly Burakov
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 2/4] test/extmem: extend autotest to test without IOVA table Anatoly Burakov
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:29 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

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 <anatoly.burakov@intel.com>
---
 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v2 2/4] test/extmem: extend autotest to test without IOVA table
  2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
                   ` (3 preceding siblings ...)
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
@ 2018-12-21 11:29 ` Anatoly Burakov
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 3/4] test/extmem: check if memseg list is external Anatoly Burakov
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 4/4] test/extmem: extend test to cover non-heap API Anatoly Burakov
  6 siblings, 0 replies; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:29 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

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, and contiguous memzone
allocation should fail.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---

Notes:
    v2:
    - Improve condition checking on contiguous memzone test
    - Clarify commit message

 test/test/test_external_mem.c | 66 +++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 23 deletions(-)

diff --git a/test/test/test_external_mem.c b/test/test/test_external_mem.c
index 6df42e3ae..06e6ccc1d 100644
--- a/test/test/test_external_mem.c
+++ b/test/test/test_external_mem.c
@@ -31,6 +31,7 @@ check_mem(void *addr, rte_iova_t *iova, size_t pgsz, int n_pages)
 	for (i = 0; i < n_pages; i++) {
 		const struct rte_memseg *ms;
 		void *cur = RTE_PTR_ADD(addr, pgsz * i);
+		rte_iova_t expected_iova;
 
 		ms = rte_mem_virt2memseg(cur, NULL);
 		if (ms == NULL) {
@@ -42,7 +43,8 @@ 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]) {
+		expected_iova = (iova == NULL) ? RTE_BAD_IOVA : iova[i];
+		if (ms->iova != expected_iova) {
 			printf("%s():%i: IOVA mismatch\n", __func__, __LINE__);
 			return -1;
 		}
@@ -218,24 +220,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 +264,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 +329,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 +356,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 +372,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 +410,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);
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v2 3/4] test/extmem: check if memseg list is external
  2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
                   ` (4 preceding siblings ...)
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 2/4] test/extmem: extend autotest to test without IOVA table Anatoly Burakov
@ 2018-12-21 11:29 ` Anatoly Burakov
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 4/4] test/extmem: extend test to cover non-heap API Anatoly Burakov
  6 siblings, 0 replies; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:29 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

Extend the extmem autotest to check whether the memseg lists for
externally allocated memory are always marked as external.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 test/test/test_external_mem.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/test/test/test_external_mem.c b/test/test/test_external_mem.c
index 06e6ccc1d..b877f8e2e 100644
--- a/test/test/test_external_mem.c
+++ b/test/test/test_external_mem.c
@@ -13,6 +13,7 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <rte_eal_memconfig.h>
 #include <rte_errno.h>
 #include <rte_malloc.h>
 #include <rte_ring.h>
@@ -29,11 +30,19 @@ check_mem(void *addr, rte_iova_t *iova, size_t pgsz, int n_pages)
 
 	/* check that we can get this memory from EAL now */
 	for (i = 0; i < n_pages; i++) {
+		const struct rte_memseg_list *msl;
 		const struct rte_memseg *ms;
 		void *cur = RTE_PTR_ADD(addr, pgsz * i);
 		rte_iova_t expected_iova;
 
-		ms = rte_mem_virt2memseg(cur, NULL);
+		msl = rte_mem_virt2memseg_list(cur);
+		if (!msl->external) {
+			printf("%s():%i: Memseg list is not marked as external\n",
+				__func__, __LINE__);
+			return -1;
+		}
+
+		ms = rte_mem_virt2memseg(cur, msl);
 		if (ms == NULL) {
 			printf("%s():%i: Failed to retrieve memseg for external mem\n",
 				__func__, __LINE__);
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v2 4/4] test/extmem: extend test to cover non-heap API
  2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
                   ` (5 preceding siblings ...)
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 3/4] test/extmem: check if memseg list is external Anatoly Burakov
@ 2018-12-21 11:29 ` Anatoly Burakov
  2018-12-21 15:19   ` Thomas Monjalon
  6 siblings, 1 reply; 9+ messages in thread
From: Anatoly Burakov @ 2018-12-21 11:29 UTC (permalink / raw)
  To: dev; +Cc: thomas, stephen

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 <anatoly.burakov@intel.com>
---
 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 b877f8e2e..97bde1cfb 100644
--- a/test/test/test_external_mem.c
+++ b/test/test/test_external_mem.c
@@ -391,6 +391,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)
@@ -417,12 +555,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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v2 4/4] test/extmem: extend test to cover non-heap API
  2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 4/4] test/extmem: extend test to cover non-heap API Anatoly Burakov
@ 2018-12-21 15:19   ` Thomas Monjalon
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2018-12-21 15:19 UTC (permalink / raw)
  To: Anatoly Burakov; +Cc: dev, stephen

21/12/2018 12:29, Anatoly Burakov:
> 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 <anatoly.burakov@intel.com>

Series applied, thanks

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-12-21 15:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-21 11:09 [dpdk-dev] [PATCH 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
2018-12-21 11:09 ` [dpdk-dev] [PATCH 2/4] test/extmem: extend autotest to test without IOVA table Anatoly Burakov
2018-12-21 11:09 ` [dpdk-dev] [PATCH 3/4] test/extmem: check if memseg list is external Anatoly Burakov
2018-12-21 11:09 ` [dpdk-dev] [PATCH 4/4] test/extmem: extend test to cover non-heap API Anatoly Burakov
2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 1/4] test/extmem: refactor and rename test functions Anatoly Burakov
2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 2/4] test/extmem: extend autotest to test without IOVA table Anatoly Burakov
2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 3/4] test/extmem: check if memseg list is external Anatoly Burakov
2018-12-21 11:29 ` [dpdk-dev] [PATCH v2 4/4] test/extmem: extend test to cover non-heap API Anatoly Burakov
2018-12-21 15:19   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).