From patchwork Tue Aug 16 10:29:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 12944593 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E89BC2BB41 for ; Tue, 16 Aug 2022 10:29:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9404B11ADD6; Tue, 16 Aug 2022 10:29:34 +0000 (UTC) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F4268ECA3 for ; Tue, 16 Aug 2022 10:29:15 +0000 (UTC) Received: by mail-wm1-x32d.google.com with SMTP id h1so5013246wmd.3 for ; Tue, 16 Aug 2022 03:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=/7pcMlkWYdqvd9nF4xjztw1PEhSKdH6W+Iikd1ByWuw=; b=fjgXliTQmp5AXMdjyj5BNorQm9b2QUgkuF9SUN7Rt5bCG3Yq9Kr1x94ZifYm+8nVx0 inz8PqyRLDZjqb5gY81bWFL0yvLSIjXMVAKdCo8E5qpHS2UAhTiT/w55V1fR2cD5Pd2B 1Rx+cRG/T9KhAKwyGRinIsjzPbukSldQFl1GGVizLBrfm1XMPI72YWtoNtMgkYEmKW05 TXbTLePLT8qZVgAgEuCwywy9mlzdoK4LGNXQ3/iGFhUMp7OpcHa3REKtRBee4KGA151v 8ho4BL9+LhpURGEzBp4FXtfYChdegmjZyBxMB5w8yIaqOYOy9rxlBIE1yRCag9ZeJB1e IxVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=/7pcMlkWYdqvd9nF4xjztw1PEhSKdH6W+Iikd1ByWuw=; b=zft2D0yfvSt8ldbUVAlpowzRnXSLQhG4F2vgrSd40nzSzCxW4u57YpMoOBEGyK9p+F aPgm/3XqrNeAZsAyczr2376C+Z23E0mzbOFqoyFBwM47n3MkB1asmtwnNa5qI42u/vz/ 2bRAji1pBSncEW1mGdGBb/aKvoY3uZijekcM+av5ElSjeD7T2ZTbxMa1wqQIvpT3WGdZ jfr5JivyllBmEFoUl+0XU7VaO8Qc8VAvUAh8pWIZTHehrSVpV45Q6ycYOGBZ5rVs3a9w noodne378Hfsz7qnTQcvuqelumHQ63IIfsTYUPLIo8mbp3ZL65AdY8QHVPJSuNlEjFwz 27PA== X-Gm-Message-State: ACgBeo2XWGfuvkc/Fo/gEDdrY1/ITP0i/7HIARBBKDwGsNMYN9wh8OSH NfL90bXH7+CDDfrhvMJX2Wc= X-Google-Smtp-Source: AA6agR4bNICp6baTecdnoJqeEJgR+Z8OLujzSNuslJ6EgUSTKVKO7aJi7ympl6exGaWyuJ1XuiVDSg== X-Received: by 2002:a05:600c:1f08:b0:3a5:e8d6:ddd2 with SMTP id bd8-20020a05600c1f0800b003a5e8d6ddd2mr7393277wmb.57.1660645753401; Tue, 16 Aug 2022 03:29:13 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id m9-20020adffe49000000b002251639bfd0sm1668407wrs.59.2022.08.16.03.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 03:29:13 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888() Date: Tue, 16 Aug 2022 12:29:01 +0200 Message-Id: <20220816102903.276879-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220816102903.276879-1-jose.exposito89@gmail.com> References: <20220816102903.276879-1-jose.exposito89@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org, tzimmermann@suse.de, magalilemes00@gmail.com, airlied@linux.ie, maira.canal@usp.br, dlatypov@google.com, linux-kernel@vger.kernel.org, geert@linux-m68k.org, tales.aparecida@gmail.com, davidgow@google.com, =?utf-8?b?Sm9zw6kgRXhww7Nz?= =?utf-8?b?aXRv?= , isabbasso@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Extend the existing test cases to test the conversion from XRGB8888 to RGB888. Signed-off-by: José Expósito Reviewed-by: David Gow --- .../gpu/drm/tests/drm_format_helper_test.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 828487071796..08d08e7ab19a 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -27,6 +27,11 @@ struct convert_to_rgb565_result { const u16 expected_swab[TEST_BUF_SIZE]; }; +struct convert_to_rgb888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb8888_case { const char *name; unsigned int pitch; @@ -34,6 +39,7 @@ struct convert_xrgb8888_case { const u32 xrgb8888[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; + struct convert_to_rgb888_result rgb888_result; }; static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { @@ -51,6 +57,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -69,6 +79,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -109,6 +123,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0xE0FF, 0xFF07, }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -141,6 +164,17 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00A8, 0x8E6B, 0x330A, 0x0000, 0x0000, }, }, + .rgb888_result = { + .dst_pitch = 15, + .expected = { + 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, }, }; @@ -255,9 +289,40 @@ static void xrgb8888_to_rgb565_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); } +static void xrgb8888_to_rgb888_test(struct kunit *test) +{ + const struct convert_xrgb8888_case *params = test->param_value; + const struct convert_to_rgb888_result *result = ¶ms->rgb888_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb8888 = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB8888), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch, + ¶ms->clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(&dst, buf); + + xrgb8888 = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888); + iosys_map_set_vaddr(&src, xrgb8888); + + drm_fb_xrgb8888_to_rgb888(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(xrgb8888_to_rgb565_test, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params), {} }; From patchwork Tue Aug 16 10:29:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 12944594 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 21EE4C2BB41 for ; Tue, 16 Aug 2022 10:29:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EEB1D8D173; Tue, 16 Aug 2022 10:29:53 +0000 (UTC) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 11B9290DE1 for ; Tue, 16 Aug 2022 10:29:16 +0000 (UTC) Received: by mail-wm1-x32b.google.com with SMTP id r83-20020a1c4456000000b003a5cb389944so5223395wma.4 for ; Tue, 16 Aug 2022 03:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ZUx34QkHnBswCsUg5dOcBaoezDJ6gfWumxiIbYHCirs=; b=iNJTjNTrsT+WogTYPkEAEhy9SRvgJoM0IwoK9HllLm5bRoE/UsSQi9ijHQE9b1MCLb fjEu5WK399K8xPkUwnOfprDq5JfgJVZB5pCJfXqgWND3NuePAvnNxdTSffr3esCV6qan o7mJUbSkrDjNZOJnEtHMVUVsJCgLxjZx1n7imAv8lIk4GSFnq3fRSWiJRDepn/Kynn26 jPY0bJ67ZLEIFOn34quychCwurRDo2DzV+EnDxdEyZo/+WM01IJ/iqgAKldJdixIqrWD lwDrTYkT6J+vqSR5Kp8+REV8TPmB/ChCFek2dzfC3lhKt1szDPOY4W+87Dr0ncsLn1TO x+2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ZUx34QkHnBswCsUg5dOcBaoezDJ6gfWumxiIbYHCirs=; b=SbUsdkgFdFD6wd4PC3UIgHJhC3UoMBATciBhSVSkW9NYvTwMS3UsGR+Xgxj4YjDj8c Jc9NTdruj4lm9m8MuZ6wxv/Pp39+/rCXtkcWi8wkJrUB6aTfx88Kl7i77mw8XxCY0z9u FZYEsawvT/DfwRFwrwBZNJqCffoWp7sGKmtun4578Bl2mjbCJXBVyLdpKOBTyunK3BIF YlvuU5uyMyiOb3x4cYsO3HrYkZbTkJXTnKp/D34VIqvqyxTyUQeeHVFYzrgMLSUlcaPT gTxibQqKYHEKG+2t+NdHgV5L04jJg7zinixcV/1Mjclb0Djp2tYc4lgwbC9P/S8fnjIb OgIg== X-Gm-Message-State: ACgBeo1/KJxUL3h8UMn6dLvv0wT+1lDAUN8cNRJ7bPZkVeawsUZoCPpu 4vUPFa7dFPOHAz/wRQhcYdg= X-Google-Smtp-Source: AA6agR5iHzQVr37Imsp8vtLPGEI0c14MbmGxjtQYWSuBdSpxix+OPsAN07NhKDaJU7WiPHcoHA4NgQ== X-Received: by 2002:a05:600c:3ba0:b0:3a5:b73a:8773 with SMTP id n32-20020a05600c3ba000b003a5b73a8773mr16993312wms.64.1660645754524; Tue, 16 Aug 2022 03:29:14 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id m9-20020adffe49000000b002251639bfd0sm1668407wrs.59.2022.08.16.03.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 03:29:14 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010() Date: Tue, 16 Aug 2022 12:29:02 +0200 Message-Id: <20220816102903.276879-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220816102903.276879-1-jose.exposito89@gmail.com> References: <20220816102903.276879-1-jose.exposito89@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org, tzimmermann@suse.de, magalilemes00@gmail.com, airlied@linux.ie, maira.canal@usp.br, dlatypov@google.com, linux-kernel@vger.kernel.org, geert@linux-m68k.org, tales.aparecida@gmail.com, davidgow@google.com, =?utf-8?b?Sm9zw6kgRXhww7Nz?= =?utf-8?b?aXRv?= , isabbasso@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Extend the existing test cases to test the conversion from XRGB8888 to XRGB2101010. Signed-off-by: José Expósito Reviewed-by: David Gow Reported-by: kernel test robot --- .../gpu/drm/tests/drm_format_helper_test.c | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 08d08e7ab19a..d8536db4de1e 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -32,6 +32,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_xrgb2101010_result { + unsigned int dst_pitch; + const u32 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb8888_case { const char *name; unsigned int pitch; @@ -40,6 +45,7 @@ struct convert_xrgb8888_case { struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_xrgb2101010_result xrgb2101010_result; }; static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { @@ -61,6 +67,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF00000 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -83,6 +93,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF00000 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -132,6 +146,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { + 0x3FFFFFFF, 0x00000000, + 0x3FF00000, 0x000FFC00, + 0x000003FF, 0x3FF003FF, + 0x3FFFFC00, 0x000FFFFF, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -175,6 +198,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 20, + .expected = { + 0x03844672, 0x0444D414, 0x2A20300C, 0x00000000, 0x00000000, + 0x1B1705CD, 0x03844672, 0x0444D414, 0x00000000, 0x00000000, + 0x2A20300C, 0x1B1705CD, 0x03844672, 0x00000000, 0x00000000, + }, + }, }, }; @@ -319,10 +350,42 @@ static void xrgb8888_to_rgb888_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb8888_to_xrgb2101010_test(struct kunit *test) +{ + const struct convert_xrgb8888_case *params = test->param_value; + const struct convert_to_xrgb2101010_result *result = ¶ms->xrgb2101010_result; + size_t dst_size; + __u32 *buf = NULL; + __u32 *xrgb8888 = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB8888), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010, + result->dst_pitch, ¶ms->clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(&dst, buf); + + xrgb8888 = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888); + iosys_map_set_vaddr(&src, xrgb8888); + + drm_fb_xrgb8888_to_xrgb2101010(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); + buf = le32buf_to_cpu(test, buf, TEST_BUF_SIZE); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(xrgb8888_to_rgb565_test, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params), {} }; From patchwork Tue Aug 16 10:29:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 12944592 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FD41C2BB41 for ; Tue, 16 Aug 2022 10:29:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 93B15112058; Tue, 16 Aug 2022 10:29:34 +0000 (UTC) Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by gabe.freedesktop.org (Postfix) with ESMTPS id B6E3D8D173 for ; Tue, 16 Aug 2022 10:29:17 +0000 (UTC) Received: by mail-wm1-x329.google.com with SMTP id k17so5024712wmr.2 for ; Tue, 16 Aug 2022 03:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=J8iZCnBWtxZ0luRrE1AM5j//meG3qtyDdNSPKnb1YHs=; b=hUkuVh9lEKqrEmzF5ZobH61GwSmNKxGbR7mofpKpO0nrfUJoLYzig7Z7klxVp3W6l5 b8JLj1/EwCiuPmDaQyouGnTbFPdmTJBNIfidM1NmZAvHi2FBp5MhrEaLms+GDqNTavrn umEHH/FCQQQ0ygdgj+V4KyQWboAkPfFgnRGr7jNOujVtwpSZyvzvXRCUnqWMzMIcXgeN Q7WvkKOSPOcbdWNEsbJBbS9UGTWjeLmJk42QF7Nd5GmsJRi/8ZDWVumIXnzhlEWAYVHW w4S7GTQlBh89aM0Jov5MrcrndqdGBQzeWz2RXh5+/LSV6R82DyB1Th1hQrNv5vAMcSgP FbQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=J8iZCnBWtxZ0luRrE1AM5j//meG3qtyDdNSPKnb1YHs=; b=J/btkD5jLhr49Pfk+1jx3aTn5BFgizgg7Ub/thMJ9i62sL8PGN8zMGu5TquuVlcTTK Ajpia7/eiThRtw/V63yhDr5xTdNld3eDolY2kAySk31AkQnyu+L4XjvpdYl3r18y/2ir aVJ8HbnlgAik4n9dKgsHhI2ygOywp8v/hzEF8IMLGoXgAxycOC54AnmX4J6XOrAO3bba Dvnoy8xD6RN/AmcomJAsbUmmCjbGNrbCOHZCtQTV/L3lOQqT/n//fz8MjltHNU09TSdL mrAMcJd0ldT/PTZuqXOTC5evGnDBD28DZNuMOOmZQea6vtIhk0sB2gUGX0u719bXCjco hMNA== X-Gm-Message-State: ACgBeo0RymYjYYm3X0f8lxVri+dmAZNmWbVu83M+sXlB0oavdfCZKttG ++7FcdnkY3sRIPmZmmkZxLw= X-Google-Smtp-Source: AA6agR5GZrhy96PxyNn6J8YPvp9VPH4OOXh2X8llRt4ZS2gJe7pGP8FEXNNx6VOywUColdgeHjlAMg== X-Received: by 2002:a7b:cbd0:0:b0:3a6:9f6:a3e8 with SMTP id n16-20020a7bcbd0000000b003a609f6a3e8mr1140857wmi.13.1660645755719; Tue, 16 Aug 2022 03:29:15 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id m9-20020adffe49000000b002251639bfd0sm1668407wrs.59.2022.08.16.03.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 03:29:15 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8() Date: Tue, 16 Aug 2022 12:29:03 +0200 Message-Id: <20220816102903.276879-4-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220816102903.276879-1-jose.exposito89@gmail.com> References: <20220816102903.276879-1-jose.exposito89@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org, tzimmermann@suse.de, magalilemes00@gmail.com, airlied@linux.ie, maira.canal@usp.br, dlatypov@google.com, linux-kernel@vger.kernel.org, geert@linux-m68k.org, tales.aparecida@gmail.com, davidgow@google.com, =?utf-8?b?Sm9zw6kgRXhww7Nz?= =?utf-8?b?aXRv?= , isabbasso@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Extend the existing test cases to test the conversion from XRGB8888 to grayscale. Signed-off-by: José Expósito Reviewed-by: David Gow --- .../gpu/drm/tests/drm_format_helper_test.c | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index d8536db4de1e..2f548aa51a30 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result { const u32 expected[TEST_BUF_SIZE]; }; +struct convert_to_gray8_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb8888_case { const char *name; unsigned int pitch; @@ -46,6 +51,7 @@ struct convert_xrgb8888_case { struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; struct convert_to_xrgb2101010_result xrgb2101010_result; + struct convert_to_gray8_result gray8_result; }; static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { @@ -71,6 +77,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = 0, .expected = { 0x3FF00000 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -97,6 +107,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = 0, .expected = { 0x3FF00000 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -155,6 +169,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x3FFFFC00, 0x000FFFFF, }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0x4C, 0x99, + 0x19, 0x66, + 0xE5, 0xB2, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -206,6 +229,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x2A20300C, 0x1B1705CD, 0x03844672, 0x00000000, 0x00000000, }, }, + .gray8_result = { + .dst_pitch = 5, + .expected = { + 0x3C, 0x33, 0x34, 0x00, 0x00, + 0x6F, 0x3C, 0x33, 0x00, 0x00, + 0x34, 0x6F, 0x3C, 0x00, 0x00, + }, + }, }, }; @@ -381,11 +412,42 @@ static void xrgb8888_to_xrgb2101010_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb8888_to_gray8_test(struct kunit *test) +{ + const struct convert_xrgb8888_case *params = test->param_value; + const struct convert_to_gray8_result *result = ¶ms->gray8_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb8888 = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB8888), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch, + ¶ms->clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(&dst, buf); + + xrgb8888 = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888); + iosys_map_set_vaddr(&src, xrgb8888); + + drm_fb_xrgb8888_to_gray8(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(xrgb8888_to_rgb565_test, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(xrgb8888_to_gray8_test, convert_xrgb8888_gen_params), {} };