From patchwork Tue Oct 22 01:00:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11203359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3559B1895 for ; Tue, 22 Oct 2019 01:00:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C98620B7C for ; Tue, 22 Oct 2019 01:00:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C98620B7C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 70CA76E2ED; Tue, 22 Oct 2019 01:00:43 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5BE876E2EC; Tue, 22 Oct 2019 01:00:42 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id d17so9618199qto.3; Mon, 21 Oct 2019 18:00:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=hPZfHaMMDlb1wqPqvBr8Gx2HzSXsopXZIOCoxineNIc=; b=K0Gm0j+hHbuwEV35Xil/3loa05qv5HXkVG2xqhf9AvJbDK4pG4jXORs13OXEEaEMjj BSnIMv4FSzgLmMbdHoSWf3FErbg/GiSM7m2LmwWuqYcCe4DmK2CYxLtc0QF1mv3PMKdA i9Iv6y0ITa93ydzsRFT7YDyWmjW8tVY6jP0LWHT//k+00BM4ofw1ftR19Gu4Q+NYm73F I/KI23c5/qkWzykwpffHYJ0YY41fBlG0LI/sRiWogXiT5+s8XZnDq2Y/utc43jVNVugk AuOOZp57bYALE1KfjBIY946AHac7moPa9P06GCp+GjFGjC7n9dG0QILcSdG8tL06S2Yo izcg== X-Gm-Message-State: APjAAAX6eABKAnd1BuV/ON04LQZSEXHf196uFcz1UxRVXENXcMaPFpH7 hT3rSBoKhOgH0lMdnrojddo= X-Google-Smtp-Source: APXvYqxJxfIoUqxBFVukWHpSkYW2/n52tQXQkXozHb1l2hdfpgiF6w0uZvv7wDq60XoLwh90N7X+MA== X-Received: by 2002:a0c:d2b4:: with SMTP id q49mr562940qvh.135.1571706041277; Mon, 21 Oct 2019 18:00:41 -0700 (PDT) Received: from smtp.gmail.com (toroon12-3096782342.sdsl.bell.ca. [184.149.38.6]) by smtp.gmail.com with ESMTPSA id h23sm8209043qkk.128.2019.10.21.18.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 18:00:40 -0700 (PDT) From: Brian Starkey X-Google-Original-From: Brian Starkey Date: Mon, 21 Oct 2019 22:00:39 -0300 To: Simon Ser , Brian Starkey , Liviu Dudau , Petri Latvala , Arkadiusz Hiler , Daniel Vetter Message-ID: <20191022010032.pgqop52v4gz5omlc@smtp.gmail.com> MIME-Version: 1.0 User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=hPZfHaMMDlb1wqPqvBr8Gx2HzSXsopXZIOCoxineNIc=; b=qPBxSY+8l19D9UfmcLnePlMiCZJJu+/reFOTJekk26sVVtleqlLkEwxjg72hzoFLbI ReVGPaFGycslI6SmTkCJNwPVXPjaJb6jUAeBPpyJbF1NCbTqh69Uo/nlF4XokSAvyNVy q+QCC9qJrcpvXC5URiIp7NvNrbR+PPDeixQ1DlL29L+G5favKb7llxZ/yTjl0EPpodPG s9XDP5xd5bzU/l3nDaNJ+SmLXsGzYHXcMBVTYkaKj6ix0/bYKJ304DllmHKtu2goDX3k uOs9oWMC7ikAxsjgFnGarjkMR/ckVxVyC/nUoC2loESuyjG8tsHWNQap9JL4CyovoqT0 74Tg== Subject: [Intel-gfx] [PATCH v7 i-g-t 4/4] kms_writeback: Add writeback-check-output X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add a test which makes commits using the writeback connector, and checks the output buffer hash to make sure it is/isn't written as appropriate. V6: Simon Ser - Add igt documentation with igt_describe - Replace int ret by unsigned int fd_id when calling igt_create_fb - Add a descriptive error message if sync_fence_wait fail - Replace color_idx variable by i - Use in_fb instead of out_fb for getting the expected CRC - Drop unnecessary parentheses - Replace igt_fb_mod_to_tiling to DRM_FORMAT_MOD_LINEAR Signed-off-by: Brian Starkey [rebased and updated the patch to address feedback] Signed-off-by: Rodrigo Siqueira --- tests/kms_writeback.c | 123 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/tests/kms_writeback.c b/tests/kms_writeback.c index a373ec4d..068595b9 100644 --- a/tests/kms_writeback.c +++ b/tests/kms_writeback.c @@ -30,6 +30,7 @@ #include "igt.h" #include "igt_core.h" #include "igt_fb.h" +#include "sw_sync.h" IGT_TEST_DESCRIPTION("Exercise writeback feature."); @@ -196,6 +197,115 @@ static void writeback_test_fb(igt_output_t *output, igt_fb_t *valid_fb, igt_fb_t igt_assert(ret == -EINVAL); } +static void fill_fb(igt_fb_t *fb, double color[3]) +{ + cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb); + igt_assert(cr); + + igt_paint_color(cr, 0, 0, fb->width, fb->height, + color[0], color[1], color[2]); +} + +static void get_and_wait_out_fence(igt_output_t *output) +{ + int ret; + + igt_assert(output->writeback_out_fence_fd >= 0); + + ret = sync_fence_wait(output->writeback_out_fence_fd, 1000); + igt_assert_f(ret == 0, "sync_fence_wait failed: %s\n", strerror(-ret)); + close(output->writeback_out_fence_fd); + output->writeback_out_fence_fd = -1; +} + +static void writeback_sequence(igt_output_t *output, igt_plane_t *plane, + igt_fb_t *in_fb, igt_fb_t *out_fbs[], int n_commits) +{ + int i; + double in_fb_colors[2][3] = { + { 1.0, 0.0, 0.0 }, + { 0.0, 1.0, 0.0 }, + }; + double clear_color[3] = { 1.0, 1.0, 1.0 }; + igt_crc_t cleared_crc, out_expected; + + for (i = 0; i < n_commits; i++) { + /* Change the input color each time */ + fill_fb(in_fb, in_fb_colors[i % 2]); + + if (out_fbs[i]) { + igt_crc_t out_before; + + /* Get the expected CRC */ + igt_fb_get_crc(in_fb, &out_expected); + + fill_fb(out_fbs[i], clear_color); + if (i == 0) + igt_fb_get_crc(out_fbs[i], &cleared_crc); + igt_fb_get_crc(out_fbs[i], &out_before); + igt_assert_crc_equal(&cleared_crc, &out_before); + } + + /* Commit */ + igt_plane_set_fb(plane, in_fb); + igt_output_set_writeback_fb(output, out_fbs[i]); + + igt_display_commit_atomic(output->display, + DRM_MODE_ATOMIC_ALLOW_MODESET, + NULL); + if (out_fbs[i]) + get_and_wait_out_fence(output); + + /* Make sure the old output buffer is untouched */ + if (i > 0 && out_fbs[i - 1] && out_fbs[i] != out_fbs[i - 1]) { + igt_crc_t out_prev; + igt_fb_get_crc(out_fbs[i - 1], &out_prev); + igt_assert_crc_equal(&cleared_crc, &out_prev); + } + + /* Make sure this output buffer is written */ + if (out_fbs[i]) { + igt_crc_t out_after; + igt_fb_get_crc(out_fbs[i], &out_after); + igt_assert_crc_equal(&out_expected, &out_after); + + /* And clear it, for the next time */ + fill_fb(out_fbs[i], clear_color); + } + } +} + +static void writeback_check_output(igt_output_t *output, igt_plane_t *plane, + igt_fb_t *input_fb, igt_fb_t *output_fb) +{ + igt_fb_t *out_fbs[2] = { 0 }; + igt_fb_t second_out_fb; + unsigned int fb_id; + + /* One commit, with a writeback. */ + writeback_sequence(output, plane, input_fb, &output_fb, 1); + + /* Two commits, the second with no writeback */ + out_fbs[0] = output_fb; + writeback_sequence(output, plane, input_fb, out_fbs, 2); + + /* Two commits, both with writeback */ + out_fbs[1] = output_fb; + writeback_sequence(output, plane, input_fb, out_fbs, 2); + + fb_id = igt_create_fb(output_fb->fd, + output_fb->width, output_fb->height, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_MOD_LINEAR, &second_out_fb); + igt_require(fb_id > 0); + + /* Two commits, with different writeback buffers */ + out_fbs[1] = &second_out_fb; + writeback_sequence(output, plane, input_fb, out_fbs, 2); + + igt_remove_fb(output_fb->fd, &second_out_fb); +} + igt_main { igt_display_t display; @@ -283,6 +393,19 @@ igt_main igt_remove_fb(display.drm_fd, &invalid_fb); } + igt_describe("Check writeback output with CRC validation"); + igt_subtest("writeback-check-output") { + igt_fb_t output_fb; + fb_id = igt_create_fb(display.drm_fd, mode.hdisplay, + mode.vdisplay, DRM_FORMAT_XRGB8888, + DRM_FORMAT_MOD_LINEAR, &output_fb); + igt_require(fb_id > 0); + + writeback_check_output(output, plane, &input_fb, &output_fb); + + igt_remove_fb(display.drm_fd, &output_fb); + } + igt_fixture { igt_remove_fb(display.drm_fd, &input_fb); igt_display_fini(&display);