diff options
-rw-r--r-- | lib/ioctl_wrappers.c | 16 | ||||
-rw-r--r-- | lib/ioctl_wrappers.h | 1 | ||||
-rw-r--r-- | tests/gem_ctx_param.c | 120 |
3 files changed, 67 insertions, 70 deletions
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index 110465e0..8632878f 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -871,6 +871,17 @@ void gem_context_destroy(int fd, uint32_t ctx_id) do_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); } +int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p) +{ +#define LOCAL_I915_GEM_CONTEXT_GETPARAM 0x34 +#define LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_GETPARAM, struct local_i915_gem_context_param) + if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, p)) + return -errno; + + errno = 0; + return 0; +} + /** * gem_context_get_param: * @fd: open i915 drm file descriptor @@ -883,11 +894,10 @@ void gem_context_destroy(int fd, uint32_t ctx_id) */ void gem_context_get_param(int fd, struct local_i915_gem_context_param *p) { -#define LOCAL_I915_GEM_CONTEXT_GETPARAM 0x34 -#define LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_GETPARAM, struct local_i915_gem_context_param) - do_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, p); + igt_assert(__gem_context_get_param(fd, p) == 0); } + int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p) { #define LOCAL_I915_GEM_CONTEXT_SETPARAM 0x35 diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index 0d42ba95..115011c9 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -126,6 +126,7 @@ void gem_context_require_param(int fd, uint64_t param); void gem_context_get_param(int fd, struct local_i915_gem_context_param *p); void gem_context_set_param(int fd, struct local_i915_gem_context_param *p); int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p); +int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p); #define LOCAL_I915_GEM_USERPTR 0x33 #define LOCAL_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_USERPTR, struct local_i915_gem_userptr) diff --git a/tests/gem_ctx_param.c b/tests/gem_ctx_param.c index b75800c7..a0055fe2 100644 --- a/tests/gem_ctx_param.c +++ b/tests/gem_ctx_param.c @@ -25,141 +25,127 @@ */ #include "igt.h" -#include <stdlib.h> -#include <sys/ioctl.h> -#include <stdio.h> IGT_TEST_DESCRIPTION("Basic test for context set/get param input validation."); -int fd; -int32_t ctx; - -#define LOCAL_I915_GEM_CONTEXT_GETPARAM 0x34 -#define LOCAL_I915_GEM_CONTEXT_SETPARAM 0x35 -#define LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_GETPARAM, struct local_i915_gem_context_param) -#define LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_SETPARAM, struct local_i915_gem_context_param) - -#define TEST_SUCCESS(ioc) \ - do_ioctl(fd, (ioc), &ctx_param); -#define TEST_FAIL(ioc, exp_errno) \ - do_ioctl_err(fd, (ioc), &ctx_param, exp_errno); - igt_main { - struct local_i915_gem_context_param ctx_param; + struct local_i915_gem_context_param arg; + int fd; + uint32_t ctx; - memset(&ctx_param, 0, sizeof(ctx_param)); + memset(&arg, 0, sizeof(arg)); igt_fixture { fd = drm_open_driver_render(DRIVER_INTEL); ctx = gem_context_create(fd); } - ctx_param.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; + arg.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; igt_subtest("basic") { - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM); + arg.context = ctx; + gem_context_get_param(fd, &arg); + gem_context_set_param(fd, &arg); } igt_subtest("basic-default") { - ctx_param.context = 0; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM); + arg.context = 0; + gem_context_get_param(fd, &arg); + gem_context_set_param(fd, &arg); } igt_subtest("invalid-ctx-get") { - ctx_param.context = 2; - TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, ENOENT); + arg.context = 2; + igt_assert_eq(__gem_context_get_param(fd, &arg), -ENOENT); } igt_subtest("invalid-ctx-set") { - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - ctx_param.context = 2; - TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, ENOENT); + arg.context = ctx; + gem_context_get_param(fd, &arg); + arg.context = 2; + igt_assert_eq(__gem_context_set_param(fd, &arg), -ENOENT); } igt_subtest("invalid-size-get") { - ctx_param.context = ctx; - ctx_param.size = 8; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - igt_assert(ctx_param.size == 0); + arg.context = ctx; + arg.size = 8; + gem_context_get_param(fd, &arg); + igt_assert(arg.size == 0); } igt_subtest("invalid-size-set") { - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - ctx_param.size = 8; - TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, EINVAL); - ctx_param.size = 0; + arg.context = ctx; + gem_context_get_param(fd, &arg); + arg.size = 8; + igt_assert_eq(__gem_context_set_param(fd, &arg), -EINVAL); + arg.size = 0; } - ctx_param.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; + arg.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; igt_subtest("non-root-set") { igt_fork(child, 1) { igt_drop_root(); - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - ctx_param.value--; - TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, EPERM); + arg.context = ctx; + gem_context_get_param(fd, &arg); + arg.value--; + igt_assert_eq(__gem_context_set_param(fd, &arg), -EPERM); } igt_waitchildren(); } igt_subtest("root-set") { - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - ctx_param.value--; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM); + arg.context = ctx; + gem_context_get_param(fd, &arg); + arg.value--; + gem_context_set_param(fd, &arg); } - ctx_param.param = LOCAL_CONTEXT_PARAM_NO_ZEROMAP; + arg.param = LOCAL_CONTEXT_PARAM_NO_ZEROMAP; igt_subtest("non-root-set-no-zeromap") { igt_fork(child, 1) { igt_drop_root(); - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - ctx_param.value--; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM); + arg.context = ctx; + gem_context_get_param(fd, &arg); + arg.value--; + gem_context_set_param(fd, &arg); } igt_waitchildren(); } igt_subtest("root-set-no-zeromap-enabled") { - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - ctx_param.value = 1; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM); + arg.context = ctx; + gem_context_get_param(fd, &arg); + arg.value = 1; + gem_context_set_param(fd, &arg); } igt_subtest("root-set-no-zeromap-disabled") { - ctx_param.context = ctx; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM); - ctx_param.value = 0; - TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM); + arg.context = ctx; + gem_context_get_param(fd, &arg); + arg.value = 0; + gem_context_set_param(fd, &arg); } /* NOTE: This testcase intentionally tests for the next free parameter * to catch ABI extensions. Don't "fix" this testcase without adding all * the tests for the new param first. */ - ctx_param.param = LOCAL_CONTEXT_PARAM_GTT_SIZE + 1; + arg.param = LOCAL_CONTEXT_PARAM_GTT_SIZE + 1; igt_subtest("invalid-param-get") { - ctx_param.context = ctx; - TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, EINVAL); + arg.context = ctx; + igt_assert_eq(__gem_context_get_param(fd, &arg), -EINVAL); } igt_subtest("invalid-param-set") { - ctx_param.context = ctx; - TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, EINVAL); + arg.context = ctx; + igt_assert_eq(__gem_context_set_param(fd, &arg), -EINVAL); } igt_fixture |