From: Paulo Zanoni <paulo.r.zan...@intel.com>

These tests currently trigger WARNs on our Kernel. Let's make sure we
fix the bugs and they never come back.

v2: Reorganize the code a little bit, and improve the tests.

Signed-off-by: Paulo Zanoni <paulo.r.zan...@intel.com>
---
 tests/pm_rpm.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 113 insertions(+), 10 deletions(-)

diff --git a/tests/pm_rpm.c b/tests/pm_rpm.c
index 869e6f3..f720f86 100644
--- a/tests/pm_rpm.c
+++ b/tests/pm_rpm.c
@@ -277,13 +277,15 @@ static uint32_t get_fb(struct mode_set_data *data, int 
width, int height)
        igt_assert(false);
 }
 
-static bool enable_one_screen_with_type(struct mode_set_data *data,
-                                       enum screen_type type)
+static bool find_connector_for_modeset(struct mode_set_data *data,
+                                      enum screen_type type,
+                                      uint32_t *connector_id,
+                                      drmModeModeInfoPtr *mode)
 {
-       uint32_t crtc_id = 0, buffer_id = 0, connector_id = 0;
-       drmModeModeInfoPtr mode = NULL;
-       int i, rc;
+       int i;
 
+       *connector_id = 0;
+       *mode = NULL;
        for (i = 0; i < data->res->count_connectors; i++) {
                drmModeConnectorPtr c = data->connectors[i];
 
@@ -296,13 +298,23 @@ static bool enable_one_screen_with_type(struct 
mode_set_data *data,
                        continue;
 
                if (c->connection == DRM_MODE_CONNECTED && c->count_modes) {
-                       connector_id = c->connector_id;
-                       mode = &c->modes[0];
+                       *connector_id = c->connector_id;
+                       *mode = &c->modes[0];
                        break;
                }
        }
 
-       if (connector_id == 0)
+       return (*connector_id != 0);
+}
+
+static bool enable_one_screen_with_type(struct mode_set_data *data,
+                                       enum screen_type type)
+{
+       uint32_t crtc_id = 0, buffer_id = 0, connector_id;
+       drmModeModeInfoPtr mode;
+       int rc;
+
+       if (!find_connector_for_modeset(data, type, &connector_id, &mode))
                return false;
 
        crtc_id = data->res->crtcs[0];
@@ -310,8 +322,6 @@ static bool enable_one_screen_with_type(struct 
mode_set_data *data,
 
        igt_assert(crtc_id);
        igt_assert(buffer_id);
-       igt_assert(connector_id);
-       igt_assert(mode);
 
        rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0, &connector_id,
                            1, mode);
@@ -1407,6 +1417,93 @@ static void dpms_mode_unset_subtest(enum screen_type 
type)
        igt_assert(wait_for_suspended());
 }
 
+static void fill_igt_fb(struct igt_fb *fb, uint32_t color)
+{
+       int i;
+       uint32_t *ptr;
+
+       ptr = gem_mmap__cpu(drm_fd, fb->gem_handle, fb->size, 0);
+       for (i = 0; i < fb->size/sizeof(uint32_t); i++)
+               ptr[i] = color;
+       igt_assert(munmap(ptr, fb->size) == 0);
+}
+
+/* At some point, this test triggered WARNs in the Kernel. */
+static void cursor_subtest(bool dpms)
+{
+       uint32_t crtc_id = 0, connector_id;
+       drmModeModeInfoPtr mode;
+       int rc;
+       struct igt_fb scanout_fb, cursor_fb1, cursor_fb2;
+
+       disable_all_screens(&ms_data);
+       igt_assert(wait_for_suspended());
+
+       igt_require(find_connector_for_modeset(&ms_data, SCREEN_TYPE_ANY,
+                                              &connector_id, &mode));
+
+       crtc_id = ms_data.res->crtcs[0];
+       igt_assert(crtc_id);
+
+       igt_create_fb(drm_fd, mode->hdisplay, mode->vdisplay,
+                     DRM_FORMAT_XRGB8888, false, &scanout_fb);
+       igt_create_fb(drm_fd, 64, 64, DRM_FORMAT_ARGB8888, false, &cursor_fb1);
+       igt_create_fb(drm_fd, 64, 64, DRM_FORMAT_ARGB8888, false, &cursor_fb2);
+
+       fill_igt_fb(&scanout_fb, 0xFF);
+       fill_igt_fb(&cursor_fb1, 0xFF00FFFF);
+       fill_igt_fb(&cursor_fb2, 0xFF00FF00);
+
+       rc = drmModeSetCrtc(drm_fd, crtc_id, scanout_fb.fb_id, 0, 0,
+                           &connector_id, 1, mode);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_active());
+
+       rc = drmModeSetCursor(drm_fd, crtc_id, cursor_fb1.gem_handle,
+                             cursor_fb1.width, cursor_fb1.height);
+       igt_assert(rc == 0);
+       rc = drmModeMoveCursor(drm_fd, crtc_id, 0, 0);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_active());
+
+       if (dpms)
+               disable_all_screens_dpms(&ms_data);
+       else
+               disable_all_screens(&ms_data);
+       igt_assert(wait_for_suspended());
+
+       /* First, just move the cursor. */
+       rc = drmModeMoveCursor(drm_fd, crtc_id, 1, 1);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_suspended());
+
+       /* Then unset it, and set a new one. */
+       rc = drmModeSetCursor(drm_fd, crtc_id, 0, 0, 0);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_suspended());
+
+       rc = drmModeSetCursor(drm_fd, crtc_id, cursor_fb2.gem_handle,
+                             cursor_fb1.width, cursor_fb2.height);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_suspended());
+
+       /* Move the new cursor. */
+       rc = drmModeMoveCursor(drm_fd, crtc_id, 2, 2);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_suspended());
+
+       /* Now set a new one without unsetting the previous one. */
+       rc = drmModeSetCursor(drm_fd, crtc_id, cursor_fb1.gem_handle,
+                             cursor_fb1.width, cursor_fb1.height);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_suspended());
+
+       /* Make sure nothing remains for the other tests. */
+       rc = drmModeSetCursor(drm_fd, crtc_id, 0, 0, 0);
+       igt_assert(rc == 0);
+       igt_assert(wait_for_suspended());
+}
+
 int rounds = 50;
 bool stay = false;
 
@@ -1480,6 +1577,12 @@ int main(int argc, char *argv[])
        igt_subtest("gem-idle")
                gem_idle_subtest();
 
+       /* Cursors */
+       igt_subtest("cursor")
+               cursor_subtest(false);
+       igt_subtest("cursor-dpms")
+               cursor_subtest(true);
+
        /* Misc */
        igt_subtest("reg-read-ioctl")
                reg_read_ioctl_subtest();
-- 
2.0.1

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

Reply via email to