Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4036650iog; Tue, 21 Jun 2022 10:41:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sKGmE7NQHVWO0UjHY7zyVpzwNhDZKEw3ZPD+78yjKU28DIIgG3YfJ/PNTSIZOOgE7k9UW2 X-Received: by 2002:a17:907:e93:b0:722:e082:2787 with SMTP id ho19-20020a1709070e9300b00722e0822787mr5618424ejc.618.1655833275497; Tue, 21 Jun 2022 10:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655833275; cv=none; d=google.com; s=arc-20160816; b=gLbcDrLtSnEZTbvoYUA1PVpDmKwDDexjQyJdTr832+794k/gPqdWlCJnc1ZsoDtIN4 T9iZwl1sJFSacMscUmydN00dTq76nO1V7JTbl1IOlvSQ8CfMHTcbwKMHkGWJ1L12+OIy Iahcf3Xh7b7DKqZ4oEYnCV40fYksagHJVk9G3erfMUpy99A9pX6KkGb5eXPE0tyUJ2mg oU/mHp6WoGh2yy6Qw/iAmUyA+lLeVXJARDxAsJdFj8M3Y78LGyTQjiH/uM1p5qzIqPTb QWSrERLVklaKWbD4P5+7xm7Kh829ybmFetLX8OoZkjyF2lXepZ7y8l7h4RIeAaLDohHl x3lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vpkerxjI2bVCUwBu2TqOMcIJPwr5ktQseMgFP8QQMNg=; b=Ve/Ot2iKeYS6t2pshEprrsaVK9kKDQf9HuZr1ohn6BRqtYtoXc+pJ2FLy/sWcPJecH mi32Fazd5PrQ31uOCTxqfXXBFmlO1bIofdX6yLRmDz8blGCh+6UDgR07Bz1e75k+rUXW KWpCKWREyN5rNIQSELLoL1C8lGJe1geVVzcLRnabGnQgquwjP4+RZVZfy13APDA3edvz dsmVhHtniV1k/gLQt505548Bsr6shu4tCdnmyRgwf4qDxrKEvm7xrQa5/0F4G9ABOyOj ipYvRr2i3g+D5LlJkkZa49+OqC0Tjp0znov+92Qsx735A27ZLjIgbaq0x726UA3ASTsu 7zgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=V6lRlgLp; 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 qc25-20020a170906d8b900b00711d56b4ec3si14007462ejb.795.2022.06.21.10.40.49; Tue, 21 Jun 2022 10:41:15 -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=V6lRlgLp; 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 S235961AbiFURhn (ORCPT + 99 others); Tue, 21 Jun 2022 13:37:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235575AbiFURhl (ORCPT ); Tue, 21 Jun 2022 13:37:41 -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 444772C673 for ; Tue, 21 Jun 2022 10:37:40 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id s1so19933722wra.9 for ; Tue, 21 Jun 2022 10:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=vpkerxjI2bVCUwBu2TqOMcIJPwr5ktQseMgFP8QQMNg=; b=V6lRlgLpxQGeiIHZmLpabeazuSqDwEOLTP+n/scvR2nTqz6GdOqXw0WYzRuzE2j0rC PbBWOsW2vM4BzfxBi5vE1V7wBKRRvEHOESpQhRpocPAh49goA0UrmoUB0SbrqMNQb4yl 8D+jaVlXcunixC1W9O+IDDzQdSioLQ+SHwFMNwaMEEObpCB08TkRyAgPEFCzNrseEokf xSGOD/EBMAbzVZwOaEXwtck8Zv/ePjeI7cciXr311LIdm+FmSWWWwVAjMqvvVgU70JrK wr/CQnBjhlJVSQYEwOHFnAR75UltByiaxhbPHapFf7ySMHjw5rO662okm1yN8u7WXNei kVdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=vpkerxjI2bVCUwBu2TqOMcIJPwr5ktQseMgFP8QQMNg=; b=2ibKKrKMB0jxuVrSLIxKUpW9fIS9rHZnwhjPK+F+U6yudJ36VvjhN+dOcyxVE4EOF6 Fp9npz2XNxOC4z8v4sxQERwvNvBFiudquOZjl1CZ6ixObwUWBfofU7F7vfrzQSh1Om8f rgDd6Vc763+J/wzDHI6AcjtbqtdW7GHhRNekSqD7Vb3eUz0OjiZlkALE/w83j/s68MdW 4q0ZqGe87izxqBfZwAQ9kaokL6u8FqU/mAY0xBOyq50C6tejd7NmCVYLDbRLlT2geAF+ 55RHkW41WCsg7IcTzdhvN+xogKCnneuxbIk+wWjU6pEgIMIIWm+gcb/jgDBh3ysHdhO2 9T3g== X-Gm-Message-State: AJIora9qARgOS2yC94ZdP25CaxeCuakI6HtmMuIAolTNSqXYDMT6T6AA 2EFtPjHnilfilhiZZXMrOVM= X-Received: by 2002:a05:6000:1888:b0:218:3fab:c510 with SMTP id a8-20020a056000188800b002183fabc510mr29904831wri.473.1655833058630; Tue, 21 Jun 2022 10:37:38 -0700 (PDT) Received: from elementary ([94.73.36.128]) by smtp.gmail.com with ESMTPSA id c14-20020adffb4e000000b0021b8863514fsm10298232wrs.79.2022.06.21.10.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 10:37:38 -0700 (PDT) Date: Tue, 21 Jun 2022 19:37:32 +0200 From: =?iso-8859-1?Q?Jos=E9_Exp=F3sito?= To: David Gow Cc: Javier Martinez Canillas , Daniel Latypov , Thomas Zimmermann , maarten.lankhorst@linux.intel.com, Maxime Ripard , David Airlie , Daniel Vetter , Jani Nikula , =?iso-8859-1?Q?Ma=EDra?= Canal , Isabella Basso , magalilemes00@gmail.com, tales.aparecida@gmail.com, dri-devel@lists.freedesktop.org, KUnit Development , Linux Kernel Mailing List Subject: Re: [PATCH v4 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332() Message-ID: <20220621173732.GA3209@elementary> References: <20220620160640.3790-1-jose.exposito89@gmail.com> <20220620160640.3790-3-jose.exposito89@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Hi David, On Tue, Jun 21, 2022 at 05:38:33PM +0800, David Gow wrote: > On Tue, Jun 21, 2022 at 12:06 AM Jos? Exp?sito > wrote: > > > > 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 > > --- > > These tests all pass properly on my system, and look good to me from a > KUnit point of view. Thanks very much. > > A couple of small notes below, which you can take or leave as you > wish: they mostly focus on potential future tests. > > Regardless, > Reviewed-by: David Gow Thanks a lot for your review :) > Cheers, > -- David > > > 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]; > > Why is this 4*TEST_BUF_SIZE if there are the same number of pixels > (which in rgb332 are 8-bit, not 32-bit) as in xrgb8888. I see there's > a pitch test, which does need some extra memory, but not a full 4 > times (less than double, by the looks of things). Having this be 4 * > implies (to me) that the aim is to have the same total memory > available between xrgb8888 and expected, which doesn't seem to need to > be the case. Maybe make this 2 * or similar? To be honest, TEST_BUF_SIZE length is quite arbitrary. I chose a number big enough so large formats, like RGB565, fit in the buffer without changing the constant in future patches unnecessarily. I added some extra space so other possible test cases don't need to change it if testing with larger input. The *4 multiplier is there so both buffers have the same size. > Relatedly, if instead of naming this 'expected', it were named rgb332, > it'd be possible to extend this struct to add other formats expected > values, and test several formats with the same list of test inputs. > (dst_pitch would probably need to become dst_pitch_rgb332 eventually, > too). This is all something which could wait for a later patch, but is > food for thought. I'd love to see an xrgb8888_to_rgb565 test at some > point, too. The patches for RGB565, including the small refactors you mentioned plus the avility to swap or not bytes are already available in my tree [1] (last 4 patches, in case you want to look at them). They are waiting to be rebased once this series is merged. As you pointed out, some minor refactoring is required and you are right about the destination pitch. Hopefully, the end result is simple and easy to follow despite the refactor patches. Thanks again for your review, Jose [1] https://github.com/JoseExposito/linux/commits/patch-drm-format-helper-rgb565-kunit > > +}; > > + > > +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 > >