From patchwork Mon Aug 5 23:39:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754238 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 94D83C3DA7F for ; Mon, 5 Aug 2024 23:38:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0BD5510E2D1; Mon, 5 Aug 2024 23:38:18 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="PYsejpm0"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 99E4F10E2D1 for ; Mon, 5 Aug 2024 23:38:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 8117941A4C; Tue, 6 Aug 2024 01:38:15 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TiQmIZDmqkaK; Tue, 6 Aug 2024 01:38:14 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901094; bh=XCc7ZOrvTZrwc6yFbw7XVS/EHwSAuKbarqYVeLcXtRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PYsejpm0yKjCFL3CIjaqYRVQUFhoS70/9BBE0RryLbHbpXUAbhb+SjlN55PoNGYiK 2TJJ+NFFKcGccM8UabcdbrriNaLvrRQmXd8gm2+rrcsRrS9CPnBUTRu3mZiIY9qf3c 71XjL0E31RVrgwBB96hG1r9LUf9iBjh8OaQI2nNxcWXhAIYtpkty6up2+sZjP2YkwV ntSAnkzFchNQMm+F6v35uBwQSSa2dFkSUNnaZrxaqPJHMqg7/3cs4zCHF/ey+BEeZ9 rEX0eGCC5P2Z8S49uuURzq7hYyeRXVK0KVIudCMqMZt8rr440LCFiBRtySXBOSnDpF lmzElPK0pBeww== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 1/9] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests Date: Mon, 5 Aug 2024 20:39:26 -0300 Message-ID: <20240805234022.18586-2-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The dev_private member of drm_device is deprecated and its use should be avoided. Stop using it by embedding the drm_device onto a mock struct. The new mock struct allows to share variables and even further mocks over the tests in a cleaner way than using dev_private void pointer. Also start using drm_kunit_helper_alloc_drm_device() for allocating the drm_device mock. Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- v2: - Start using drm_kunit_helper_alloc_drm_device() for drm_device mock. - Rename struct drm_mock to drm_framebuffer_test_priv v3: - Replace the use of void pointer on drm_framebuffer_test_priv struct. - Document struct drm_framebuffer_test_priv here. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 54 ++++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 06f03b78c9c4..3882a88b6631 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -8,8 +8,10 @@ #include #include +#include #include #include +#include #include #include "../drm_crtc_internal.h" @@ -317,12 +319,25 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { }, }; +/* + * This struct is intended to provide a way to mocked functions communicate + * with the outer test when it can't be achieved by using its return value. In + * this way, the functions that receive the mocked drm_device, for example, can + * grab a reference to this and actually return something to be used on some + * expectation. + */ +struct drm_framebuffer_test_priv { + struct drm_device dev; + bool buffer_created; +}; + static struct drm_framebuffer *fb_create_mock(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) { - int *buffer_created = dev->dev_private; - *buffer_created = 1; + struct drm_framebuffer_test_priv *priv = container_of(dev, typeof(*priv), dev); + + priv->buffer_created = true; return ERR_PTR(-EINVAL); } @@ -332,30 +347,37 @@ static struct drm_mode_config_funcs mock_config_funcs = { static int drm_framebuffer_test_init(struct kunit *test) { - struct drm_device *mock; + struct device *parent; + struct drm_framebuffer_test_priv *priv; + struct drm_device *dev; + + parent = drm_kunit_helper_alloc_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); - mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); + priv = drm_kunit_helper_alloc_drm_device(test, parent, typeof(*priv), + dev, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); + dev = &priv->dev; - mock->mode_config.min_width = MIN_WIDTH; - mock->mode_config.max_width = MAX_WIDTH; - mock->mode_config.min_height = MIN_HEIGHT; - mock->mode_config.max_height = MAX_HEIGHT; - mock->mode_config.funcs = &mock_config_funcs; + dev->mode_config.min_width = MIN_WIDTH; + dev->mode_config.max_width = MAX_WIDTH; + dev->mode_config.min_height = MIN_HEIGHT; + dev->mode_config.max_height = MAX_HEIGHT; + dev->mode_config.funcs = &mock_config_funcs; - test->priv = mock; + test->priv = priv; return 0; } static void drm_test_framebuffer_create(struct kunit *test) { const struct drm_framebuffer_test *params = test->param_value; - struct drm_device *mock = test->priv; - int buffer_created = 0; + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; - mock->dev_private = &buffer_created; - drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL); - KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created); + priv->buffer_created = false; + drm_internal_framebuffer_create(dev, ¶ms->cmd, NULL); + KUNIT_EXPECT_EQ(test, params->buffer_created, priv->buffer_created); } static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, char *desc) From patchwork Mon Aug 5 23:39:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754239 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 D0589C3DA7F for ; Mon, 5 Aug 2024 23:38:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1DB9910E2D2; Mon, 5 Aug 2024 23:38:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="OsXeUcdB"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id D4CC510E2D2 for ; Mon, 5 Aug 2024 23:38:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id B71C8419DB; Tue, 6 Aug 2024 01:38:27 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fU_kVoksRdwi; Tue, 6 Aug 2024 01:38:26 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901106; bh=hdt7+HC6BtHhK+jHHNwc4wG89rZaKps0KSw5On+WLWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OsXeUcdB28dSZPWkTmCTjVIvDAEfzFu9sj3ZkgXfY8+nNp11IU+C3GbCp6wc7Fr2+ pS/TTUYGz7im/sfZ5n42PNfn7in95k+i/szqF2oiegtxQoqUFtyO7Hw3EvsjP/A1P5 gtPIlALWgyz5Ft6qbD66l35an/VKd1ej8HmBGyAfT8Kbahh9AHrmwlardGGS9qxDEm rBe3KFb5H5qj2eNEqJUYnz5XQQY5HXuWFmk3EtaX80rSQEDfR9LfTMw055rocwrQDs YNSgSVHZO8z/c3/6YpsuGOg307iF28MC74Pb6tMv0ZxEZXzCJ1q4+4k9b00rdsmkX7 J+piqRHtkMCfg== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 2/9] drm/tests: Add parameters to the drm_test_framebuffer_create test Date: Mon, 5 Aug 2024 20:39:27 -0300 Message-ID: <20240805234022.18586-3-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Extend the existing test case to cover: 1. Invalid flag atribute in the struct drm_mode_fb_cmd2. 2. Pixel format which requires non-linear modifier with DRM_FORMAT_MOD_LINEAR set. 3. Buffer offset for inexistent plane Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- v2: - Remove strcpy to strscpy change. v3: - Rename and commment the "Buffer offset for inexistent plane" test case. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 3882a88b6631..3ed987423322 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -21,6 +21,8 @@ #define MIN_HEIGHT 4 #define MAX_HEIGHT 4096 +#define DRM_MODE_FB_INVALID BIT(2) + struct drm_framebuffer_test { int buffer_created; struct drm_mode_fb_cmd2 cmd; @@ -85,6 +87,24 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { 4 * MAX_WIDTH, 0, 0 }, } }, + +/* + * All entries in members that represents per-plane values (@modifier, @handles, + * @pitches and @offsets) must be zero when unused. + */ +{ .buffer_created = 0, .name = "ABGR8888 Buffer offset for inexistent plane", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, + .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, UINT_MAX / 2, 0 }, + .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, + } +}, + +{ .buffer_created = 0, .name = "ABGR8888 Invalid flag", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, + .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, + .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_INVALID, + } +}, { .buffer_created = 1, .name = "ABGR8888 Set DRM_MODE_FB_MODIFIERS without modifiers", .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, @@ -264,6 +284,13 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, } }, +{ .buffer_created = 0, .name = "YUV420_10BIT Invalid modifier(DRM_FORMAT_MOD_LINEAR)", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YUV420_10BIT, + .handles = { 1, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, + .modifier = { DRM_FORMAT_MOD_LINEAR, 0, 0 }, + .pitches = { MAX_WIDTH, 0, 0 }, + } +}, { .buffer_created = 1, .name = "X0L2 Normal sizes", .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_X0L2, .handles = { 1, 0, 0 }, .pitches = { 1200, 0, 0 } From patchwork Mon Aug 5 23:39:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754240 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 2C58DC3DA7F for ; Mon, 5 Aug 2024 23:38:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 96D9F10E2D3; Mon, 5 Aug 2024 23:38:33 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="YWi2fsm7"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id F1BB510E2D3 for ; Mon, 5 Aug 2024 23:38:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id CBF9441A0D; Tue, 6 Aug 2024 01:38:30 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2AJUJ6Gjgze4; Tue, 6 Aug 2024 01:38:30 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901110; bh=wlDPrqJloqXoPvzIW0o43ht0FObE1/bhLSwf/mqTox0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YWi2fsm7oETrTu8BFBF0W3KyQH+b83JfF0V/OfakzAlOE7qTUJUTUJQGD+9i+lisE YKUh1aT8HiQTen61Ms6e1MXhdKUeIVB67b26H3x426/iieLIVSs0KDEMUtC6fJjjJn sUJUK8n637vJRgyjcplndu3blxHpSxc8BWe8zUtD+ftK7k0TQ2A9VpppTKiYxUItwf U+khDKe3JYEei60UwGOn4/SDpdFlYb+gWHNUCcTf5BhirCr3IGNPiyXfuHthYs/kPJ z5BMpLdWLpzUnCd8H8oAp28rIyAw8XTLOsgnAVNyHG3EmLW0sc4sZ/WCLQnm0qmexH vria+SlHeB25Q== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 3/9] drm/tests: Replace strcpy to strscpy on drm_test_framebuffer_create test Date: Mon, 5 Aug 2024 20:39:28 -0300 Message-ID: <20240805234022.18586-4-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Replace the use of strcpy to strscpy on the test_to_desc of the drm_test_framebuffer_create test for better security and reliability. Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 3ed987423322..4b1884be9d7a 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -409,7 +409,7 @@ static void drm_test_framebuffer_create(struct kunit *test) static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, char *desc) { - strcpy(desc, t->name); + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); } KUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases, From patchwork Mon Aug 5 23:39:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754241 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 C4603C52D6D for ; Mon, 5 Aug 2024 23:38:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A6F310E2D4; Mon, 5 Aug 2024 23:38:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="asyPKJIH"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 59D0310E2D5 for ; Mon, 5 Aug 2024 23:38:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 3E09341C96; Tue, 6 Aug 2024 01:38:34 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YsZ_RUbW-pnJ; Tue, 6 Aug 2024 01:38:33 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901113; bh=cxYQopgho+9q6IPHDaCIDr5EtYdSvtCPQ2rteYnmafM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=asyPKJIH5ArBvUk8Hn9Bm5qnNmbqC9hXIT6sQ3SAih7Yti3tAK12Fa1+rvQJlPQX4 2r85wKsab+TkfmdvHia75K2fg8JN+RngBbWIBUPOt3KJh/F70D2s2XYmCw2FK76Tq1 5MuEh+unPuduw9jiGqpr5orW0mmTkQsvNrIk8+XxXWGUVou2bstC9c9pFfqKtbOpqT WwFMUB+4ZdPkKfQyG5uBr+13Dlg0G5HYUvONM26wPweXsUmawvSssOTFX7UHoen/qD +Brpg8FVgC/Nb+BDDAz5hH73h2EKtkDXcCFkFGRtCMo4f45p+Ox5E2b4U/b9EHBmAO gbvZDi0ZgoWVQ== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 4/9] drm/tests: Add test case for drm_internal_framebuffer_create() Date: Mon, 5 Aug 2024 20:39:29 -0300 Message-ID: <20240805234022.18586-5-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Introduce a test to cover the creation of framebuffer with modifier on a device that doesn't support it. Signed-off-by: Carlos Eduardo Gallo Filho --- v2: - Reorder kunit cases alphabetically. v3: - Replace the use of void pointer on drm_framebuffer_test_priv struct. - Test return value of drm_internal_framebuffer_create(). - Change test documentation to don't rely on another test. v4: - Reorder expectation value. - Remove unneeded expectation. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 4b1884be9d7a..2ea3abfd5e7a 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -415,8 +415,32 @@ static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, c KUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases, drm_framebuffer_test_to_desc); +/* Tries to create a framebuffer with modifiers without drm_device supporting it */ +static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_framebuffer *fb; + + /* A valid cmd with modifier */ + struct drm_mode_fb_cmd2 cmd = { + .width = MAX_WIDTH, .height = MAX_HEIGHT, + .pixel_format = DRM_FORMAT_ABGR8888, .handles = { 1, 0, 0 }, + .offsets = { UINT_MAX / 2, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 }, + .flags = DRM_MODE_FB_MODIFIERS, + }; + + priv->buffer_created = false; + dev->mode_config.fb_modifiers_not_supported = 1; + + fb = drm_internal_framebuffer_create(dev, &cmd, NULL); + KUNIT_EXPECT_EQ(test, priv->buffer_created, false); + KUNIT_EXPECT_EQ(test, PTR_ERR(fb), -EINVAL); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), + KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), { } }; From patchwork Mon Aug 5 23:39:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754242 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 92FEDC3DA7F for ; Mon, 5 Aug 2024 23:38:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0372610E2D5; Mon, 5 Aug 2024 23:38:41 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="TJuoqoqx"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id BB33110E2D5 for ; Mon, 5 Aug 2024 23:38:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 9F01B419DB; Tue, 6 Aug 2024 01:38:37 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wtfodAOLA_bi; Tue, 6 Aug 2024 01:38:36 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901116; bh=TNw+4TUvG5q2B83KkombW/c+lYkfCTu08Y5Ep2VOai4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TJuoqoqx0VtYGc4Zlyxty1Xk9nZidSvdccqv+3WbaHOZV/q7eOAmd863MbZWloSOq JOutC3svqL0qpKl4TSIvYBQ5IZyJ1+2Uqc9mwoD85yZ9m/X1evLaKIpsQXx9ej6aCx mSWyn7lV141Ne//28Awb+lgvnuNCuiXRIGNvPVsIh7JblobHBD94K8KcgaR1sF/MO4 oLWdfJUCBAGtdCYR2z+XMW4ZpTA+/xVUkfpH1s0oZIDq5KWd5ad/Xy43dMlsTjxcNC BkZtqYjkBUYECSniMHvthPZ+bmlzMwy9fI1BFV+sNpxGIfyzlc2qE7qtUwRZoTx8Mm 4edEAMNqQK3iw== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 5/9] drm/tests: Add test for drm_framebuffer_check_src_coords() Date: Mon, 5 Aug 2024 20:39:30 -0300 Message-ID: <20240805234022.18586-6-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a parametrized test for the drm_framebuffer_check_src_coords function. Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- v2: - Order kunit cases alphabetically. - Rename check_src_coords_case to drm_framebuffer_check_src_coords_case. - Remove unnecessary comments. - Add framebuffer size as a parameter and use edge values. --- drivers/gpu/drm/drm_framebuffer.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 61 ++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 888aadb6a4ac..9cd85ac789bb 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -99,6 +99,7 @@ int drm_framebuffer_check_src_coords(uint32_t src_x, uint32_t src_y, return 0; } +EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_framebuffer_check_src_coords); /** * drm_mode_addfb - add an FB to the graphics configuration diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 2ea3abfd5e7a..1924e3f9538e 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -438,7 +439,67 @@ static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test) KUNIT_EXPECT_EQ(test, PTR_ERR(fb), -EINVAL); } +/* Parameters for testing drm_framebuffer_check_src_coords function */ +struct drm_framebuffer_check_src_coords_case { + const char *name; + const int expect; + const unsigned int fb_size; + const uint32_t src_x; + const uint32_t src_y; + + /* Deltas to be applied on source */ + const uint32_t dsrc_w; + const uint32_t dsrc_h; +}; + +static const struct drm_framebuffer_check_src_coords_case +drm_framebuffer_check_src_coords_cases[] = { + { .name = "Success: source fits into fb", + .expect = 0, + }, + { .name = "Fail: overflowing fb with x-axis coordinate", + .expect = -ENOSPC, .src_x = 1, .fb_size = UINT_MAX, + }, + { .name = "Fail: overflowing fb with y-axis coordinate", + .expect = -ENOSPC, .src_y = 1, .fb_size = UINT_MAX, + }, + { .name = "Fail: overflowing fb with source width", + .expect = -ENOSPC, .dsrc_w = 1, .fb_size = UINT_MAX - 1, + }, + { .name = "Fail: overflowing fb with source height", + .expect = -ENOSPC, .dsrc_h = 1, .fb_size = UINT_MAX - 1, + }, +}; + +static void drm_test_framebuffer_check_src_coords(struct kunit *test) +{ + const struct drm_framebuffer_check_src_coords_case *params = test->param_value; + const uint32_t src_x = params->src_x; + const uint32_t src_y = params->src_y; + const uint32_t src_w = (params->fb_size << 16) + params->dsrc_w; + const uint32_t src_h = (params->fb_size << 16) + params->dsrc_h; + const struct drm_framebuffer fb = { + .width = params->fb_size, + .height = params->fb_size + }; + int ret; + + ret = drm_framebuffer_check_src_coords(src_x, src_y, src_w, src_h, &fb); + KUNIT_EXPECT_EQ(test, ret, params->expect); +} + +static void +check_src_coords_test_to_desc(const struct drm_framebuffer_check_src_coords_case *t, + char *desc) +{ + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(check_src_coords, drm_framebuffer_check_src_coords_cases, + check_src_coords_test_to_desc); + static struct kunit_case drm_framebuffer_tests[] = { + KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), { } From patchwork Mon Aug 5 23:39:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754243 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 995E0C3DA4A for ; Mon, 5 Aug 2024 23:38:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 165BE10E2D7; Mon, 5 Aug 2024 23:38:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="K/BM5nLv"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB48310E2D7 for ; Mon, 5 Aug 2024 23:38:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id C773341A0D; Tue, 6 Aug 2024 01:38:40 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id muYUCYpM-iVI; Tue, 6 Aug 2024 01:38:40 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901120; bh=q1+huwKay14UpDzqMJxlu5h358BCrFvEf1bOIaJLiVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K/BM5nLvMH5LopZXTROBduo7QWnjoDl0uKPTAim+kKGw0gi0Xw1IbKbcWo0oICgmV CV/QOUzb9uDHC/ZBe6OccmY0ZP4q89lvVmImBzY9vS175Gj42VIiy2qzj+TF43Rg5J uMGEjQQ7wjoaMHlgRaCVAQIncINM1dWC6v9huxbqwGwHIaAlwz0oF5gI8l2y+4uih8 mmpQpt+Ki+4ntMl12UncbU0nTjGeZc5SX2ePMoy4KLIdv3iPjQlBxWg1lAdQmjfPZk FB2hZv+a7QYj6w4bJqLBvb9qyys2HMP8D7+FhEdfVQz9fAVr9EjE6+tYH8CT3/QzHK fwZ6JonqppgHA== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 6/9] drm/tests: Add test for drm_framebuffer_cleanup() Date: Mon, 5 Aug 2024 20:39:31 -0300 Message-ID: <20240805234022.18586-7-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a single KUnit test case for the drm_framebuffer_cleanup function. Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- v2: - Reorder kunit cases alphabetically. - Rely on drm_kunit_helper_alloc_device() for mock initialization. v3: - Init framebuffers using drm_framebuffer_init(). - Add documentation. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 1924e3f9538e..908583d74b20 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -498,8 +498,40 @@ check_src_coords_test_to_desc(const struct drm_framebuffer_check_src_coords_case KUNIT_ARRAY_PARAM(check_src_coords, drm_framebuffer_check_src_coords_cases, check_src_coords_test_to_desc); +/* + * Test if drm_framebuffer_cleanup() really pops out the framebuffer object + * from device's fb_list and decrement the number of framebuffers for that + * device, which is the only things it does. + */ +static void drm_test_framebuffer_cleanup(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct list_head *fb_list = &dev->mode_config.fb_list; + struct drm_format_info format = { }; + struct drm_framebuffer fb1 = { .dev = dev, .format = &format }; + struct drm_framebuffer fb2 = { .dev = dev, .format = &format }; + + /* This will result on [fb_list] -> fb2 -> fb1 */ + drm_framebuffer_init(dev, &fb1, NULL); + drm_framebuffer_init(dev, &fb2, NULL); + + drm_framebuffer_cleanup(&fb1); + + /* Now fb2 is the only one element on fb_list */ + KUNIT_ASSERT_TRUE(test, list_is_singular(&fb2.head)); + KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 1); + + drm_framebuffer_cleanup(&fb2); + + /* Now fb_list is empty */ + KUNIT_ASSERT_TRUE(test, list_empty(fb_list)); + KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 0); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), + KUNIT_CASE(drm_test_framebuffer_cleanup), KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), { } From patchwork Mon Aug 5 23:39:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754244 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 594D2C3DA7F for ; Mon, 5 Aug 2024 23:38:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD52D10E2D9; Mon, 5 Aug 2024 23:38:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="c3vGVl1v"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4533010E2D9 for ; Mon, 5 Aug 2024 23:38:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 2B1BF41A24; Tue, 6 Aug 2024 01:38:44 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4Iza0WtUX72G; Tue, 6 Aug 2024 01:38:43 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901123; bh=bsgFFLHh75ijQ55czeGmxAy5GK6I7T8ny0FIdoEwj2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=c3vGVl1vyhfDwiiMNBTs6wZJvp+qixUaXl03sWR1E1QTGYlxx2BQMe2LLhpzIMmDQ Kr0Y8pMOJwt0QWxDhI6sxboASXchg1PuOQxqhOIGlu/y1S4VMJ4NtHpd7NlALxqX2F hHh+hpqVc3jiCOAmDzYN1JjF2nO7GzdvCH/I9osSxLd/oRMtpjveDOCjmt0ZDRTqil ODmOFe63i7Zkkp0VJAvX80xJa7ntqUoxnJ9S2lIogjfT+7QHVhUYlnKNqHuvzrYJYJ 0HpNXm6fSbxl8o9/WNbbQmA3V+S4XIfn3Lxf+88bDnCxHtg/zdO17tWfbIoVbaxGAa Hr6EJ9z/Ll5rg== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 7/9] drm/tests: Add test for drm_framebuffer_lookup() Date: Mon, 5 Aug 2024 20:39:32 -0300 Message-ID: <20240805234022.18586-8-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add two KUnit test cases for the drm_framebuffer_lookup function, one for the base case, that tests if the lookup finds the correct framebuffer object and another that tests the lookup for an inexistent framebuffer. Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- v2: - Reorder kunit cases alphabetically. - Replace drm_mode_object_add() call to drm_framebuffer_init(). - Rely on drm_kunit_helper_alloc_device() for mock initialization. v3: - Rename framebuffer variables. - Add documentation. - Split the lookup for inexistent framebuffer into another test. - Call drm_framebuffer_put after lookup on drm_test_framebuffer_lookup test. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 908583d74b20..e11b5bc9a105 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -529,10 +529,51 @@ static void drm_test_framebuffer_cleanup(struct kunit *test) KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 0); } +/* + * Initialize a framebuffer, lookup its id and test if the returned reference + * matches. + */ +static void drm_test_framebuffer_lookup(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_format_info format = { }; + struct drm_framebuffer expected_fb = { .dev = dev, .format = &format }; + struct drm_framebuffer *returned_fb; + uint32_t id = 0; + int ret; + + ret = drm_framebuffer_init(dev, &expected_fb, NULL); + KUNIT_ASSERT_EQ(test, ret, 0); + id = expected_fb.base.id; + + /* Looking for expected_fb */ + returned_fb = drm_framebuffer_lookup(dev, NULL, id); + KUNIT_EXPECT_PTR_EQ(test, returned_fb, &expected_fb); + drm_framebuffer_put(returned_fb); + + drm_framebuffer_cleanup(&expected_fb); +} + +/* Try to lookup an id that is not linked to a framebuffer */ +static void drm_test_framebuffer_lookup_inexistent(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_framebuffer *fb; + uint32_t id = 0; + + /* Looking for an inexistent framebuffer */ + fb = drm_framebuffer_lookup(dev, NULL, id); + KUNIT_EXPECT_NULL(test, fb); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), KUNIT_CASE(drm_test_framebuffer_cleanup), KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), + KUNIT_CASE(drm_test_framebuffer_lookup), + KUNIT_CASE(drm_test_framebuffer_lookup_inexistent), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), { } }; From patchwork Mon Aug 5 23:39:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754245 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 09F8FC3DA4A for ; Mon, 5 Aug 2024 23:38:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 832C210E2D8; Mon, 5 Aug 2024 23:38:50 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="gYWZUQJb"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id AD6E010E2D8 for ; Mon, 5 Aug 2024 23:38:48 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 9756A41A31; Tue, 6 Aug 2024 01:38:47 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PyWzkTeCWuQD; Tue, 6 Aug 2024 01:38:46 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901126; bh=3d7IJSOtZj007dEKYdJ98kyAdZzqzlCA1H3qob533Z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gYWZUQJbW0DeSkuCC7sIZLDcOndG/EyYnG9Z4nA8/xqsQUX3PjXvZoa97dkuTUb5o u9BokoCXabc0r3GJPC68YN2gKW6iCGwi3hcSwlFsKdC0Oym7jIAsHeVFRavLgui+Ug bLTd7T2Swr1qid6IhLQ2SaWqtDn82I+2ASkp+FM4loe8eDMLs9RBMpculIVQuW/LsF 2YihZSVJJMgPkHT6aCSTJura4jMdk+PsjwDMre4tvSzzU48z3+Ll55+GbGc2lXAO9I /+MEvb0Q80wxvzz4RZtJ3GmtR0brJPYoL45S1ij6NyqPPF91CZvgSpldthTehdbB6C UYAnEqBk7mtEA== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 8/9] drm/tests: Add test for drm_framebuffer_init() Date: Mon, 5 Aug 2024 20:39:33 -0300 Message-ID: <20240805234022.18586-9-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add three KUnit test cases for the drm_framebuffer_init function: 1. Test if expected values are being set after drm_framebuffer_init() call. 2. Try to init a framebuffer without setting its format. 3. Try calling drm_framebuffer_init() with mismatch of the drm_device passed at the first argument and the one pointed by fb->dev. Signed-off-by: Carlos Eduardo Gallo Filho --- v2: - Reorder kunit cases alphabetically. - Let fb1.dev unset instead of set it to wrong_drm to test mismatched drm_device passed as drm_framebuffer_init() argument. - Clean the framebuffer object. v3: - Split into three tests. - Add documentation. - Stop testing lookup here. v4: - Export drm_framebuffer_free for test. - Document what is expected on drm_test_framebuffer_init test. - Use a valid drm_device on drm_test_framebuffer_init_dev_mismatch test. --- drivers/gpu/drm/drm_framebuffer.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 84 ++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 9cd85ac789bb..47e6e8577b62 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -839,6 +839,7 @@ void drm_framebuffer_free(struct kref *kref) fb->funcs->destroy(fb); } +EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_framebuffer_free); /** * drm_framebuffer_init - initialize a framebuffer diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index e11b5bc9a105..72314805839d 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -5,6 +5,7 @@ * Copyright (c) 2022 MaĆ­ra Canal */ +#include #include #include @@ -568,10 +569,93 @@ static void drm_test_framebuffer_lookup_inexistent(struct kunit *test) KUNIT_EXPECT_NULL(test, fb); } +/* + * Test if drm_framebuffer_init initializes the framebuffer successfully, + * asserting that its modeset object struct and its refcount are correctly + * set and that strictly one framebuffer is initialized. + */ +static void drm_test_framebuffer_init(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_format_info format = { }; + struct drm_framebuffer fb1 = { .dev = dev, .format = &format }; + struct drm_framebuffer_funcs funcs = { }; + int ret; + + ret = drm_framebuffer_init(dev, &fb1, &funcs); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* Check if fb->funcs is actually set to the drm_framebuffer_funcs passed on */ + KUNIT_EXPECT_PTR_EQ(test, fb1.funcs, &funcs); + + /* The fb->comm must be set to the current running process */ + KUNIT_EXPECT_STREQ(test, fb1.comm, current->comm); + + /* The fb->base must be successfully initialized */ + KUNIT_EXPECT_NE(test, fb1.base.id, 0); + KUNIT_EXPECT_EQ(test, fb1.base.type, DRM_MODE_OBJECT_FB); + KUNIT_EXPECT_EQ(test, kref_read(&fb1.base.refcount), 1); + KUNIT_EXPECT_PTR_EQ(test, fb1.base.free_cb, &drm_framebuffer_free); + + /* There must be just that one fb initialized */ + KUNIT_EXPECT_EQ(test, dev->mode_config.num_fb, 1); + KUNIT_EXPECT_PTR_EQ(test, dev->mode_config.fb_list.prev, &fb1.head); + KUNIT_EXPECT_PTR_EQ(test, dev->mode_config.fb_list.next, &fb1.head); + + drm_framebuffer_cleanup(&fb1); +} + +/* Try to init a framebuffer without setting its format */ +static void drm_test_framebuffer_init_bad_format(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_framebuffer fb1 = { .dev = dev, .format = NULL }; + struct drm_framebuffer_funcs funcs = { }; + int ret; + + /* Fails if fb.format isn't set */ + ret = drm_framebuffer_init(dev, &fb1, &funcs); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); +} + +/* + * Test calling drm_framebuffer_init() passing a framebuffer linked to a + * different drm_device parent from the one passed on the first argument, which + * must fail. + */ +static void drm_test_framebuffer_init_dev_mismatch(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *right_dev = &priv->dev; + struct drm_device *wrong_dev; + struct device *wrong_dev_parent; + struct drm_format_info format = { }; + struct drm_framebuffer fb1 = { .dev = right_dev, .format = &format }; + struct drm_framebuffer_funcs funcs = { }; + int ret; + + wrong_dev_parent = kunit_device_register(test, "drm-kunit-wrong-device-mock"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, wrong_dev_parent); + + wrong_dev = __drm_kunit_helper_alloc_drm_device(test, wrong_dev_parent, + sizeof(struct drm_device), + 0, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, wrong_dev); + + /* Fails if fb->dev doesn't point to the drm_device passed on first arg */ + ret = drm_framebuffer_init(wrong_dev, &fb1, &funcs); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), KUNIT_CASE(drm_test_framebuffer_cleanup), KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), + KUNIT_CASE(drm_test_framebuffer_init), + KUNIT_CASE(drm_test_framebuffer_init_bad_format), + KUNIT_CASE(drm_test_framebuffer_init_dev_mismatch), KUNIT_CASE(drm_test_framebuffer_lookup), KUNIT_CASE(drm_test_framebuffer_lookup_inexistent), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), From patchwork Mon Aug 5 23:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13754246 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 DF1B9C3DA7F for ; Mon, 5 Aug 2024 23:38:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5681C10E2DC; Mon, 5 Aug 2024 23:38:53 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="kpGz97bm"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id E306810E2DC for ; Mon, 5 Aug 2024 23:38:51 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id C36DD41255; Tue, 6 Aug 2024 01:38:50 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oI1y-NH_KPzi; Tue, 6 Aug 2024 01:38:49 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1722901129; bh=eIiKDd7PD5sklMxxfFS9fHCxQ/wJduZqr50Xb84T8kA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kpGz97bmjlGioicwlX1Y3Efyqhge5gt+Jxv7BvWTBrnrHC9xMfEqEFpY3h/l/ohyC dd1c3eKAws2zxcgVX+Acm6Wl2x2bI9QDpZR1hC7ZAmauBFhNwXYI2opKBRSfK2xTHZ PYqqO/9TcgWUAZ0d/u7DMxjyJHtutQIP8Tpl146tgswwCLaT47K5sxHnm5VxsKOOSe Br4GWyfI+4aOZuoNdZDkacgpc3Az1LaDRyyJ4eLqT2wGgwuNHcLiE+n1FByhBOEtLW Nhm4MceBIN9aukJKD0h9gGlTtIWA0vI+oDt9AsD5m1tZsWJnOvbjsDv1/nAgogYgcf q3pLywNRyqX9g== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 9/9] drm/tests: Add test for drm_framebuffer_free() Date: Mon, 5 Aug 2024 20:39:34 -0300 Message-ID: <20240805234022.18586-10-gcarlos@disroot.org> In-Reply-To: <20240805234022.18586-1-gcarlos@disroot.org> References: <20240805234022.18586-1-gcarlos@disroot.org> 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a single KUnit test case for the drm_framebuffer_free function. Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- v2: - Reorder kunit cases alphabetically. v3: - Replace the use of void pointer on drm_framebuffer_test_priv struct. - Remove the test with unregistered framebuffer object. - Add documentation. v4: - Export drm_mode_object_add for test. --- drivers/gpu/drm/drm_mode_object.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 50 ++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c index df4cc0e8e263..e943205a2394 100644 --- a/drivers/gpu/drm/drm_mode_object.c +++ b/drivers/gpu/drm/drm_mode_object.c @@ -81,6 +81,7 @@ int drm_mode_object_add(struct drm_device *dev, { return __drm_mode_object_add(dev, obj, obj_type, true, NULL); } +EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_mode_object_add); void drm_mode_object_register(struct drm_device *dev, struct drm_mode_object *obj) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 72314805839d..6ea04cc8f324 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -358,6 +358,7 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { struct drm_framebuffer_test_priv { struct drm_device dev; bool buffer_created; + bool buffer_freed; }; static struct drm_framebuffer *fb_create_mock(struct drm_device *dev, @@ -649,10 +650,59 @@ static void drm_test_framebuffer_init_dev_mismatch(struct kunit *test) KUNIT_EXPECT_EQ(test, ret, -EINVAL); } +static void destroy_free_mock(struct drm_framebuffer *fb) +{ + struct drm_framebuffer_test_priv *priv = container_of(fb->dev, typeof(*priv), dev); + + priv->buffer_freed = true; +} + +static struct drm_framebuffer_funcs framebuffer_funcs_free_mock = { + .destroy = destroy_free_mock, +}; + +/* + * In summary, the drm_framebuffer_free() function must implicitly call + * fb->funcs->destroy() and garantee that the framebufer object is unregistered + * from the drm_device idr pool. + */ +static void drm_test_framebuffer_free(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_mode_object *obj; + struct drm_framebuffer fb = { + .dev = dev, + .funcs = &framebuffer_funcs_free_mock, + }; + int id, ret; + + priv->buffer_freed = false; + + /* + * Mock a framebuffer that was not unregistered at the moment of the + * drm_framebuffer_free() call. + */ + ret = drm_mode_object_add(dev, &fb.base, DRM_MODE_OBJECT_FB); + KUNIT_ASSERT_EQ(test, ret, 0); + id = fb.base.id; + + drm_framebuffer_free(&fb.base.refcount); + + /* The framebuffer object must be unregistered */ + obj = drm_mode_object_find(dev, NULL, id, DRM_MODE_OBJECT_FB); + KUNIT_EXPECT_PTR_EQ(test, obj, NULL); + KUNIT_EXPECT_EQ(test, fb.base.id, 0); + + /* Test if fb->funcs->destroy() was called */ + KUNIT_EXPECT_EQ(test, priv->buffer_freed, true); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), KUNIT_CASE(drm_test_framebuffer_cleanup), KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), + KUNIT_CASE(drm_test_framebuffer_free), KUNIT_CASE(drm_test_framebuffer_init), KUNIT_CASE(drm_test_framebuffer_init_bad_format), KUNIT_CASE(drm_test_framebuffer_init_dev_mismatch),