[PATCH 3/4] selftests/bpf: Add test for dmabuf_iter
Song Liu
song at kernel.org
Mon Apr 21 18:08:27 UTC 2025
On Mon, Apr 14, 2025 at 3:53 PM T.J. Mercier <tjmercier at google.com> wrote:
>
> This test creates a udmabuf and uses a BPF program that prints dmabuf
> metadata with the new dmabuf_iter to verify it can be found.
>
> Signed-off-by: T.J. Mercier <tjmercier at google.com>
> ---
[...]
> +
> +
> +static void subtest_dmabuf_iter_check_udmabuf(struct dmabuf_iter *skel)
> +{
> + static const char test_buffer_name[] = "udmabuf_test_buffer_for_iter";
> + const size_t test_buffer_size = 10 * getpagesize();
> +
> + ASSERT_LE(sizeof(test_buffer_name), DMA_BUF_NAME_LEN, "NAMETOOLONG");
> +
> + int memfd = memfd_create("memfd_test", MFD_ALLOW_SEALING);
> + ASSERT_OK_FD(memfd, "memfd_create");
Please do not mix variable declaration with the rest of the code. Also,
please run checkpatch.pl on the patches. I see a few warnings.
> +
> + ASSERT_OK(ftruncate(memfd, test_buffer_size), "ftruncate");
> +
> + ASSERT_OK(fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK), "seal");
> +
> + int dev_udmabuf = open("/dev/udmabuf", O_RDONLY);
> + ASSERT_OK_FD(dev_udmabuf, "open udmabuf");
> +
[...]
> +
> + ASSERT_TRUE(found_test_udmabuf, "found_test_buffer");
> +
> + free(line);
> + fclose(iter_file);
> + close(iter_fd);
> + close(udmabuf);
> + close(memfd);
> +}
> +
> +void test_dmabuf_iter(void)
> +{
> + struct dmabuf_iter *skel = NULL;
> + char buf[256];
> + int iter_fd;
> +
> + skel = dmabuf_iter__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "dmabuf_iter__open_and_load"))
> + return;
> +
> + if (!ASSERT_OK(dmabuf_iter__attach(skel), "skel_attach"))
> + goto destroy;
> +
> + iter_fd = bpf_iter_create(bpf_link__fd(skel->links.dmabuf_collector));
> + if (!ASSERT_GE(iter_fd, 0, "iter_create"))
Use ASSERT_OK_FD here?
> + goto destroy;
> +
> + memset(buf, 0, sizeof(buf));
> + while (read(iter_fd, buf, sizeof(buf) > 0)) {
> + /* Read out all contents */
> + }
> +
[...]
More information about the dri-devel
mailing list