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 2/2] tests/vc4_mmap: Create test for VC4's Mmap BO IOCTL
Date: Fri, 23 Dec 2022 18:44:37 -0300 [thread overview]
Message-ID: <20221223214433.31547-3-mcanal@igalia.com> (raw)
In-Reply-To: <20221223214433.31547-1-mcanal@igalia.com>
Add two igt_subtests for DRM_IOCTL_VC4_MMAP_BO, which tests the possible
invalid parameters for the IOCTL and also 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_vc4.c | 2 ++
tests/vc4/meson.build | 1 +
tests/vc4/vc4_mmap.c | 55 +++++++++++++++++++++++++++++++++++++++
tests/vc4_ci/vc4.testlist | 2 ++
4 files changed, 60 insertions(+)
create mode 100644 tests/vc4/vc4_mmap.c
diff --git a/lib/igt_vc4.c b/lib/igt_vc4.c
index 91f7f4b5..6b6ad16c 100644
--- a/lib/igt_vc4.c
+++ b/lib/igt_vc4.c
@@ -138,6 +138,8 @@ igt_vc4_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
do_ioctl(fd, DRM_IOCTL_VC4_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/vc4/meson.build b/tests/vc4/meson.build
index 76e6f16c..518f6043 100644
--- a/tests/vc4/meson.build
+++ b/tests/vc4/meson.build
@@ -3,6 +3,7 @@ vc4_progs = [
'vc4_dmabuf_poll',
'vc4_label_bo',
'vc4_lookup_fail',
+ 'vc4_mmap',
'vc4_perfmon',
'vc4_purgeable_bo',
'vc4_tiling',
diff --git a/tests/vc4/vc4_mmap.c b/tests/vc4/vc4_mmap.c
new file mode 100644
index 00000000..8666edf2
--- /dev/null
+++ b/tests/vc4/vc4_mmap.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2022 Igalia S.L.
+ */
+
+#include "igt.h"
+#include "igt_vc4.h"
+
+IGT_TEST_DESCRIPTION("Tests for the VC4's mmap IOCTL");
+
+igt_main
+{
+ int fd;
+
+ igt_fixture {
+ fd = drm_open_driver(DRIVER_VC4);
+ igt_require(igt_vc4_is_v3d(fd));
+ }
+
+ igt_describe("Make sure an invalid BO cannot be mapped.");
+ igt_subtest("mmap-bad-handle") {
+ struct drm_vc4_mmap_bo get = {
+ .handle = 0xd0d0d0d0,
+ };
+ do_ioctl_err(fd, DRM_IOCTL_VC4_MMAP_BO, &get, EINVAL);
+ }
+
+ 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") {
+ int handle = igt_vc4_create_bo(fd, PAGE_SIZE);
+ uint32_t *map = igt_vc4_mmap_bo(fd, handle, PAGE_SIZE, PROT_READ | PROT_WRITE);
+ uint8_t expected[PAGE_SIZE];
+
+
+ /* Testing contents of newly created objects. */
+ memset(expected, 0, sizeof(expected));
+ igt_assert_eq(memcmp(map, expected, sizeof(expected)), 0);
+
+ /* Testing coherency of writes and mmap reads. */
+ memset(map, 0xd0, PAGE_SIZE);
+ memset(expected, 0xd0, PAGE_SIZE);
+ igt_assert_eq(memcmp(expected, map, sizeof(expected)), 0);
+
+ /* Testing that mapping stays after close */
+ gem_close(fd, handle);
+ igt_assert_eq(memcmp(expected, map, sizeof(expected)), 0);
+
+ /* Testing unmapping */
+ munmap(map, PAGE_SIZE);
+ }
+
+ igt_fixture
+ close(fd);
+}
diff --git a/tests/vc4_ci/vc4.testlist b/tests/vc4_ci/vc4.testlist
index 1b41538e..889d0035 100644
--- a/tests/vc4_ci/vc4.testlist
+++ b/tests/vc4_ci/vc4.testlist
@@ -8,6 +8,8 @@ igt@vc4/vc4_label_bo@set-bad-handle
igt@vc4/vc4_label_bo@set-bad-name
igt@vc4/vc4_label_bo@set-kernel-name
igt@vc4/vc4_lookup_fail@bad-color-write
+igt@vc4/vc4_mmap@mmap-bad-handle
+igt@vc4/vc4_mmap@mmap-bo
igt@vc4/vc4_perfmon@create-perfmon-0
igt@vc4/vc4_perfmon@create-perfmon-exceed
igt@vc4/vc4_perfmon@create-perfmon-invalid-events
--
2.38.1
next prev parent 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 ` [igt-dev] [PATCH i-g-t 1/2] tests/v3d_mmap: Improve tests from V3D's Mmap BO IOCTL Maíra Canal
2022-12-23 21:44 ` Maíra Canal [this message]
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-3-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