Add tests to xe_vm that exercise the new DRM_IOCTL_XE_VM_GET_PROPERTY ioctl. Specifically, add input validation tests that exercise the return values for improperly formatted ioctl structures.
v2: - Make vm creation consistent between patches (jcavitt) Signed-off-by: Jonathan Cavitt <jonathan.cav...@intel.com> --- tests/intel/xe_vm.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c index 5cbd56037e..5c189f7af1 100644 --- a/tests/intel/xe_vm.c +++ b/tests/intel/xe_vm.c @@ -2366,6 +2366,71 @@ static void invalid_vm_id(int fd) do_ioctl_err(fd, DRM_IOCTL_XE_VM_DESTROY, &destroy, ENOENT); } +/** + * SUBTEST: vm-get-property-invalid-reserved + * Functionality: ioctl_input_validation + * Description: Check query with invalid reserved returns expected error code + * + * SUBTEST: vm-get-property-invalid-vm-id + * Functionality: ioctl_input_validation + * Description: Check query with invalid vm_id returns expected error code + * + * SUBTEST: vm-get-property-invalid-size + * Functionality: ioctl_input_validation + * Description: Check query with invalid size return expected error code + * + * SUBTEST: vm-get-property-invalid-property + * Functionality: ioctl_input_validation + * Description: Check query with invalid property returns expected error code + */ +static void get_property_invalid_reserved(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .reserved[0] = 0xdeadbeef, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, EINVAL); +} + +static void get_property_invalid_vm_id(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .vm_id = 0xdeadbeef, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, ENOENT); +} + +static void get_property_invalid_size(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .vm_id = vm, + .property = DRM_XE_VM_GET_PROPERTY_FAULTS, + .size = -1, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, EINVAL); +} + +static void get_property_invalid_property(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .vm_id = vm, + .property = 0xdeadbeef, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, EINVAL); +} + +static void test_get_property(int fd, void (*func)(int fd, uint32_t vm)) +{ + uint32_t vm; + + vm = xe_vm_create(fd, 0, 0); + func(fd, vm); + xe_vm_destroy(fd, vm); +} + igt_main { struct drm_xe_engine_class_instance *hwe, *hwe_non_copy = NULL; @@ -2478,6 +2543,17 @@ igt_main { } }; + const struct vm_get_property { + const char *name; + void (*test)(int fd, uint32_t vm); + } xe_vm_get_property_tests[] = { + { "invalid-reserved", get_property_invalid_reserved }, + { "invalid-vm-id", get_property_invalid_vm_id }, + { "invalid-size", get_property_invalid_size }, + { "invalid-property", get_property_invalid_property }, + { } + }; + igt_fixture { fd = drm_open_driver(DRIVER_XE); @@ -2757,6 +2833,11 @@ igt_main igt_subtest("invalid-vm-id") invalid_vm_id(fd); + for (const struct vm_get_property *f = xe_vm_get_property_tests; f->name; f++) { + igt_subtest_f("vm-get-property-%s", f->name) + test_get_property(fd, f->test); + } + igt_fixture drm_close_driver(fd); } -- 2.43.0