From patchwork Mon Mar 5 14:21:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10259007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3C20960134 for ; Mon, 5 Mar 2018 14:21:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B83328A40 for ; Mon, 5 Mar 2018 14:21:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2026628A57; Mon, 5 Mar 2018 14:21:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 41D0228A40 for ; Mon, 5 Mar 2018 14:21:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 14EAE6E323; Mon, 5 Mar 2018 14:21:45 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by gabe.freedesktop.org (Postfix) with ESMTP id AA1DC6E311 for ; Mon, 5 Mar 2018 14:21:43 +0000 (UTC) Received: by mail.bootlin.com (Postfix, from userid 110) id A416A2071F; Mon, 5 Mar 2018 15:21:41 +0100 (CET) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id 4456A2077B; Mon, 5 Mar 2018 15:21:31 +0100 (CET) From: Maxime Ripard To: intel-gfx@lists.freedesktop.org Date: Mon, 5 Mar 2018 15:21:27 +0100 Message-Id: <20180305142129.18352-2-maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180305142129.18352-1-maxime.ripard@bootlin.com> References: <20180305142129.18352-1-maxime.ripard@bootlin.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH i-g-t 1/3] tests/chamelium: Move some functions and structures to a common place 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: Maxime Ripard , eben@raspberrypi.org, Thomas Petazzoni Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP We are going to use a few functions already defined in kms_chamelium in other tests. Let's move them out in a separate file / header. Signed-off-by: Maxime Ripard --- tests/Makefile.sources | 5 ++ tests/helpers_chamelium.c | 165 ++++++++++++++++++++++++++++++++++++++++++++ tests/helpers_chamelium.h | 65 ++++++++++++++++++ tests/kms_chamelium.c | 170 +--------------------------------------------- 4 files changed, 236 insertions(+), 169 deletions(-) create mode 100644 tests/helpers_chamelium.c create mode 100644 tests/helpers_chamelium.h diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 23f859beecef..c27226fc96c9 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -275,6 +275,11 @@ scripts = \ IMAGES = pass.png 1080p-left.png 1080p-right.png +kms_chamelium_SOURCES = \ + kms_chamelium.c \ + helpers_chamelium.h \ + helpers_chamelium.c + testdisplay_SOURCES = \ testdisplay.c \ testdisplay.h \ diff --git a/tests/helpers_chamelium.c b/tests/helpers_chamelium.c new file mode 100644 index 000000000000..2d60a8c5f944 --- /dev/null +++ b/tests/helpers_chamelium.c @@ -0,0 +1,165 @@ +/* + * Copyright © 2016 Red Hat Inc. + * + * 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: + * Lyude Paul + */ +#include "helpers_chamelium.h" + +void require_connector_present(data_t *data, unsigned int type) +{ + int i; + bool found = false; + + for (i = 0; i < data->port_count && !found; i++) { + if (chamelium_port_get_type(data->ports[i]) == type) + found = true; + } + + igt_require_f(found, "No port of type %s was found\n", + kmstest_connector_type_str(type)); +} + +drmModeConnection reprobe_connector(data_t *data, struct chamelium_port *port) +{ + drmModeConnector *connector; + drmModeConnection status; + + igt_debug("Reprobing %s...\n", chamelium_port_get_name(port)); + connector = chamelium_port_get_connector(data->chamelium, port, true); + igt_assert(connector); + status = connector->connection; + + drmModeFreeConnector(connector); + return status; +} + +void wait_for_connector(data_t *data, struct chamelium_port *port, + drmModeConnection status) +{ + bool finished = false; + + igt_debug("Waiting for %s to %sconnect...\n", + chamelium_port_get_name(port), + status == DRM_MODE_DISCONNECTED ? "dis" : ""); + + /* + * Rely on simple reprobing so we don't fail tests that don't require + * that hpd events work in the event that hpd doesn't work on the system + */ + igt_until_timeout(HOTPLUG_TIMEOUT) { + if (reprobe_connector(data, port) == status) { + finished = true; + return; + } + + usleep(50000); + } + + igt_assert(finished); +} + +void reset_state(data_t *data, struct chamelium_port *port) +{ + int p; + + chamelium_reset(data->chamelium); + + if (port) { + wait_for_connector(data, port, DRM_MODE_DISCONNECTED); + } else { + for (p = 0; p < data->port_count; p++) { + port = data->ports[p]; + wait_for_connector(data, port, DRM_MODE_DISCONNECTED); + } + } +} + +igt_output_t *prepare_output(data_t *data, struct chamelium_port *port) +{ + igt_display_t *display = &data->display; + igt_output_t *output; + drmModeRes *res; + drmModeConnector *connector = + chamelium_port_get_connector(data->chamelium, port, false); + enum pipe pipe; + bool found = false; + + igt_assert(res = drmModeGetResources(data->drm_fd)); + + /* The chamelium's default EDID has a lot of resolutions, way more then + * we need to test + */ + chamelium_port_set_edid(data->chamelium, port, data->edid_id); + + chamelium_plug(data->chamelium, port); + wait_for_connector(data, port, DRM_MODE_CONNECTED); + + igt_display_reset(display); + + output = igt_output_from_connector(display, connector); + + for_each_pipe(display, pipe) { + if (!igt_pipe_connector_valid(pipe, output)) + continue; + + found = true; + break; + } + + igt_assert_f(found, "No pipe found for output %s\n", igt_output_name(output)); + + igt_output_set_pipe(output, pipe); + + drmModeFreeConnector(connector); + drmModeFreeResources(res); + + return output; +} + +void enable_output(data_t *data, struct chamelium_port *port, + igt_output_t *output, drmModeModeInfo *mode, + struct igt_fb *fb) +{ + igt_display_t *display = output->display; + igt_plane_t *primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); + drmModeConnector *connector = chamelium_port_get_connector( + data->chamelium, port, false); + + igt_assert(primary); + + igt_plane_set_size(primary, mode->hdisplay, mode->vdisplay); + igt_plane_set_fb(primary, fb); + igt_output_override_mode(output, mode); + + /* Clear any color correction values that might be enabled */ + igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_DEGAMMA_LUT, NULL, 0); + igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_GAMMA_LUT, NULL, 0); + igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_CTM, NULL, 0); + + igt_display_commit2(display, COMMIT_ATOMIC); + + if (chamelium_port_get_type(port) == DRM_MODE_CONNECTOR_VGA) + usleep(250000); + + drmModeFreeConnector(connector); +} diff --git a/tests/helpers_chamelium.h b/tests/helpers_chamelium.h new file mode 100644 index 000000000000..5ae67bc4410d --- /dev/null +++ b/tests/helpers_chamelium.h @@ -0,0 +1,65 @@ +/* + * Copyright © 2016 Red Hat Inc. + * + * 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: + * Lyude Paul + */ +#include "igt.h" + +#define HOTPLUG_TIMEOUT 20 /* seconds */ + +#define HPD_STORM_PULSE_INTERVAL_DP 100 /* ms */ +#define HPD_STORM_PULSE_INTERVAL_HDMI 200 /* ms */ + +#define HPD_TOGGLE_COUNT_VGA 5 +#define HPD_TOGGLE_COUNT_DP_HDMI 15 +#define HPD_TOGGLE_COUNT_FAST 3 + +struct chamelium_frame_dump { + unsigned char *bgr; + size_t size; + int width; + int height; + struct chamelium_port *port; +}; + +typedef struct { + struct chamelium *chamelium; + struct chamelium_port **ports; + igt_display_t display; + int port_count; + + int drm_fd; + + int edid_id; + int alt_edid_id; +} data_t; + +void require_connector_present(data_t *data, unsigned int type); +drmModeConnection reprobe_connector(data_t *data, struct chamelium_port *port); +void wait_for_connector(data_t *data, struct chamelium_port *port, + drmModeConnection status); +void reset_state(data_t *data, struct chamelium_port *port); +igt_output_t *prepare_output(data_t *data, struct chamelium_port *port); +void enable_output(data_t *data, struct chamelium_port *port, + igt_output_t *output, drmModeModeInfo *mode, + struct igt_fb *fb); diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c index 8855a8300049..6419b72fcc9f 100644 --- a/tests/kms_chamelium.c +++ b/tests/kms_chamelium.c @@ -25,32 +25,12 @@ */ #include "config.h" +#include "helpers_chamelium.h" #include "igt.h" #include #include -typedef struct { - struct chamelium *chamelium; - struct chamelium_port **ports; - igt_display_t display; - int port_count; - - int drm_fd; - - int edid_id; - int alt_edid_id; -} data_t; - -#define HOTPLUG_TIMEOUT 20 /* seconds */ - -#define HPD_STORM_PULSE_INTERVAL_DP 100 /* ms */ -#define HPD_STORM_PULSE_INTERVAL_HDMI 200 /* ms */ - -#define HPD_TOGGLE_COUNT_VGA 5 -#define HPD_TOGGLE_COUNT_DP_HDMI 15 -#define HPD_TOGGLE_COUNT_FAST 3 - static void get_connectors_link_status_failed(data_t *data, bool *link_status_failed) { @@ -76,62 +56,6 @@ get_connectors_link_status_failed(data_t *data, bool *link_status_failed) } } -static void -require_connector_present(data_t *data, unsigned int type) -{ - int i; - bool found = false; - - for (i = 0; i < data->port_count && !found; i++) { - if (chamelium_port_get_type(data->ports[i]) == type) - found = true; - } - - igt_require_f(found, "No port of type %s was found\n", - kmstest_connector_type_str(type)); -} - -static drmModeConnection -reprobe_connector(data_t *data, struct chamelium_port *port) -{ - drmModeConnector *connector; - drmModeConnection status; - - igt_debug("Reprobing %s...\n", chamelium_port_get_name(port)); - connector = chamelium_port_get_connector(data->chamelium, port, true); - igt_assert(connector); - status = connector->connection; - - drmModeFreeConnector(connector); - return status; -} - -static void -wait_for_connector(data_t *data, struct chamelium_port *port, - drmModeConnection status) -{ - bool finished = false; - - igt_debug("Waiting for %s to %sconnect...\n", - chamelium_port_get_name(port), - status == DRM_MODE_DISCONNECTED ? "dis" : ""); - - /* - * Rely on simple reprobing so we don't fail tests that don't require - * that hpd events work in the event that hpd doesn't work on the system - */ - igt_until_timeout(HOTPLUG_TIMEOUT) { - if (reprobe_connector(data, port) == status) { - finished = true; - return; - } - - usleep(50000); - } - - igt_assert(finished); -} - static int chamelium_vga_modes[][2] = { { 1600, 1200 }, { 1920, 1200 }, @@ -202,23 +126,6 @@ check_analog_bridge(data_t *data, struct chamelium_port *port) return false; } -static void -reset_state(data_t *data, struct chamelium_port *port) -{ - int p; - - chamelium_reset(data->chamelium); - - if (port) { - wait_for_connector(data, port, DRM_MODE_DISCONNECTED); - } else { - for (p = 0; p < data->port_count; p++) { - port = data->ports[p]; - wait_for_connector(data, port, DRM_MODE_DISCONNECTED); - } - } -} - static void test_basic_hotplug(data_t *data, struct chamelium_port *port, int toggle_count) { @@ -408,81 +315,6 @@ test_suspend_resume_edid_change(data_t *data, struct chamelium_port *port, igt_skip_on(!link_status_failed[0][p] && link_status_failed[1][p]); } -static igt_output_t * -prepare_output(data_t *data, - struct chamelium_port *port) -{ - igt_display_t *display = &data->display; - igt_output_t *output; - drmModeRes *res; - drmModeConnector *connector = - chamelium_port_get_connector(data->chamelium, port, false); - enum pipe pipe; - bool found = false; - - igt_assert(res = drmModeGetResources(data->drm_fd)); - - /* The chamelium's default EDID has a lot of resolutions, way more then - * we need to test - */ - chamelium_port_set_edid(data->chamelium, port, data->edid_id); - - chamelium_plug(data->chamelium, port); - wait_for_connector(data, port, DRM_MODE_CONNECTED); - - igt_display_reset(display); - - output = igt_output_from_connector(display, connector); - - for_each_pipe(display, pipe) { - if (!igt_pipe_connector_valid(pipe, output)) - continue; - - found = true; - break; - } - - igt_assert_f(found, "No pipe found for output %s\n", igt_output_name(output)); - - igt_output_set_pipe(output, pipe); - - drmModeFreeConnector(connector); - drmModeFreeResources(res); - - return output; -} - -static void -enable_output(data_t *data, - struct chamelium_port *port, - igt_output_t *output, - drmModeModeInfo *mode, - struct igt_fb *fb) -{ - igt_display_t *display = output->display; - igt_plane_t *primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); - drmModeConnector *connector = chamelium_port_get_connector( - data->chamelium, port, false); - - igt_assert(primary); - - igt_plane_set_size(primary, mode->hdisplay, mode->vdisplay); - igt_plane_set_fb(primary, fb); - igt_output_override_mode(output, mode); - - /* Clear any color correction values that might be enabled */ - igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_DEGAMMA_LUT, NULL, 0); - igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_GAMMA_LUT, NULL, 0); - igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_CTM, NULL, 0); - - igt_display_commit2(display, COMMIT_ATOMIC); - - if (chamelium_port_get_type(port) == DRM_MODE_CONNECTOR_VGA) - usleep(250000); - - drmModeFreeConnector(connector); -} - static void test_display_crc(data_t *data, struct chamelium_port *port, int count, bool fast)