From patchwork Fri Aug 25 16:07:16 2023 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: 13366116 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 EE0C3C001DB for ; Fri, 25 Aug 2023 16:08:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A31B910E6C4; Fri, 25 Aug 2023 16:08:16 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3DB3B10E6C4 for ; Fri, 25 Aug 2023 16:08:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id E696140DCA; Fri, 25 Aug 2023 18:08:13 +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 MG5M8nFeLYlw; Fri, 25 Aug 2023 18:08:13 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979693; bh=NREuScQqpzr9B7RRBvcYJeAp/EjqDAnHFpfcC5B3YYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hjQ7ZQQtj6n657S9N5PzIeNX9GS51wi3a1UTVtQZ9uFoSZzSN0Q/5ZHFL08W24E0T 4Unhwm6k3jEk4ZsbL17OX4EjMn8iAXtuNjrETPEGZU1cRSiyv7i3qJsz2n5p3nsYz9 aeqluHEZcAfmGZ1PrO5w975XWHNSlzWiIHiWUm/iHj8SWv1T2xdGfb8LUaQn4Q9S5f dyN2xj5eAhCN+JKPsT2baXNOjOxRDmnjhDf80/ZM/E5FlR1vWsRBu7jieRhRViKOrs AA79QWDzKnwQ45Agx9iub5NpD4S1l7zvPWLtkMhhX44MH3Zv7k35gBhvnkZjo4Drdl lgSAmr7/r0nyQ== To: dri-devel@lists.freedesktop.org Subject: [PATCH 01/10] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests Date: Fri, 25 Aug 2023 13:07:16 -0300 Message-ID: <20230825160725.12861-2-gcarlos@disroot.org> In-Reply-To: <20230825160725.12861-1-gcarlos@disroot.org> References: <20230825160725.12861-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo 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 with a void pointer like dev_private, using it instead. Signed-off-by: Carlos Eduardo Gallo Filho --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 29 +++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index f759d9f3b76e..173d42b145ed 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -317,11 +317,17 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { }, }; +struct drm_mock { + struct drm_device dev; + void *private; +}; + 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; + struct drm_mock *mock = container_of(dev, typeof(*mock), dev); + int *buffer_created = mock->private; *buffer_created = 1; return ERR_PTR(-EINVAL); } @@ -332,16 +338,18 @@ static struct drm_mode_config_funcs mock_config_funcs = { static int drm_framebuffer_test_init(struct kunit *test) { - struct drm_device *mock; + struct drm_mock *mock; + struct drm_device *dev; mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); + dev = &mock->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; return 0; @@ -350,11 +358,12 @@ static int drm_framebuffer_test_init(struct kunit *test) static void drm_test_framebuffer_create(struct kunit *test) { const struct drm_framebuffer_test *params = test->param_value; - struct drm_device *mock = test->priv; + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; int buffer_created = 0; - mock->dev_private = &buffer_created; - drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL); + mock->private = &buffer_created; + drm_internal_framebuffer_create(dev, ¶ms->cmd, NULL); KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created); } From patchwork Fri Aug 25 16:07:17 2023 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: 13366117 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 A5D88C3DA6F for ; Fri, 25 Aug 2023 16:08:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BADC310E6C8; Fri, 25 Aug 2023 16:08:26 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2C00610E6C8 for ; Fri, 25 Aug 2023 16:08:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id E047E40DCA; Fri, 25 Aug 2023 18:08:22 +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 LRJoKbmpQyCu; Fri, 25 Aug 2023 18:08:22 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979701; bh=mgyL1N+7+SyFuNb21Y8CXsSIwHN5ILLjhMJBRnDfwsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K8Ov8ebuH4pOXlk6oRvSK+EnGs5qrMdoiEfzhZBo8BkSYP0UpDOBawMkN+aD3fvvr S9jqY1crsi/YrCZ8SWFpPaDQI1f7RbGyXoF0ys8gTtboODn2MnLQBkVMOCva92T+Sy jJj6+35kndgBJg75Q1AB0RiwwYPMWXAL6i/0jbA4L4LUoNlMPrxl7TwPE2b8EwGg+g krHWRy2v3YtA55WUKg8CSl45b5qvUHXW80yelAZykyjSVqlj21Ji/xUIHU6J5i9HGL NR6w3pn+oSMFxhXpiNs/TTnMM6VIBUW/QRhghYJZNe98kfpOh7418jh//HkUP6urN4 /+huzZTzmym6g== To: dri-devel@lists.freedesktop.org Subject: [PATCH 02/10] drm/tests: Add parameters to the drm_test_framebuffer_create test Date: Fri, 25 Aug 2023 13:07:17 -0300 Message-ID: <20230825160725.12861-3-gcarlos@disroot.org> In-Reply-To: <20230825160725.12861-1-gcarlos@disroot.org> References: <20230825160725.12861-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo 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. Non-zero buffer offset for an unused plane Also replace strcpy to strscpy on test_to_desc for improved security and reliability. Signed-off-by: Carlos Eduardo Gallo Filho --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 173d42b145ed..aeaf2331f9cc 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -19,6 +19,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; @@ -83,6 +85,18 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { 4 * MAX_WIDTH, 0, 0 }, } }, +{ .buffer_created = 0, .name = "ABGR8888 Non-zero buffer offset for unused 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 }, @@ -262,6 +276,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 } @@ -369,7 +390,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 Fri Aug 25 16:07:18 2023 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: 13366118 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 ADE5AC71133 for ; Fri, 25 Aug 2023 16:08:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A444C10E6CB; Fri, 25 Aug 2023 16:08:34 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id AD5C010E6C6 for ; Fri, 25 Aug 2023 16:08:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 5EBC4413B7; Fri, 25 Aug 2023 18:08:31 +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 cjxVK5hksRVP; Fri, 25 Aug 2023 18:08:30 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979710; bh=O67py2nFOxoSGH7NgFXOdNdwHRs5g1jXdaIEuVqQ6hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=I/cHaX0CDQUgeQM4Q05794whY1ihsbgEMg9Wdu2yrK5wJZ4TIlZ/pLwW+4EmdE5EN vfxFxBwXhPQVgz80AT6qG2DqUiswNF/7DTWSlzx1Q9ujf+UX6yNaIaokggqpXCosGY QI26HG9IUfPcbY9pJYONTGD3a4iKbsaKh9xeULSX5B6b/AtVcJBEZyosRUcTVPy+sO ln8GXZvuST4J6ccQiT/Og5T9jkU0BodNMvGbO+JYRRrR0jb7tI+lvbfTfrSC4H1Onl y4tpdOJRw/wtdtWkKi00bWDq42NSADZXaKSZyIgRe1HERkIfETf5pIRaWH7pmrec1W OGN2N2QjbzVUQ== To: dri-devel@lists.freedesktop.org Subject: [PATCH 03/10] drm/tests: Add test case for drm_internal_framebuffer_create() Date: Fri, 25 Aug 2023 13:07:18 -0300 Message-ID: <20230825160725.12861-4-gcarlos@disroot.org> In-Reply-To: <20230825160725.12861-1-gcarlos@disroot.org> References: <20230825160725.12861-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo 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 --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index aeaf2331f9cc..b20871e88995 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -396,7 +396,35 @@ 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); +/* + * This test is very similar to drm_test_framebuffer_create, except that it + * set mock->mode_config.fb_modifiers_not_supported member to 1, covering + * the case of trying to create a framebuffer with modifiers without the + * device really supporting it. + */ +static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + int buffer_created = 0; + + /* 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, + }; + + mock->private = &buffer_created; + dev->mode_config.fb_modifiers_not_supported = 1; + + drm_internal_framebuffer_create(dev, &cmd, NULL); + KUNIT_EXPECT_EQ(test, 0, buffer_created); +} + static struct kunit_case drm_framebuffer_tests[] = { + KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), { } }; From patchwork Fri Aug 25 16:07:19 2023 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: 13366119 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 3E2F0C3DA6F for ; Fri, 25 Aug 2023 16:08:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3771810E6C6; Fri, 25 Aug 2023 16:08:39 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F0F110E6CD for ; Fri, 25 Aug 2023 16:08:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 0F21F40EFD; Fri, 25 Aug 2023 18:08:36 +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 RJ1lN6w-bRaM; Fri, 25 Aug 2023 18:08:35 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979715; bh=66FDIYweIUmVcCsItABOpdYkcLbsfZhCHZ8Q0xFCTAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BzK9RSYa3xAajgLng8HtIFtRo/Gczz8+9nrt+C0hZbDVokIUvSZqNaJuBGCqDy9nP 1KmBzzGyPWSebJy2IStIwBPyCaVn0ij1YRnDk5WXIeThijjm8vWnXWNzGoqMvUUhwf 1RoPNONhTKPiKX+OomxQMCICYcH3N4ERSYIuNSBWWlvoYHk3ps1SOLfXUTIxx8REJW QnVxQu99yXNym+OpyhD/ajJajgt3UtEDr3H4C3gJnexZldO8XZ/BtnpcEa7kH7bbYm 4N5lyjEp5qbI8BPqLbrm8RaAQofhrCGQLw7+9bVvpKCEWnJxnYNgd83AOXGtlAmbCl 8QkkM0Dvl51kA== To: dri-devel@lists.freedesktop.org Subject: [PATCH 04/10] drm/tests: Add test for drm_framebuffer_check_src_coords() Date: Fri, 25 Aug 2023 13:07:19 -0300 Message-ID: <20230825160725.12861-5-gcarlos@disroot.org> In-Reply-To: <20230825160725.12861-1-gcarlos@disroot.org> References: <20230825160725.12861-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo 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 --- 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 aff3746dedfb..9fbf3c85618f 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 b20871e88995..0e0e8216bbbc 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -9,11 +9,15 @@ #include #include +#include #include #include #include "../drm_crtc_internal.h" +#define FB_WIDTH 800 +#define FB_HEIGHT 600 + #define MIN_WIDTH 4 #define MAX_WIDTH 4096 #define MIN_HEIGHT 4 @@ -423,8 +427,65 @@ static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test) KUNIT_EXPECT_EQ(test, 0, buffer_created); } +/* Parameters for testing drm_framebuffer_check_src_coords function */ +struct check_src_coords_case { + const char *name; /* Description of the parameter case */ + const int expect; /* Expected return value by the function */ + + /* Deltas to be applied on source */ + const uint32_t dsrc_x; + const uint32_t dsrc_y; + const uint32_t dsrc_w; + const uint32_t dsrc_h; +}; + +static const struct check_src_coords_case check_src_coords_cases[] = { + { .name = "Success: source fits into fb", + .expect = 0, + }, + { .name = "Fail: overflowing fb with x-axis coordinate", + .expect = -ENOSPC, .dsrc_x = 1, + }, + { .name = "Fail: overflowing fb with y-axis coordinate", + .expect = -ENOSPC, .dsrc_y = 1, + }, + { .name = "Fail: overflowing fb with source width", + .expect = -ENOSPC, .dsrc_w = 1, + }, + { .name = "Fail: overflowing fb with source height", + .expect = -ENOSPC, .dsrc_h = 1, + }, +}; + +static void drm_test_framebuffer_check_src_coords(struct kunit *test) +{ + const struct check_src_coords_case *params = test->param_value; + const uint32_t src_x = 0 + params->dsrc_x; + const uint32_t src_y = 0 + params->dsrc_y; + const uint32_t src_w = (FB_WIDTH << 16) + params->dsrc_w; + const uint32_t src_h = (FB_HEIGHT << 16) + params->dsrc_h; + const struct drm_framebuffer fb = { + .width = FB_WIDTH, + .height = FB_HEIGHT, + }; + 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 check_src_coords_case *t, + char *desc) +{ + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(check_src_coords, check_src_coords_cases, + check_src_coords_test_to_desc); + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), + 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), { } }; From patchwork Fri Aug 25 16:07:20 2023 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: 13366120 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 A5DEFC3DA6F for ; Fri, 25 Aug 2023 16:08:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9427210E6CA; Fri, 25 Aug 2023 16:08:44 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id C5A7310E6CA for ; Fri, 25 Aug 2023 16:08:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 886E041280; Fri, 25 Aug 2023 18:08: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 VpwzMEPK6YY7; Fri, 25 Aug 2023 18:08:39 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979719; bh=OYfbtrnU4OnxyA4/6sFVcjPEzIje++zxCrtt6ew88QM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZLUVKpXk3Sw7HhVGGBIvg0wpa3JTiKw4h9cGyBrckZ3MknYv/OvCumHkpGTkadnR+ 5dzJiOgButzSJ6cq+ZrYy1VoeU9R/8x11uLXiGiFTmUwKHlAheKdAO9sj9f+u5B3Bw 2ByLw1b6Yw1T+9JBZ+zZTYduYRRpiqnLEOpX7kLkSZ5BuEwoATOycR5UAqWwyZxkXM mdfr3Bd+N+orTWdHUc8sn58/sAUdszGXLe8p0eGUgPkC+X1gC7K6JGvwuLFfFVYVHr 0GjpZsqGEK7XAF3AV4kBwK9NF3fA7mfrIgna74kwaEKFhs4h6dJ7+NK9khdqFa2JpH LbhjiXsFGBGTg== To: dri-devel@lists.freedesktop.org Subject: [PATCH 05/10] drm/tests: Add test for drm_framebuffer_cleanup() Date: Fri, 25 Aug 2023 13:07:20 -0300 Message-ID: <20230825160725.12861-6-gcarlos@disroot.org> In-Reply-To: <20230825160725.12861-1-gcarlos@disroot.org> References: <20230825160725.12861-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo 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 --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 0e0e8216bbbc..16d9cf4bed88 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -370,6 +370,9 @@ static int drm_framebuffer_test_init(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); dev = &mock->dev; + mutex_init(&dev->mode_config.fb_lock); + INIT_LIST_HEAD(&dev->mode_config.fb_list); + dev->mode_config.num_fb = 0; dev->mode_config.min_width = MIN_WIDTH; dev->mode_config.max_width = MAX_WIDTH; dev->mode_config.min_height = MIN_HEIGHT; @@ -380,6 +383,14 @@ static int drm_framebuffer_test_init(struct kunit *test) return 0; } +static void drm_framebuffer_test_exit(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + + mutex_destroy(&dev->mode_config.fb_lock); +} + static void drm_test_framebuffer_create(struct kunit *test) { const struct drm_framebuffer_test *params = test->param_value; @@ -483,7 +494,44 @@ static void check_src_coords_test_to_desc(const struct check_src_coords_case *t, KUNIT_ARRAY_PARAM(check_src_coords, check_src_coords_cases, check_src_coords_test_to_desc); +static void drm_test_framebuffer_cleanup(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + struct list_head *fb_list = &dev->mode_config.fb_list; + struct drm_framebuffer fb1 = { .dev = dev }; + struct drm_framebuffer fb2 = { .dev = dev }; + + /* This must result on [fb_list] -> fb1 -> fb2 */ + list_add_tail(&fb1.head, fb_list); + list_add_tail(&fb2.head, fb_list); + dev->mode_config.num_fb = 2; + + KUNIT_ASSERT_PTR_EQ(test, fb_list->prev, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb_list->next, &fb1.head); + KUNIT_ASSERT_PTR_EQ(test, fb1.head.prev, fb_list); + KUNIT_ASSERT_PTR_EQ(test, fb1.head.next, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.prev, &fb1.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.next, fb_list); + + drm_framebuffer_cleanup(&fb1); + + /* Now [fb_list] -> fb2 */ + KUNIT_ASSERT_PTR_EQ(test, fb_list->prev, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb_list->next, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.prev, fb_list); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.next, fb_list); + 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(drm_test_framebuffer_cleanup), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), 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), @@ -493,6 +541,7 @@ static struct kunit_case drm_framebuffer_tests[] = { static struct kunit_suite drm_framebuffer_test_suite = { .name = "drm_framebuffer", .init = drm_framebuffer_test_init, + .exit = drm_framebuffer_test_exit, .test_cases = drm_framebuffer_tests, }; From patchwork Fri Aug 25 16:07:21 2023 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: 13366121 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 28799C3DA6F for ; Fri, 25 Aug 2023 16:08:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 60E4C10E6CC; Fri, 25 Aug 2023 16:08:50 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4D44510E6CC for ; Fri, 25 Aug 2023 16:08:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 0DBFE40EFD; Fri, 25 Aug 2023 18:08:45 +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 UeHYGLQuw__G; Fri, 25 Aug 2023 18:08:44 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979724; bh=0LF+ZkkGQUjuFnbTwCUUcP0NI72TB7o23qw7MoB3BMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U0DD2sFI0EctTVizCGH08AdJs9blM+FCYoPyZTcrXzm+t89wQmZTyO2VZpLHz7qvG pFn8xl7CNZZqKHNxeJCx0qncS0193DX3iRFIzWRhxW9I1Evw5l3W/wVttuP1bjRPGd A25WZTOQ9RfxJDHjMQ0iNjDy+hopthK7Apn2kDF/VsYUjGGLI+0h3RYBwngsGojWkY ijctRpJ+kTTu6UQoW7fVwf8IcbJ+MvU5xvv/2gdzki8D/L5qyTl8Dzjp5O4dJ8J7Kn lvIu8ADt/P3f2oCNmnBuYixf334RsdU/c4VIBNKkA5zyQUlndQTO+UZXGW74PPuHHO yGNE1zoOMIkbg== To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/10] drm/tests: Add test for drm_framebuffer_lookup() Date: Fri, 25 Aug 2023 13:07:21 -0300 Message-ID: <20230825160725.12861-7-gcarlos@disroot.org> In-Reply-To: <20230825160725.12861-1-gcarlos@disroot.org> References: <20230825160725.12861-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a single KUnit test case for the drm_framebuffer_lookup function. Signed-off-by: Carlos Eduardo Gallo Filho --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 16d9cf4bed88..3d14d35b4c4d 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -370,6 +371,10 @@ static int drm_framebuffer_test_init(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); dev = &mock->dev; + dev->driver = kunit_kzalloc(test, sizeof(*dev->driver), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev->driver); + + idr_init_base(&dev->mode_config.object_idr, 1); mutex_init(&dev->mode_config.fb_lock); INIT_LIST_HEAD(&dev->mode_config.fb_list); dev->mode_config.num_fb = 0; @@ -530,8 +535,31 @@ static void drm_test_framebuffer_cleanup(struct kunit *test) KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 0); } +static void drm_test_framebuffer_lookup(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + struct drm_framebuffer fb1 = { }; + struct drm_framebuffer *fb2; + uint32_t id = 0; + int ret; + + ret = drm_mode_object_add(dev, &fb1.base, DRM_MODE_OBJECT_FB); + KUNIT_ASSERT_EQ(test, ret, 0); + id = fb1.base.id; + + /* Looking for fb1 */ + fb2 = drm_framebuffer_lookup(dev, NULL, id); + KUNIT_EXPECT_PTR_EQ(test, fb2, &fb1); + + /* Looking for an inexistent framebuffer */ + fb2 = drm_framebuffer_lookup(dev, NULL, id + 1); + KUNIT_EXPECT_NULL(test, fb2); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE(drm_test_framebuffer_cleanup), + KUNIT_CASE(drm_test_framebuffer_lookup), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), 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), From patchwork Fri Aug 25 16:11:08 2023 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: 13366122 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 8238FC71133 for ; Fri, 25 Aug 2023 16:11:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DBB7510E6CE; Fri, 25 Aug 2023 16:11:16 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE6CD10E6CE for ; Fri, 25 Aug 2023 16:11:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 7B91240DB9; Fri, 25 Aug 2023 18:11:13 +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 poRfREpXN1fi; Fri, 25 Aug 2023 18:11:12 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979872; bh=lBnr9BHCQJz/tR6buqaorkeGrdpjUc6C/fWk0NhZg/0=; h=From:To:Cc:Subject:Date; b=AKBbSN3RKYDl2y5qnihVnD/GZIRWL0cw8Nvy2bACfhxabYEV9mJHQzpv7nWp9TNdZ c9OD634DJO9KoEAYCm25oNSK92k39uJobgzqxe/8vswRy2UW0CCezjZPnh7dkVOSEr 7WDQb42pAFmPAiunpoZ7/ouEH0KYxCxDztM2EJbZsQokiGRPFB2OTeY7C3c/iRGVmv v6fgV1XvryQrhbKs9zb/4Mnv+k5WhCAMuSccs8v7OtbgYgzVhqpD6fYPo1ULp4/9Bf 8hsTnO4x2QnO1SxVg3XKUI3fp9qGSFya/sLEwDdS6oIQODyM+VJ+/UVEwiuIjNFV27 5sCXWMmaT9ycg== To: dri-devel@lists.freedesktop.org Subject: [PATCH 07/10] drm/tests: Add test for drm_framebuffer_init() Date: Fri, 25 Aug 2023 13:11:08 -0300 Message-ID: <20230825161108.13701-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a single KUnit test case for the drm_framebuffer_init function. Signed-off-by: Carlos Eduardo Gallo Filho --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 3d14d35b4c4d..50d88bf3fa65 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -557,8 +557,60 @@ static void drm_test_framebuffer_lookup(struct kunit *test) KUNIT_EXPECT_NULL(test, fb2); } +static void drm_test_framebuffer_init(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + struct drm_device wrong_drm = { }; + struct drm_format_info format = { }; + struct drm_framebuffer fb1 = { .dev = dev, .format = &format }; + struct drm_framebuffer *fb2; + struct drm_framebuffer_funcs funcs = { }; + int ret; + + /* Fails if fb->dev doesn't point to the drm_device passed on first arg */ + fb1.dev = &wrong_drm; + ret = drm_framebuffer_init(dev, &fb1, &funcs); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); + fb1.dev = dev; + + /* Fails if fb.format isn't set */ + fb1.format = NULL; + ret = drm_framebuffer_init(dev, &fb1, &funcs); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); + fb1.format = &format; + + ret = drm_framebuffer_init(dev, &fb1, &funcs); + KUNIT_EXPECT_EQ(test, ret, 0); + + /* + * Check if fb->funcs is actually set to the drm_framebuffer_funcs + * passed to it + */ + 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_EQ(test, fb1.base.id, 1); + 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); + + /* Checks if the fb is really published and findable */ + fb2 = drm_framebuffer_lookup(dev, NULL, fb1.base.id); + KUNIT_EXPECT_PTR_EQ(test, fb2, &fb1); + + /* 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); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE(drm_test_framebuffer_cleanup), + KUNIT_CASE(drm_test_framebuffer_init), KUNIT_CASE(drm_test_framebuffer_lookup), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), From patchwork Fri Aug 25 16:11:48 2023 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: 13366123 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 DD737C3DA6F for ; Fri, 25 Aug 2023 16:11:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5250310E6D2; Fri, 25 Aug 2023 16:11:56 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2636B10E6D2 for ; Fri, 25 Aug 2023 16:11:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id CEE2D40D83; Fri, 25 Aug 2023 18:11:52 +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 71RMPZk8EU4j; Fri, 25 Aug 2023 18:11:52 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979912; bh=cjtiCIVPvKmi0KHHG/emXJ6JrAyrcA7ZlmZ787o4ORA=; h=From:To:Cc:Subject:Date; b=kcttNbmhEyaJIuXoZWkDIl8WmK7ExiTzZ2o0gf+MLWP4dp2gCYdkdD1rmtxjTJH4a 7Vc/RT/FbJ/W+OKzbRwClebBK9DPm42rjdqoYk6cNWOEdTcx0fUtNdqvDQmIp9Fa5P iK5y8n1+PgVdXwi7vEisGjnoGw8v/PCpPeVS4dYcBISlq9AN2QIJbrOra+7O6evMzp XZy4VsFPynczbFfmuYTbCPP//WFNL7FFM0JMxSd2fZid/L4NHLMkVg+JfDR18NQc4c GrSf+BWZpnWXAzv72dsGuf9a3RmsnL+o1xj0vXale0Di28dVgodIwPkf5cPPdA37qe VXnAzzib7I1sg== To: dri-devel@lists.freedesktop.org Subject: [PATCH 08/10] drm/tests: Add test for drm_framebuffer_free() Date: Fri, 25 Aug 2023 13:11:48 -0300 Message-ID: <20230825161149.13841-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo 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 --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 50d88bf3fa65..8eca92fdc645 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -608,8 +608,57 @@ static void drm_test_framebuffer_init(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, dev->mode_config.fb_list.next, &fb1.head); } +static void destroy_free_mock(struct drm_framebuffer *fb) +{ + struct drm_mock *mock = container_of(fb->dev, typeof(*mock), dev); + int *buffer_freed = mock->private; + *buffer_freed = 1; +} + +static struct drm_framebuffer_funcs framebuffer_funcs_free_mock = { + .destroy = destroy_free_mock, +}; + +static void drm_test_framebuffer_free(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + struct drm_mode_object *obj; + struct drm_framebuffer fb = { + .dev = dev, + .funcs = &framebuffer_funcs_free_mock, + }; + int buffer_freed = 0; + int id, ret; + + mock->private = &buffer_freed; + + /* + * Case where the fb isn't registered. Just test if + * drm_framebuffer_free calls fb->funcs->destroy + */ + drm_framebuffer_free(&fb.base.refcount); + KUNIT_EXPECT_EQ(test, buffer_freed, 1); + + buffer_freed = 0; + + ret = drm_mode_object_add(dev, &fb.base, DRM_MODE_OBJECT_FB); + KUNIT_ASSERT_EQ(test, ret, 0); + id = fb.base.id; + + /* Now, test with the fb registered, that must end unregistered */ + drm_framebuffer_free(&fb.base.refcount); + KUNIT_EXPECT_EQ(test, fb.base.id, 0); + KUNIT_EXPECT_EQ(test, buffer_freed, 1); + + /* Test if the old id of the fb was really removed from the idr pool */ + obj = drm_mode_object_find(dev, NULL, id, DRM_MODE_OBJECT_FB); + KUNIT_EXPECT_PTR_EQ(test, obj, NULL); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE(drm_test_framebuffer_cleanup), + KUNIT_CASE(drm_test_framebuffer_free), KUNIT_CASE(drm_test_framebuffer_init), KUNIT_CASE(drm_test_framebuffer_lookup), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), From patchwork Fri Aug 25 16:11:49 2023 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: 13366124 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 987C3C71133 for ; Fri, 25 Aug 2023 16:12:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF9DB10E6D5; Fri, 25 Aug 2023 16:12:01 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 311AD10E6D4 for ; Fri, 25 Aug 2023 16:12:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id E719A40D83; Fri, 25 Aug 2023 18:11:58 +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 GZokuR-yVmeY; Fri, 25 Aug 2023 18:11:58 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1692979917; bh=cQkPjVtEov5m71kcpErH1rBNEpNlsOEMRd7A9dfTV9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cQPKQXG1XsI0h7RANHa9PjmcgC+xmd9izTJwDxHdURN6EQ5I/RMUyWEzTVsph2EWX CfddW0TwWXRuKpR9bowJMq2WnjxR6GSwsVx1EGMeKseY2HG0PwhrZB4trUGWKmbiws 7P5DBFzzSqWYOIu7RJCadACvxxM3/iPnAHnJy1QGLM2mD/8AGdALsQnaYuthMkZ4x5 GmBQHHoUl388dUe5cKoDBEjDIbBMDyIyrtUKZ9Uxd6fGgJEmMwzoFMNl6vOBNsc030 TIpw53VX52WjJqvgmOu1DeFN7XNxghpiFpOSFoL+QiCN+/yQrLxgHNmoxRNZehczRP NGSJGLrTeBa1Q== To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/10] drm/tests: Add test for drm_mode_addfb2() Date: Fri, 25 Aug 2023 13:11:49 -0300 Message-ID: <20230825161149.13841-2-gcarlos@disroot.org> In-Reply-To: <20230825161149.13841-1-gcarlos@disroot.org> References: <20230825161149.13841-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: , Cc: =?utf-8?q?Andr=C3=A9_Almeida?= , Thomas Zimmermann , Carlos Eduardo Gallo Filho , Maxime Ripard , =?utf-8?q?Ma=C3=ADra_Canal?= , Tales Lelo da Aparecida , David Gow , =?utf-8?q?Micha=C5=82_Winiarski?= , Arthur Grillo Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a single KUnit test case for the drm_mode_addfb2 function. Signed-off-by: Carlos Eduardo Gallo Filho --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 100 ++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 8eca92fdc645..b8ddd7e34db5 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 @@ -343,8 +344,18 @@ 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 @private and actually return something to be used on some + * expectation. Also having the @test member allows doing expectations from + * inside mocked functions. + */ struct drm_mock { struct drm_device dev; + struct drm_file file_priv; + struct kunit *test; void *private; }; @@ -366,13 +377,18 @@ static int drm_framebuffer_test_init(struct kunit *test) { struct drm_mock *mock; struct drm_device *dev; + struct drm_file *file_priv; + struct drm_driver *driver; mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); dev = &mock->dev; + file_priv = &mock->file_priv; - dev->driver = kunit_kzalloc(test, sizeof(*dev->driver), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev->driver); + driver = kunit_kzalloc(test, sizeof(*dev->driver), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, driver); + driver->driver_features = DRIVER_MODESET; + dev->driver = driver; idr_init_base(&dev->mode_config.object_idr, 1); mutex_init(&dev->mode_config.fb_lock); @@ -384,6 +400,9 @@ static int drm_framebuffer_test_init(struct kunit *test) dev->mode_config.max_height = MAX_HEIGHT; dev->mode_config.funcs = &mock_config_funcs; + mutex_init(&file_priv->fbs_lock); + INIT_LIST_HEAD(&file_priv->fbs); + test->priv = mock; return 0; } @@ -392,8 +411,10 @@ static void drm_framebuffer_test_exit(struct kunit *test) { struct drm_mock *mock = test->priv; struct drm_device *dev = &mock->dev; + struct drm_file *file_priv = &mock->file_priv; mutex_destroy(&dev->mode_config.fb_lock); + mutex_destroy(&file_priv->fbs_lock); } static void drm_test_framebuffer_create(struct kunit *test) @@ -656,7 +677,82 @@ static void drm_test_framebuffer_free(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, obj, NULL); } +static struct drm_framebuffer * +fb_create_addfb2_mock(struct drm_device *dev, struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *cmd) +{ + struct drm_mock *mock = container_of(dev, typeof(*mock), dev); + struct drm_framebuffer *fb; + struct kunit *test = mock->test; + + fb = kunit_kzalloc(test, sizeof(*fb), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fb); + + fb->base.id = 1; + + mock->private = fb; + return fb; +} + +static struct drm_mode_config_funcs config_funcs_addfb2_mock = { + .fb_create = fb_create_addfb2_mock, +}; + +static void drm_test_framebuffer_addfb2(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + struct drm_file *file_priv = &mock->file_priv; + struct drm_framebuffer *fb = NULL; + int ret; + + /* A valid cmd */ + struct drm_mode_fb_cmd2 cmd = { + .width = 600, .height = 600, + .pixel_format = DRM_FORMAT_ABGR8888, + .handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 }, + }; + + mock->test = test; + dev->mode_config.funcs = &config_funcs_addfb2_mock; + + /* Must fail due to missing DRIVER_MODESET support */ + ret = drm_mode_addfb2(dev, &cmd, file_priv); + KUNIT_EXPECT_EQ(test, ret, -EOPNOTSUPP); + KUNIT_ASSERT_PTR_EQ(test, mock->private, NULL); + + /* Set DRIVER_MODESET support */ + dev->driver_features = dev->driver->driver_features; + + /* + * Set an invalid cmd to trigger a fail on the + * drm_internal_framebuffer_create function + */ + cmd.width = 0; + ret = drm_mode_addfb2(dev, &cmd, file_priv); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); + KUNIT_ASSERT_PTR_EQ(test, mock->private, NULL); + cmd.width = 600; /* restore to a valid value */ + + ret = drm_mode_addfb2(dev, &cmd, file_priv); + KUNIT_EXPECT_EQ(test, ret, 0); + + /* The fb_create_addfb2_mock set fb id to 1 */ + KUNIT_EXPECT_EQ(test, cmd.fb_id, 1); + + fb = mock->private; + + /* The fb must be properly added to the file_priv->fbs list */ + KUNIT_EXPECT_PTR_EQ(test, file_priv->fbs.prev, &fb->filp_head); + KUNIT_EXPECT_PTR_EQ(test, file_priv->fbs.next, &fb->filp_head); + + /* There must be just one fb on the list */ + KUNIT_EXPECT_PTR_EQ(test, fb->filp_head.prev, &file_priv->fbs); + KUNIT_EXPECT_PTR_EQ(test, fb->filp_head.next, &file_priv->fbs); +} + static struct kunit_case drm_framebuffer_tests[] = { + KUNIT_CASE(drm_test_framebuffer_addfb2), KUNIT_CASE(drm_test_framebuffer_cleanup), KUNIT_CASE(drm_test_framebuffer_free), KUNIT_CASE(drm_test_framebuffer_init),