All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stylon Wang <stylon.wang@amd.com>
To: igt-dev@lists.freedesktop.org
Cc: harry.wentland@amd.com, anson.jacob@amd.com,
	rodrigo.siqueira@amd.com, Stylon Wang <stylon.wang@amd.com>
Subject: [igt-dev] [PATCH i-g-t] test/amdgpu: Test max-bpc fallback for 4K modes on HDMI
Date: Wed, 29 Sep 2021 13:22:14 +0800	[thread overview]
Message-ID: <20210929052214.437157-1-stylon.wang@amd.com> (raw)

[Why]
There was a driver regression with which too high max-bpc setting
causes 4K video modes failing stream validation and dropped from
mode list.

[How]
Add this test to catch the regression.

Signed-off-by: Stylon Wang <stylon.wang@amd.com>
---
 tests/amdgpu/amd_max_bpc.c | 190 +++++++++++++++++++++++++++++++++++++
 tests/amdgpu/meson.build   |   1 +
 2 files changed, 191 insertions(+)
 create mode 100644 tests/amdgpu/amd_max_bpc.c

diff --git a/tests/amdgpu/amd_max_bpc.c b/tests/amdgpu/amd_max_bpc.c
new file mode 100644
index 00000000..914034d3
--- /dev/null
+++ b/tests/amdgpu/amd_max_bpc.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, 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 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
+ */
+
+#include "igt.h"
+#include <fcntl.h>
+
+IGT_TEST_DESCRIPT("Test 4K HDMI regression if max bpc is too high");
+
+/* Common test data. */
+typedef struct data {
+	igt_display_t display;
+	igt_plane_t *primary;
+	igt_output_t *output;
+	igt_pipe_t *pipe;
+	igt_pipe_crc_t *pipe_crc;
+	igt_pipe_crc_t *pipe_crc_dither;
+	drmModeModeInfo *mode;
+	enum pipe pipe_id;
+	int fd;
+	int w;
+	int h;
+} data_t;
+
+/* BPC connector state. */
+typedef struct output_bpc {
+	unsigned int current;
+	unsigned int maximum;
+} output_bpc_t;
+
+static drmModeModeInfo uhd_mode = {
+	  594000,
+	  3840, 4016, 4104, 4400, 0,
+	  2160, 2168, 2178, 2250, 0,
+	  60, 0x5|DRM_MODE_FLAG_PIC_AR_64_27,
+	  0x40,
+	  "3840x2160@60", /* VIC 107 */
+	  };
+
+/* Returns the current and maximum bpc from the connector debugfs. */
+static output_bpc_t get_output_bpc(data_t *data)
+{
+	char buf[256];
+	char *start_loc;
+	int fd, res;
+	output_bpc_t info;
+
+	fd = igt_debugfs_connector_dir(data->fd, data->output->name, O_RDONLY);
+	igt_assert(fd >= 0);
+
+	res = igt_debugfs_simple_read(fd, "output_bpc", buf, sizeof(buf));
+
+	igt_require(res > 0);
+
+	close(fd);
+
+	igt_assert(start_loc = strstr(buf, "Current: "));
+	igt_assert_eq(sscanf(start_loc, "Current: %u", &info.current), 1);
+
+	igt_assert(start_loc = strstr(buf, "Maximum: "));
+	igt_assert_eq(sscanf(start_loc, "Maximum: %u", &info.maximum), 1);
+
+	return info;
+}
+
+/* Verifies that connector has the correct output bpc. */
+static void assert_output_bpc(data_t *data, unsigned int bpc)
+{
+	output_bpc_t info = get_output_bpc(data);
+
+	igt_require_f(info.maximum >= bpc,
+		      "Monitor doesn't support %u bpc, max is %u\n", bpc,
+		      info.maximum);
+
+	igt_assert_eq(info.current, bpc);
+}
+
+/* Common test setup. */
+static void test_init(data_t *data)
+{
+	igt_display_t *display = &data->display;
+
+	/* It doesn't matter which pipe we choose on amdpgu. */
+	data->pipe_id = PIPE_A;
+	data->pipe = &data->display.pipes[data->pipe_id];
+
+	igt_display_reset(display);
+
+	/* find a connected HDMI output */
+	data->output = NULL;
+	for (int i=0; i < data->display.n_outputs; ++i) {
+		drmModeConnector *connector = data->display.outputs[i].config.connector;
+		if (connector->connection == DRM_MODE_CONNECTED &&
+				(connector->connector_type == DRM_MODE_CONNECTOR_HDMIA)) {
+			data->output = &data->display.outputs[i];
+		}
+	}
+	igt_assert_f(data->output, "Requires connected HDMI output\n");
+
+	igt_output_set_prop_value(data->output, IGT_CONNECTOR_MAX_BPC, 10);
+	igt_output_override_mode(data->output, &uhd_mode);
+
+	data->mode = igt_output_get_mode(data->output);
+	igt_assert(data->mode);
+	assert_output_bpc(data, 8);
+
+	data->primary =
+		igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);
+
+	data->pipe_crc = igt_pipe_crc_new(data->fd, data->pipe_id,
+					  INTEL_PIPE_CRC_SOURCE_AUTO);
+
+	igt_output_set_pipe(data->output, data->pipe_id);
+
+	data->w = data->mode->hdisplay;
+	data->h = data->mode->vdisplay;
+}
+
+/* Common test cleanup. */
+static void test_fini(data_t *data)
+{
+	igt_pipe_crc_free(data->pipe_crc);
+	igt_display_reset(&data->display);
+}
+
+static void test_4k_mode_max_bpc(data_t *data)
+{
+	igt_display_t *display = &data->display;
+	igt_fb_t rfb;
+	int max_bpc = 16;
+
+	test_init(data);
+
+	igt_info("Setting output max bpc to %d\n", max_bpc);
+
+	igt_output_set_prop_value(data->output, IGT_CONNECTOR_MAX_BPC, max_bpc);
+
+	igt_create_pattern_fb(data->fd, data->w, data->h, DRM_FORMAT_XRGB8888, 0, &rfb);
+	igt_plane_set_fb(data->primary, &rfb);
+	igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
+
+	test_fini(data);
+	igt_remove_fb(data->fd, &rfb);
+}
+
+igt_main
+{
+	data_t data;
+
+	igt_skip_on_simulation();
+
+	memset(&data, 0, sizeof(data));
+
+	igt_fixture
+	{
+		data.fd = drm_open_driver_master(DRIVER_AMDGPU);
+
+		kmstest_set_vt_graphics_mode();
+
+		igt_display_require(&data.display, data.fd);
+		igt_require(data.display.is_atomic);
+		igt_display_require_output(&data.display);
+	}
+
+	igt_describe("Tests overly high 'max bpc' should not affect 4K modes on HDMI");
+	igt_subtest("4k-mode-max-bpc") test_4k_mode_max_bpc(&data);
+
+	igt_fixture
+	{
+		igt_display_fini(&data.display);
+	}
+}
diff --git a/tests/amdgpu/meson.build b/tests/amdgpu/meson.build
index aec71cb5..b736c456 100644
--- a/tests/amdgpu/meson.build
+++ b/tests/amdgpu/meson.build
@@ -11,6 +11,7 @@ if libdrm_amdgpu.found()
 			  'amd_hotplug',
 			  'amd_info',
 			  'amd_prime',
+			  'amd_max_bpc',
 			  'amd_module_load',
 			  'amd_mem_leak',
 			  'amd_link_settings',
-- 
2.32.0

             reply	other threads:[~2021-09-29  5:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  5:22 Stylon Wang [this message]
2021-09-29  5:28 ` [igt-dev] ✗ Fi.CI.BUILD: failure for test/amdgpu: Test max-bpc fallback for 4K modes on HDMI Patchwork
2021-09-29  5:33 ` [igt-dev] ✗ GitLab.Pipeline: warning " Patchwork
2021-09-29 17:32 ` [igt-dev] [PATCH i-g-t] " Rodrigo Siqueira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210929052214.437157-1-stylon.wang@amd.com \
    --to=stylon.wang@amd.com \
    --cc=anson.jacob@amd.com \
    --cc=harry.wentland@amd.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=rodrigo.siqueira@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.