From patchwork Sun Aug 28 16:45:15 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: 12957268 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 60195ECAAD2 for ; Sun, 28 Aug 2022 16:45:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4A73110EDFD; Sun, 28 Aug 2022 16:45:38 +0000 (UTC) Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by gabe.freedesktop.org (Postfix) with ESMTPS id DE7C310E187 for ; Sun, 28 Aug 2022 16:45:32 +0000 (UTC) Received: by mail-wr1-x431.google.com with SMTP id bu22so7162997wrb.3 for ; Sun, 28 Aug 2022 09:45:32 -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=vJhh/lTctUSQJ2j9ZuvCFA+0ks2hV9Sn9L7SV18NIxM=; b=gfPdja9H01Nsbt78g1QvgP7UzzDh1NJ8LR4shpPhYcuXAW8sQcqev4YENRnS7EBVQV qN3vfQT9D8vFRp73NoGa+ZPMkO7a1O/VIG1dyT8/f4V+y6PgbRRaCt45OlX6XTU8zslB AjJwABgxu0QIr2LMu6Ap87UrF7u8aUf/nrl3G3zr/yrC+e+cOE9V9mYvbJxDvzZSHZ2f uImN86d62hS7Oevq4jfxeSqZsTEWrqNzbqyK46q5VyEyT3UXCOPnq3YLIKAZyzsqjZca 5LRn/s8pmOb9lQ7hyq/CS+wSEhSbci7mN5jOa69D9LiJf8pJqpDxUntAqPakMDe4LCAr qGfg== 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=vJhh/lTctUSQJ2j9ZuvCFA+0ks2hV9Sn9L7SV18NIxM=; b=IyRM7zHs118rMTvANjoasH5MDesrO7KDjnc9HPZP9QJhzt+AJ3u9ioklzJxxo5tZBu yUh2JSPQ9+FY+vl3o2otAz8EPwQwbbkqPVyBgi9CPrmYyr59ouyxleLkz+aaILQG3C0P kYn8EZnUnqEgshnJ0a96Rac9z+4RT0gTIr/hXxGkpJCeJBUiqrvB2+y/yT3ZGCqdQOZ/ miwGWJ6yDltSi4L6kJkwB9z2DiASRrygGwFva/C0Y3edbqTahWsEMDX2TFmFj02001ND mB759XVDdh8FHduyCYFd//fbmAOfhkrApn+haoxIdcjFQlF8jOZgVFSwuHMj9Irlb1+l FAJA== X-Gm-Message-State: ACgBeo2w9RIA9kT3M/0SpPAlY/+JCRSdItEJK+3BlDKtQ6BtgNKaNez8 qHl3faXxA+HPA1mgiui0gZQ= X-Google-Smtp-Source: AA6agR7xVlLAVUPoNOFYZfbfV0dfk38RLDO+1uN29xU/u2TnyUYcM1sM7o2jLcVqNTro6XhluVmOdg== X-Received: by 2002:a5d:48c5:0:b0:225:2f99:430d with SMTP id p5-20020a5d48c5000000b002252f99430dmr4859815wrs.358.1661705131425; Sun, 28 Aug 2022 09:45:31 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id e14-20020adfef0e000000b0021d6924b777sm399926wro.115.2022.08.28.09.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 09:45:31 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH v3 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888() Date: Sun, 28 Aug 2022 18:45:15 +0200 Message-Id: <20220828164517.185092-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220828164517.185092-1-jose.exposito89@gmail.com> References: <20220828164517.185092-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 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 Sun Aug 28 16:45:16 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: 12957270 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 0ADC4ECAAD5 for ; Sun, 28 Aug 2022 16:46:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8179D10E6B7; Sun, 28 Aug 2022 16:46:00 +0000 (UTC) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by gabe.freedesktop.org (Postfix) with ESMTPS id F18E710E187 for ; Sun, 28 Aug 2022 16:45:33 +0000 (UTC) Received: by mail-wm1-x330.google.com with SMTP id i188-20020a1c3bc5000000b003a7b6ae4eb2so2027918wma.4 for ; Sun, 28 Aug 2022 09:45:33 -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=rJjTif4+g5XOJTLGqcyodmj0ft42i9kQrxGSEhjuF08=; b=Pvj0SKWtb33+3HVhsjkEkZ5GgQ0eNUZe2o+u4wVpGiQCn/j0CFIPO+ys9JKt7gRLZv 9ipl2H03xu6JEqsWwae1pJtYEP4Ipqb3ViOVP4WXHr2EZOa0iuK3lJWlzLz05yU2G9Vq whM1f8LbY9IzA0mbf41d7DI59MDN1fIu7l/P44212hYv3Ph3JgKyTaJGyhGlTLr3osrP GDAMF8WCMAuW5lsll5HBXVn63RFgShTj2V2f2a2uYptxCU0ZgnFneacjQ8qb82p9ez9D 1H3l2zSMmz8pt4gigEipmM6gJYeJkqlbIJroGiKCZLYVS1Rc6X4rqdGw9aKyPfGWL6fa 20sw== 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=rJjTif4+g5XOJTLGqcyodmj0ft42i9kQrxGSEhjuF08=; b=W4/WCMKMUBRcdnxOWNupjFLS5Pozb/WNyrG/HBpIpejpFEC9LbrRlXWQ+8h/yDVkjQ 5P5EGvmRqGoWTCgVeH3yAjJN6ZLka/RoWsZl12qgLxrg9qLMDmVVfTOQLWqZCqovKJGW ewv/D3GzLjhNvlDDvuTZiP77ZZlsaPTNeQuu8mjFtukwNzZJuG302ImBD86b3NHs/bcS OW9QMeI5rW+3h+fPR6UlB/ytoBBWM9b4RBqbGKUVm53+6NrlS/suAiHB3L40GEipoLl8 iVprJ161Fy/hqheGDazor3eJlptKER0IQG2iwvsnWLo7oP1N3zZ+8dJZZETYnC+rkeHR CgOw== X-Gm-Message-State: ACgBeo3CDbAJS+PlRgO47sJZ+FdFBmUr7bLssaRQJ9sxPuf/DA0IKk8Y JhyUzNwufTqw4gP4SfYsrWk= X-Google-Smtp-Source: AA6agR61Qf1qoXk3S6nbbo9zG7j/gKVHvd8fiDrV83u8UUr3CghkpN7OQdWH5rinK8Y3DItW1BVRnw== X-Received: by 2002:a05:600c:4e0f:b0:3a5:e065:9b50 with SMTP id b15-20020a05600c4e0f00b003a5e0659b50mr4846594wmq.35.1661705132495; Sun, 28 Aug 2022 09:45:32 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id e14-20020adfef0e000000b0021d6924b777sm399926wro.115.2022.08.28.09.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 09:45:32 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH v3 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010() Date: Sun, 28 Aug 2022 18:45:16 +0200 Message-Id: <20220828164517.185092-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220828164517.185092-1-jose.exposito89@gmail.com> References: <20220828164517.185092-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 56642816fdff..b9a9fea0f6f1 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 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 Sun Aug 28 16:45:17 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: 12957269 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 76EB6ECAAD2 for ; Sun, 28 Aug 2022 16:46:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0711110EE92; Sun, 28 Aug 2022 16:46:01 +0000 (UTC) Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by gabe.freedesktop.org (Postfix) with ESMTPS id E898810EEC0 for ; Sun, 28 Aug 2022 16:45:38 +0000 (UTC) Received: by mail-wr1-x436.google.com with SMTP id c7so824057wrp.11 for ; Sun, 28 Aug 2022 09:45:38 -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=T5aRwr6pqcsQk7PMMmsjKOURSAFgkEiep7tVEjgOEu8=; b=eMVxp40D8zIPnnJMVchQvjuBddHTX1y2JuTilTMpaHdYOA3XVTrIWrxlutKoh5Nnuz aKR4a/L3hZGTg+L7entXUOpqVn8ZqYYSHIxRgrubT0r10RqyTRyF1HuFeQSVwqZLjxaQ 8+EvGwx+RxWdNbrXTLipQ8kNEUiFeIg7Bp514To1u9GAxH2v9v5jqZ4PYMD7TW1N5V5A EvfFeD3dWFN2c5+OF+BY+osUyL7oh6/c2dCBx724bE38b3IrzlagAPlnIhKXAHqQ6QNI kfTKrBAqOVr+nbulqjGoYep5kW+hPrqa3K8omCdGojVz7II+/B1ovpVktKLGStfFESER JkCg== 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=T5aRwr6pqcsQk7PMMmsjKOURSAFgkEiep7tVEjgOEu8=; b=Q+JXhFwSem/02tSeC9YCFLbIm/uFU1NhCewSNR0Uoz9QUZRCw9H4z7nnZdkTDCgezf Eo+6YoWyy0QJ9E7NN5xNkEQlmNGS4psuIvYe3hkiE2TcseqN28PS7Qtvzjc8BNqaHoi5 efkQjrObsSeI9vWtJ7LGiVtuP4Bn8DKfaNEmaO5u6NuD1sAf2FvMF+0FJDKAx24W6nJV uRQkmDULEgBEBY7zWOfci60NmJ+Gq2yHIDSn8sjrr6de70NWjm5ellDji3c5NuYqfn88 eEh5pBmr/B1aKmgPohVjwdyZLw5lKq542IUJKoEUkHK0cAZtlAsTV3pycO+oZOrS/sSz r/1A== X-Gm-Message-State: ACgBeo3xynKLonhBK/Z35VHTFApQh8p4DGpaIay+DYg33T56hW0oDXeG YJSB40gYQ0HhzWPtIrYZ2tI= X-Google-Smtp-Source: AA6agR7V+NPsMLy1J0fh4fleBXVJLxyvQiVED33xvrwNFZhd+KyuovF8/BugiqKciBpAajCx3/Uc/g== X-Received: by 2002:a05:6000:702:b0:225:4a84:89ea with SMTP id bs2-20020a056000070200b002254a8489eamr4708496wrb.194.1661705137422; Sun, 28 Aug 2022 09:45:37 -0700 (PDT) Received: from localhost.localdomain ([94.73.32.249]) by smtp.gmail.com with ESMTPSA id e14-20020adfef0e000000b0021d6924b777sm399926wro.115.2022.08.28.09.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 09:45:37 -0700 (PDT) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: javierm@redhat.com Subject: [PATCH v3 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8() Date: Sun, 28 Aug 2022 18:45:17 +0200 Message-Id: <20220828164517.185092-4-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220828164517.185092-1-jose.exposito89@gmail.com> References: <20220828164517.185092-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 --- .../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), {} };