Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3506090rwb; Tue, 16 Aug 2022 04:25:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR4QSE1CifjjOY/s5NyjGTiU8DHu++VXXGvdctRPWJjczGVBhqhnl3aR6ne/yTwljqDHGGqQ X-Received: by 2002:a17:907:969f:b0:730:b649:ff90 with SMTP id hd31-20020a170907969f00b00730b649ff90mr13240037ejc.337.1660649130378; Tue, 16 Aug 2022 04:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660649130; cv=none; d=google.com; s=arc-20160816; b=RjsgsHHn2ukam1dF2mQ1SyKV6XClp7Q74Ov70SJIjt5Ncj/dPPfbcb2zV+Jx8DHE/t zVVIdexhcw8U2L+uwgcNqm5Y7OGExupCtp5QiAkzcDgasCgA/EkqTF+gyLrWkWck9+Yd XzxdYxc/LO5fMpBA5GQyFVLGTRZ6ACyiJIafrXVamhWm7tMuKFYxGbh560bSgcqAA5Tm eabXrQJSbrHplZ9A1Ma7XxljKOnKVLoT2cxXIsk6Q3ORveVnO9gsH1u4Pb1CpDMW4M+G EeEk9yyGJzIb9ZLbU40jJ/zC8NIQf2SZHniZiaOKJuxtgqMJy4vI6TCwphitZ4wuyg6h gqpw== 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=J8iZCnBWtxZ0luRrE1AM5j//meG3qtyDdNSPKnb1YHs=; b=fqtvJwbfQDHSHn+0yqpFLJKgtP7JkLMM/qplUCJapcDjaLFvpWKUMHTr6z/ZZoaoJb SSQLx4beSq7dKqZu1mTdv75zOOTV/JcyMetOtxw6q8thuFZ2599muOz9X9jIZscGBtGs iLB37Wu+vA5a4BfP03oUv9C/Hbb0fZ6R2bs6IfKNqERHFhU0YQrhrc6sfwgFiufginFD 00Vze2d6o7w7v3TXNF74lujzxHkSkXuSal6YkmIEBeaIW3HUERfild8xQjYhEpmwkz2V 5iAMsLQmV5ZZNAq/HyggSuwO0ll3FzpYH7CwjjBmKX2BGKpYwZAU2/0pE4WDKgsFm5z6 eXVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hUkuVh9l; 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 ds8-20020a170907724800b00730bc62507csi10580022ejc.125.2022.08.16.04.25.04; Tue, 16 Aug 2022 04:25:30 -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=hUkuVh9l; 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 S235160AbiHPLCc (ORCPT + 99 others); Tue, 16 Aug 2022 07:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235133AbiHPLBw (ORCPT ); Tue, 16 Aug 2022 07:01:52 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEFF0CAC7E for ; Tue, 16 Aug 2022 03:29:17 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id d5so2732138wms.5 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=dUbIqQOZmGG8iVR3B9Vsa0yWNchhL2pxdn/dfQK0FNYiRxF52u+l4ta8nsxJJqH3FW 6C4111X2YTzsNf5cllXnD6avx29hjrLFHoGYUV5/UxMvId8AWRrP0iDBuqqqQiaOTRMp YUW9dhS1EmImzh7KDFnF7BvuTfYCyyDZXTiQT2YJWxCU5ejn7EuOW/U41UAUI+OShMyA gvX5r71bwf3PmaER9tTz/5vXcV3gtANEuzn8qJkFSQKkubao9tx/KJOVXkMPKa+L+k9b bhhS3yWyx/RcaRl2/Emsy/8cppFAJDMM1RRh8ZD5uqACIf5x4q2mTW2eRyGWFxm2TBEY +uYA== X-Gm-Message-State: ACgBeo2AilVCMwRwc4bksqMhAj094AjaeoYhF4vFRG7qiCtXQfi5ipin 2E0nV3OyyFQLSFczYp6IBP8= 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?q?Jos=C3=A9=20Exp=C3=B3sito?= To: javierm@redhat.com Cc: davidgow@google.com, dlatypov@google.com, tzimmermann@suse.de, mripard@kernel.org, daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, jani.nikula@linux.intel.com, maira.canal@usp.br, isabbasso@riseup.net, magalilemes00@gmail.com, tales.aparecida@gmail.com, geert@linux-m68k.org, 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 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 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 Extend the existing test cases to test the conversion from XRGB8888 to grayscale. 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), {} }; -- 2.25.1