DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, stephen@networkplumber.org
Subject: [dpdk-dev] [PATCH 4/4] test/extmem: extend test to cover non-heap API
Date: Fri, 21 Dec 2018 11:09:15 +0000	[thread overview]
Message-ID: <740fcadac150c128f62cc2761dfe00fd10c90990.1545390524.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <c822e5e21620d0fa4b2930d9e89bce44e80eac73.1545390524.git.anatoly.burakov@intel.com>
In-Reply-To: <c822e5e21620d0fa4b2930d9e89bce44e80eac73.1545390524.git.anatoly.burakov@intel.com>

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

  parent reply	other threads:[~2018-12-21 11:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=740fcadac150c128f62cc2761dfe00fd10c90990.1545390524.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).