[PATCH i-g-t v5 07/10] tests/imagination: Add VM_CONTEXT tests
Robert Mazur <[email protected]> Tue, 28 Jul 2026 09:19:02 +0200
| Newsgroups | org.freedesktop.lists.igt-dev |
|---|---|
| Message-ID | <20260728-test-imagination-add-support-v5-7-33049f0d1937@imgtec.com> |
From: Donald Robson <[email protected]> Add subtests for VM context create and destroy ioctls, including invalid padding and bad handle error paths. Signed-off-by: Donald Robson <[email protected]> Signed-off-by: Robert Mazur <[email protected]> --- lib/igt_pvr.c | 43 +++++++++++++++++++++ lib/igt_pvr.h | 3 ++ tests/imagination/meson.build | 1 + tests/imagination/pvr_vm_context.c | 78 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) diff --git a/lib/igt_pvr.c b/lib/igt_pvr.c index c1e68aef1..d9f620141 100644 --- a/lib/igt_pvr.c +++ b/lib/igt_pvr.c @@ -164,3 +164,46 @@ igt_pvr_get_static_data_areas(int fd, uint32_t *array_len_out) return sdas; } + +/** + * igt_pvr_ioctl_create_vm_context: + * @fd: The file descriptor of the DRM device. + * @expect_err: Expected error code, or 0 if no error is expected. + * + * Function to create a VM context. + * + * Returns: The handle of the created VM context. + */ +uint32_t igt_pvr_ioctl_create_vm_context(int fd, int expect_err) +{ + struct drm_pvr_ioctl_create_vm_context_args args = {0}; + + if (expect_err) + do_ioctl_err(fd, DRM_IOCTL_PVR_CREATE_VM_CONTEXT, &args, + expect_err); + else + do_ioctl(fd, DRM_IOCTL_PVR_CREATE_VM_CONTEXT, &args); + + return args.handle; +} + +/** + * igt_pvr_ioctl_destroy_vm_context: + * @fd: The file descriptor of the DRM device. + * @handle: The handle of the VM context to destroy. + * @expect_err: Expected error code, or 0 if no error is expected. + * + * Function to destroy a VM context. + */ +void igt_pvr_ioctl_destroy_vm_context(int fd, uint32_t handle, int expect_err) +{ + struct drm_pvr_ioctl_destroy_vm_context_args args = { + .handle = handle, + }; + + if (expect_err) + do_ioctl_err(fd, DRM_IOCTL_PVR_DESTROY_VM_CONTEXT, &args, + expect_err); + else + do_ioctl(fd, DRM_IOCTL_PVR_DESTROY_VM_CONTEXT, &args); +} diff --git a/lib/igt_pvr.h b/lib/igt_pvr.h index 19909480b..871c8a48e 100644 --- a/lib/igt_pvr.h +++ b/lib/igt_pvr.h @@ -21,4 +21,7 @@ igt_pvr_get_heap_info(int fd, uint32_t *array_len_out); struct drm_pvr_static_data_area * igt_pvr_get_static_data_areas(int fd, uint32_t *array_len_out); +uint32_t igt_pvr_ioctl_create_vm_context(int fd, int expect_err); +void igt_pvr_ioctl_destroy_vm_context(int fd, uint32_t handle, int expect_err); + #endif /* IGT_PVR_H */ diff --git a/tests/imagination/meson.build b/tests/imagination/meson.build index fc24d0220..ffacce1fb 100644 --- a/tests/imagination/meson.build +++ b/tests/imagination/meson.build @@ -2,6 +2,7 @@ pvr_progs = [ 'pvr_dev_query', 'pvr_gem', 'pvr_gpu_info', 'pvr_heap_info', + 'pvr_vm_context', ] pvr_deps = test_deps diff --git a/tests/imagination/pvr_vm_context.c b/tests/imagination/pvr_vm_context.c new file mode 100644 index 000000000..a41c39aff --- /dev/null +++ b/tests/imagination/pvr_vm_context.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0 or MIT +/* Copyright (c) 2026 Imagination Technologies Ltd. All Rights Reserved */ + +#include <errno.h> +#include <stddef.h> +#include <stdint.h> +#include <unistd.h> + +#include "igt.h" +#include "igt_pvr.h" + +#include "pvr_drm.h" + +int igt_main() +{ + int fd; + + igt_fixture() + { + fd = drm_open_driver(DRIVER_POWERVR); + } + + igt_describe("Test valid VM context creation and destruction"); + igt_subtest("create-and-destroy-vm-ctx") + { + const uint32_t handle = igt_pvr_ioctl_create_vm_context(fd, 0); + + igt_pvr_ioctl_destroy_vm_context(fd, handle, 0); + } + + igt_describe("Test VM context creation with bad padding"); + igt_subtest("create-vm-ctx-bad-padding") + { + struct drm_pvr_ioctl_create_vm_context_args args = { + ._padding_4 = 1, + }; + + do_ioctl_err(fd, DRM_IOCTL_PVR_CREATE_VM_CONTEXT, &args, EINVAL); + } + + igt_describe("Test VM context destruction with bad padding"); + igt_subtest("destroy-vm-ctx-bad-padding") + { + struct drm_pvr_ioctl_destroy_vm_context_args args = { + ._padding_4 = 1, + }; + + do_ioctl_err(fd, DRM_IOCTL_PVR_DESTROY_VM_CONTEXT, &args, EINVAL); + } + + igt_describe("Test VM context destruction with bad handle"); + igt_subtest("destroy-vm-ctx-bad-handle") + { + struct drm_pvr_ioctl_destroy_vm_context_args args = { + .handle = 0xbad6bad6, + }; + + do_ioctl_err(fd, DRM_IOCTL_PVR_DESTROY_VM_CONTEXT, &args, EINVAL); + } + + igt_describe("Test VM context destruction with handle that is not a VM context"); + igt_subtest("destroy-vm-ctx-handle-is-not-vm-ctx") + { + size_t size = 4096; + const uint32_t bo_handle = igt_pvr_ioctl_create_bo(fd, &size); + struct drm_pvr_ioctl_destroy_vm_context_args args = { + .handle = bo_handle, + }; + + do_ioctl_err(fd, DRM_IOCTL_PVR_DESTROY_VM_CONTEXT, &args, EINVAL); + gem_close(fd, bo_handle); + } + + igt_fixture() + { + drm_close_driver(fd); + } +} -- 2.43.0