Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3034743iog; Mon, 20 Jun 2022 09:46:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3CwO8+CZayL434W6hmSYw92fcGJbds/ewjZKET9Ys22DpkNJx6WihGFDkPpc+ZoWEtcTK X-Received: by 2002:a17:906:ece3:b0:6f3:da10:138a with SMTP id qt3-20020a170906ece300b006f3da10138amr22257686ejb.438.1655743563203; Mon, 20 Jun 2022 09:46:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655743563; cv=none; d=google.com; s=arc-20160816; b=HSyXBhFY/X8WOOH6hT9bhnKiJgRwBF6Mfrg+CrZ9lV95y7JNZKbnSoEgTXIWDefFo+ Z5U49+yeeOkG7uEnkEwjQvVVfIhfbzDzYaYBeixXDw0ArePFa8aWRhO5a7DwiVGwK3hs r8ARrstNJCWjNOMdrK0Ct/3UXgbKxkpWwjlyzTdIfGUM88XCLiSRFgK6oSlbPG2PCpk1 Ip4Sv/79KBb/61s6Tux91bx+j+6YmbGq41fRYPZLQC6vJom6eCUIunFbvvpi3mgLmW5L XehDAMseFiCBTRMENp7AkJoEHnGX9hKJnI/K1pWuxm0zfblCQ90LJqhek6JRTp26z7Ag OcMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uCtSgznZLSWcgZUe7uaypmZ48M3vuKUf9cmAm6fcKwM=; b=XfCsQiYkPHKwP7paAg1w37+EGuN+0A9H3s2jMT5LsbzeKOn+GLdZ1jQkyvYS2bK7JU bUrKWUdFfm7ut02Awj6vzHHsQGHnhxoEzGjbv9GeGVHYhSVgu4cWlYn4nsIRb8x+q6J0 ZfW9BCeXQ6vB3v2drKTFWXsvBkwE80XDDJC2+3vePoaDaOtd7cB5ApZfNdp5zP5Zwuml CXAey5ZFT7ruOml8LAw7schwsB/kEd4A+rkgdi/gqbV+6CBeQtbNtJ3SlH5Sydk6E1V6 kTyN6wF+/kZyWC8oI0ooEc/RxU02XI7+MkAaUyckkUoTLdKUcD/nXaIKOcvmuAxGl8gw NLGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=X4sD8HNQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a17090791d000b00712034f1a2bsi11752211ejz.589.2022.06.20.09.45.38; Mon, 20 Jun 2022 09:46:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=X4sD8HNQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243565AbiFTQG6 (ORCPT + 99 others); Mon, 20 Jun 2022 12:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237834AbiFTQG4 (ORCPT ); Mon, 20 Jun 2022 12:06:56 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2FD8201B7 for ; Mon, 20 Jun 2022 09:06:54 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id o8so15347354wro.3 for ; Mon, 20 Jun 2022 09:06:54 -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=uCtSgznZLSWcgZUe7uaypmZ48M3vuKUf9cmAm6fcKwM=; b=X4sD8HNQPXaochofCb2qluGWdMuEg+QCNtCRSsG32TAGPmspnirXYTs/e8o+g+l3Xf vwLyA9JjG8n6iiBAyBQyHlEVJkVuYFyxiirh+fR03UoYYkfLV6rFVuvhPbKZIhBtztaR 0j2UnpKRxvtGwuIJNnq8oqJvAsPEw0ESdlTC3Z4/QT8uTCEa6rvTC5GdQi+uXGxhrgD3 KnmuN73eFokm2mqFDNEK/+UIVBQ0yI5t6PEMN0guGmgkxyb6cxytnF0eZ4Jdg+d42yaM 0on7c1vUjUtDRFwiFpFaeOWu7gfNuvezm2GeemBViVqJVOQPawOryUm5HXA9pZlsCceL wF2Q== 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=uCtSgznZLSWcgZUe7uaypmZ48M3vuKUf9cmAm6fcKwM=; b=KY2NSxjde1wDkFFb2dRywoxIZ8tkBKMUVn290LC1bleYxvBexGkBrSQLFFQ/lpkQWs yOWw7QQAzD01xLuBaTBOg2mh3e6SfP5IiLatndT5HgzmrCx9YPn/RulzkJz1ILRFnNtG dn4lR5JWKh1+uBMY3z3XzCALb05HqVY5uz80V9iyKeoihI/3M+5D7+EVIe8AiKWLAJu4 5z3mFIF5lFXELVXJv0ba1L3M1UitaHQFtcOHePn280mn1r8NCQgwRS9tsh7V3PJYl2tN qWqcb4SgA1WKRchYi+7zgv/uFdBLEUCs/Nd1IrLuX8H4uET9ZBRBLuCZfN1Q36xfbHw9 yS1Q== X-Gm-Message-State: AJIora91UawS0M7q0ncFLRYF/QAFxXMuOXtXcICXBqvrOLb3BGrZYBwd RvmJ7pg6YudlAneeq78l7Qo= X-Received: by 2002:a5d:64e4:0:b0:21b:940a:a002 with SMTP id g4-20020a5d64e4000000b0021b940aa002mr2420334wri.360.1655741212943; Mon, 20 Jun 2022 09:06:52 -0700 (PDT) Received: from localhost.localdomain ([94.73.36.128]) by smtp.gmail.com with ESMTPSA id h14-20020a5d430e000000b0021b90cc66a1sm2986096wrq.2.2022.06.20.09.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 09:06:52 -0700 (PDT) From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= To: javierm@redhat.com Cc: davidgow@google.com, dlatypov@google.com, tzimmermann@suse.de, maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@linux.ie, daniel@ffwll.ch, jani.nikula@linux.intel.com, maira.canal@usp.br, isabbasso@riseup.net, magalilemes00@gmail.com, tales.aparecida@gmail.com, dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Subject: [PATCH v4 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332() Date: Mon, 20 Jun 2022 18:06:39 +0200 Message-Id: <20220620160640.3790-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220620160640.3790-1-jose.exposito89@gmail.com> References: <20220620160640.3790-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 known colors: White, black, red, green, blue, magenta, yellow and cyan - Other colors: Randomly picked - Destination pitch How to run the tests? $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/tests \ --kconfig_add CONFIG_VIRTIO_UML=y \ --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y Suggested-by: Javier Martinez Canillas Reviewed-by: Javier Martinez Canillas Acked-by: Thomas Zimmermann Signed-off-by: José Expósito --- drivers/gpu/drm/Kconfig | 16 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/tests/.kunitconfig | 3 + drivers/gpu/drm/tests/Makefile | 3 + .../gpu/drm/tests/drm_format_helper_test.c | 161 ++++++++++++++++++ 5 files changed, 184 insertions(+) create mode 100644 drivers/gpu/drm/tests/.kunitconfig create mode 100644 drivers/gpu/drm/tests/Makefile create mode 100644 drivers/gpu/drm/tests/drm_format_helper_test.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 22e7fa48d693..6c2256e8474b 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_KUNIT_TEST + tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS + depends on DRM && KUNIT=y + select DRM_KMS_HELPER + default KUNIT_ALL_TESTS + help + This builds unit tests for DRM. This option is not useful for + distributions or general kernels, but only for kernel + developers working on DRM and associated drivers. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". + config DRM_KMS_HELPER tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 13ef240b3d2b..db8ffcf4e048 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -76,6 +76,7 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o # obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-$(CONFIG_DRM_KUNIT_TEST) += tests/ obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o diff --git a/drivers/gpu/drm/tests/.kunitconfig b/drivers/gpu/drm/tests/.kunitconfig new file mode 100644 index 000000000000..6ec04b4c979d --- /dev/null +++ b/drivers/gpu/drm/tests/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_KUNIT_TEST=y diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile new file mode 100644 index 000000000000..2c8273796d9d --- /dev/null +++ b/drivers/gpu/drm/tests/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_DRM_KUNIT_TEST) += drm_format_helper_test.o diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c new file mode 100644 index 000000000000..98583bf56044 --- /dev/null +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -0,0 +1,161 @@ +// 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 + +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[] = { + { + .name = "single_pixel_source_buffer", + .pitch = 1 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(0, 0, 1, 1), + .xrgb8888 = { 0x01FF0000 }, + .expected = { 0xE0 }, + }, + { + .name = "single_pixel_clip_rectangle", + .pitch = 2 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 1, 1), + .xrgb8888 = { + 0x00000000, 0x00000000, + 0x00000000, 0x10FF0000, + }, + .expected = { 0xE0 }, + }, + { + /* Well known colors: White, black, red, green, blue, magenta, + * yellow and cyan. Different values for the X in XRGB8888 to + * make sure it is ignored. Partial clip area. + */ + .name = "well_known_colors", + .pitch = 4 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 2, 4), + .xrgb8888 = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000, + 0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000, + 0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000, + 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000, + }, + .expected = { + 0xFF, 0x00, + 0xE0, 0x1C, + 0x03, 0xE3, + 0xFC, 0x1F, + }, + }, + { + /* Randomly picked colors. Full buffer within the clip area. */ + .name = "destination_pitch", + .pitch = 3 * 4, + .dst_pitch = 5, + .clip = DRM_RECT_INIT(0, 0, 3, 3), + .xrgb8888 = { + 0xA10E449C, 0xB1114D05, 0xC1A80303, + 0xD16C7073, 0xA20E449C, 0xB2114D05, + 0xC2A80303, 0xD26C7073, 0xA30E449C, + }, + .expected = { + 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 convert + * between formats. + * @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 dst_format, unsigned int dst_pitch, + const struct drm_rect *clip) +{ + const struct drm_format_info *dst_fi = drm_format_info(dst_format); + + if (!dst_fi) + return -EINVAL; + + if (!dst_pitch) + dst_pitch = drm_rect_width(clip) * dst_fi->cpp[0]; + + return dst_pitch * drm_rect_height(clip); +} + +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 = test->param_value; + size_t dst_size; + __u8 *dst = NULL; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB8888), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB332, params->dst_pitch, + ¶ms->clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + dst = kunit_kzalloc(test, 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[] = { + KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test, + xrgb8888_to_rgb332_gen_params), + {} +}; + +static struct kunit_suite drm_format_helper_test_suite = { + .name = "drm_format_helper_test", + .test_cases = 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é Expósito "); -- 2.25.1