From: Zack Rusin <zack.rusin@broadcom.com>
To: igt-dev@lists.freedesktop.org
Cc: ian.forbes@broadcom.com, martin.krastev@broadcom.com,
maaz.mombasawala@broadcom.com, kamil.konieczny@linux.intel.com,
Zack Rusin <zack.rusin@broadcom.com>
Subject: [PATCH i-g-t] tests/dumb_buffer: Add subtests for mixing dumb buffers with prime
Date: Fri, 28 Jun 2024 15:03:18 -0400 [thread overview]
Message-ID: <20240628190318.700537-1-zack.rusin@broadcom.com> (raw)
New versions of KWin are extensively using dumb buffers with prime. Add
some basic tests to verify that mixing the dumb buffer interface
with prime ends up with a well formed buffer.
Signed-off-by: Zack Rusin <zack.rusin@broadcom.com>
---
tests/dumb_buffer.c | 94 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/tests/dumb_buffer.c b/tests/dumb_buffer.c
index 8e243459c..62e9b419d 100644
--- a/tests/dumb_buffer.c
+++ b/tests/dumb_buffer.c
@@ -69,6 +69,18 @@
* SUBTEST: map-uaf
*
* SUBTEST: map-valid
+ *
+ * SUBTEST: dmabuf-read
+ * Description: Make a dumb buffer, map it using the dumb buffer interface,
+ * export it via prime, mmap the prime buffer and check
+ * that its contents matches what we wrote to the dumb
+ * buffer.
+ *
+ * SUBTEST: dmabuf-write
+ * Description: Make a dumb buffer, map and write to it using the prime
+ * interface, than map it using the dumb buffer interface
+ * and check whether its contents matches what we wrote using
+ * the prime interface.
*/
IGT_TEST_DESCRIPTION("This is a test for the generic dumb buffer interface.");
@@ -388,6 +400,82 @@ static void always_clear(int fd, int timeout)
igt_info("Checked %'lu page allocations\n", checked);
}
+static const uint32_t pattern[] = {
+ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff,
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000,
+ 0x00ffff00, 0xff0000ff, 0x00ff00ff, 0xff00ff00,
+ 0xff0000ff, 0x00ff00ff, 0x00ffff00, 0xff00ff00
+};
+
+static void dmabuf_read(int fd)
+{
+ struct drm_mode_create_dumb create = {
+ .width = 64,
+ .height = 64,
+ .bpp = 32,
+ };
+ int dma_buf_fd;
+ uint32_t *ptr;
+
+ dumb_create(fd, &create);
+ ptr = dumb_map(fd, create.handle, create.size, PROT_WRITE);
+ igt_assert(ptr != MAP_FAILED);
+ igt_assert(ptr != NULL);
+ igt_assert(create.size > sizeof(pattern));
+ memcpy(ptr, pattern, sizeof(pattern));
+ munmap(ptr, create.size);
+
+ dma_buf_fd = prime_handle_to_fd_for_mmap(fd, create.handle);
+
+ /* Skip if DRM_RDWR is not supported */
+ igt_skip_on(errno == EINVAL);
+
+ ptr = mmap(NULL, create.size, PROT_READ | PROT_WRITE, MAP_SHARED, dma_buf_fd, 0);
+ igt_assert(ptr != MAP_FAILED);
+
+ /* Check pattern correctness */
+ igt_assert(memcmp(ptr, pattern, sizeof(pattern)) == 0);
+
+ munmap(ptr, create.size);
+ close(dma_buf_fd);
+
+ dumb_destroy(fd, create.handle);
+}
+
+static void dmabuf_write(int fd)
+{
+ struct drm_mode_create_dumb create = {
+ .width = 64,
+ .height = 64,
+ .bpp = 32,
+ };
+ int dma_buf_fd;
+ uint32_t *ptr;
+
+ dumb_create(fd, &create);
+
+ dma_buf_fd = prime_handle_to_fd_for_mmap(fd, create.handle);
+ /* Skip if DRM_RDWR is not supported */
+ igt_skip_on(errno == EINVAL);
+
+ ptr = mmap(NULL, create.size, PROT_READ | PROT_WRITE, MAP_SHARED, dma_buf_fd, 0);
+ igt_assert(ptr != MAP_FAILED);
+ memcpy(ptr, pattern, sizeof(pattern));
+ munmap(ptr, create.size);
+
+
+ ptr = dumb_map(fd, create.handle, create.size, PROT_READ);
+ igt_assert(ptr != MAP_FAILED);
+ igt_assert(ptr != NULL);
+ igt_assert(create.size > sizeof(pattern));
+ igt_assert(memcmp(ptr, pattern, sizeof(pattern)) == 0);
+ munmap(ptr, create.size);
+
+ close(dma_buf_fd);
+
+ dumb_destroy(fd, create.handle);
+}
+
igt_main
{
int fd = -1;
@@ -414,6 +502,12 @@ igt_main
igt_subtest("create-clear")
always_clear(fd, 30);
+ igt_subtest("dmabuf-read")
+ dmabuf_read(fd);
+
+ igt_subtest("dmabuf-write")
+ dmabuf_write(fd);
+
igt_fixture {
drm_close_driver(fd);
}
--
2.40.1
next reply other threads:[~2024-06-28 19:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 19:03 Zack Rusin [this message]
2024-06-28 19:48 ` ✗ GitLab.Pipeline: warning for tests/dumb_buffer: Add subtests for mixing dumb buffers with prime Patchwork
2024-06-28 20:02 ` ✓ CI.xeBAT: success " Patchwork
2024-06-28 20:11 ` ✗ Fi.CI.BAT: failure " Patchwork
2024-06-28 21:24 ` ✓ CI.xeFULL: success " Patchwork
2024-07-26 19:21 ` [PATCH i-g-t] " Kamil Konieczny
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=20240628190318.700537-1-zack.rusin@broadcom.com \
--to=zack.rusin@broadcom.com \
--cc=ian.forbes@broadcom.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=maaz.mombasawala@broadcom.com \
--cc=martin.krastev@broadcom.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