From patchwork Mon Mar 27 13:38:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13189368 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 48D33C7619A for ; Mon, 27 Mar 2023 13:39:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7370010E5A5; Mon, 27 Mar 2023 13:39:20 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id EA35510E373 for ; Mon, 27 Mar 2023 13:39:17 +0000 (UTC) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4PlYnd2LCLz9swg; Mon, 27 Mar 2023 13:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1679924357; bh=WUgMvcyfP7N4X9nJBfVcDYuHTwzlHOO9X8baahXgs7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kPbaPGIE4T+H6t60x6Pih42fyHDwcT7jZtxMCp9M9L8FUtAv+CJKZDh7U2KIt6s0u Yn9qravXwqE40Q1hmviEuNHuPOmIgQL8KCfQbeW4s/FVFfJeuTcjcIReGarmQamKSM xO2lYYfHJx8k6EFWRVBy/G0OEOaSi0F57mlI3Znk= X-Riseup-User-ID: 5AFE1440F84AAC1CD7B6D231CFFA258E5C30D24E7A2454E03C3675E189E93AEC Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4PlYnX4plcz1yBT; Mon, 27 Mar 2023 13:39:12 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/5] drm/tests: Test drm_rect_intersect() Date: Mon, 27 Mar 2023 10:38:44 -0300 Message-Id: <20230327133848.5250-2-arthurgrillo@riseup.net> In-Reply-To: <20230327133848.5250-1-arthurgrillo@riseup.net> References: <20230327133848.5250-1-arthurgrillo@riseup.net> 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: carlos.craveiro@usp.br, tales.aparecida@gmail.com, dlatypov@google.com, javierm@redhat.com, mairacanal@riseup.net, maxime@cerno.tech, andrealmeid@riseup.net, Arthur Grillo , matheus.vieira.g@usp.br Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Insert test for the drm_rect_intersect() function, it also create a helper for comparing drm_rects more easily. Signed-off-by: Arthur Grillo --- drivers/gpu/drm/tests/drm_rect_test.c | 139 ++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index e9809ea32696..3654c0be3d6b 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -9,6 +9,17 @@ #include +#include + +static void drm_rect_compare(struct kunit *test, const struct drm_rect *r, + const struct drm_rect *expected) +{ + KUNIT_EXPECT_EQ(test, r->x1, expected->x1); + KUNIT_EXPECT_EQ(test, r->y1, expected->y1); + KUNIT_EXPECT_EQ(test, drm_rect_width(r), drm_rect_width(expected)); + KUNIT_EXPECT_EQ(test, drm_rect_height(r), drm_rect_height(expected)); +} + static void drm_test_rect_clip_scaled_div_by_zero(struct kunit *test) { struct drm_rect src, dst, clip; @@ -196,11 +207,139 @@ static void drm_test_rect_clip_scaled_signed_vs_unsigned(struct kunit *test) KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n"); } +struct drm_rect_intersect_case { + const char *description; + struct drm_rect r1, r2; + bool should_be_visible; + struct drm_rect expected_intersection; +}; + +static const struct drm_rect_intersect_case drm_rect_intersect_cases[] = { + { + .description = "top-left X bottom-right", + .r1 = DRM_RECT_INIT(1, 1, 2, 2), + .r2 = DRM_RECT_INIT(0, 0, 2, 2), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(1, 1, 1, 1), + }, + { + .description = "top-right X bottom-left", + .r1 = DRM_RECT_INIT(0, 0, 2, 2), + .r2 = DRM_RECT_INIT(1, -1, 2, 2), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(1, 0, 1, 1), + }, + { + .description = "bottom-left X top-right", + .r1 = DRM_RECT_INIT(1, -1, 2, 2), + .r2 = DRM_RECT_INIT(0, 0, 2, 2), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(1, 0, 1, 1), + }, + { + .description = "bottom-right X top-left", + .r1 = DRM_RECT_INIT(0, 0, 2, 2), + .r2 = DRM_RECT_INIT(1, 1, 2, 2), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(1, 1, 1, 1), + }, + { + .description = "right X left", + .r1 = DRM_RECT_INIT(0, 0, 2, 1), + .r2 = DRM_RECT_INIT(1, 0, 3, 1), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(1, 0, 1, 1), + }, + { + .description = "left X right", + .r1 = DRM_RECT_INIT(1, 0, 3, 1), + .r2 = DRM_RECT_INIT(0, 0, 2, 1), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(1, 0, 1, 1), + }, + { + .description = "up X bottom", + .r1 = DRM_RECT_INIT(0, 0, 1, 2), + .r2 = DRM_RECT_INIT(0, -1, 1, 3), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(0, 0, 1, 2), + }, + { + .description = "bottom X up", + .r1 = DRM_RECT_INIT(0, -1, 1, 3), + .r2 = DRM_RECT_INIT(0, 0, 1, 2), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(0, 0, 1, 2), + }, + { + .description = "touching corner", + .r1 = DRM_RECT_INIT(0, 0, 1, 1), + .r2 = DRM_RECT_INIT(1, 1, 2, 2), + .should_be_visible = false, + .expected_intersection = DRM_RECT_INIT(1, 1, 0, 0), + }, + { + .description = "touching side", + .r1 = DRM_RECT_INIT(0, 0, 1, 1), + .r2 = DRM_RECT_INIT(1, 0, 1, 1), + .should_be_visible = false, + .expected_intersection = DRM_RECT_INIT(1, 0, 0, 1), + }, + { + .description = "equal rects", + .r1 = DRM_RECT_INIT(0, 0, 2, 2), + .r2 = DRM_RECT_INIT(0, 0, 2, 2), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(0, 0, 2, 2), + }, + { + .description = "inside another", + .r1 = DRM_RECT_INIT(0, 0, 2, 2), + .r2 = DRM_RECT_INIT(1, 1, 1, 1), + .should_be_visible = true, + .expected_intersection = DRM_RECT_INIT(1, 1, 1, 1), + }, + { + .description = "far away", + .r1 = DRM_RECT_INIT(0, 0, 1, 1), + .r2 = DRM_RECT_INIT(3, 6, 1, 1), + .should_be_visible = false, + .expected_intersection = DRM_RECT_INIT(3, 6, -2, -5), + }, +}; + +static void drm_rect_intersect_case_desc(const struct drm_rect_intersect_case *t, char *desc) +{ + if (!t->description) + snprintf(desc, KUNIT_PARAM_DESC_SIZE, + DRM_RECT_FMT " X " DRM_RECT_FMT, + DRM_RECT_ARG(&t->r1), DRM_RECT_ARG(&t->r2)); + else + snprintf(desc, KUNIT_PARAM_DESC_SIZE, + "%s: " DRM_RECT_FMT " X " DRM_RECT_FMT, + t->description, DRM_RECT_ARG(&t->r1), DRM_RECT_ARG(&t->r2)); +} + +KUNIT_ARRAY_PARAM(drm_rect_intersect, drm_rect_intersect_cases, drm_rect_intersect_case_desc); + +static void drm_test_rect_intersect(struct kunit *test) +{ + const struct drm_rect_intersect_case *params = test->param_value; + struct drm_rect r1_aux = params->r1; + bool visible; + + visible = drm_rect_intersect(&r1_aux, ¶ms->r2); + + KUNIT_EXPECT_EQ(test, visible, params->should_be_visible); + drm_rect_compare(test, &r1_aux, ¶ms->expected_intersection); +} + static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_clip_scaled_div_by_zero), KUNIT_CASE(drm_test_rect_clip_scaled_not_clipped), KUNIT_CASE(drm_test_rect_clip_scaled_clipped), KUNIT_CASE(drm_test_rect_clip_scaled_signed_vs_unsigned), + KUNIT_CASE_PARAM(drm_test_rect_intersect, drm_rect_intersect_gen_params), { } }; From patchwork Mon Mar 27 13:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13189371 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 720B0C761A6 for ; Mon, 27 Mar 2023 13:39:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 24E6C10E5CF; Mon, 27 Mar 2023 13:39:36 +0000 (UTC) Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by gabe.freedesktop.org (Postfix) with ESMTPS id CDDD810E5C4 for ; Mon, 27 Mar 2023 13:39:33 +0000 (UTC) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4PlYnk2KpszDr07; Mon, 27 Mar 2023 13:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1679924373; bh=G+63XP5wcg7jD1vPsJ/NozI4ge3Dhjgooy42h6s25Wo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SurOPJ/+Oz6CUGi6wioQ5PGWZjB6nEF229kPPW8xjJARg5eQ7tNKavNG5JYEv5e3P P3+PAzraZ0Si8YUbjnQUsVr1C2B9yXBAR4lfWko2sHJIjwhY+XAtSwFn6LSRGb+OVN N7kMt9L3j9vScswdUZLIREbp5jr2sOgkhOKULWHw= X-Riseup-User-ID: A20F34228033A100078A234D5F15A968DA11267FE65F610997E808C5F5182AD6 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4PlYnf02x5z1yPW; Mon, 27 Mar 2023 13:39:17 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/5] drm/tests: Test drm_rect_calc_hscale() Date: Mon, 27 Mar 2023 10:38:45 -0300 Message-Id: <20230327133848.5250-3-arthurgrillo@riseup.net> In-Reply-To: <20230327133848.5250-1-arthurgrillo@riseup.net> References: <20230327133848.5250-1-arthurgrillo@riseup.net> 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: carlos.craveiro@usp.br, tales.aparecida@gmail.com, dlatypov@google.com, javierm@redhat.com, mairacanal@riseup.net, maxime@cerno.tech, andrealmeid@riseup.net, Arthur Grillo , matheus.vieira.g@usp.br Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Insert test for the drm_rect_hscale() function, besides the test for the usual case it also test for the exceptions. Signed-off-by: Arthur Grillo --- drivers/gpu/drm/tests/drm_rect_test.c | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index 3654c0be3d6b..c282e1cf9c30 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -10,6 +10,7 @@ #include #include +#include static void drm_rect_compare(struct kunit *test, const struct drm_rect *r, const struct drm_rect *expected) @@ -334,12 +335,68 @@ static void drm_test_rect_intersect(struct kunit *test) drm_rect_compare(test, &r1_aux, ¶ms->expected_intersection); } +static void drm_test_rect_calc_hscale(struct kunit *test) +{ + struct drm_rect src, dst; + int scaling_factor; + + drm_rect_init(&src, 0, 0, 2 << 16, 0); + drm_rect_init(&dst, 0, 0, 1 << 16, 0); + + scaling_factor = drm_rect_calc_hscale(&src, &dst, 0, INT_MAX); + + KUNIT_EXPECT_EQ(test, scaling_factor, 2); +} + +static void drm_test_rect_calc_hscale_out_of_range(struct kunit *test) +{ + struct drm_rect src, dst; + int scaling_factor; + + drm_rect_init(&src, 0, 0, 10 << 16, 0); + drm_rect_init(&dst, 0, 0, 1 << 16, 0); + + scaling_factor = drm_rect_calc_hscale(&src, &dst, 3, 5); + + KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE); + + drm_rect_init(&src, 0, 0, 2 << 16, 0); + drm_rect_init(&dst, 0, 0, 1 << 16, 0); + + scaling_factor = drm_rect_calc_hscale(&src, &dst, 3, 5); + + KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE); +} + +static void drm_test_rect_calc_hscale_negative_args(struct kunit *test) +{ + struct drm_rect src, dst; + int scaling_factor; + + drm_rect_init(&src, 0, 0, -1 << 16, 0); + drm_rect_init(&dst, 0, 0, 1 << 16, 0); + + scaling_factor = drm_rect_calc_hscale(&src, &dst, 0, INT_MAX); + + KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL); + + drm_rect_init(&src, 0, 0, 1 << 16, 0); + drm_rect_init(&dst, 0, 0, -1 << 16, 0); + + scaling_factor = drm_rect_calc_hscale(&src, &dst, 0, INT_MAX); + + KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL); +} + static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_clip_scaled_div_by_zero), KUNIT_CASE(drm_test_rect_clip_scaled_not_clipped), KUNIT_CASE(drm_test_rect_clip_scaled_clipped), KUNIT_CASE(drm_test_rect_clip_scaled_signed_vs_unsigned), KUNIT_CASE_PARAM(drm_test_rect_intersect, drm_rect_intersect_gen_params), + KUNIT_CASE(drm_test_rect_calc_hscale), + KUNIT_CASE(drm_test_rect_calc_hscale_out_of_range), + KUNIT_CASE(drm_test_rect_calc_hscale_negative_args), { } }; From patchwork Mon Mar 27 13:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13189369 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 05D50C7619A for ; Mon, 27 Mar 2023 13:39:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 36D4510E373; Mon, 27 Mar 2023 13:39:31 +0000 (UTC) Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by gabe.freedesktop.org (Postfix) with ESMTPS id 34DB610E373 for ; Mon, 27 Mar 2023 13:39:28 +0000 (UTC) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4PlYnq4Sh1zDqJ5; Mon, 27 Mar 2023 13:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1679924367; bh=ZbhbxRPpqDxBPpby6AoAh/6FbNAP69FxdKFtXX5L7hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVLQSiQD1rtzcXaC+wyZ73Pon6lzWv5BPgkUlEEjTqkSHR9TDx/WP4Y/GEyucngw/ PHggt4JHAAlwISmzZ9q1eCOomSzIycA/O261NeUBD+JugENEJIvl7NPdQg38zHhVIW 07nt+XtappCtDA8ZjFXXqL51UtQ80BRoXYntUB/o= X-Riseup-User-ID: F91D87FED72F9C272E056779BC978E916EA9140D17E370AE1C1D0F6D102C0229 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4PlYnk4cVvz1yBT; Mon, 27 Mar 2023 13:39:22 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 3/5] drm/tests: Test drm_rect_calc_vscale() Date: Mon, 27 Mar 2023 10:38:46 -0300 Message-Id: <20230327133848.5250-4-arthurgrillo@riseup.net> In-Reply-To: <20230327133848.5250-1-arthurgrillo@riseup.net> References: <20230327133848.5250-1-arthurgrillo@riseup.net> 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: carlos.craveiro@usp.br, tales.aparecida@gmail.com, dlatypov@google.com, javierm@redhat.com, mairacanal@riseup.net, maxime@cerno.tech, andrealmeid@riseup.net, Arthur Grillo , matheus.vieira.g@usp.br Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Insert test for the drm_rect_vscale() function, besides the test for the usual case it also test for the exceptions. Signed-off-by: Arthur Grillo --- drivers/gpu/drm/tests/drm_rect_test.c | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index c282e1cf9c30..a14da86ef435 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -388,6 +388,59 @@ static void drm_test_rect_calc_hscale_negative_args(struct kunit *test) KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL); } +static void drm_test_rect_calc_vscale(struct kunit *test) +{ + struct drm_rect src, dst; + int scaling_factor; + + drm_rect_init(&src, 0, 0, 0, 2 << 16); + drm_rect_init(&dst, 0, 0, 0, 1 << 16); + + scaling_factor = drm_rect_calc_vscale(&src, &dst, 0, INT_MAX); + + KUNIT_EXPECT_EQ(test, scaling_factor, 2); +} + +static void drm_test_rect_calc_vscale_out_of_range(struct kunit *test) +{ + struct drm_rect src, dst; + int scaling_factor; + + drm_rect_init(&src, 0, 0, 0, 10 << 16); + drm_rect_init(&dst, 0, 0, 0, 1 << 16); + + scaling_factor = drm_rect_calc_vscale(&src, &dst, 3, 5); + + KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE); + + drm_rect_init(&src, 0, 0, 0, 2 << 16); + drm_rect_init(&dst, 0, 0, 0, 1 << 16); + + scaling_factor = drm_rect_calc_vscale(&src, &dst, 3, 5); + + KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE); +} + +static void drm_test_rect_calc_vscale_negative_args(struct kunit *test) +{ + struct drm_rect src, dst; + int scaling_factor; + + drm_rect_init(&src, 0, 0, 0, -1 << 16); + drm_rect_init(&dst, 0, 0, 0, 1 << 16); + + scaling_factor = drm_rect_calc_vscale(&src, &dst, 0, INT_MAX); + + KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL); + + drm_rect_init(&src, 0, 0, 0, 1 << 16); + drm_rect_init(&dst, 0, 0, 0, -1 << 16); + + scaling_factor = drm_rect_calc_vscale(&src, &dst, 0, INT_MAX); + + KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL); +} + static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_clip_scaled_div_by_zero), KUNIT_CASE(drm_test_rect_clip_scaled_not_clipped), @@ -397,6 +450,9 @@ static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_calc_hscale), KUNIT_CASE(drm_test_rect_calc_hscale_out_of_range), KUNIT_CASE(drm_test_rect_calc_hscale_negative_args), + KUNIT_CASE(drm_test_rect_calc_vscale), + KUNIT_CASE(drm_test_rect_calc_vscale_out_of_range), + KUNIT_CASE(drm_test_rect_calc_vscale_negative_args), { } }; From patchwork Mon Mar 27 13:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13189370 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 A45CAC7619A for ; Mon, 27 Mar 2023 13:39:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E840910E5C4; Mon, 27 Mar 2023 13:39:34 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id D4C7410E5C5 for ; Mon, 27 Mar 2023 13:39:33 +0000 (UTC) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4PlYnx1t2Cz9sxg; Mon, 27 Mar 2023 13:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1679924373; bh=/bfFGeqwiqoMHm+NmXx6be5uF11lPLbY8nHHZIjdVqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Afve9XREglBVefOZ6izy+fJf54Zyk/czU02APq1nNepXQWSfehH4xxBW4Wwuhcq5a PYdz9VrdTIiJKYntMDhHdR7QN/KF3ziT3D76hgp0hQRAm+Bmyj0iWGOdnREmla6DHH qhRsPDtKISf+KNjm16FzTd2Fs0bx9Xiwp2nyuROc= X-Riseup-User-ID: 2F549D14A803D7B119720449EEC47D34385F0980A59F0E61CE3BA1750F3FB841 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4PlYnr0Hkgz1yBT; Mon, 27 Mar 2023 13:39:27 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/5] drm/tests: Test drm_rect_rotate() Date: Mon, 27 Mar 2023 10:38:47 -0300 Message-Id: <20230327133848.5250-5-arthurgrillo@riseup.net> In-Reply-To: <20230327133848.5250-1-arthurgrillo@riseup.net> References: <20230327133848.5250-1-arthurgrillo@riseup.net> 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: carlos.craveiro@usp.br, tales.aparecida@gmail.com, dlatypov@google.com, javierm@redhat.com, mairacanal@riseup.net, maxime@cerno.tech, andrealmeid@riseup.net, Arthur Grillo , matheus.vieira.g@usp.br Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Insert test for the drm_rect_rotate() function, create test cases for all the rotation modes. Signed-off-by: Arthur Grillo --- drivers/gpu/drm/tests/drm_rect_test.c | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index a14da86ef435..bb3fff09cb7b 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -441,6 +442,76 @@ static void drm_test_rect_calc_vscale_negative_args(struct kunit *test) KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL); } +struct drm_rect_rotate_case { + const char *name; + unsigned int rotation; + struct drm_rect rect; + int width, height; + struct drm_rect expected; +}; + +static const struct drm_rect_rotate_case drm_rect_rotate_cases[] = { + { + .name = "reflect x", + .rotation = DRM_MODE_REFLECT_X, + .rect = DRM_RECT_INIT(0, 0, 5, 5), + .width = 5, .height = 10, + .expected = DRM_RECT_INIT(0, 0, 5, 5), + }, + { + .name = "reflect y", + .rotation = DRM_MODE_REFLECT_Y, + .rect = DRM_RECT_INIT(0, 0, 5, 5), + .width = 5, .height = 10, + .expected = DRM_RECT_INIT(0, 5, 5, 5), + }, + { + .name = "rotate 0", + .rotation = DRM_MODE_ROTATE_0, + .rect = DRM_RECT_INIT(0, 0, 5, 5), + .width = 5, .height = 10, + .expected = DRM_RECT_INIT(0, 0, 5, 5), + }, + { + .name = "rotate 90", + .rotation = DRM_MODE_ROTATE_90, + .rect = DRM_RECT_INIT(0, 0, 5, 10), + .width = 5, .height = 10, + .expected = DRM_RECT_INIT(0, 0, 10, 5), + }, + { + .name = "rotate 180", + .rotation = DRM_MODE_ROTATE_180, + .rect = DRM_RECT_INIT(0, 0, 5, 10), + .width = 5, .height = 10, + .expected = DRM_RECT_INIT(0, 0, 5, 10), + }, + { + .name = "rotate 270", + .rotation = DRM_MODE_ROTATE_270, + .rect = DRM_RECT_INIT(0, 0, 5, 10), + .width = 5, .height = 10, + .expected = DRM_RECT_INIT(0, 0, 10, 5), + }, +}; + +static void drm_rect_case_desc(const struct drm_rect_rotate_case *t, char *desc) +{ + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(drm_rect_rotate, drm_rect_rotate_cases, drm_rect_case_desc); + +static void drm_test_rect_rotate(struct kunit *test) +{ + const struct drm_rect_rotate_case *params = test->param_value; + struct drm_rect r = params->rect; + + drm_rect_rotate(&r, params->width, params->height, params->rotation); + + drm_rect_compare(test, &r, ¶ms->expected); +} + static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_clip_scaled_div_by_zero), KUNIT_CASE(drm_test_rect_clip_scaled_not_clipped), @@ -453,6 +524,7 @@ static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_calc_vscale), KUNIT_CASE(drm_test_rect_calc_vscale_out_of_range), KUNIT_CASE(drm_test_rect_calc_vscale_negative_args), + KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params), { } }; From patchwork Mon Mar 27 13:38:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13189372 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 A21B1C7619A for ; Mon, 27 Mar 2023 13:39:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A96E210E5D2; Mon, 27 Mar 2023 13:39:43 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id DF00710E5C5 for ; Mon, 27 Mar 2023 13:39:38 +0000 (UTC) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4PlYp22lbHz9sxg; Mon, 27 Mar 2023 13:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1679924378; bh=jwkx7cxH5mPQnO6CaM5FAIAMPPA/T2adQyIjgxt87Tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZmDqsvoZhauOv6HkFOEDgY/UCpQwFuXJZlAqM2q5/mUsr2HdNsjr8wcme19DFXWd WOF4inViKehJhRJfJTrnLbo5OzKtrrVBx1H1I7vp/yPxObDakwAeF54x0DJQowLf5/ FXtMfuDkYhegV3rp3LODhfqhyZ3/FvhV/90PY9A8= X-Riseup-User-ID: 758E7C7CCDD08DA7240F4A9A599C93395DFD60E8B1078E6E3A4705A299DC72CB Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4PlYnx5Wnnz1yBT; Mon, 27 Mar 2023 13:39:33 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 5/5] drm/test: Test drm_rect_rotate_inv() Date: Mon, 27 Mar 2023 10:38:48 -0300 Message-Id: <20230327133848.5250-6-arthurgrillo@riseup.net> In-Reply-To: <20230327133848.5250-1-arthurgrillo@riseup.net> References: <20230327133848.5250-1-arthurgrillo@riseup.net> 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: carlos.craveiro@usp.br, tales.aparecida@gmail.com, dlatypov@google.com, javierm@redhat.com, mairacanal@riseup.net, maxime@cerno.tech, andrealmeid@riseup.net, Arthur Grillo , matheus.vieira.g@usp.br Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Insert test for the drm_rect_rotate_inv() function, by expanding the existing test framework for the drm_rect_rotate(). Signed-off-by: Arthur Grillo --- drivers/gpu/drm/tests/drm_rect_test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index bb3fff09cb7b..f3805a8512de 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -512,6 +512,16 @@ static void drm_test_rect_rotate(struct kunit *test) drm_rect_compare(test, &r, ¶ms->expected); } +static void drm_test_rect_rotate_inv(struct kunit *test) +{ + const struct drm_rect_rotate_case *params = test->param_value; + struct drm_rect r = params->expected; + + drm_rect_rotate_inv(&r, params->width, params->height, params->rotation); + + drm_rect_compare(test, &r, ¶ms->rect); +} + static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_clip_scaled_div_by_zero), KUNIT_CASE(drm_test_rect_clip_scaled_not_clipped), @@ -525,6 +535,7 @@ static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_calc_vscale_out_of_range), KUNIT_CASE(drm_test_rect_calc_vscale_negative_args), KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params), + KUNIT_CASE_PARAM(drm_test_rect_rotate_inv, drm_rect_rotate_gen_params), { } };