From patchwork Mon Sep 19 07:15:29 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: 12979721 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 21FBEECAAD3 for ; Mon, 19 Sep 2022 07:16:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 76B6610E548; Mon, 19 Sep 2022 07:16:17 +0000 (UTC) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3EE5D10E543 for ; Mon, 19 Sep 2022 07:15:44 +0000 (UTC) Received: by mail-wr1-x42f.google.com with SMTP id k9so46092346wri.0 for ; Mon, 19 Sep 2022 00:15:44 -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:subject:date; bh=GmFNK/zSR9Rz0xfVrBIcsxHUWDojCNRY4rMdARjPXgM=; b=mrprQ4j4X9S7NdKzFKxZtHmc6zlyFcMfJ6CNtPFf4By3uM0dOcPnk9KYRSwerrv9sD JFIYDz1+LmpAC5v1YHKLTzWSwwKYCfBZcqj+rg44YKQBb+f6CA12W2A4pXFKh6+BpobC i0yDY28oyTCg9tmuogbhhp9Pf7FaEXHglSpG+IXcXOuR4Nhtdl9PTnJCy5nWpIFHD8rs fud6yjSre1+8XSybhYhel3qB0f3Oi3xHgyvU81B6nb+hHNy0uga4knFkeFdWg8hYfqfO vLc2lNKqCZlb6yybOzWYNUNgUQaokIb5iELGE5QKzQb62BehlaW0e7i4bFc59VSOaxyq rLqg== 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 :subject:date; bh=GmFNK/zSR9Rz0xfVrBIcsxHUWDojCNRY4rMdARjPXgM=; b=pOgacCVEZYxpzMgyO49xZ13sPfw4JpnTnkUOczAOclM1Wn13/8RGeJ7H6ycXvBpufK DhtKfrA7traAFGscGcXS+pGw0eaNjTrxkIIlUNNm1O9+A+IvFE4CeGDdaHWynphwcFId MqHfmscBWS/rmATsCk9yq/IVcnv43q5/MYGjFK5dyUB4EVigPj9XlR4pssVHCJAjJ8qy IUXH85Xyf865JCuDaWdDpkqQNytksU6TlfbrwuiS7TZbVUlB95aqmsKKTXJo09ti+aTo LEOzsgkA5ybGA/1dwywR68Ma+01BGJgA4ZPZCyLoL5QfYFc7fPBYnF4ZdHmj/agC4vj2 Kgbg== X-Gm-Message-State: ACrzQf2n9+9hVQORK04oJAQ5UERBcZrYwAi/qDda+bb8P1GcCiuaVVEP ucrNVKK9IWqEYxaWStQ9qEU= X-Google-Smtp-Source: AMsMyM4xAR4z6zxcivfiR1WN/lF8jc8pfwiQfaTjLfoJBgpH1JZdz8+JsLSkoywLNrLNULCmPepxwg== X-Received: by 2002:a5d:6609:0:b0:22a:3965:d5ad with SMTP id n9-20020a5d6609000000b0022a3965d5admr9907142wru.62.1663571742634; Mon, 19 Sep 2022 00:15:42 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id l3-20020a5d4bc3000000b0022ac12fff29sm12864564wrt.65.2022.09.19.00.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 00:15:42 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH v4 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888() Date: Mon, 19 Sep 2022 09:15:29 +0200 Message-Id: <20220919071531.105124-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919071531.105124-1-jose.exposito89@gmail.com> References: <20220919071531.105124-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, =?utf-8?q?Ma=C3=ADra_Can?= =?utf-8?q?al?= , 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. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../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 ab49f5e8796c..cc1ab672314a 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 drm_test_fb_xrgb8888_to_rgb565(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); } +static void drm_test_fb_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(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params), {} }; From patchwork Mon Sep 19 07:15:30 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: 12979720 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 8CF8AC54EE9 for ; Mon, 19 Sep 2022 07:16:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DC1A610E545; Mon, 19 Sep 2022 07:15:54 +0000 (UTC) Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7050410E544 for ; Mon, 19 Sep 2022 07:15:45 +0000 (UTC) Received: by mail-wr1-x432.google.com with SMTP id z6so13541131wrq.1 for ; Mon, 19 Sep 2022 00:15:45 -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:subject:date; bh=Y+/9Eo/+FGAJXwWdsnxjUOBvrjDggVecVUqEpljQ8Wk=; b=ViUfs/eBqECjm7D7VWc7N4a82hDDl4MzRy5bhTYFej2oWh9Y+dzSw5MOyCoWiuZQpM Ji+iy79Z9ZFmZ3Xtxfmb4VEeN8rnjIBZTaqi0dqoVZJvNChhdlw/qBX6MH7FcdLSknRC /iyc2Xw5lFLahewd1ROXvKYQswYWjecUX6gTSSP2iJZHNBhbnf/p38HU4IqqH7ptsh1O NWADMLOd2TvjlHburh5KMwoNZpbe+jMrOM/q/mDlbjDadkpgSVJtkAd5+8JABPZTSQRM dPEusn487wgbVEMqXuTNN9njMcOqRpPWyp+40+cFAfUFU9Vo402J9PGBFRIsGQHsg38P 860A== 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 :subject:date; bh=Y+/9Eo/+FGAJXwWdsnxjUOBvrjDggVecVUqEpljQ8Wk=; b=g4225S04SeRaOu1lafKKr84rnyHBAqylybQL7ClWCB0nzeufmNqAkbaWke5VaT02KJ vGH/IgLrOOt6iMWyFUpAVLQDkVgcPyfg3MYi8ICLXnLX6qpjVvdqQA4VQKjMY6AYWD9M 4BRgiNBa/qmXPvtlfg0QrTvuz7vvjt9BZy/Ax6DGjZe1XWeSaeWllQLLMkgLZFG5UpPG OctcgL73L+zyPs9da3DM23NZAAwera9eAXtjydfh3YzW8Wq9yCs4uhPxLX8KGxPPuiq+ f0USP3vIC2IawymgJ4VMTViPQ7AleTlRWDB9isw0LwgFRTlBZ0YpmingLtN/wH7FTLLr PKeQ== X-Gm-Message-State: ACrzQf04s3b22YlHX4tYbKnob8h07b9r/FfNo8Bm5I6K71tqWVY5wlKY hrVwCyT191aWFFlT8XuraqM= X-Google-Smtp-Source: AMsMyM5nvUP3P5v4Z2/2BG3H3e4ejGni9OAuNRCLJSe/+rsrn4BbPRCmQYGaplUpbRi7Epj+nWtYtw== X-Received: by 2002:a5d:6852:0:b0:228:c94b:a5b0 with SMTP id o18-20020a5d6852000000b00228c94ba5b0mr9382436wrw.540.1663571743768; Mon, 19 Sep 2022 00:15:43 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id l3-20020a5d4bc3000000b0022ac12fff29sm12864564wrt.65.2022.09.19.00.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 00:15:43 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH v4 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010() Date: Mon, 19 Sep 2022 09:15:30 +0200 Message-Id: <20220919071531.105124-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919071531.105124-1-jose.exposito89@gmail.com> References: <20220919071531.105124-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, =?utf-8?q?Ma=C3=ADra_Can?= =?utf-8?q?al?= , 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. In order to be able to call drm_fb_xrgb8888_to_xrgb2101010() when compiling CONFIG_DRM_KMS_HELPER as a module export the symbol. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- drivers/gpu/drm/drm_format_helper.c | 1 + .../gpu/drm/tests/drm_format_helper_test.c | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index 4afc4ac27342..e2f76621453c 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -553,6 +553,7 @@ void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, drm_fb_xrgb8888_to_xrgb2101010_line); } +EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010); static void drm_fb_xrgb8888_to_gray8_line(void *dbuf, const void *sbuf, unsigned int pixels) { diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index cc1ab672314a..09d358b54da0 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 drm_test_fb_xrgb8888_to_rgb888_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void drm_test_fb_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(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params), {} }; From patchwork Mon Sep 19 07:15:31 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: 12979719 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 7438EC54EE9 for ; Mon, 19 Sep 2022 07:16:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 552C010E544; Mon, 19 Sep 2022 07:15:53 +0000 (UTC) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75EF210E545 for ; Mon, 19 Sep 2022 07:15:45 +0000 (UTC) Received: by mail-wr1-x429.google.com with SMTP id r7so4955026wrm.2 for ; Mon, 19 Sep 2022 00:15:45 -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:subject:date; bh=qfGjedfOfmqcmzpgBDloDio1P9ZSKZd/Kz8vAVqEXrA=; b=I/cZGAOmF7yLIHC6L1ZReI1Zr+la6gtckoj0oh31FXw7VNcw0Gbiov07i1Slmiq097 rBlJ+EVXnKgTBHMR/5ASoB5Rio02rb6EzdfikO5QobiWNiU385CF8AbdHuqX+p46rBSK PCWzI6YN+409UnP5W2CqulmsOEX+Es4eIX+PxA0ezxskF7e9RAmi9kDS5CDClp0Mt7nx JCz6JHdHcsNbAHiFIeOMLFQzXG+rofrE8sqbybvhtoIjOrfW1TSlMMt9rCf/RPdiA8mR jJW0xrMuTbKHsPxUOYi+W5k09FQrdixs6R4zQf1xqUHvdNo0qNz45cyeqA5OnzCkYYYY t81g== 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 :subject:date; bh=qfGjedfOfmqcmzpgBDloDio1P9ZSKZd/Kz8vAVqEXrA=; b=BEN/1pk+jKf9En2TtcIx5kM62jKgqK0F3vYn4IkdQD8ukHZPbExU5GNfLk80jC/UYa jY9Om4hXGumard2WFd7IVdlf7cMvHDaIbE52bjFoTOF/4plEf2yYipedmtJGCojgZdaS V3wNlKkvXhs5hoplF38xpBP1569D2vagZY3U8OQu0G2DCymQ5npfGAjWw0cJzxt2/GCa ycDlA3/dSoUae5YIoPfnYIZb2iDU+2NNyFY1cCFCAUQGPTj2mPamT/OK8rWAC6LQC1y9 brnXsl5NqIUD6t3RsHjDNXZ/PydQvH0Nir58bTJbtvc52sM7z0OaRQvlLxkhQDuNjAQB J8yA== X-Gm-Message-State: ACrzQf2xfEYn2lqEPuSEpY2u3dF+CjMFNSCmkyw6TfJdvSvSfH8jRKk7 hSXObA5ViUSLV1hqARcgjKE= X-Google-Smtp-Source: AMsMyM6dBRYmU965RelyzKog9pKkRLMn4BxhBotd8j55/PpvNwhGT3YtQ0KoUvz9HEP8xrL990Allw== X-Received: by 2002:adf:fb50:0:b0:22a:e4e9:a6b3 with SMTP id c16-20020adffb50000000b0022ae4e9a6b3mr6977062wrs.467.1663571744981; Mon, 19 Sep 2022 00:15:44 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id l3-20020a5d4bc3000000b0022ac12fff29sm12864564wrt.65.2022.09.19.00.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 00:15:44 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH v4 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8() Date: Mon, 19 Sep 2022 09:15:31 +0200 Message-Id: <20220919071531.105124-4-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919071531.105124-1-jose.exposito89@gmail.com> References: <20220919071531.105124-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, =?utf-8?q?Ma=C3=ADra_Can?= =?utf-8?q?al?= , 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. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito Acked-by: Maxime Ripard --- .../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 09d358b54da0..71722e828abe 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 drm_test_fb_xrgb8888_to_xrgb2101010_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void drm_test_fb_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(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8_test, convert_xrgb8888_gen_params), {} };