public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Maíra Canal" <mcanal@igalia.com>
To: "Melissa Wen" <mwen@igalia.com>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Emma Anholt" <emma@anholt.net>,
	"Maxime Ripard" <maxime@cerno.tech>
Cc: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 1/2] tests/v3d_mmap: Improve tests from V3D's Mmap BO IOCTL
Date: Fri, 23 Dec 2022 18:44:35 -0300	[thread overview]
Message-ID: <20221223214433.31547-2-mcanal@igalia.com> (raw)
In-Reply-To: <20221223214433.31547-1-mcanal@igalia.com>

The current tests for the V3D's Mmap IOCTL don't cover all the
possible invalid parameters on drm_v3d_mmap_bo. Therefore, add a
subtest to make sure that flags on drm_v3d_mmap_bo is zero and also
add a subtest to test the read/write coherency of a newly mapped bo.
Moreover, also adds a check to assure that the mmap's offset is a
multiple of the page size as returned by sysconf(_SC_PAGE_SIZE).

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 lib/igt_v3d.c             |  2 ++
 tests/v3d/v3d_mmap.c      | 34 ++++++++++++++++++++++++++++++++++
 tests/v3d_ci/v3d.testlist |  2 ++
 3 files changed, 38 insertions(+)

diff --git a/lib/igt_v3d.c b/lib/igt_v3d.c
index 5aa583da..68d11d7f 100644
--- a/lib/igt_v3d.c
+++ b/lib/igt_v3d.c
@@ -108,6 +108,8 @@ igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
 
 	do_ioctl(fd, DRM_IOCTL_V3D_MMAP_BO, &mmap_bo);
 
+	igt_assert_eq(mmap_bo.offset % sysconf(_SC_PAGE_SIZE), 0);
+
 	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset);
 	if (ptr == MAP_FAILED)
 		return NULL;
diff --git a/tests/v3d/v3d_mmap.c b/tests/v3d/v3d_mmap.c
index 5e2385bd..8c822663 100644
--- a/tests/v3d/v3d_mmap.c
+++ b/tests/v3d/v3d_mmap.c
@@ -33,6 +33,14 @@ igt_main
 	igt_fixture
 		fd = drm_open_driver(DRIVER_V3D);
 
+	igt_describe("Make sure that flags is equal to zero.");
+	igt_subtest("mmap-bad-flags") {
+		struct drm_v3d_mmap_bo get = {
+			.flags = 1,
+		};
+		do_ioctl_err(fd, DRM_IOCTL_V3D_MMAP_BO, &get, EINVAL);
+	}
+
 	igt_describe("Make sure an invalid BO cannot be mapped.");
 	igt_subtest("mmap-bad-handle") {
 		struct drm_v3d_mmap_bo get = {
@@ -41,6 +49,32 @@ igt_main
 		do_ioctl_err(fd, DRM_IOCTL_V3D_MMAP_BO, &get, ENOENT);
 	}
 
+	igt_describe("Test basics of newly mapped bo like default content, write and read "
+		     "coherency, mapping existence after gem_close and unmapping.");
+	igt_subtest("mmap-bo") {
+		struct v3d_bo *bo = igt_v3d_create_bo(fd, PAGE_SIZE);
+		uint8_t expected[PAGE_SIZE];
+
+		igt_v3d_bo_mmap(fd, bo);
+
+		/* Testing contents of newly created objects. */
+		memset(expected, 0, sizeof(expected));
+		igt_assert_eq(memcmp(bo->map, expected, sizeof(expected)), 0);
+
+		/* Testing coherency of writes and mmap reads. */
+		memset(bo->map, 0xd0, PAGE_SIZE);
+		memset(expected, 0xd0, PAGE_SIZE);
+		igt_assert_eq(memcmp(expected, bo->map, sizeof(expected)), 0);
+
+		/* Testing that mapping stays after close */
+		gem_close(fd, bo->handle);
+		igt_assert_eq(memcmp(expected, bo->map, sizeof(expected)), 0);
+
+		/* Testing unmapping */
+		munmap(bo->map, PAGE_SIZE);
+		free(bo);
+	}
+
 	igt_fixture
 		close(fd);
 }
diff --git a/tests/v3d_ci/v3d.testlist b/tests/v3d_ci/v3d.testlist
index 64359fb7..ce8c4f6c 100644
--- a/tests/v3d_ci/v3d.testlist
+++ b/tests/v3d_ci/v3d.testlist
@@ -7,7 +7,9 @@ igt@v3d/v3d_get_bo_offset@get-bad-handle
 igt@v3d/v3d_get_param@base-params
 igt@v3d/v3d_get_param@get-bad-param
 igt@v3d/v3d_get_param@get-bad-flags
+igt@v3d/v3d_mmap@mmap-bad-flags
 igt@v3d/v3d_mmap@mmap-bad-handle
+igt@v3d/v3d_mmap@mmap-bo
 igt@v3d/v3d_perfmon@create-perfmon-0
 igt@v3d/v3d_perfmon@create-perfmon-exceed
 igt@v3d/v3d_perfmon@create-perfmon-invalid-counters
-- 
2.38.1

  reply	other threads:[~2022-12-23 21:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-23 21:44 [igt-dev] [PATCH i-g-t 0/2] Tests for V3D/VC4 Mmap BO IOCTLs Maíra Canal
2022-12-23 21:44 ` Maíra Canal [this message]
2022-12-23 21:44 ` [igt-dev] [PATCH i-g-t 2/2] tests/vc4_mmap: Create test for VC4's Mmap BO IOCTL Maíra Canal
2022-12-23 22:34 ` [igt-dev] ✓ Fi.CI.BAT: success for Tests for V3D/VC4 Mmap BO IOCTLs Patchwork
2022-12-23 23:47 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2022-12-28 22:01 ` [igt-dev] [PATCH i-g-t 0/2] " Melissa Wen

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=20221223214433.31547-2-mcanal@igalia.com \
    --to=mcanal@igalia.com \
    --cc=andrealmeid@igalia.com \
    --cc=emma@anholt.net \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=maxime@cerno.tech \
    --cc=mwen@igalia.com \
    /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