[Intel-gfx] [PATCH 1/2] tests: Add gem_ctx_params

Mika Kuoppala mika.kuoppala at linux.intel.com
Thu Jan 29 05:32:50 PST 2015


Add gem_ctx_params to check context parameters ioctl test for
set and getting ban periods.

Cc: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Mika Kuoppala <mika.kuoppala at intel.com>
---
 tests/Makefile.sources |   1 +
 tests/gem_ctx_params.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 212 insertions(+)
 create mode 100644 tests/gem_ctx_params.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 74deec3..54bea34 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -25,6 +25,7 @@ TESTS_progs_M = \
 	gem_cs_tlb \
 	gem_ctx_bad_exec \
 	gem_ctx_exec \
+	gem_ctx_params \
 	gem_dummy_reloc_loop \
 	gem_evict_alignment \
 	gem_evict_everything \
diff --git a/tests/gem_ctx_params.c b/tests/gem_ctx_params.c
new file mode 100644
index 0000000..f831ecd
--- /dev/null
+++ b/tests/gem_ctx_params.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Mika Kuoppala <mika.kuoppala at intel.com>
+ *
+ */
+
+#include "drmtest.h"
+#include "ioctl_wrappers.h"
+#include "igt_aux.h"
+
+IGT_TEST_DESCRIPTION("Checks for context parameters");
+
+struct local_drm_i915_gem_context_create {
+	__u32 ctx_id;
+	__u32 pad;
+};
+
+struct local_drm_i915_gem_context_destroy {
+	__u32 ctx_id;
+	__u32 pad;
+};
+
+#define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_gem_context_create)
+#define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_gem_context_destroy)
+
+static uint32_t context_create(int fd)
+{
+	struct local_drm_i915_gem_context_create create;
+	int ret;
+
+	create.ctx_id = rand();
+	create.pad = rand();
+
+	ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
+	igt_assert(ret == 0);
+
+	return create.ctx_id;
+}
+
+static int context_destroy(int fd, uint32_t ctx_id)
+{
+	int ret;
+	struct local_drm_i915_gem_context_destroy destroy;
+
+	destroy.ctx_id = ctx_id;
+	destroy.pad = rand();
+
+	ret = drmIoctl(fd, CONTEXT_DESTROY_IOCTL, &destroy);
+	if (ret != 0)
+		return -errno;
+
+	return 0;
+}
+
+static int _get_ban_period(int fd, struct local_i915_gem_context_param *p)
+{
+	int r;
+
+	r = gem_context_get_param(fd, p);
+	if (r == -1)
+		return errno;
+
+	return 0;
+}
+
+static int get_ban_period(int fd, int ctx)
+{
+	struct local_i915_gem_context_param p;
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	p.size = rand();
+	p.context = rand();
+	if (p.context == ctx)
+		p.context = ctx + 1;
+	p.value = ((uint64_t)rand() << 32) | rand();
+
+	igt_assert(gem_context_get_param(fd, &p) == -1);
+	igt_assert(errno == ENOENT);
+
+	p.context = ctx;
+	p.param = 0xdeadf00d;
+
+	igt_assert(gem_context_get_param(fd, &p) == -1);
+	igt_assert(errno == EINVAL);
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	igt_assert(gem_context_get_param(fd, &p) == 0);
+	igt_assert(errno == 0);
+	igt_assert(p.size == 0);
+
+	return p.value;
+}
+
+static int set_ban_period(int fd, struct local_i915_gem_context_param *p)
+{
+	int r;
+
+	r = gem_context_set_param(fd, p);
+	if (r == -1)
+		return errno;
+
+	return 0;
+}
+
+static void test_ctx_params_invalid(bool new_ctx)
+{
+	struct local_i915_gem_context_param p;
+	int fd, period;
+	uint32_t ctx;
+
+	fd = drm_open_any();
+
+	igt_require(gem_context_has_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD));
+
+	if (new_ctx)
+		ctx = context_create(fd);
+	else
+		ctx = 0;
+
+	period = get_ban_period(fd, ctx);
+	igt_assert(period > 2);
+
+	p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+	p.size = 0xdeadf00d;
+	p.context = ctx;
+	p.value = ((uint64_t)rand() << 32) | rand();
+
+	igt_assert(set_ban_period(fd, &p) == EINVAL);
+
+	p.size = 0;
+	p.context = 0xdeadf00d;
+
+	igt_assert(set_ban_period(fd, &p) == ENOENT);
+
+	p.size = 0;
+	p.context = ctx;
+	p.value = period;
+
+	igt_fork(child, 1) {
+		const int tmp = p.value;
+
+		igt_drop_root();
+		p.value = tmp - 2;
+
+		igt_assert(set_ban_period(fd, &p) == EPERM);
+		igt_assert(_get_ban_period(fd, &p) >= 0);
+		p.value = tmp - 2;
+		igt_assert(set_ban_period(fd, &p) == EPERM);
+		p.value = tmp + 2;
+		igt_assert(set_ban_period(fd, &p) == 0);
+		p.value = tmp;
+		igt_assert(set_ban_period(fd, &p) == EPERM);
+	}
+
+	igt_waitchildren();
+
+	p.value = period;
+	igt_assert(set_ban_period(fd, &p) == 0);
+
+	p.size = 0;
+	p.context = ctx;
+	p.value = period + 1;
+
+	igt_assert(set_ban_period(fd, &p) == 0);
+
+	p.size = 0;
+	p.context = ctx;
+	p.value = period - 2;
+	igt_assert(set_ban_period(fd, &p) == 0);
+
+	if (ctx != 0) {
+		context_destroy(fd, ctx);
+		igt_assert(_get_ban_period(fd, &p) == ENOENT);
+		igt_assert(set_ban_period(fd, &p) == ENOENT);
+	}
+
+	close(fd);
+
+	igt_assert(set_ban_period(fd, &p) == EBADF);
+	igt_assert(_get_ban_period(fd, &p) == EBADF);
+}
+
+igt_main
+{
+	igt_subtest("params-default-invalid")
+		test_ctx_params_invalid(false);
+
+	igt_subtest("params-ctx-invalid")
+		test_ctx_params_invalid(true);
+}
-- 
1.9.1



More information about the Intel-gfx mailing list