From patchwork Tue Sep 9 23:09:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Vivi X-Patchwork-Id: 4873311 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26EA9C0338 for ; Tue, 9 Sep 2014 23:09:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2B500201B4 for ; Tue, 9 Sep 2014 23:09:16 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D26FA2018E for ; Tue, 9 Sep 2014 23:09:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1DC7189D9B; Tue, 9 Sep 2014 16:09:14 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id D0ECE89D9B for ; Tue, 9 Sep 2014 16:09:12 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 09 Sep 2014 16:03:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,494,1406617200"; d="scan'208";a="600530920" Received: from rdvivi-bratislava.jf.intel.com ([10.7.196.158]) by orsmga002.jf.intel.com with ESMTP; 09 Sep 2014 16:09:12 -0700 From: Rodrigo Vivi To: intel-gfx@lists.freedesktop.org Date: Tue, 9 Sep 2014 19:09:12 -0400 Message-Id: <1410304152-5669-1-git-send-email-rodrigo.vivi@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1409794206-2126-3-git-send-email-rodrigo.vivi@intel.com> References: <1409794206-2126-3-git-send-email-rodrigo.vivi@intel.com> Cc: Rodrigo Vivi Subject: [Intel-gfx] [PATCH] tests/kms_sink_crc_basic: Simplify test by using igt_kms functions X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP v2: sink CRC R, G and B might change depending on display. So let's split the colors and bitwise them. Signed-off-by: Rodrigo Vivi --- tests/kms_sink_crc_basic.c | 175 +++++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 93 deletions(-) diff --git a/tests/kms_sink_crc_basic.c b/tests/kms_sink_crc_basic.c index 3703dc1..a7febe8 100644 --- a/tests/kms_sink_crc_basic.c +++ b/tests/kms_sink_crc_basic.c @@ -34,20 +34,18 @@ #include "igt_debugfs.h" #include "igt_kms.h" +#define CRC_BLACK "000000000000" + enum color { - WHITE, - BLACK, - NUM_COLORS, + RED, + GREEN, }; typedef struct { - struct kmstest_connector_config config; - struct igt_fb fb; -} connector_t; - -typedef struct { int drm_fd; - drmModeRes *resources; + igt_display_t display; + struct igt_fb fb_green, fb_red; + igt_plane_t *primary; } data_t; static void get_crc(char *crc) { @@ -59,111 +57,104 @@ static void get_crc(char *crc) { igt_require(ret > 0); fclose(file); -} - -static uint32_t create_fb(data_t *data, - int w, int h, - double r, double g, double b, - struct igt_fb *fb) -{ - cairo_t *cr; - uint32_t fb_id; - - fb_id = igt_create_fb(data->drm_fd, w, h, - DRM_FORMAT_XRGB8888, I915_TILING_NONE, fb); - igt_assert(fb_id); - cr = igt_get_cairo_ctx(data->drm_fd, fb); - igt_paint_color(cr, 0, 0, w, h, r, g, b); - igt_assert(cairo_status(cr) == 0); - - return fb_id; + /* Black screen is always invalid */ + igt_assert(strcmp(crc, CRC_BLACK) != 0); } -static bool -connector_set_mode(data_t *data, connector_t *connector, drmModeModeInfo *mode, - enum color crtc_color) +static void assert_color(char *crc, enum color color) { - struct kmstest_connector_config *config = &connector->config; - unsigned int fb_id; + char color_mask[5] = "FFFF\0"; + char rs[5], gs[5], bs[5]; + unsigned int rh, gh, bh, mask; int ret; - if (crtc_color == WHITE) - fb_id = create_fb(data, mode->hdisplay, mode->vdisplay, - 1.0, 1.0, 1.0, &connector->fb); - else - fb_id = create_fb(data, mode->hdisplay, mode->vdisplay, - 0.0, 0.0, 0.0, &connector->fb); - igt_assert(fb_id); - - ret = drmModeSetCrtc(data->drm_fd, - config->crtc->crtc_id, - connector->fb.fb_id, - 0, 0, /* x, y */ - &config->connector->connector_id, - 1, - mode); - igt_assert(ret == 0); - - return 0; -} - -static void basic_sink_crc_check(data_t *data, uint32_t connector_id) -{ - connector_t connector; - char ref_crc_white[12]; - char ref_crc_black[12]; - char crc_check[12]; - - igt_require(kmstest_get_connector_config(data->drm_fd, - connector_id, - 1 << 0, - &connector.config)); - - /*Go White*/ - connector_set_mode(data, &connector, &connector.config.default_mode, WHITE); + sscanf(color_mask, "%4x", &mask); - /* get reference crc for white color */ - get_crc(ref_crc_white); + memcpy(rs, &crc[0], 4); + rs[4] = '\0'; + ret = sscanf(rs, "%4x", &rh); + igt_require(ret > 0); - /* Go Black */ - connector_set_mode(data, &connector, &connector.config.default_mode, BLACK); + memcpy(gs, &crc[4], 4); + gs[4] = '\0'; + ret = sscanf(gs, "%4x", &gh); + igt_require(ret > 0); - /* get reference crc for black color */ - get_crc(ref_crc_black); + memcpy(bs, &crc[8], 4); + bs[4] = '\0'; + ret = sscanf(bs, "%4x", &bh); + igt_require(ret > 0); - igt_assert(strcmp(ref_crc_black, ref_crc_white) != 0); + switch (color) { + case RED: + igt_assert((rh & mask) != 0 && + (gh & mask) == 0 && + (bh & mask) == 0); + break; + case GREEN: + igt_assert((rh & mask) == 0 && + (gh & mask) != 0 && + (bh & mask) == 0); + break; + default: + igt_fail(-1); + } +} - /*Go White again*/ - connector_set_mode(data, &connector, &connector.config.default_mode, WHITE); +static void basic_sink_crc_check(data_t *data) +{ + char crc[13]; - get_crc(crc_check); - igt_assert(strcmp(crc_check, ref_crc_white) == 0); + /* Go Green */ + igt_plane_set_fb(data->primary, &data->fb_green); + igt_display_commit(&data->display); - /* Go Black again */ - connector_set_mode(data, &connector, &connector.config.default_mode, BLACK); + /* It should be Green */ + get_crc(crc); + assert_color(crc, GREEN); - get_crc(crc_check); - igt_assert(strcmp(crc_check, ref_crc_black) == 0); + /* Go Red */ + igt_plane_set_fb(data->primary, &data->fb_red); + igt_display_commit(&data->display); - kmstest_free_connector_config(&connector.config); + /* It should be Red */ + get_crc(crc); + assert_color(crc, RED); } static void run_test(data_t *data) { - int i; - drmModeConnectorPtr c; - uint32_t connector_id = 0; + igt_display_t *display = &data->display; + igt_output_t *output; + drmModeModeInfo *mode; - for (i = 0; i < data->resources->count_connectors; i++) { - connector_id = data->resources->connectors[i]; - c = drmModeGetConnector(data->drm_fd, connector_id); + for_each_connected_output(display, output) { + drmModeConnectorPtr c = output->config.connector; if (c->connector_type != DRM_MODE_CONNECTOR_eDP || c->connection != DRM_MODE_CONNECTED) continue; - basic_sink_crc_check(data, connector_id); + igt_output_set_pipe(output, PIPE_ANY); + + mode = igt_output_get_mode(output); + + igt_create_color_fb(data->drm_fd, + mode->hdisplay, mode->vdisplay, + DRM_FORMAT_XRGB8888, I915_TILING_X, + 0.0, 1.0, 0.0, + &data->fb_green); + + igt_create_color_fb(data->drm_fd, + mode->hdisplay, mode->vdisplay, + DRM_FORMAT_XRGB8888, I915_TILING_X, + 1.0, 0.0, 0.0, + &data->fb_red); + + data->primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); + + basic_sink_crc_check(data); return; } @@ -179,11 +170,9 @@ igt_simple_main data.drm_fd = drm_open_any(); kmstest_set_vt_graphics_mode(); - - data.resources = drmModeGetResources(data.drm_fd); - igt_assert(data.resources); + igt_display_init(&data.display, data.drm_fd); run_test(&data); - drmModeFreeResources(data.resources); + igt_display_fini(&data.display); }