[igt-dev] [PATCH v3 3/3] tests: gem_exec_basic: add "exec-ctx" buffer execution demo test

Andi Shyti
2018-11-26T20:44:05Z

The "exec-ctx" is a demo subtest inserted in the gem_exec_basic
test. The main scope is to demonstrate an alternative way for
querying engines as implemented in the new API in commit 87079e04
("lib: implement new engine discovery interface").

The "exec-ctx" subtest simply gets the list of engines, binds
them to a context and executes a buffer. This is done through a
new "for_each_engine_ctx" loop which iterates through the
engines.

Signed-off-by: Andi Shyti <andi.shyti@intel.com>
---
tests/i915/gem_exec_basic.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)

diff --git a/tests/i915/gem_exec_basic.c b/tests/i915/gem_exec_basic.c
index dcb83864..70128547 100644
--- a/tests/i915/gem_exec_basic.c
+++ b/tests/i915/gem_exec_basic.c
@@ -114,6 +114,22 @@ static void gtt(int fd, unsigned ring)
munmap(execbuf, 4096);
}

+static void execbuf_in_ctx(int fd, uint32_t engine, uint32_t ctx, uint32_t handle)
+{
+ struct drm_i915_gem_exec_object2 exec = {
+ .handle = handle,
+ };
+ struct drm_i915_gem_execbuffer2 execbuf = {
+ .buffers_ptr = to_user_pointer(&exec),
+ .buffer_count = 1,
+ .flags = engine,
+ .rsvd1 = ctx & I915_EXEC_CONTEXT_ID_MASK,
+ };
+
+ igt_assert(execbuf.rsvd1);
+ gem_execbuf(fd, &execbuf);
+}
+
igt_main
{
const struct intel_execution_engine *e;
@@ -135,6 +151,22 @@ igt_main
gtt(fd, e->exec_id | e->flags);
}

+ igt_subtest("exec-ctx") {
+ uint32_t ctx_id, r;
+ uint32_t handle;
+ uint32_t bbend = MI_BATCH_BUFFER_END;
+
+ ctx_id = gem_context_create(fd);
+ handle = gem_create(fd, 4096);
+ gem_write(fd, handle, 0, &bbend, sizeof(bbend));
+
+ for_each_engine_ctx(fd, ctx_id, r)
+ execbuf_in_ctx(fd, r, ctx_id, handle);
+
+ gem_close(fd, handle);
+ gem_context_destroy(fd, ctx_id);
+ }
+
igt_fixture {
igt_stop_hang_detector();
close(fd);
--
2.20.0.rc1