From patchwork Tue Oct 24 19:09:52 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: 13435192 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 1045BC00A8F for ; Tue, 24 Oct 2023 19:10:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2CAD410E47B; Tue, 24 Oct 2023 19:10:21 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id B551510E482 for ; Tue, 24 Oct 2023 19:10:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 5B32E408F8; Tue, 24 Oct 2023 21:10:18 +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 4frr9Gg0Sn6U; Tue, 24 Oct 2023 21:10:17 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174617; bh=DiKl2koVnBGX21+lmWWRQuD/jkk8B2lf0cH1gy4HOp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BcYmTDSHRwuT7i0oke0GdbnHuyaHsPD6fuHJ2iq6zvYjItePZwDv3v+bgbS8R9Rcs 2fzgHzAbYcA3OjsOblNVhtX3REThDlNth+vMOeywMTqOKQIQGpJEEa5PhGrWFTgrk3 jFHblFDrkGNqVR894IAvsVHzorZW8uJ6p+3kMcHTRPcMNIxUcisFO9I57cVllpc5M4 p1PRJqmUMy33y3cvOBcBPf1bisU1nVdYUosvIL5PNbMzP2eYlNF1zq0rfVd0bZ2//o HP3uNKnK3Dm79CQ+BIKPs3dVSvU3GxcFXqn5UWTHZ1hD+oEuEphX2oyhfBHySuAw9/ 9rb/SrsQe8sMA== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 01/11] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests Date: Tue, 24 Oct 2023 16:09:52 -0300 Message-ID: <20231024191002.1620-2-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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. Also start using drm_kunit_helper_alloc_drm_device() for allocating the drm_device mock. Signed-off-by: Carlos Eduardo Gallo Filho --- v2: - Start using drm_kunit_helper_alloc_drm_device() for drm_device mock. - Rename struct drm_mock to drm_framebuffer_test_priv --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 42 ++++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index f759d9f3b76e..9c6170edd5f7 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,11 +319,17 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { }, }; +struct drm_framebuffer_test_priv { + 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_framebuffer_test_priv *priv = container_of(dev, typeof(*priv), dev); + int *buffer_created = priv->private; *buffer_created = 1; return ERR_PTR(-EINVAL); } @@ -332,29 +340,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; + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; int buffer_created = 0; - mock->dev_private = &buffer_created; - drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL); + priv->private = &buffer_created; + drm_internal_framebuffer_create(dev, ¶ms->cmd, NULL); KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created); } From patchwork Tue Oct 24 19:09:53 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: 13435193 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 9F0A7C00A8F for ; Tue, 24 Oct 2023 19:10:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0551E10E47C; Tue, 24 Oct 2023 19:10:27 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9F02010E47C for ; Tue, 24 Oct 2023 19:10:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 5F879408F8; Tue, 24 Oct 2023 21:10:24 +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 cdazFlb28SyP; Tue, 24 Oct 2023 21:10:23 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174623; bh=qNJH4yQCHq9jqsFNiYXxGgJSx73+TQ4kyjBByujZh2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=a0UfHn+602CTuno6osT2Rw40I4K3k2jRjqQOvpYutuPfDpty8EAtIFAZN5oO7lLzS NbUXyFwS2V3MnpgU7H8YenFEPrUTgnN8YOuIowpiBr+1xBsnXYEOiYRsZKaqK8d9oY 3y8Vwv+QihEMbuo5od48a7MZmgEjslmDNTuELi+bu+gr30BUF9622xx6q2g8JQgkBg s70ElTnUWnL3+cnDpl9YemSYgmalkKE2vloF9vhHuRn3tCL02i5t8VaJknEI5Tjxr+ v+qyTtxQ5ZfheWNonA16ViC/wtzmSLfUwjODhQTA5kbfUqsF89mb53hgIR6qx+wsPw jiGT/LN5Wu3Gw== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 02/11] drm/tests: Add parameters to the drm_test_framebuffer_create test Date: Tue, 24 Oct 2023 16:09:53 -0300 Message-ID: <20231024191002.1620-3-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- v2: - Remove strcpy to strscpy change. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 9c6170edd5f7..659cbd5a3be3 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,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 }, @@ -264,6 +278,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 Tue Oct 24 19:09:54 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: 13435194 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 C23FFC25B6B for ; Tue, 24 Oct 2023 19:10:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 10E7B10E47D; Tue, 24 Oct 2023 19:10:33 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3D50D10E47D for ; Tue, 24 Oct 2023 19:10:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id EF2D4408F8; Tue, 24 Oct 2023 21:10:29 +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 b20wkq-0792A; Tue, 24 Oct 2023 21:10:29 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174629; bh=xG41h1/DHO5ER3lxWs270Udv8i/mW1twDfbQMTeqiNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PACCjmOAwbBwO1o2jHU80iT4hCvYQi3n1ZBT8K7Z9piCzMgHL2h7vbwyn0d1+/6rm YRNGkYq5fe1IfEypIZZ44D4GxSIAPhfQI7e6u37KZabv2QKQRlXaeYwxAuYpNV/sFS eMwzRG654pKI4/7ydpHumeVCsMPh0W29bCkErJJLr73OwRfzRGUng84uQ2xAOFhAon rfBS9FAsQTDuRB0ZJqgEiEwC9QX5wgj+ymtl7jB5JbhkZh3yc6jtcK4EhWEHDmFZ2t q32CmADfHRd8ptrNJiiirBqIuJ6vZ7iOQP79TAm6BKXt4V2yxkcAidVy2XfZSfwYWy rQdy/8L/J9AuA== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 03/11] drm/tests: Replace strcpy to strscpy on drm_test_framebuffer_create test Date: Tue, 24 Oct 2023 16:09:54 -0300 Message-ID: <20231024191002.1620-4-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , Arthur Grillo 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 659cbd5a3be3..eb76a71644e9 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -397,7 +397,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 Tue Oct 24 19:09:55 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: 13435195 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 0F119C00A8F for ; Tue, 24 Oct 2023 19:10:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6905C10E481; Tue, 24 Oct 2023 19:10:48 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3F5010E480 for ; Tue, 24 Oct 2023 19:10:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 92189419BC; Tue, 24 Oct 2023 21:10: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 szOVVpzjSUQh; Tue, 24 Oct 2023 21:10:44 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174644; bh=Q9rZD8Rln0ANnHRh1OHokVw7Xr16LrkSUc+tByqUo1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TsO7VC1Exa2UeL3A0bGji/FyAV3M5eHzYhklQArQGl36ZcDRNBXdrydsfdydrmMcV h+ehRWpiTOWrY/PxyXhs6savFM6Zcf6oFy4QL7pPXXX9qBCWqrWCe1WazLtEj3Bqb2 Yl0dybSpZNOiUg8ZQ2uIx06DpqV77egScBEA6MtdUXb4YaoFpy8e14vPT3xvXAJO9F 5WKSYSgaaO0/qZWe+udsHC3yRk3cvw0mvV/e6BT++reN3jgU5eytpkaEPdh+R1IzAE TCkqyeXLUzMsEy991Och2iZ1k34brdJpH2G004sktC3gf06FWHpBt6w+P1UMGBhrqj 5F9FYcOnUfKWA== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 04/11] drm/tests: Add test case for drm_internal_framebuffer_create() Date: Tue, 24 Oct 2023 16:09:55 -0300 Message-ID: <20231024191002.1620-5-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- v2: - Reorder kunit cases alphabetically. --- 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 eb76a71644e9..8a9b6d08d639 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -403,8 +403,36 @@ 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 dev->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_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->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, + }; + + priv->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_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), + KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), { } }; From patchwork Tue Oct 24 19:09:56 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: 13435196 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 51D55C07545 for ; Tue, 24 Oct 2023 19:11:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1771710E480; Tue, 24 Oct 2023 19:11:02 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id D025E10E482 for ; Tue, 24 Oct 2023 19:10:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 8AB0F41ABF; Tue, 24 Oct 2023 21:10: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 N3nnleWsHl9O; Tue, 24 Oct 2023 21:10:57 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174657; bh=L00NlW2dLKkJxsszs3+whc7LDl3yiKAj88AsbZ8oQxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aLz9xXAOTolBp+kU8ftBK4rySfqyCIdAHkFcwRopyI4cBiMQac8NUnxXIA2jUV/Qk LRTqUIjTLa+tCm+cPSW6uOESpnhJAPl1fnuXEpK0z19HfnVxvAvpNkab7ZIHYIZutE zaiUN6ftbIXiit408TjiVJ0aIjTn8cTPY4G8a9laVc3TYGyizCZCGH3geT7bSKWVZA 1YzLRGkvdhMMCGkLlZ43eg/SHw0K9QyzUysQo4JPsfNuZyWUQQJoG76yydPKW6GBRL 7cIgOEv58EUgoWwX/s+C9A94zAypYGNYtS3PsL+2ayEWUu++s23QNOVSBhHuCIAM/P ZCd8aGO5BBWyg== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 05/11] drm/tests: Add test for drm_framebuffer_check_src_coords() Date: Tue, 24 Oct 2023 16:09:56 -0300 Message-ID: <20231024191002.1620-6-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- 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 d3ba0698b84b..a4b264e4ac97 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 8a9b6d08d639..7b51862fb0f2 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 @@ -430,7 +431,67 @@ 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 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 Tue Oct 24 19:09:57 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: 13435197 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 E2A47C07545 for ; Tue, 24 Oct 2023 19:11:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E41310E482; Tue, 24 Oct 2023 19:11:14 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id D317210E486 for ; Tue, 24 Oct 2023 19:11:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 7FE50419BC; Tue, 24 Oct 2023 21:11:10 +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 cDqeAapOMyjG; Tue, 24 Oct 2023 21:11:09 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174669; bh=yEKpIBb7hDWC2UjERUf4B9ebwRmJUaPxM8ESGmaaNcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cjRRM8CtE/O2tRFUW2V/eEdUhUYu+TZ0yt9+VZm8nDoyC6C2oBTjUinBWqsoG67iy 029P9wf7JqSRJiHyORcsCCXxaYGTWq7kguoEqJSNOVgtEYLfSiw2P70VRojwZQLHAu reVM3NfvKTwPgOFN9ABeNmg8fbv1wgyhOI+kIL/L12Rzwlou8sRttd71STQzZkm/jt oSPOzvPd8PB7trLATct6TnDRn+VLnwGjsutDv62k1RT2/eu34r9mvs24zH1aY6CSoU i0burNcI2sUpGoJk+k7PciYw6uMYr3LCOBfpCGXTTleD7alJazLEWkgEg33rbm7Ncv C5vUJ1GqbmcsQ== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 06/11] drm/tests: Add test for drm_framebuffer_cleanup() Date: Tue, 24 Oct 2023 16:09:57 -0300 Message-ID: <20231024191002.1620-7-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- v2: - Reorder kunit cases alphabetically. - Rely on drm_kunit_helper_alloc_device() for mock initialization. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 7b51862fb0f2..a63f30985f75 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -490,8 +490,45 @@ 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); +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_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_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 Tue Oct 24 19:09:58 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: 13435198 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 2A7CEC07545 for ; Tue, 24 Oct 2023 19:11:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 79E3B10E484; Tue, 24 Oct 2023 19:11:20 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5EF2510E483 for ; Tue, 24 Oct 2023 19:11:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 1FC3241AA0; Tue, 24 Oct 2023 21:11:17 +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 wuEisYSXWb3U; Tue, 24 Oct 2023 21:11:16 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174676; bh=7qgVKaq0bGOawttIrXJG6a6aZjnwW6w8TF15hqpJFqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hOURSApql/ivLtqYyQlwJhy8lc2ymROwpvQsWJjlrFzC8nMTao9Bwmz+PyVogdb5C rwb0Cbx3hpASTb+E4OQC3Lj1aZW5iMVrvigoPSPZR/6I1O40HhlpL9nVFzuqVKuv3K gf6yo3H/dL2bcpk/BcbwfVvsL++jH+b1wGsp0S82HisgWskUri60rBG0CWS/IFQ9jB //TMZOwo+GLc593tHSUsFfkwURWl2X4qId87NeW6+F02JDdC4TL6rWfB1qyRSXBcwL XVPDjE+mmMnusYqFSuVUqpT6WHkByt3CK6+PQwJTPhP8+df5gJs2L9+zJV/rkLmBIa 92H0W0KciERRQ== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 07/11] drm/tests: Add test for drm_framebuffer_lookup() Date: Tue, 24 Oct 2023 16:09:58 -0300 Message-ID: <20231024191002.1620-8-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- 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. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index a63f30985f75..fb9589dd8aed 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -526,10 +526,36 @@ 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_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 *fb2; + uint32_t id = 0; + int ret; + + ret = drm_framebuffer_init(dev, &fb1, NULL); + 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); + + drm_framebuffer_cleanup(&fb1); +} + 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_modifiers_not_supported), { } }; From patchwork Tue Oct 24 19:09:59 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: 13435199 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 E35E9C00A8F for ; Tue, 24 Oct 2023 19:11:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 12AFD10E483; Tue, 24 Oct 2023 19:11:32 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id C6D5C10E483 for ; Tue, 24 Oct 2023 19:11:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 6FB94407DE; Tue, 24 Oct 2023 21:11: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 7v15vkDB1d8S; Tue, 24 Oct 2023 21:11:26 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174686; bh=njXCWGY8vUBFw4K8QFGULZiAWgcgqnEflsk6TiGUCIM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QbJzRvP0kDvGte46AwCG4aIdsuygTfafNW3EifsZfL0mSa3yvamHAd+QauYEQeBJy Pl2WDJ/SWEhCptXoJf5xSD+WYeWGMhmQMCIzms91acIDm7xd2b57IMsL98PKYpgFtr lPfBRsxbc4bNF70qhVl5miQgPB8MVjiAXNcPdxalBC4Q5lsx+xkqnSqOZ7R7Pi8hV7 N/tSIKWgsf/PmIs4MU7gYklkOv3tF1GYlbZ3VpU0k7k4K49jvopEM52ySkM0N+OSl3 fex8SbAFbd533vmYvQR+Z63CFQvgKHqHxZ9+oYZmhrGick7I2Ko8V1c6aYMdpHaFBG 5+8ToXTDzQ4JA== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 08/11] drm/tests: Add test for drm_framebuffer_init() Date: Tue, 24 Oct 2023 16:09:59 -0300 Message-ID: <20231024191002.1620-9-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- 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. --- 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 fb9589dd8aed..eedd5e920279 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -551,10 +551,62 @@ static void drm_test_framebuffer_lookup(struct kunit *test) drm_framebuffer_cleanup(&fb1); } +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 = { .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 */ + ret = drm_framebuffer_init(dev, &fb1, &funcs); + KUNIT_ASSERT_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_ASSERT_EQ(test, ret, -EINVAL); + fb1.format = &format; + + 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 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_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); + + /* 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); + + drm_framebuffer_cleanup(&fb1); +} + 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_lookup), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), { } From patchwork Tue Oct 24 19:10:00 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: 13435200 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 B1AB6C07545 for ; Tue, 24 Oct 2023 19:11:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3090110E487; Tue, 24 Oct 2023 19:11:39 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7AEF010E485 for ; Tue, 24 Oct 2023 19:11:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 261E741A79; Tue, 24 Oct 2023 21:11: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 rzrmORnB6rEc; Tue, 24 Oct 2023 21:11:35 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174695; bh=ayvIn1gb3GHnc2l0wgnoLFWK5/qk0P5APIvoHqK3nUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iH5ABCSV8YimBzVkjXCp48y65zdtnk6HwXyNM1uf025ySr8GhFfoTXc4vqrQJFDSu 9rVFwHMxH0cE97rE7Vp6Vy09+4CAb2J0T71esq9w97/zVhPHkVMaHCH4ewKlZQGdNd 6y9tBpiIzwSHn6Ss5kRp7CH1IDk29GAHa/qqATRchmtEMbwkRzHP84MDt7h5D/6ZuL +4cbTcFkC7Apc6P/bQ5Spzvxiih1V11O8V+CKtXKoLGyq3+evZS7nTQUUoEN2dhJWG wACDmqCcb8VLAvc3l/XE/1Jsh/QhqH6p7bS2PnZk6/kegih9cBP5ic4SiSx+GS3I/F cUy+uZY4GfJ1w== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 09/11] drm/tests: Add test for drm_framebuffer_free() Date: Tue, 24 Oct 2023 16:10:00 -0300 Message-ID: <20231024191002.1620-10-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- v2: - Reorder kunit cases alphabetically. --- 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 eedd5e920279..dbe412d0dca4 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -602,10 +602,59 @@ static void drm_test_framebuffer_init(struct kunit *test) drm_framebuffer_cleanup(&fb1); } +static void destroy_free_mock(struct drm_framebuffer *fb) +{ + struct drm_framebuffer_test_priv *priv = container_of(fb->dev, typeof(*priv), dev); + int *buffer_freed = priv->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_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 buffer_freed = 0; + int id, ret; + + priv->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_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_lookup), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), From patchwork Tue Oct 24 19:10:01 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: 13435201 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 A7502C07545 for ; Tue, 24 Oct 2023 19:11:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA7BD10E486; Tue, 24 Oct 2023 19:11:47 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id DD11E10E488 for ; Tue, 24 Oct 2023 19:11:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 8D05841AC4; Tue, 24 Oct 2023 21:11: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 PsmiCaOHQFAZ; Tue, 24 Oct 2023 21:11:43 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174703; bh=cpKhqPg2spRLSQkozkiRlKIUstGpeki3AKzBL74ciY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aAudvwRNGT4v87G4vcbCESUgVZExpXOJRvYcqbPfjQFksAYSKKNORF0VWQI0jv63K /rBc8K4aJQi6Kg/WJ2QxxjodEiJu0GbEHLTOqBVKGVM3L7jlir5l/+mUw8jAQ/Jw8L dNTxZ9pI5Iww3URVZNEQTtCfB9oFlGZJIVhqIIcIEzAOj7FcyQJJp6HTO8O4vZgH24 +v83qBGaoYfyYxe7j/+dYHmvBJLx/jsyR711uqoGl0bH7rPJ7o+QRm4Nn9y7s0IWo+ 9LNh94YAG6lzeyKma3h0RIxFUKG1fCzFqwPho4sMZ5krgWSM0k659L5lT9fs7mx/DV At94SHlhKWLAg== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 10/11] drm/tests: Add test for drm_mode_addfb2() Date: Tue, 24 Oct 2023 16:10:01 -0300 Message-ID: <20231024191002.1620-11-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , 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 --- v2: - Reorder kunit cases alphabetically. - Rely on drm_kunit_helper_alloc_device() for mock initialization. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 104 ++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index dbe412d0dca4..149e1985e53f 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 @@ -341,8 +342,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_framebuffer_test_priv { struct drm_device dev; + struct drm_file file_priv; + struct kunit *test; void *private; }; @@ -365,14 +376,16 @@ static int drm_framebuffer_test_init(struct kunit *test) struct device *parent; struct drm_framebuffer_test_priv *priv; struct drm_device *dev; + struct drm_file *file_priv; parent = drm_kunit_helper_alloc_device(test); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); priv = drm_kunit_helper_alloc_drm_device(test, parent, typeof(*priv), - dev, 0); + dev, DRIVER_MODESET); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); dev = &priv->dev; + file_priv = &priv->file_priv; dev->mode_config.min_width = MIN_WIDTH; dev->mode_config.max_width = MAX_WIDTH; @@ -380,10 +393,22 @@ 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 = priv; + return 0; } +static void drm_framebuffer_test_exit(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_file *file_priv = &priv->file_priv; + + mutex_destroy(&file_priv->fbs_lock); +} + static void drm_test_framebuffer_create(struct kunit *test) { const struct drm_framebuffer_test *params = test->param_value; @@ -650,7 +675,83 @@ 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_framebuffer_test_priv *priv = container_of(dev, typeof(*priv), dev); + struct drm_framebuffer *fb; + struct kunit *test = priv->test; + + fb = kunit_kzalloc(test, sizeof(*fb), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fb); + + fb->base.id = 1; + + priv->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_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_file *file_priv = &priv->file_priv; + struct drm_framebuffer *fb = NULL; + u32 driver_features; + 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 }, + }; + + priv->test = test; + dev->mode_config.funcs = &config_funcs_addfb2_mock; + + /* Must fail due to missing DRIVER_MODESET support */ + driver_features = dev->driver_features; + dev->driver_features = 0u; + ret = drm_mode_addfb2(dev, &cmd, file_priv); + KUNIT_EXPECT_EQ(test, ret, -EOPNOTSUPP); + KUNIT_ASSERT_PTR_EQ(test, priv->private, NULL); + dev->driver_features = 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, priv->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 = priv->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_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), @@ -664,6 +765,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 Tue Oct 24 19:10:02 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: 13435202 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 19831C07545 for ; Tue, 24 Oct 2023 19:11:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F2D310E488; Tue, 24 Oct 2023 19:11:57 +0000 (UTC) Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 64F5510E485 for ; Tue, 24 Oct 2023 19:11:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 9C93E41A42; Tue, 24 Oct 2023 21: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 YfPHRlnwXK9x; Tue, 24 Oct 2023 21:11:51 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1698174711; bh=BVIYdZxkU68rXZ/RWqSgLWyL4kBauhz/JWSa0EsNwDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dUDVHq1zx3ptISf2ZVC6iLznu5odjrbHGx3q4LDEBpKYyYhk5wgI6YUp1siOjgYnt Reie8W5YrQN8/J8WG2XNw9lLG9ZT/UAvS9jQl5hjfTTaZCQ5OtVtdeDV88e8IPNCY0 WXrN4nMbY+rb3pa1Amk25BTOOwVAqC0j4rRSlfxbf4JyrqsldbJQzwJXKN4P/w9rAK WqvmSoNfAJGDLYWbTZFjZ12dyVFUaJ/ctxwyGuiq/Bn5zw+b5tuQPNg9Dr1y+Jzn/Z edCZj3oJItalZYrSlPAzvGP2j4XR/RQJkO+AilKfP2ck6FFA5eXKF0zem3d1hbmNA+ X4sAZmQgGth3g== To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 11/11] drm/tests: Add test for drm_fb_release() Date: Tue, 24 Oct 2023 16:10:02 -0300 Message-ID: <20231024191002.1620-12-gcarlos@disroot.org> In-Reply-To: <20231024191002.1620-1-gcarlos@disroot.org> References: <20231024191002.1620-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 , Arthur Grillo Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a single KUnit test case for the drm_fb_release function, which also implicitly test the static legacy_remove_fb function. Signed-off-by: Carlos Eduardo Gallo Filho --- v2: - Rely on drm_kunit_helper_alloc_device() for mock initialization. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 142 +++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 149e1985e53f..70b14e05dc83 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -750,7 +751,148 @@ static void drm_test_framebuffer_addfb2(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, fb->filp_head.next, &file_priv->fbs); } +static void drm_framebuffer_fb_release_remove_mock(struct kref *kref) +{ + struct drm_framebuffer *fb = container_of(kref, typeof(*fb), base.refcount); + struct drm_framebuffer_test_priv *priv = container_of(fb->dev, typeof(*priv), dev); + bool *obj_released = priv->private; + + obj_released[fb->base.id - 1] = true; +} + +static int crtc_set_config_fb_release_mock(struct drm_mode_set *set, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_crtc *crtc = set->crtc; + struct drm_framebuffer_test_priv *priv = container_of(crtc->dev, typeof(*priv), dev); + bool *obj_released = priv->private; + + obj_released[crtc->base.id - 1] = true; + obj_released[crtc->primary->base.id - 1] = true; + return 0; +} + +static int disable_plane_fb_release_mock(struct drm_plane *plane, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_framebuffer_test_priv *priv = container_of(plane->dev, typeof(*priv), dev); + bool *obj_released = priv->private; + + obj_released[plane->base.id - 1] = true; + return 0; +} + +#define NUM_OBJS 5 + +/* + * The drm_fb_release function implicitly calls at some point the + * drm_framebuffer_remove, which actually removes framebuffers + * based on the driver supporting or not the atomic API. To simplify + * this test, let it rely on legacy removing and leave the atomic remove + * to be tested in another test case. By doing that, we can also test + * the legacy_remove_fb function entirely. + */ +static void drm_test_fb_release(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_file *file_priv = &priv->file_priv; + struct drm_plane_funcs plane_funcs = { + .disable_plane = disable_plane_fb_release_mock + }; + struct drm_crtc_funcs crtc_funcs = { + .set_config = crtc_set_config_fb_release_mock + }; + struct drm_framebuffer *fb1, *fb2; + struct drm_plane *plane1, *plane2; + struct drm_crtc *crtc; + bool *obj_released; + + /* + * obj_released[i] where "i" is the obj.base.id - 1. Note that the + * "released" word means different things for each kind of obj, which + * in case of a framebuffer, means that it was freed, while for the + * crtc and plane, means that it was deactivated. + */ + obj_released = kunit_kzalloc(test, NUM_OBJS * sizeof(bool), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, obj_released); + priv->private = obj_released; + + fb1 = kunit_kzalloc(test, sizeof(*fb1), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fb1); + list_add(&fb1->filp_head, &file_priv->fbs); + kref_init(&fb1->base.refcount); + fb1->dev = dev; + fb1->base.free_cb = drm_framebuffer_fb_release_remove_mock; + fb1->base.id = 1; + + fb2 = kunit_kzalloc(test, sizeof(*fb2), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fb2); + list_add(&fb2->filp_head, &file_priv->fbs); + kref_init(&fb2->base.refcount); + fb2->dev = dev; + fb2->base.free_cb = drm_framebuffer_fb_release_remove_mock; + fb2->base.id = 2; + + plane1 = kunit_kzalloc(test, sizeof(*plane1), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane1); + list_add(&plane1->head, &dev->mode_config.plane_list); + drm_modeset_lock_init(&plane1->mutex); + plane1->dev = dev; + plane1->funcs = &plane_funcs; + plane1->base.id = 3; + + plane2 = kunit_kzalloc(test, sizeof(*plane2), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane2); + list_add(&plane2->head, &dev->mode_config.plane_list); + drm_modeset_lock_init(&plane2->mutex); + plane2->dev = dev; + plane2->funcs = &plane_funcs; + plane2->base.id = 4; + + crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc); + list_add(&crtc->head, &dev->mode_config.crtc_list); + drm_modeset_lock_init(&crtc->mutex); + crtc->dev = dev; + crtc->funcs = &crtc_funcs; + crtc->base.id = 5; + + /* + * Attach fb2 to some planes to stress the case where we have more than + * one reference to the fb. plane1 is attached to crtc as primary plane + * and plane2 will represent any non-primary plane, allowing to cover + * all codepaths on legacy_remove_fb + */ + crtc->primary = plane1; + plane1->crtc = crtc; + plane1->fb = fb2; + plane2->fb = fb2; + /* Each plane holds one reference to fb */ + drm_framebuffer_get(fb2); + drm_framebuffer_get(fb2); + + drm_fb_release(file_priv); + + KUNIT_EXPECT_TRUE(test, list_empty(&file_priv->fbs)); + + /* Every object from this test should be released */ + for (int i = 0; i < 5; i++) + KUNIT_EXPECT_EQ(test, obj_released[i], 1); + + KUNIT_EXPECT_FALSE(test, kref_read(&fb1->base.refcount)); + KUNIT_EXPECT_FALSE(test, kref_read(&fb2->base.refcount)); + + KUNIT_EXPECT_PTR_EQ(test, plane1->crtc, NULL); + KUNIT_EXPECT_PTR_EQ(test, plane1->fb, NULL); + KUNIT_EXPECT_PTR_EQ(test, plane1->old_fb, NULL); + KUNIT_EXPECT_PTR_EQ(test, plane2->crtc, NULL); + KUNIT_EXPECT_PTR_EQ(test, plane2->fb, NULL); + KUNIT_EXPECT_PTR_EQ(test, plane2->old_fb, NULL); +} + static struct kunit_case drm_framebuffer_tests[] = { + KUNIT_CASE(drm_test_fb_release), KUNIT_CASE(drm_test_framebuffer_addfb2), KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), KUNIT_CASE(drm_test_framebuffer_cleanup),