From: Chris Wilson <chris@chris-wilson.co.uk> To: intel-gfx@lists.freedesktop.org Cc: igt-dev@lists.freedesktop.org Subject: [PATCH igt] tests/gem_ctx_param: Update invalid param Date: Sat, 17 Feb 2018 09:49:17 +0000 [thread overview] Message-ID: <20180217094917.3736-1-chris@chris-wilson.co.uk> (raw) In-Reply-To: <20180216232059.7905-2-chris@chris-wilson.co.uk> From: Antonio Argenziano <antonio.argenziano@intel.com> Since commit: drm/i915/scheduler: Support user-defined priorities, the driver support an extra context param to set context's priority. Add tests for that interface and update invalid tests. v2: - Add arg size validation test. (Chris) - Add arg value overflow test. (Chris) - Add test for unsupported platforms. (Chris) - Feed interface with all priority values and in random order. (Chris) v3: - Parametrize tests. (Chris) v4: - Code-style refactoring. (Chris) Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Michal Winiarski <michal.winiarski@intel.com> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> --- tests/gem_ctx_param.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/tests/gem_ctx_param.c b/tests/gem_ctx_param.c index db68f57b..6745b0f1 100644 --- a/tests/gem_ctx_param.c +++ b/tests/gem_ctx_param.c @@ -24,10 +24,119 @@ * Daniel Vetter <daniel.vetter@ffwll.ch> */ +#include <fcntl.h> +#include <limits.h> + #include "igt.h" IGT_TEST_DESCRIPTION("Basic test for context set/get param input validation."); +#define BIT(x) (1ul << (x)) + +#define NEW_CTX BIT(0) +#define USER BIT(1) + +static int reopen_driver(int fd) +{ + char path[256]; + + snprintf(path, sizeof(path), "/proc/self/fd/%d", fd); + fd = open(path, O_RDWR); + igt_assert_lte(0, fd); + + return fd; +} + +static void set_priority(int i915) +{ + static const int64_t test_values[] = { + /* Test space too big, pick significant values */ + INT_MIN, + + I915_CONTEXT_MIN_USER_PRIORITY - 1, + I915_CONTEXT_MIN_USER_PRIORITY, + I915_CONTEXT_MIN_USER_PRIORITY + 1, + + I915_CONTEXT_DEFAULT_PRIORITY - 1, + I915_CONTEXT_DEFAULT_PRIORITY, + I915_CONTEXT_DEFAULT_PRIORITY + 1, + + I915_CONTEXT_MAX_USER_PRIORITY - 1, + I915_CONTEXT_MAX_USER_PRIORITY, + I915_CONTEXT_MAX_USER_PRIORITY + 1, + + INT_MAX + }; + unsigned int size; + int64_t *values; + + igt_require(getuid() == 0); + + size = ARRAY_SIZE(test_values); + values = malloc(sizeof(test_values) * 2); + igt_assert(values); + + for (unsigned i = 0; i < size; i++) { + values[i] = test_values[i]; + values[i + size] = test_values[i] | (uint64_t)rand() << 32; + } + + igt_permute_array(values, size, igt_exchange_int64); + + igt_fork(flags, NEW_CTX | USER) { + int fd = reopen_driver(i915); + struct drm_i915_gem_context_param arg = { + .param = I915_CONTEXT_PARAM_PRIORITY, + .ctx_id = flags & NEW_CTX ? gem_context_create(fd) : 0, + }; + int64_t old_prio; + + + if (flags & USER) { + igt_debug("Dropping root privilege\n"); + igt_drop_root(); + } + + gem_context_get_param(fd, &arg); + old_prio = arg.value; + + for (unsigned i = 0; i < size; i++) { + int64_t prio = values[i]; + int expected = 0; + int err; + + arg.value = prio; + + if (flags & USER && + prio > I915_CONTEXT_DEFAULT_PRIORITY) + expected = -EPERM; + + if (prio < I915_CONTEXT_MIN_USER_PRIORITY || + prio > I915_CONTEXT_MAX_USER_PRIORITY) + expected = -EINVAL; + + err =__gem_context_set_param(fd, &arg); + igt_assert_f(err == expected, + "Priority requested %" PRId64 ", expected result %d, returned %d\n", + prio, expected, err); + + gem_context_get_param(fd, &arg); + if (!err) + old_prio = prio; + igt_assert_eq(arg.value, old_prio); + } + + arg.value = 0; + gem_context_set_param(fd, &arg); + + if (flags & NEW_CTX) + gem_context_destroy(fd, arg.ctx_id); + } + + igt_waitchildren(); + free(values); +} + igt_main { struct drm_i915_gem_context_param arg; @@ -138,11 +247,52 @@ igt_main gem_context_set_param(fd, &arg); } + arg.param = I915_CONTEXT_PARAM_PRIORITY; + + igt_subtest("set-priority-not-supported") { + igt_require(!gem_scheduler_has_ctx_priority(fd)); + + arg.ctx_id = ctx; + arg.size = 0; + + igt_assert_eq(__gem_context_set_param(fd, &arg), -ENODEV); + } + + igt_subtest_group { + igt_fixture { + igt_require(gem_scheduler_has_ctx_priority(fd)); + } + + igt_subtest("get-priority-new-ctx") { + struct drm_i915_gem_context_param local_arg = arg; + uint32_t local_ctx = gem_context_create(fd); + + local_arg.ctx_id = local_ctx; + + gem_context_get_param(fd, &local_arg); + igt_assert_eq(local_arg.value, I915_CONTEXT_DEFAULT_PRIORITY); + + gem_context_destroy(fd, local_ctx); + } + + igt_subtest("set-priority-invalid-size") { + struct drm_i915_gem_context_param local_arg = arg; + local_arg.ctx_id = ctx; + local_arg.value = 0; + local_arg.size = ~0; + + igt_assert_eq(__gem_context_set_param(fd, &local_arg), -EINVAL); + } + + igt_subtest("set-priority-range") + set_priority(fd); + } + /* 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. */ - arg.param = I915_CONTEXT_PARAM_BANNABLE + 1; + arg.param = I915_CONTEXT_PARAM_PRIORITY + 1; igt_subtest("invalid-param-get") { arg.ctx_id = ctx; -- 2.16.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Chris Wilson <chris@chris-wilson.co.uk> To: intel-gfx@lists.freedesktop.org Cc: igt-dev@lists.freedesktop.org Subject: [Intel-gfx] [PATCH igt] tests/gem_ctx_param: Update invalid param Date: Sat, 17 Feb 2018 09:49:17 +0000 [thread overview] Message-ID: <20180217094917.3736-1-chris@chris-wilson.co.uk> (raw) In-Reply-To: <20180216232059.7905-2-chris@chris-wilson.co.uk> From: Antonio Argenziano <antonio.argenziano@intel.com> Since commit: drm/i915/scheduler: Support user-defined priorities, the driver support an extra context param to set context's priority. Add tests for that interface and update invalid tests. v2: - Add arg size validation test. (Chris) - Add arg value overflow test. (Chris) - Add test for unsupported platforms. (Chris) - Feed interface with all priority values and in random order. (Chris) v3: - Parametrize tests. (Chris) v4: - Code-style refactoring. (Chris) Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Michal Winiarski <michal.winiarski@intel.com> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> --- tests/gem_ctx_param.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/tests/gem_ctx_param.c b/tests/gem_ctx_param.c index db68f57b..6745b0f1 100644 --- a/tests/gem_ctx_param.c +++ b/tests/gem_ctx_param.c @@ -24,10 +24,119 @@ * Daniel Vetter <daniel.vetter@ffwll.ch> */ +#include <fcntl.h> +#include <limits.h> + #include "igt.h" IGT_TEST_DESCRIPTION("Basic test for context set/get param input validation."); +#define BIT(x) (1ul << (x)) + +#define NEW_CTX BIT(0) +#define USER BIT(1) + +static int reopen_driver(int fd) +{ + char path[256]; + + snprintf(path, sizeof(path), "/proc/self/fd/%d", fd); + fd = open(path, O_RDWR); + igt_assert_lte(0, fd); + + return fd; +} + +static void set_priority(int i915) +{ + static const int64_t test_values[] = { + /* Test space too big, pick significant values */ + INT_MIN, + + I915_CONTEXT_MIN_USER_PRIORITY - 1, + I915_CONTEXT_MIN_USER_PRIORITY, + I915_CONTEXT_MIN_USER_PRIORITY + 1, + + I915_CONTEXT_DEFAULT_PRIORITY - 1, + I915_CONTEXT_DEFAULT_PRIORITY, + I915_CONTEXT_DEFAULT_PRIORITY + 1, + + I915_CONTEXT_MAX_USER_PRIORITY - 1, + I915_CONTEXT_MAX_USER_PRIORITY, + I915_CONTEXT_MAX_USER_PRIORITY + 1, + + INT_MAX + }; + unsigned int size; + int64_t *values; + + igt_require(getuid() == 0); + + size = ARRAY_SIZE(test_values); + values = malloc(sizeof(test_values) * 2); + igt_assert(values); + + for (unsigned i = 0; i < size; i++) { + values[i] = test_values[i]; + values[i + size] = test_values[i] | (uint64_t)rand() << 32; + } + + igt_permute_array(values, size, igt_exchange_int64); + + igt_fork(flags, NEW_CTX | USER) { + int fd = reopen_driver(i915); + struct drm_i915_gem_context_param arg = { + .param = I915_CONTEXT_PARAM_PRIORITY, + .ctx_id = flags & NEW_CTX ? gem_context_create(fd) : 0, + }; + int64_t old_prio; + + + if (flags & USER) { + igt_debug("Dropping root privilege\n"); + igt_drop_root(); + } + + gem_context_get_param(fd, &arg); + old_prio = arg.value; + + for (unsigned i = 0; i < size; i++) { + int64_t prio = values[i]; + int expected = 0; + int err; + + arg.value = prio; + + if (flags & USER && + prio > I915_CONTEXT_DEFAULT_PRIORITY) + expected = -EPERM; + + if (prio < I915_CONTEXT_MIN_USER_PRIORITY || + prio > I915_CONTEXT_MAX_USER_PRIORITY) + expected = -EINVAL; + + err =__gem_context_set_param(fd, &arg); + igt_assert_f(err == expected, + "Priority requested %" PRId64 ", expected result %d, returned %d\n", + prio, expected, err); + + gem_context_get_param(fd, &arg); + if (!err) + old_prio = prio; + igt_assert_eq(arg.value, old_prio); + } + + arg.value = 0; + gem_context_set_param(fd, &arg); + + if (flags & NEW_CTX) + gem_context_destroy(fd, arg.ctx_id); + } + + igt_waitchildren(); + free(values); +} + igt_main { struct drm_i915_gem_context_param arg; @@ -138,11 +247,52 @@ igt_main gem_context_set_param(fd, &arg); } + arg.param = I915_CONTEXT_PARAM_PRIORITY; + + igt_subtest("set-priority-not-supported") { + igt_require(!gem_scheduler_has_ctx_priority(fd)); + + arg.ctx_id = ctx; + arg.size = 0; + + igt_assert_eq(__gem_context_set_param(fd, &arg), -ENODEV); + } + + igt_subtest_group { + igt_fixture { + igt_require(gem_scheduler_has_ctx_priority(fd)); + } + + igt_subtest("get-priority-new-ctx") { + struct drm_i915_gem_context_param local_arg = arg; + uint32_t local_ctx = gem_context_create(fd); + + local_arg.ctx_id = local_ctx; + + gem_context_get_param(fd, &local_arg); + igt_assert_eq(local_arg.value, I915_CONTEXT_DEFAULT_PRIORITY); + + gem_context_destroy(fd, local_ctx); + } + + igt_subtest("set-priority-invalid-size") { + struct drm_i915_gem_context_param local_arg = arg; + local_arg.ctx_id = ctx; + local_arg.value = 0; + local_arg.size = ~0; + + igt_assert_eq(__gem_context_set_param(fd, &local_arg), -EINVAL); + } + + igt_subtest("set-priority-range") + set_priority(fd); + } + /* 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. */ - arg.param = I915_CONTEXT_PARAM_BANNABLE + 1; + arg.param = I915_CONTEXT_PARAM_PRIORITY + 1; igt_subtest("invalid-param-get") { arg.ctx_id = ctx; -- 2.16.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2018-02-17 9:49 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-02-16 23:20 [PATCH igt 1/2] lib/igt_aux: Add function to swap int64 in array Chris Wilson 2018-02-16 23:20 ` [PATCH igt 2/2] tests/gem_ctx_param: Update invalid param Chris Wilson 2018-02-17 9:11 ` [PATCH igt] " Chris Wilson 2018-02-17 9:49 ` Chris Wilson [this message] 2018-02-17 9:49 ` [Intel-gfx] " Chris Wilson 2018-02-17 0:16 ` ✓ Fi.CI.BAT: success for series starting with [1/2] lib/igt_aux: Add function to swap int64 in array Patchwork 2018-02-17 1:19 ` ✓ Fi.CI.IGT: " Patchwork 2018-02-17 9:43 ` ✗ Fi.CI.BAT: failure for series starting with [1/2] lib/igt_aux: Add function to swap int64 in array (rev2) Patchwork 2018-02-17 10:07 ` [igt-dev] ✗ Fi.CI.BAT: failure for tests/gem_ctx_param: Update invalid param Patchwork -- strict thread matches above, loose matches on Subject: below -- 2018-02-16 13:49 [PATCH igt 2/2] " Chris Wilson 2018-02-16 18:37 ` [PATCH igt] " Chris Wilson
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180217094917.3736-1-chris@chris-wilson.co.uk \ --to=chris@chris-wilson.co.uk \ --cc=igt-dev@lists.freedesktop.org \ --cc=intel-gfx@lists.freedesktop.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.