[igt-dev] [PATCH i-g-t 2/4] tests/kms_legacy_colorkey: Test a lot more things

Ville Syrjala ville.syrjala at linux.intel.com
Fri Jan 31 20:15:52 UTC 2020


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Try to test that we can actually use the colorkey ioctl to
ask for different colorkeying modes, and make sure the kernel
rejects invalid/unsupported flags, etc.

What we're still missing is looking at the crc to make sure
the color keying actually works. But let's leave that for
the future.

v2: Refactor each subtest into its own function
v3: Rework the expected_ret stuff to handle multiple
    sprite planes

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 tests/kms_legacy_colorkey.c | 167 ++++++++++++++++++++++++++++++------
 1 file changed, 143 insertions(+), 24 deletions(-)

diff --git a/tests/kms_legacy_colorkey.c b/tests/kms_legacy_colorkey.c
index de9610a75e5c..b0168a917517 100644
--- a/tests/kms_legacy_colorkey.c
+++ b/tests/kms_legacy_colorkey.c
@@ -22,49 +22,168 @@
  */
 
 #include "igt.h"
+#include "i915_drm.h"
 #include <errno.h>
 
 
-IGT_TEST_DESCRIPTION("Check that the legacy set colorkey ioctl only works on sprite planes.");
+IGT_TEST_DESCRIPTION("Check that the legacy set colorkey ioctl works.");
 
-static int drm_fd;
-static igt_display_t display;
-static int p;
-static igt_plane_t *plane;
-static uint32_t max_id;
+struct data {
+	igt_display_t display;
+	igt_plane_t *plane;
+	int drm_fd;
+	enum pipe pipe;
+	uint32_t devid;
+};
 
-static void test_plane(uint32_t plane_id, int expected_ret)
+static void test_plane(struct data *data,
+		       uint32_t plane_id,
+		       uint32_t flags,
+		       int expected_ret)
 {
 	struct drm_intel_sprite_colorkey ckey = {
 		.plane_id = plane_id,
+		.flags = flags,
 	};
 
-	igt_assert(drmCommandWrite(drm_fd, DRM_I915_SET_SPRITE_COLORKEY, &ckey,
+	igt_assert(drmCommandWrite(data->drm_fd,
+				   DRM_I915_SET_SPRITE_COLORKEY, &ckey,
 				   sizeof(ckey)) == expected_ret);
 }
 
-igt_simple_main
+static uint32_t max_plane_id(struct data *data)
 {
-	drm_fd = drm_open_driver_master(DRIVER_INTEL);
+	uint32_t max_id = 0;
+	igt_plane_t *plane;
+	enum pipe pipe;
 
-	kmstest_set_vt_graphics_mode();
+	for_each_pipe(&data->display, pipe) {
+		for_each_plane_on_pipe(&data->display, pipe, plane)
+			max_id = max(max_id, plane->drm_plane->plane_id);
+	}
 
-	igt_display_require(&display, drm_fd);
+	return max_id;
+}
 
-	for_each_pipe(&display, p) {
-		for_each_plane_on_pipe(&display, p, plane) {
-			bool is_valid = (plane->type == DRM_PLANE_TYPE_PRIMARY ||
-			                 plane->type == DRM_PLANE_TYPE_CURSOR);
-			test_plane(plane->drm_plane->plane_id,
-				   is_valid ? -ENOENT : 0);
+static void test_invalid_plane_id(struct data *data)
+{
+	/* try some invalid plane IDs */
+	test_plane(data, 0, 0, -ENOENT);
+	test_plane(data, max_plane_id(data) + 1, 0, -ENOENT);
+}
 
-			max_id = max(max_id, plane->drm_plane->plane_id);
-		}
+static int expected_ret(struct data *data, uint32_t flags)
+{
+	igt_plane_t *plane = data->plane;
+
+	switch (flags) {
+	case 0:
+	case I915_SET_COLORKEY_NONE:
+	case I915_SET_COLORKEY_SOURCE:
+		if (plane->type != DRM_PLANE_TYPE_OVERLAY)
+			return -ENOENT;
+
+		return 0;
+	case I915_SET_COLORKEY_DESTINATION:
+		if (plane->type != DRM_PLANE_TYPE_OVERLAY)
+			return -ENOENT;
+
+		/* VLV/CHV don't support dst colorkey (yet) */
+		if (IS_VALLEYVIEW(data->devid) ||
+		    IS_CHERRYVIEW(data->devid))
+			return -EINVAL;
+
+		/*
+		 * Only the first sprite plane gets to
+		 * use destination colorkeying.
+		 */
+		return plane->index == 1 ? 0 : -EINVAL;
+	default:
+		return -EINVAL;
+	}
+}
+
+static void test_overlays(struct data *data, uint32_t flags)
+{
+	for_each_plane_on_pipe(&data->display, data->pipe, data->plane) {
+		uint32_t plane_id = data->plane->drm_plane->plane_id;
+
+		test_plane(data, plane_id, flags, expected_ret(data, flags));
+		test_plane(data, plane_id, 0, expected_ret(data, 0));
+	}
+}
+
+static void test_invalid_flags(struct data *data)
+{
+	igt_skip_on(data->pipe >= data->display.n_pipes);
+
+	/* dst + src keying is not supported */
+	test_overlays(data, I915_SET_COLORKEY_DESTINATION |
+		      I915_SET_COLORKEY_SOURCE);
+
+	/* test some undefined flags */
+	test_overlays(data, 1 << 3);
+	test_overlays(data, 1 << 31);
+}
+
+static void test_no_colorkey(struct data *data)
+{
+	igt_skip_on(data->pipe >= data->display.n_pipes);
+
+	/* no flags should work */
+	test_overlays(data, 0);
+
+	/* the "none" flag should be ignore by the kernel */
+	test_overlays(data, I915_SET_COLORKEY_NONE);
+}
+
+static void test_src_colorkey(struct data *data)
+{
+	igt_skip_on(data->pipe >= data->display.n_pipes);
+
+	test_overlays(data, I915_SET_COLORKEY_SOURCE);
+}
+
+static void test_dst_colorkey(struct data *data)
+{
+	igt_skip_on(data->pipe >= data->display.n_pipes);
+
+	test_overlays(data, I915_SET_COLORKEY_DESTINATION);
+}
+
+static struct data data;
+
+igt_main
+{
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
+
+		data.devid = intel_get_drm_devid(data.drm_fd);
+
+		kmstest_set_vt_graphics_mode();
+
+		igt_display_require(&data.display, data.drm_fd);
 	}
 
-	/* try some invalid IDs too */
-	test_plane(0, -ENOENT);
-	test_plane(max_id + 1, -ENOENT);
+	igt_subtest("invalid-plane-id")
+		test_invalid_plane_id(&data);
+
+	for_each_pipe_static(data.pipe) {
+		igt_subtest_f("pipe-%s-invalid-flags", kmstest_pipe_name(data.pipe))
+			test_invalid_flags(&data);
+
+		igt_subtest_f("pipe-%s-no-colorkey", kmstest_pipe_name(data.pipe))
+			test_no_colorkey(&data);
+
+		igt_subtest_f("pipe-%s-src-colorkey", kmstest_pipe_name(data.pipe))
+			test_src_colorkey(&data);
+
+		igt_subtest_f("pipe-%s-dst-colorkey", kmstest_pipe_name(data.pipe))
+			test_dst_colorkey(&data);
+	}
 
-	igt_display_fini(&display);
+	igt_fixture
+		igt_display_fini(&data.display);
 }
-- 
2.24.1



More information about the igt-dev mailing list