Commit 08eeaa13 authored by Maxime Ripard's avatar Maxime Ripard

drm/tests: Add output formats tests

Now that we track the HDMI output format as part of the connector state,
let's add a few tests to make sure it works as expected.
Reviewed-by: default avatarDave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240527-kms-hdmi-connector-state-v15-8-c5af16c3aae2@kernel.orgSigned-off-by: default avatarMaxime Ripard <mripard@kernel.org>
parent 948f01d5
......@@ -363,6 +363,42 @@ static void drm_test_connector_hdmi_init_bpc_12(struct kunit *test)
KUNIT_EXPECT_NOT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id));
}
/*
* Test that the registration of an HDMI connector with no supported
* format fails.
*/
static void drm_test_connector_hdmi_init_formats_empty(struct kunit *test)
{
struct drm_connector_init_priv *priv = test->priv;
int ret;
ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
0,
8);
KUNIT_EXPECT_LT(test, ret, 0);
}
/*
* Test that the registration of an HDMI connector not listing RGB as a
* supported format fails.
*/
static void drm_test_connector_hdmi_init_formats_no_rgb(struct kunit *test)
{
struct drm_connector_init_priv *priv = test->priv;
int ret;
ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_YUV422),
8);
KUNIT_EXPECT_LT(test, ret, 0);
}
/*
* Test that the registration of an HDMI connector with an HDMI
* connector type succeeds.
......@@ -448,6 +484,8 @@ static struct kunit_case drmm_connector_hdmi_init_tests[] = {
KUNIT_CASE(drm_test_connector_hdmi_init_bpc_12),
KUNIT_CASE(drm_test_connector_hdmi_init_bpc_invalid),
KUNIT_CASE(drm_test_connector_hdmi_init_bpc_null),
KUNIT_CASE(drm_test_connector_hdmi_init_formats_empty),
KUNIT_CASE(drm_test_connector_hdmi_init_formats_no_rgb),
KUNIT_CASE(drm_test_connector_hdmi_init_null_ddc),
KUNIT_CASE_PARAM(drm_test_connector_hdmi_init_type_valid,
drm_connector_hdmi_init_type_valid_gen_params),
......@@ -525,10 +563,69 @@ static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
.test_cases = drm_get_tv_mode_from_name_tests,
};
struct drm_hdmi_connector_get_output_format_name_test {
unsigned int kind;
const char *expected_name;
};
#define OUTPUT_FORMAT_TEST(_kind, _name) \
{ \
.kind = _kind, \
.expected_name = _name, \
}
static void drm_test_drm_hdmi_connector_get_output_format_name(struct kunit *test)
{
const struct drm_hdmi_connector_get_output_format_name_test *params =
test->param_value;
KUNIT_EXPECT_STREQ(test,
drm_hdmi_connector_get_output_format_name(params->kind),
params->expected_name);
}
static const
struct drm_hdmi_connector_get_output_format_name_test
drm_hdmi_connector_get_output_format_name_valid_tests[] = {
OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_RGB, "RGB"),
OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV420, "YUV 4:2:0"),
OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV422, "YUV 4:2:2"),
OUTPUT_FORMAT_TEST(HDMI_COLORSPACE_YUV444, "YUV 4:4:4"),
};
static void
drm_hdmi_connector_get_output_format_name_valid_desc(const struct drm_hdmi_connector_get_output_format_name_test *t,
char *desc)
{
sprintf(desc, "%s", t->expected_name);
}
KUNIT_ARRAY_PARAM(drm_hdmi_connector_get_output_format_name_valid,
drm_hdmi_connector_get_output_format_name_valid_tests,
drm_hdmi_connector_get_output_format_name_valid_desc);
static void drm_test_drm_hdmi_connector_get_output_format_name_invalid(struct kunit *test)
{
KUNIT_EXPECT_NULL(test, drm_hdmi_connector_get_output_format_name(4));
};
static struct kunit_case drm_hdmi_connector_get_output_format_name_tests[] = {
KUNIT_CASE_PARAM(drm_test_drm_hdmi_connector_get_output_format_name,
drm_hdmi_connector_get_output_format_name_valid_gen_params),
KUNIT_CASE(drm_test_drm_hdmi_connector_get_output_format_name_invalid),
{ }
};
static struct kunit_suite drm_hdmi_connector_get_output_format_name_test_suite = {
.name = "drm_hdmi_connector_get_output_format_name",
.test_cases = drm_hdmi_connector_get_output_format_name_tests,
};
kunit_test_suites(
&drmm_connector_hdmi_init_test_suite,
&drmm_connector_init_test_suite,
&drm_get_tv_mode_from_name_test_suite
&drm_get_tv_mode_from_name_test_suite,
&drm_hdmi_connector_get_output_format_name_test_suite
);
MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
......
......@@ -349,6 +349,15 @@ static void drm_test_check_output_bpc_crtc_mode_not_changed(struct kunit *test)
static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = {
KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_changed),
KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_not_changed),
/*
* TODO: We should have tests to check that a change in the
* format triggers a CRTC mode change just like we do for the
* RGB Quantization and BPC.
*
* However, we don't have any way to control which format gets
* picked up aside from changing the BPC or mode which would
* already trigger a mode change.
*/
{ }
};
......@@ -429,10 +438,33 @@ static void drm_test_check_bpc_12_value(struct kunit *test)
KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 0);
}
/*
* Test that the value of the output format property out of reset is set
* to RGB, even if the driver supports more than that.
*/
static void drm_test_check_format_value(struct kunit *test)
{
struct drm_atomic_helper_connector_hdmi_priv *priv;
struct drm_connector_state *conn_state;
struct drm_connector *conn;
priv = drm_atomic_helper_connector_hdmi_init(test,
BIT(HDMI_COLORSPACE_RGB) |
BIT(HDMI_COLORSPACE_YUV422) |
BIT(HDMI_COLORSPACE_YUV444),
8);
KUNIT_ASSERT_NOT_NULL(test, priv);
conn = &priv->connector;
conn_state = conn->state;
KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_RGB);
}
static struct kunit_case drm_atomic_helper_connector_hdmi_reset_tests[] = {
KUNIT_CASE(drm_test_check_bpc_8_value),
KUNIT_CASE(drm_test_check_bpc_10_value),
KUNIT_CASE(drm_test_check_bpc_12_value),
KUNIT_CASE(drm_test_check_format_value),
{ }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment