[PATCH i-g-t 5/5] tests/dumb_buffer: Add subtests for mixing dumb buffers with prime

Kamil Konieczny kamil.konieczny at linux.intel.com
Fri Jun 28 16:02:57 UTC 2024


Hi Zack,
On 2024-06-27 at 15:56:15 -0400, Zack Rusin wrote:
> 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 at broadcom.com>
> ---
>  tests/dumb_buffer.c | 96 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 96 insertions(+)
> 

This seems unrelated to your series, please send it in separate
one. Few more nits below.

> diff --git a/tests/dumb_buffer.c b/tests/dumb_buffer.c
> index 8e243459c..0651f5d83 100644
> --- a/tests/dumb_buffer.c
> +++ b/tests/dumb_buffer.c
> @@ -69,6 +69,20 @@
>   * 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.
> + * Functionality: dumb_buffers, prime, dmabuf, mmap
----- ^
Do you need it here?

> + *
> + * 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.
> + * Functionality: dumb_buffers, prime, dmabuf, mmap
----- ^
Same here.

Regards,
Kamil

>   */
>  
>  IGT_TEST_DESCRIPTION("This is a test for the generic dumb buffer interface.");
> @@ -388,6 +402,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 +504,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
> 


More information about the igt-dev mailing list