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)

Signed-off-by: Antonio Argenziano <antonio.argenzi...@intel.com>
Cc: Chris Wilson <ch...@chris-wilson.co.uk>
Cc: Michal Winiarski <michal.winiar...@intel.com>
---
 tests/gem_ctx_param.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 142 insertions(+), 1 deletion(-)

diff --git a/tests/gem_ctx_param.c b/tests/gem_ctx_param.c
index c20ae1ee..96eb2c3a 100644
--- a/tests/gem_ctx_param.c
+++ b/tests/gem_ctx_param.c
@@ -25,6 +25,7 @@
  */
 
 #include "igt.h"
+#include <limits.h>
 
 IGT_TEST_DESCRIPTION("Basic test for context set/get param input validation.");
 
@@ -136,11 +137,151 @@ igt_main
                gem_context_set_param(fd, &arg);
        }
 
+       arg.param = I915_CONTEXT_PARAM_PRIORITY;
+
+#define MAX_USER_SET_PRIO I915_CONTEXT_DEFAULT_PRIORITY /* Current max prio 
for non-root users */
+#define PRIO_RANGE (I915_CONTEXT_MAX_USER_PRIORITY - 
I915_CONTEXT_MIN_USER_PRIORITY)
+#define USER_PRIO_RANGE (MAX_USER_SET_PRIO - I915_CONTEXT_MIN_USER_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") {
+                       arg.ctx_id = gem_context_create(fd);
+
+                       gem_context_get_param(fd, &arg);
+                       igt_assert_eq(arg.value, 0);
+               }
+
+               igt_subtest("set-priority-invalid-size") {
+                       arg.ctx_id = ctx;
+                       arg.value = 0;
+                       arg.size = ~0;
+
+                       igt_assert_eq(__gem_context_set_param(fd, &arg), 
-EINVAL);
+               }
+
+               igt_subtest("root-set-priority") {
+                       int prio_values[PRIO_RANGE + 1];
+                       for (int i = 0; i < PRIO_RANGE + 1; i++)
+                               prio_values[i] = i + 
I915_CONTEXT_MIN_USER_PRIORITY;
+                       igt_permute_array(prio_values, ARRAY_SIZE(prio_values), 
igt_exchange_int);
+
+                       arg.ctx_id = ctx;
+                       arg.size = 0;
+
+                       for (int i = 0; i < PRIO_RANGE + 1; i++) {
+                               arg.value = prio_values[i];
+                               gem_context_set_param(fd, &arg);
+
+                               gem_context_get_param(fd, &arg);
+                               igt_assert_eq(arg.value, prio_values[i]); /* 
Verify prio was set */
+                       }
+               }
+
+               igt_subtest("root-set-priority-invalid-value") {
+                       int prio_levels[]
+                               = {INT_MIN,
+                                       I915_CONTEXT_MIN_USER_PRIORITY - 1,
+                                       I915_CONTEXT_MAX_USER_PRIORITY + 1,
+                                       INT_MAX}; /* Test space too big pick 
significant values */
+                       int old_value;
+                       arg.ctx_id = ctx;
+
+                       gem_context_get_param(fd, &arg);
+                       old_value = arg.value;
+
+                       for (int i = 0; i < ARRAY_SIZE(prio_levels); i++) {
+                               arg.value = prio_levels[i];
+                               igt_assert_eq(__gem_context_set_param(fd, 
&arg), -EINVAL);
+
+                               gem_context_get_param(fd, &arg);
+                               igt_assert_eq(arg.value, old_value); /* Verify 
prio was not set */
+                       }
+               }
+
+               igt_subtest("root-set-priority-overflow-value") {
+                       uint64_t prio_values[PRIO_RANGE + 1];
+                       for (int i = 0; i < PRIO_RANGE + 1; i++)
+                               prio_values[i] = (0x1 << 32) + (i + 
I915_CONTEXT_MIN_USER_PRIORITY);
+                       igt_permute_array(prio_values, ARRAY_SIZE(prio_values), 
igt_exchange_int);
+
+                       arg.ctx_id = gem_context_create(fd);
+                       arg.size = 0;
+
+                       for (int i = 0; i < PRIO_RANGE + 1; i++) {
+                               arg.value = prio_values[i];
+                               igt_assert_eq(__gem_context_set_param(fd, 
&arg), -EINVAL);
+
+                               gem_context_get_param(fd, &arg);
+                               igt_assert_eq(arg.value, 
I915_CONTEXT_DEFAULT_PRIORITY); /* Verify prio was set */
+                       }
+               }
+
+               igt_subtest("user-set-priority") {
+                       int prio_values[USER_PRIO_RANGE + 1];
+                       for (int i = 0; i < USER_PRIO_RANGE + 1; i++)
+                               prio_values[i] = i + 
I915_CONTEXT_MIN_USER_PRIORITY;
+                       igt_permute_array(prio_values, ARRAY_SIZE(prio_values), 
igt_exchange_int);
+
+                       igt_fork(child, 1) {
+                               igt_drop_root();
+                               for (int i = 0; i < USER_PRIO_RANGE; i++) {
+                                       arg.size = 0;
+                                       arg.value = prio_values[i];
+
+                                       igt_debug("Setting prio: %d\n", 
prio_values[i]);
+                                       gem_context_set_param(fd, &arg);
+
+                                       gem_context_get_param(fd, &arg);
+                                       igt_assert_eq(arg.value, 
prio_values[i]); /* Verify prio was set */
+                               }
+                       }
+
+                       igt_waitchildren();
+               }
+
+               igt_subtest("user-set-priority-invalid-value") {
+                       int prio_values[PRIO_RANGE - USER_PRIO_RANGE];
+                       for (int i = 0; i < (PRIO_RANGE - USER_PRIO_RANGE); i++)
+                               prio_values[i] = i + (MAX_USER_SET_PRIO + 1);
+                       igt_permute_array(prio_values, ARRAY_SIZE(prio_values), 
igt_exchange_int);
+
+                       arg.ctx_id = gem_context_create(fd);
+                       arg.size = 0;
+
+                       igt_fork(child, 1) {
+                               igt_drop_root();
+
+                               for (int i = 0; i < ARRAY_SIZE(prio_values); 
i++) {
+                                       arg.value = prio_values[i];
+                                       
igt_assert_eq(__gem_context_set_param(fd, &arg), -EPERM);
+
+                                       gem_context_get_param(fd, &arg);
+                                       igt_assert_eq(arg.value, 
I915_CONTEXT_DEFAULT_PRIORITY); /* Verify prio was not set */
+                               }
+                       }
+
+                       igt_waitchildren();
+               }
+       }
+
        /* 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.14.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to