From patchwork Wed Sep 11 00:15:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Eduardo Gallo Filho X-Patchwork-Id: 13799564 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 648A2EE01F5 for ; Wed, 11 Sep 2024 00:20:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C4C610E594; Wed, 11 Sep 2024 00:20:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.b="Hl68Gri8"; dkim-atps=neutral Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id 438B110E94E for ; Wed, 11 Sep 2024 00:20:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id C1E8541A14; Wed, 11 Sep 2024 02:13:20 +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 wjocm6Cx52L7; Wed, 11 Sep 2024 02:13:20 +0200 (CEST) From: Carlos Eduardo Gallo Filho DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1726013599; bh=bsgFFLHh75ijQ55czeGmxAy5GK6I7T8ny0FIdoEwj2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Hl68Gri8Q/XdvP7NRBQS9kR8YqpXW3OCIxI1e2HGS5ERMrPigLP0ekxHudRX48Xqe Es0HtV8zUsUMYwvfqml6Y72X9JV7EPvl08MY2MGNb7YqWooINlsktffqF+B1zF4tqp oQ/NW7pzRZ+R6g0LMhoeoRxpPVfWo7Yn+pKh3kSRyCDwFtR/hFC2gQvnLX4nOefBv7 8KqFl3rMhu1vcr082X6AoYS+etRtJ6RbJAeltO2l6bPbLBiVWxp13tALl9Zc/ZHyJy odigwckEhzflZpbcmHdMSbvD8j2EAkPGduo70Xst1UcADEwET0g9ILCPsUlxLYuS1j O90nHOMZFUnxA== To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Ma=C3=ADra_Canal?= , =?utf-8?q?Andr=C3=A9_?= =?utf-8?q?Almeida?= , Arthur Grillo , Tales Lelo da Aparecida , Carlos Eduardo Gallo Filho Subject: [PATCH v4 RESEND 7/9] drm/tests: Add test for drm_framebuffer_lookup() Date: Tue, 10 Sep 2024 21:15:32 -0300 Message-ID: <20240911001559.28284-8-gcarlos@disroot.org> In-Reply-To: <20240911001559.28284-1-gcarlos@disroot.org> References: <20240911001559.28284-1-gcarlos@disroot.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add two KUnit test cases for the drm_framebuffer_lookup function, one for the base case, that tests if the lookup finds the correct framebuffer object and another that tests the lookup for an inexistent framebuffer. Signed-off-by: Carlos Eduardo Gallo Filho Acked-by: Maxime Ripard --- v2: - Reorder kunit cases alphabetically. - Replace drm_mode_object_add() call to drm_framebuffer_init(). - Rely on drm_kunit_helper_alloc_device() for mock initialization. v3: - Rename framebuffer variables. - Add documentation. - Split the lookup for inexistent framebuffer into another test. - Call drm_framebuffer_put after lookup on drm_test_framebuffer_lookup test. --- drivers/gpu/drm/tests/drm_framebuffer_test.c | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c index 908583d74b20..e11b5bc9a105 100644 --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c @@ -529,10 +529,51 @@ static void drm_test_framebuffer_cleanup(struct kunit *test) KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 0); } +/* + * Initialize a framebuffer, lookup its id and test if the returned reference + * matches. + */ +static void drm_test_framebuffer_lookup(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_format_info format = { }; + struct drm_framebuffer expected_fb = { .dev = dev, .format = &format }; + struct drm_framebuffer *returned_fb; + uint32_t id = 0; + int ret; + + ret = drm_framebuffer_init(dev, &expected_fb, NULL); + KUNIT_ASSERT_EQ(test, ret, 0); + id = expected_fb.base.id; + + /* Looking for expected_fb */ + returned_fb = drm_framebuffer_lookup(dev, NULL, id); + KUNIT_EXPECT_PTR_EQ(test, returned_fb, &expected_fb); + drm_framebuffer_put(returned_fb); + + drm_framebuffer_cleanup(&expected_fb); +} + +/* Try to lookup an id that is not linked to a framebuffer */ +static void drm_test_framebuffer_lookup_inexistent(struct kunit *test) +{ + struct drm_framebuffer_test_priv *priv = test->priv; + struct drm_device *dev = &priv->dev; + struct drm_framebuffer *fb; + uint32_t id = 0; + + /* Looking for an inexistent framebuffer */ + fb = drm_framebuffer_lookup(dev, NULL, id); + KUNIT_EXPECT_NULL(test, fb); +} + static struct kunit_case drm_framebuffer_tests[] = { KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), KUNIT_CASE(drm_test_framebuffer_cleanup), KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), + KUNIT_CASE(drm_test_framebuffer_lookup), + KUNIT_CASE(drm_test_framebuffer_lookup_inexistent), KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported), { } };