From patchwork Thu Jul 9 17:08:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paulo Zanoni X-Patchwork-Id: 6757561 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B8D429F319 for ; Thu, 9 Jul 2015 17:09:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BEE3206A5 for ; Thu, 9 Jul 2015 17:09:24 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 264E42052C for ; Thu, 9 Jul 2015 17:09:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A42D6E00D; Thu, 9 Jul 2015 10:09:22 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk0-f181.google.com (mail-qk0-f181.google.com [209.85.220.181]) by gabe.freedesktop.org (Postfix) with ESMTPS id B0B606E00D for ; Thu, 9 Jul 2015 10:09:21 -0700 (PDT) Received: by qkei195 with SMTP id i195so190121168qke.3 for ; Thu, 09 Jul 2015 10:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=jD4WPe25FwUot27wGIDrnbbe1YISgElz2EVsNNrgd9I=; b=LwTUxfdOo3R/hKyytOzDTXxHqQupT0caRz8eHg5S2uEFMp5iD6EYbDsSQJi93kEJkA 2r/J8eXR0EWYIpeN4GKJruP9tTbOvX6O5Ia06wvAGrrtWri8rSf5xYT+gEpq/EA0Bq1w XYSw3t8H1JJGiK9pgTH1ZnmoPmNx5goECElx660WKJIDxHJA4RI8VLZyB/4rwpbK0/2j mz1LOGmZQ7Fe51762PJ+jt890TXrD5sJyO3qsQ/lJ0RpQViaBWRbWeD/PlflR6YNqK1L 1wlVujz971dVEonaDuiRa+eOOtCaFlCk/YzCfA40Y5qybAnYhuvJ4yaosr4/nTVwg1P0 SPRw== X-Received: by 10.140.194.72 with SMTP id p69mr27813283qha.1.1436461759907; Thu, 09 Jul 2015 10:09:19 -0700 (PDT) Received: from localhost.localdomain (r130-pw-tresbarras.ibys.com.br. [189.76.1.243]) by smtp.gmail.com with ESMTPSA id f31sm3995157qge.27.2015.07.09.10.09.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Jul 2015 10:09:19 -0700 (PDT) From: Paulo Zanoni To: intel-gfx@lists.freedesktop.org Date: Thu, 9 Jul 2015 14:08:35 -0300 Message-Id: <1436461715-1684-1-git-send-email-przanoni@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <20150709152629.GH21858@phenom.ffwll.local> References: <20150709152629.GH21858@phenom.ffwll.local> MIME-Version: 1.0 Cc: Paulo Zanoni Subject: [Intel-gfx] [PATCH igt] tests: add kms_fbcon_fbt X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 From: Paulo Zanoni This test should test the interactions between fbcon and the frontbuffer tracking infrastructure. Right now the PSR test fails, but as soon as we merge the following kernel patches, the test wills tart passing: - drm/i915: PSR: Flush means invalidate + flush - drm/i915: fbdev restore mode needs to invalidate frontbuffer - drm/i915: fbdev_set_par reliably invalidating frontbuffer I didn't want to make this a subtest of kms_frontbuffer_tracking just because when I wrote it, I really didn't have in mind the fact that someone might just close the DRM fd in the middle of a subtest. After this commit we'll have a little bit of duplicated code among tests. I'll clean this up later. Signed-off-by: Paulo Zanoni --- tests/.gitignore | 1 + tests/Makefile.sources | 1 + tests/kms_fbcon_fbt.c | 333 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 tests/kms_fbcon_fbt.c diff --git a/tests/.gitignore b/tests/.gitignore index c31b22a..0af0899 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -131,6 +131,7 @@ kms_addfb kms_cursor_crc kms_draw_crc kms_fbc_crc +kms_fbcon_fbt kms_fence_pin_leak kms_flip kms_flip_event_leak diff --git a/tests/Makefile.sources b/tests/Makefile.sources index b9479cc..c94714b 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -65,6 +65,7 @@ TESTS_progs_M = \ kms_cursor_crc \ kms_draw_crc \ kms_fbc_crc \ + kms_fbcon_fbt \ kms_flip \ kms_flip_event_leak \ kms_flip_tiling \ diff --git a/tests/kms_fbcon_fbt.c b/tests/kms_fbcon_fbt.c new file mode 100644 index 0000000..e5d2d33 --- /dev/null +++ b/tests/kms_fbcon_fbt.c @@ -0,0 +1,333 @@ +/* + * Copyright © 2015 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * + */ + +#include +#include +#include + +#include "drmtest.h" +#include "igt_aux.h" +#include "igt_debugfs.h" +#include "igt_draw.h" +#include "igt_kms.h" + +IGT_TEST_DESCRIPTION("Test the relationship between fbcon and the frontbuffer " + "tracking infrastructure."); + +#define MAX_CONNECTORS 32 +#define DEBUGFS_MSG_SIZE 256 + +static bool do_wait_user = false; + +struct drm_info { + int fd; + drmModeResPtr res; + drmModeConnectorPtr connectors[MAX_CONNECTORS]; +}; + +struct fbc_info { + int fd; +}; + +struct psr_info { + int fd; +}; + +enum feature_status { + ENABLED, + DISABLED, +}; + +static void wait_user(const char *msg) +{ + if (!do_wait_user) + return; + + igt_info("%s Press enter...\n", msg); + while (getchar() != '\n') + ; +} + +static void setup_drm(struct drm_info *drm) +{ + int i; + + drm->fd = drm_open_any_master(); + + drm->res = drmModeGetResources(drm->fd); + igt_assert(drm->res->count_connectors <= MAX_CONNECTORS); + + for (i = 0; i < drm->res->count_connectors; i++) + drm->connectors[i] = drmModeGetConnector(drm->fd, + drm->res->connectors[i]); + + kmstest_set_vt_graphics_mode(); +} + +static void teardown_drm(struct drm_info *drm) +{ + int i; + + kmstest_restore_vt_mode(); + + for (i = 0; i < drm->res->count_connectors; i++) + drmModeFreeConnector(drm->connectors[i]); + + drmModeFreeResources(drm->res); + igt_assert(close(drm->fd) == 0); +} + +static void get_debugfs_string(int fd, char *buf) +{ + ssize_t n_read; + + lseek(fd, 0, SEEK_SET); + + n_read = read(fd, buf, DEBUGFS_MSG_SIZE -1); + igt_assert(n_read >= 0); + buf[n_read] = '\0'; +} + +static bool fbc_supported_on_chipset(int fd) +{ + char buf[DEBUGFS_MSG_SIZE]; + + get_debugfs_string(fd, buf); + return !strstr(buf, "FBC unsupported on this chipset\n"); +} + +static void setup_fbc(struct fbc_info *fbc) +{ + fbc->fd = igt_debugfs_open("i915_fbc_status", O_RDONLY); + igt_assert(fbc->fd >= 0); + + igt_require_f(fbc_supported_on_chipset(fbc->fd), + "Can't test FBC: not supported on this chipset\n"); + + igt_set_module_param_int("enable_fbc", 1); +} + +static void teardown_fbc(struct fbc_info *fbc) +{ + igt_assert(close(fbc->fd) == 0); +} + +static bool connector_can_fbc(drmModeConnectorPtr connector) +{ + return true; +} + +static bool fbc_get_status(int fd) +{ + char buf[DEBUGFS_MSG_SIZE]; + + get_debugfs_string(fd, buf); + + if (strstr(buf, "FBC enabled\n")) + return ENABLED; + else + return DISABLED; +} + +static bool fbc_wait_for_status(struct fbc_info *fbc, + enum feature_status status) +{ + return igt_wait(fbc_get_status(fbc->fd) == status, 5000, 1); +} + +typedef bool (*connector_possible_fn)(drmModeConnectorPtr connector); + +static void set_mode_for_one_screen(struct drm_info *drm, struct igt_fb *fb, + connector_possible_fn connector_possible) +{ + int i, rc; + uint32_t connector_id = 0, crtc_id; + drmModeModeInfoPtr mode; + uint32_t buffer_id; + drmModeConnectorPtr c = NULL; + + for (i = 0; i < drm->res->count_connectors; i++) { + c = drm->connectors[i]; + + if (c->connection == DRM_MODE_CONNECTED && c->count_modes && + connector_possible(c)) { + connector_id = c->connector_id; + mode = &c->modes[0]; + break; + } + } + igt_require_f(connector_id, "No connector available\n"); + + crtc_id = drm->res->crtcs[0]; + + buffer_id = igt_create_fb(drm->fd, mode->hdisplay, mode->vdisplay, + DRM_FORMAT_XRGB8888, + LOCAL_I915_FORMAT_MOD_X_TILED, fb); + igt_draw_fill_fb(drm->fd, fb, 0xFF); + + igt_info("Setting %dx%d mode for %s connector\n", + mode->hdisplay, mode->vdisplay, + kmstest_connector_type_str(c->connector_type)); + + rc = drmModeSetCrtc(drm->fd, crtc_id, buffer_id, 0, 0, &connector_id, 1, + mode); + igt_assert_eq(rc, 0); +} + +static void fbc_subtest(void) +{ + struct drm_info drm; + struct fbc_info fbc; + struct igt_fb fb; + + setup_fbc(&fbc); + + setup_drm(&drm); + + kmstest_unset_all_crtcs(drm.fd, drm.res); + wait_user("Modes unset."); + igt_assert(fbc_wait_for_status(&fbc, DISABLED)); + + set_mode_for_one_screen(&drm, &fb, connector_can_fbc); + wait_user("FBC screen set."); + igt_assert(fbc_wait_for_status(&fbc, ENABLED)); + + igt_remove_fb(drm.fd, &fb); + teardown_drm(&drm); + + /* Wait for fbcon to restore itself. */ + sleep(5); + + wait_user("Back to fbcon."); + igt_assert(fbc_wait_for_status(&fbc, DISABLED)); + + teardown_fbc(&fbc); +} + +static bool psr_supported_on_chipset(int fd) +{ + char buf[DEBUGFS_MSG_SIZE]; + + get_debugfs_string(fd, buf); + + return strstr(buf, "Sink_Support: yes\n"); +} + +static void setup_psr(struct psr_info *psr) +{ + psr->fd = igt_debugfs_open("i915_edp_psr_status", O_RDONLY); + igt_assert(psr->fd >= 0); + + igt_require_f(psr_supported_on_chipset(psr->fd), + "Can't test PSR: not supported on this chipset\n"); + + igt_set_module_param_int("enable_psr", 1); +} + +static void teardown_psr(struct psr_info *psr) +{ + igt_assert(close(psr->fd) == 0); +} + +static bool connector_can_psr(drmModeConnectorPtr connector) +{ + return (connector->connector_type == DRM_MODE_CONNECTOR_eDP); +} + +static bool psr_get_status(int fd) +{ + char buf[DEBUGFS_MSG_SIZE]; + + get_debugfs_string(fd, buf); + + if (strstr(buf, "\nActive: yes\n")) + return ENABLED; + else + return DISABLED; +} + +static bool psr_wait_for_status(struct psr_info *psr, + enum feature_status status) +{ + return igt_wait(psr_get_status(psr->fd) == status, 5000, 1); +} + +static void psr_subtest(void) +{ + struct drm_info drm; + struct psr_info psr; + struct igt_fb fb; + + setup_psr(&psr); + + setup_drm(&drm); + + kmstest_unset_all_crtcs(drm.fd, drm.res); + wait_user("Modes unset."); + igt_assert(psr_wait_for_status(&psr, DISABLED)); + + set_mode_for_one_screen(&drm, &fb, connector_can_psr); + wait_user("PSR screen set."); + igt_assert(psr_wait_for_status(&psr, ENABLED)); + + igt_remove_fb(drm.fd, &fb); + teardown_drm(&drm); + + /* Wait for fbcon to restore itself. */ + sleep(5); + + wait_user("Back to fbcon."); + igt_assert(psr_wait_for_status(&psr, DISABLED)); + + teardown_psr(&psr); +} + +static void setup_environment(void) +{ + int drm_fd; + + drm_fd = drm_open_any_master(); + igt_require(drm_fd >= 0); + igt_assert(close(drm_fd) == 0); +} + +static void teardown_environment(void) +{ +} + +igt_main +{ + igt_fixture + setup_environment(); + + igt_subtest("fbc") + fbc_subtest(); + igt_subtest("psr") + psr_subtest(); + + igt_fixture + teardown_environment(); +}