[16/25] drm/i915/selftests: Mock the engine sorting for easy validation
diff mbox series

Message ID 20191110185806.17413-16-chris@chris-wilson.co.uk
State New
Headers show
Series
  • [01/25] drm/i915: Protect context while grabbing its name for the request
Related show

Commit Message

Chris Wilson Nov. 10, 2019, 6:57 p.m. UTC
To make exploration of different sorting orders and presentation of the
engines via the uabi easier, wrap the basic engine registration into a
mock (aka standalone) selftest.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/gt/intel_engine_user.c   |  4 +
 .../gpu/drm/i915/gt/selftest_engine_user.c    | 86 +++++++++++++++++++
 .../drm/i915/selftests/i915_mock_selftests.h  |  3 +-
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/i915/gt/selftest_engine_user.c

Patch
diff mbox series

diff --git a/drivers/gpu/drm/i915/gt/intel_engine_user.c b/drivers/gpu/drm/i915/gt/intel_engine_user.c
index 7f7150a733f4..15bb05aa1986 100644
--- a/drivers/gpu/drm/i915/gt/intel_engine_user.c
+++ b/drivers/gpu/drm/i915/gt/intel_engine_user.c
@@ -293,3 +293,7 @@  unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915)
 
 	return which;
 }
+
+#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
+#include "selftest_engine_user.c"
+#endif
diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_user.c b/drivers/gpu/drm/i915/gt/selftest_engine_user.c
new file mode 100644
index 000000000000..d11cc6a4af09
--- /dev/null
+++ b/drivers/gpu/drm/i915/gt/selftest_engine_user.c
@@ -0,0 +1,86 @@ 
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright © 2019 Intel Corporation
+ */
+
+#include "i915_drv.h"
+
+static void destroy_engines(struct drm_i915_private *i915)
+{
+	struct intel_engine_cs *engine, *next;
+
+	rbtree_postorder_for_each_entry_safe(engine, next,
+					     &i915->uabi_engines, uabi_node)
+		kfree(engine);
+}
+
+static int mock_uabi_engines(void *arg)
+{
+	static const u8 limits[] = {
+		[RENDER_CLASS] = 1,
+		[COPY_ENGINE_CLASS] = 1,
+		[VIDEO_DECODE_CLASS] = I915_MAX_VCS,
+		[VIDEO_ENHANCEMENT_CLASS] = I915_MAX_VECS,
+	};
+	struct intel_engine_cs *engine;
+	struct drm_i915_private *i915;
+	unsigned long num_engines;
+	unsigned long found;
+	int c, i;
+	int err = 0;
+
+	i915 = kzalloc(sizeof(*i915), GFP_KERNEL);
+	if (!i915)
+		return -ENOMEM;
+
+	num_engines = 0;
+	for (c = 0; c < ARRAY_SIZE(limits); c++) {
+		for (i = 0; i < limits[c]; i++) {
+			engine = kzalloc(sizeof(*engine), GFP_KERNEL);
+			if (!engine)
+				goto err;
+
+			engine->i915 = i915;
+
+			engine->class = c;
+			engine->instance = i;
+
+			intel_engine_add_user(engine);
+			num_engines++;
+		}
+	}
+
+err:
+	/* Check as far as we got up to -- will explode if not quite right */
+	intel_engines_driver_register(i915);
+
+	found = 0;
+	for_each_uabi_engine(engine, i915) {
+		pr_info("%s (%d, %d) -> [%d, %d]\n",
+			engine->name,
+			engine->uabi_class,
+			engine->uabi_instance,
+			engine->class,
+			engine->instance);
+		found++;
+	}
+	if (found != num_engines) {
+		pr_err("Registered %lu engines; only found %lu uABI engines\n",
+		       num_engines, found);
+		err = -EINVAL;
+	}
+
+	destroy_engines(i915);
+	kfree(i915);
+	return err;
+}
+
+int intel_engine_user_mock_selftests(void)
+{
+	static const struct i915_subtest tests[] = {
+		SUBTEST(mock_uabi_engines),
+	};
+
+	return i915_subtests(tests, NULL);
+}
diff --git a/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h b/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
index aa5a0e7f5d9e..9a2dd8350650 100644
--- a/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
+++ b/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
@@ -14,7 +14,8 @@  selftest(fence, i915_sw_fence_mock_selftests)
 selftest(scatterlist, scatterlist_mock_selftests)
 selftest(syncmap, i915_syncmap_mock_selftests)
 selftest(uncore, intel_uncore_mock_selftests)
-selftest(engine, intel_engine_cs_mock_selftests)
+selftest(engine_cs, intel_engine_cs_mock_selftests)
+selftest(engine_user, intel_engine_user_mock_selftests)
 selftest(timelines, intel_timeline_mock_selftests)
 selftest(requests, i915_request_mock_selftests)
 selftest(objects, i915_gem_object_mock_selftests)