From nobody Tue Apr 28 19:31:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16357C433EF for ; Mon, 30 May 2022 10:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235210AbiE3KUk (ORCPT ); Mon, 30 May 2022 06:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235196AbiE3KUg (ORCPT ); Mon, 30 May 2022 06:20:36 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 412387C158 for ; Mon, 30 May 2022 03:20:35 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id l188-20020a1c25c5000000b003978df8a1e2so4076410wml.1 for ; Mon, 30 May 2022 03:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vwQvKjruiYRDvc0VTu2YTcpNWREBhBz6WODeePVxVj4=; b=ENNC1PTiwcNYIr3PUDMg6bgC0XU/eWjopPXfQaIA9N7ceAmW55Ku/n17e2HVK1+NND EWm0MwHUkRlEaSf1enL9KBmfQow7rtfwtYdAruR5jBjqv8OmPv8HlJCMh5fmRt0Arzs0 V8n2tT3Ffs5SoSjiQ6kW+BZWQaU8tjzFy9ftF+Q+ukyv52OtJ2mpmg1vysF47XxY7HPb N/21FzgvFWGPTDRTGYtofvpvT1E1W7XZ8K2662kv8U07LVLEqQhbNrtZnuHdHA7H7+co 9wfW3kbKdVi6E5pfHBgU2O8VTlmwfOF4TyEDzI94KZ24/ky2cwkIcyfmji36azPwxSsh pirA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vwQvKjruiYRDvc0VTu2YTcpNWREBhBz6WODeePVxVj4=; b=dFAB4MPGtzphE2kQ2tnfyIBW3RPUZerMePwOB3ihZBNYIphTdpIItYNo8zbrKX2jcS SKxE/dZc1/w1qJM79ydztHle+D+zFTPPs0cvUIVezb4E83ziv2X29mIXnIXsoRgZt0/t OHXQ6P27fnk0zke9FMrZOXyPw7zSsQLvxR3AdlDYpS6JEvBQYX6augkKoy5IuO1UOE+c PKwN7aOj792DceNJK19h6oQfvbQ6glqih/PzOK8sjM99fg7iBC7SpjAyHtJ7SVkDgj9p U+r02V1nQDqypr3ApJwTO35Xbo49TyzlWsXp05OZqCwe0dAh0V01sdW9f+WyNhkc5DJs qeQQ== X-Gm-Message-State: AOAM5320EVhlMlX0UTkxW67ex03fL4Ki2vJZOvB7XhCeMYnjmSA0bo3x B3gpAXkZv/P/e9iCYbroCzri+K4dIEkhyg== X-Google-Smtp-Source: ABdhPJxL3vZuVXfnKO7PAsd5B6SVjTmyB128/hMed8GbealAla7cC+s1Qs0NHQziADSKexCBBawwtg== X-Received: by 2002:a7b:c341:0:b0:37b:c619:c9f4 with SMTP id l1-20020a7bc341000000b0037bc619c9f4mr18207748wmj.38.1653906033682; Mon, 30 May 2022 03:20:33 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.128]) by smtp.gmail.com with ESMTPSA id p12-20020a05600c358c00b003973ea7e725sm12986293wmq.0.2022.05.30.03.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 03:20:33 -0700 (PDT) From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= To: javierm@redhat.com Cc: tzimmermann@suse.de, maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Subject: [RFC PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332() Date: Mon, 30 May 2022 12:20:17 +0200 Message-Id: <20220530102017.471865-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220530102017.471865-1-jose.exposito89@gmail.com> References: <20220530102017.471865-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Test the conversion from XRGB8888 to RGB332. What is tested? - Different values for the X in XRGB8888 to make sure it is ignored - Different clip values: Single pixel and full and partial buffer - Well know colors: White, black, red, green, blue, magenta, yellow and cyan - Other colors: Randomly picked - Destination pitch Suggested-by: Javier Martinez Canillas Signed-off-by: Jos=C3=A9 Exp=C3=B3sito --- drivers/gpu/drm/Kconfig | 12 ++ drivers/gpu/drm/Makefile | 3 + drivers/gpu/drm/drm_format_helper_test.c | 166 +++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 drivers/gpu/drm/drm_format_helper_test.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index e88c497fa010..d92be6faef15 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -76,6 +76,18 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. =20 +config DRM_FORMAR_HELPER_TEST + bool "drm_format_helper tests" if !KUNIT_ALL_TESTS + depends on DRM && KUNIT=3Dy + select DRM_KMS_HELPER + default KUNIT_ALL_TESTS + help + KUnit tests for the drm_format_helper APIs. This option is not + useful for distributions or general kernels, but only for kernel + developers working on DRM and associated drivers. + + If in doubt, say "N". + config DRM_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 15fe3163f822..6a7d7655d38c 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -76,6 +76,9 @@ obj-$(CONFIG_DRM_KMS_HELPER) +=3D drm_kms_helper.o # =20 obj-$(CONFIG_DRM_DEBUG_SELFTEST) +=3D selftests/ +obj-$(CONFIG_DRM_FORMAR_HELPER_TEST) +=3D drm_kms_helper.o \ + drm_format_helper_test.o +CFLAGS_drm_format_helper_test.o +=3D $(DISABLE_STRUCTLEAK_PLUGIN) =20 obj-$(CONFIG_DRM_MIPI_DBI) +=3D drm_mipi_dbi.o obj-$(CONFIG_DRM_MIPI_DSI) +=3D drm_mipi_dsi.o diff --git a/drivers/gpu/drm/drm_format_helper_test.c b/drivers/gpu/drm/drm= _format_helper_test.c new file mode 100644 index 000000000000..9c8a3007346c --- /dev/null +++ b/drivers/gpu/drm/drm_format_helper_test.c @@ -0,0 +1,166 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "drm_crtc_internal.h" + +#define TEST_BUF_SIZE 50 +#define CLIP(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) } + +struct xrgb8888_to_rgb332_case { + const char *name; + unsigned int pitch; + unsigned int dst_pitch; + struct drm_rect clip; + const u32 xrgb8888[TEST_BUF_SIZE]; + const u8 expected[4 * TEST_BUF_SIZE]; +}; + +static struct xrgb8888_to_rgb332_case xrgb8888_to_rgb332_cases[] =3D { + { + .name =3D "Single pixel source", + .pitch =3D 1 * 4, + .dst_pitch =3D 0, + .clip =3D CLIP(0, 0, 1, 1), + .xrgb8888 =3D { 0x01FF0000 }, + .expected =3D { 0xE0 }, + }, + { + .name =3D "Single pixel clip", + .pitch =3D 2 * 4, + .dst_pitch =3D 0, + .clip =3D CLIP(1, 1, 1, 1), + .xrgb8888 =3D { + 0x00000000, 0x00000000, + 0x00000000, 0x10FF0000, + }, + .expected =3D { 0xE0 }, + }, + { + .name =3D "White, black, red, green, blue, magenta, yellow, cyan", + .pitch =3D 4 * 4, + .dst_pitch =3D 0, + .clip =3D CLIP(1, 1, 2, 4), + .xrgb8888 =3D { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000, + 0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000, + 0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000, + 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000, + }, + .expected =3D { + 0xFF, 0x00, + 0xE0, 0x1C, + 0x03, 0xE3, + 0xFC, 0x1F, + }, + }, + { + .name =3D "Destination pitch", + .pitch =3D 3 * 4, + .dst_pitch =3D 5, + .clip =3D CLIP(0, 0, 3, 3), + .xrgb8888 =3D { + 0xA10E449C, 0xB1114D05, 0xC1A80303, + 0xD16C7073, 0xA20E449C, 0xB2114D05, + 0xC2A80303, 0xD26C7073, 0xA30E449C, + }, + .expected =3D { + 0x0A, 0x08, 0xA0, 0x00, 0x00, + 0x6D, 0x0A, 0x08, 0x00, 0x00, + 0xA0, 0x6D, 0x0A, 0x00, 0x00, + }, + }, +}; + +/** + * conversion_buf_size - Return the destination buffer size required to co= nvert + * between formats. + * @src_format: source buffer pixel format (DRM_FORMAT_*) + * @dst_format: destination buffer pixel format (DRM_FORMAT_*) + * @dst_pitch: Number of bytes between two consecutive scanlines within dst + * @clip: Clip rectangle area to convert + * + * Returns: + * The size of the destination buffer or negative value on error. + */ +static size_t conversion_buf_size(u32 src_format, u32 dst_format, + unsigned int dst_pitch, + const struct drm_rect *clip) +{ + const struct drm_format_info *src_fi =3D drm_format_info(src_format); + const struct drm_format_info *dst_fi =3D drm_format_info(dst_format); + size_t width =3D drm_rect_width(clip); + size_t src_nbytes; + + if (!src_fi || !dst_fi) + return -EINVAL; + + if (dst_pitch) + width =3D dst_pitch; + + src_nbytes =3D width * drm_rect_height(clip) * src_fi->cpp[0]; + if (!src_nbytes) + return 0; + + return (src_nbytes * dst_fi->cpp[0]) / src_fi->cpp[0]; +} + +static void xrgb8888_to_rgb332_case_desc(struct xrgb8888_to_rgb332_case *t, + char *desc) +{ + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(xrgb8888_to_rgb332, xrgb8888_to_rgb332_cases, + xrgb8888_to_rgb332_case_desc); + +static void xrgb8888_to_rgb332_test(struct kunit *test) +{ + const struct xrgb8888_to_rgb332_case *params =3D test->param_value; + size_t dst_size; + __u8 *dst =3D NULL; + + struct drm_framebuffer fb =3D { + .format =3D drm_format_info(DRM_FORMAT_XRGB8888), + .pitches =3D { params->pitch, 0, 0 }, + }; + + dst_size =3D conversion_buf_size(DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB332, + params->dst_pitch, ¶ms->clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + dst =3D kzalloc(dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dst); + + drm_fb_xrgb8888_to_rgb332(dst, params->dst_pitch, params->xrgb8888, + &fb, ¶ms->clip); + KUNIT_EXPECT_EQ(test, memcmp(dst, params->expected, dst_size), 0); +} + +static struct kunit_case drm_format_helper_test_cases[] =3D { + KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test, + xrgb8888_to_rgb332_gen_params), + {} +}; + +static struct kunit_suite drm_format_helper_test_suite =3D { + .name =3D "drm-format-helper-test", + .test_cases =3D drm_format_helper_test_cases, +}; + +kunit_test_suite(drm_format_helper_test_suite); + +MODULE_DESCRIPTION("KUnit tests for the drm_format_helper APIs"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Jos=C3=A9 Exp=C3=B3sito "); --=20 2.25.1