[<prev] [next>] [day] [month] [year] [list]
Message-ID: <dd41628d-ef9e-4f48-ba88-58cfc0a98458@riseup.net>
Date: Thu, 10 Nov 2022 20:11:57 -0300
From: Maíra Canal <mairacanal@...eup.net>
To: Maxime Ripard <maxime@...no.tech>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Chen-Yu Tsai <wens@...e.org>,
Maxime Ripard <mripard@...nel.org>,
Jernej Skrabec <jernej.skrabec@...il.com>,
Karol Herbst <kherbst@...hat.com>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Daniel Vetter <daniel@...ll.ch>, Lyude Paul <lyude@...hat.com>,
Samuel Holland <samuel@...lland.org>,
Joonas Lahtinen <joonas.lahtinen@...ux.intel.com>,
Thomas Zimmermann <tzimmermann@...e.de>,
Emma Anholt <emma@...olt.net>,
Rodrigo Vivi <rodrigo.vivi@...el.com>,
Tvrtko Ursulin <tvrtko.ursulin@...ux.intel.com>,
David Airlie <airlied@...ux.ie>,
Ben Skeggs <bskeggs@...hat.com>
Cc: Dom Cobley <dom@...pberrypi.com>,
Dave Stevenson <dave.stevenson@...pberrypi.com>,
nouveau@...ts.freedesktop.org, intel-gfx@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org,
Phil Elwell <phil@...pberrypi.com>,
Hans de Goede <hdegoede@...hat.com>,
Noralf Trønnes <noralf@...nnes.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Mateusz Kwiatkowski <kfyatek+publicgit@...il.com>,
linux-sunxi@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v8 12/24] drm/connector: Add a function to lookup a TV
mode by its name
Hi Maxime,
On 11/10/22 08:07, Maxime Ripard wrote:
> As part of the command line parsing rework coming in the next patches,
> we'll need to lookup drm_connector_tv_mode values by their name, already
> defined in drm_tv_mode_enum_list.
>
> In order to avoid any code duplication, let's do a function that will
> perform a lookup of a TV mode name and return its value.
>
> Reviewed-by: Noralf Trønnes <noralf@...nnes.org>
> Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@...il.com>
> Signed-off-by: Maxime Ripard <maxime@...no.tech>
>
> ---
> Changes in v7:
> - Add kunit tests
> ---
> drivers/gpu/drm/drm_connector.c | 24 ++++++++
> drivers/gpu/drm/tests/Makefile | 1 +
> drivers/gpu/drm/tests/drm_connector_test.c | 90 ++++++++++++++++++++++++++++++
> include/drm/drm_connector.h | 2 +
> 4 files changed, 117 insertions(+)
>
> diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c
> new file mode 100644
> index 000000000000..f2272b9df211
> --- /dev/null
> +++ b/drivers/gpu/drm/tests/drm_connector_test.c
> @@ -0,0 +1,90 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Kunit test for drm_modes functions
> + */
> +
> +#include <drm/drm_connector.h>
> +
> +#include <kunit/test.h>
> +
> +struct drm_get_tv_mode_from_name_test {
> + const char *name;
> + enum drm_connector_tv_mode expected_mode;
> +};
> +
> +#define TV_MODE_NAME(_name, _mode) \
> + { \
> + .name = _name, \
> + .expected_mode = _mode, \
> + }
> +
> +static void drm_test_get_tv_mode_from_name_valid(struct kunit *test)
> +{
> + const struct drm_get_tv_mode_from_name_test *params = test->param_value;
> +
> + KUNIT_EXPECT_EQ(test,
> + drm_get_tv_mode_from_name(params->name, strlen(params->name)),
> + params->expected_mode);
> +}
> +
> +static const
> +struct drm_get_tv_mode_from_name_test drm_get_tv_mode_from_name_valid_tests[] = {
> + TV_MODE_NAME("NTSC", DRM_MODE_TV_MODE_NTSC),
> + TV_MODE_NAME("NTSC-443", DRM_MODE_TV_MODE_NTSC_443),
> + TV_MODE_NAME("NTSC-J", DRM_MODE_TV_MODE_NTSC_J),
> + TV_MODE_NAME("PAL", DRM_MODE_TV_MODE_PAL),
> + TV_MODE_NAME("PAL-M", DRM_MODE_TV_MODE_PAL_M),
> + TV_MODE_NAME("PAL-N", DRM_MODE_TV_MODE_PAL_N),
> + TV_MODE_NAME("SECAM", DRM_MODE_TV_MODE_SECAM),
> +};
> +
> +static void
> +drm_get_tv_mode_from_name_valid_desc(const struct drm_get_tv_mode_from_name_test *t,
> + char *desc)
> +{
> + sprintf(desc, "%s", t->name);
> +}
I believe that it should be a blank line here for code style.
> +KUNIT_ARRAY_PARAM(drm_get_tv_mode_from_name_valid,
> + drm_get_tv_mode_from_name_valid_tests,
> + drm_get_tv_mode_from_name_valid_desc);
> +
> +static void drm_test_get_tv_mode_from_name_invalid(struct kunit *test)
> +{
> + const char *name = *(const char **)test->param_value;
> +
> + KUNIT_EXPECT_LT(test,
> + drm_get_tv_mode_from_name(name, strlen(name)),
> + 0);
> +}
> +
> +static const
> +char *drm_get_tv_mode_from_name_invalid_tests[] = {
> + /* Truncated */
> + "NTS",
> +};
Considering that there is only one invalid test, is there a particular
reason to parametrize this test?
> +
> +static void
> +drm_get_tv_mode_from_name_invalid_desc(const char **name, char *desc)
> +{
> + sprintf(desc, "%s", *name);
> +}
> +KUNIT_ARRAY_PARAM(drm_get_tv_mode_from_name_invalid,
> + drm_get_tv_mode_from_name_invalid_tests,
> + drm_get_tv_mode_from_name_invalid_desc);
> +
> +static struct kunit_case drm_get_tv_mode_from_name_tests[] = {
> + KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_valid,
> + drm_get_tv_mode_from_name_valid_gen_params),
> + KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_invalid,
> + drm_get_tv_mode_from_name_invalid_gen_params),
> + { }
> +};
> +
> +static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
> + .name = "drm_get_tv_mode_from_name",
> + .test_cases = drm_get_tv_mode_from_name_tests,
> +};
> +
> +kunit_test_suites(
> + &drm_get_tv_mode_from_name_test_suite
> +);
Considering that there is only one suite, you could use the
kunit_test_suite macro instead.
Best Regards,
- Maíra Canal
>
Powered by blists - more mailing lists