From patchwork Tue Apr 4 18:41:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13200882 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 923F2C6FD1D for ; Tue, 4 Apr 2023 18:42:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D2BA810E74A; Tue, 4 Apr 2023 18:42:20 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9E2E210E74A for ; Tue, 4 Apr 2023 18:42:18 +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 4Prc7Z0fSFz9swt; Tue, 4 Apr 2023 18:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1680633738; bh=A5/lDmkLK9v2yG/ODWcUO/GoJ7E/xCkWP3tLStk5DOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AnWp701gakqHtbaNfoRgQRl7LeyOXuT61NB44+ycxOf2T7MTtxH0CkpNUdxuuXlRu M1yJ1ewBc9NZpTtcnM9BDcO0WslkYLWC99nryh7gPam1dTOU88g0KDKDPE9z57y+Sj TdUsLI6vcCROetBk15W4rmz4+hPwW2DNnCAkfzYE= X-Riseup-User-ID: E3CCE2E198C00D2397A5F57BAEF612E9C08DE3E46CB23C7BEE6CCB85AE8B1534 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4Prc7S613qz1yjb; Tue, 4 Apr 2023 18:42:12 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 1/5] drm/tests: Add test cases for drm_rect_intersect() Date: Tue, 4 Apr 2023 15:41:54 -0300 Message-Id: <20230404184158.26290-2-arthurgrillo@riseup.net> In-Reply-To: <20230404184158.26290-1-arthurgrillo@riseup.net> References: <20230404184158.26290-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 parameterized tests for the drm_rect_intersect() to ensure correctness and prevent future regressions. Also, create a helper for testing if two drm_rects are equal. Signed-off-by: Arthur Grillo --- drivers/gpu/drm/tests/drm_rect_test.c | 148 ++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index e9809ea32696..33584f63be37 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,148 @@ 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), + }, + { + .description = "points intersecting", + .r1 = DRM_RECT_INIT(5, 10, 0, 0), + .r2 = DRM_RECT_INIT(5, 10, 0, 0), + .should_be_visible = false, + .expected_intersection = DRM_RECT_INIT(5, 10, 0, 0), + }, + { + .description = "points not intersecting", + .r1 = DRM_RECT_INIT(0, 0, 0, 0), + .r2 = DRM_RECT_INIT(5, 10, 0, 0), + .should_be_visible = false, + .expected_intersection = DRM_RECT_INIT(5, 10, -5, -10), + }, +}; + +static void drm_rect_intersect_case_desc(const struct drm_rect_intersect_case *t, char *desc) +{ + 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 Tue Apr 4 18:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13200883 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 B6E9FC6FD1D for ; Tue, 4 Apr 2023 18:42:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C4ED310E763; Tue, 4 Apr 2023 18:42:25 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6ADB110E763 for ; Tue, 4 Apr 2023 18:42:23 +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 4Prc7f6b07z9s8c; Tue, 4 Apr 2023 18:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1680633743; bh=dKVQ8eO8jDi2R7IB7DZQ7WgzzS0pv0MAq48TDS3jdd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EFmfgUbwifet6w9Vsu2gun1ngVNWQuXwqQXNML69gy0XD03WnZeah5t/6pK1J6mMn lNy8edFbILPGWJUgGXSl67N4KQRBVoOUbKot7RTzXv6J9JqTWPgpjb5vonXjnEPwrT XO1qnHFNaVqoU+EHBs216BJYJ0fAqgqg4MEfqfgA= X-Riseup-User-ID: 806A0C1E4B749755D4E7911A84116CF1554CA7C97CD80CA7CCA8392620A2E34E Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4Prc7Z3Nqsz1yNK; Tue, 4 Apr 2023 18:42:18 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 2/5] drm/tests: Add test cases for drm_rect_calc_hscale() Date: Tue, 4 Apr 2023 15:41:55 -0300 Message-Id: <20230404184158.26290-3-arthurgrillo@riseup.net> In-Reply-To: <20230404184158.26290-1-arthurgrillo@riseup.net> References: <20230404184158.26290-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 parameterized test for the drm_rect_calc_hscale() to ensure correctness and prevent future regressions. Besides the test for the usual case, tests the exceptions. 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 33584f63be37..293e5c48bb32 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) @@ -343,12 +344,83 @@ static void drm_test_rect_intersect(struct kunit *test) drm_rect_compare(test, &r1_aux, ¶ms->expected_intersection); } +struct drm_rect_scale_case { + const char *name; + struct drm_rect src, dst; + int min_range, max_range; + int expected_scaling_factor; +}; + +static const struct drm_rect_scale_case drm_rect_hscale_cases[] = { + { + .name = "normal use", + .src = DRM_RECT_INIT(0, 0, 2 << 16, 0), + .dst = DRM_RECT_INIT(0, 0, 1 << 16, 0), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = 2, + }, + { + .name = "out of max range", + .src = DRM_RECT_INIT(0, 0, 10 << 16, 0), + .dst = DRM_RECT_INIT(0, 0, 1 << 16, 0), + .min_range = 3, .max_range = 5, + .expected_scaling_factor = -ERANGE, + }, + { + .name = "out of min range", + .src = DRM_RECT_INIT(0, 0, 2 << 16, 0), + .dst = DRM_RECT_INIT(0, 0, 1 << 16, 0), + .min_range = 3, .max_range = 5, + .expected_scaling_factor = -ERANGE, + }, + { + .name = "zero dst width", + .src = DRM_RECT_INIT(0, 0, 2 << 16, 0), + .dst = DRM_RECT_INIT(0, 0, 0 << 16, 0), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = 0, + }, + { + .name = "negative src width", + .src = DRM_RECT_INIT(0, 0, -1 << 16, 0), + .dst = DRM_RECT_INIT(0, 0, 1 << 16, 0), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = -EINVAL, + }, + { + .name = "negative dst width", + .src = DRM_RECT_INIT(0, 0, 1 << 16, 0), + .dst = DRM_RECT_INIT(0, 0, -1 << 16, 0), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = -EINVAL, + }, +}; + +static void drm_rect_scale_case_desc(const struct drm_rect_scale_case *t, char *desc) +{ + strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(drm_rect_hscale, drm_rect_hscale_cases, drm_rect_scale_case_desc); + +static void drm_test_rect_calc_hscale(struct kunit *test) +{ + const struct drm_rect_scale_case *params = test->param_value; + int scaling_factor; + + scaling_factor = drm_rect_calc_hscale(¶ms->src, ¶ms->dst, + params->min_range, params->max_range); + + KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); +} + 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_PARAM(drm_test_rect_calc_hscale, drm_rect_hscale_gen_params), { } }; From patchwork Tue Apr 4 18:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13200884 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 391FEC6FD1D for ; Tue, 4 Apr 2023 18:42:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 610F010E765; Tue, 4 Apr 2023 18:42:30 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 44D9010E765 for ; Tue, 4 Apr 2023 18:42: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 mx0.riseup.net (Postfix) with ESMTPS id 4Prc7l3x6Yz9swt; Tue, 4 Apr 2023 18:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1680633747; bh=JmUJQY0/PZQ8w3L1Kjq9ObQwASlO1vRd5wgD3xC2GSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p4OofIeY+xHQw3+uEgv/1IhUQp0PjXTfYsOnnpuFXRAeZd5/KoJJjLmJlXBFMrUJu u2m+yFhtit8DxgC4YRJwGGI/H3W1d00fs5+gFIF6/nwVSaYq+5J41ILYqGwqUkZx+U X+/vTEGlkw58hteu5VNaZGe8JN4QXPy5IrLEUW78= X-Riseup-User-ID: 2123507E217BDE31779E64F4AE1355E3E8B8D02F1B53FF961238439F3C5E208D Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4Prc7g2pS9z1yNK; Tue, 4 Apr 2023 18:42:23 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 3/5] drm/tests: Add test cases for drm_rect_calc_vscale() Date: Tue, 4 Apr 2023 15:41:56 -0300 Message-Id: <20230404184158.26290-4-arthurgrillo@riseup.net> In-Reply-To: <20230404184158.26290-1-arthurgrillo@riseup.net> References: <20230404184158.26290-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 parameterized test for the drm_rect_calc_vscale() to ensure correctness and prevent future regressions. Besides the test for the usual case, tests the exceptions. It uses the same struct from drm_rect_calc_hscale(). Signed-off-by: Arthur Grillo --- drivers/gpu/drm/tests/drm_rect_test.c | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c index 293e5c48bb32..30bb4d84f3a0 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -414,6 +414,64 @@ static void drm_test_rect_calc_hscale(struct kunit *test) KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } +static const struct drm_rect_scale_case drm_rect_vscale_cases[] = { + { + .name = "normal use", + .src = DRM_RECT_INIT(0, 0, 0, 2 << 16), + .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = 2, + }, + { + .name = "out of max range", + .src = DRM_RECT_INIT(0, 0, 0, 10 << 16), + .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16), + .min_range = 3, .max_range = 5, + .expected_scaling_factor = -ERANGE, + }, + { + .name = "out of min range", + .src = DRM_RECT_INIT(0, 0, 0, 2 << 16), + .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16), + .min_range = 3, .max_range = 5, + .expected_scaling_factor = -ERANGE, + }, + { + .name = "zero dst height", + .src = DRM_RECT_INIT(0, 0, 0, 2 << 16), + .dst = DRM_RECT_INIT(0, 0, 0, 0 << 16), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = 0, + }, + { + .name = "negative src height", + .src = DRM_RECT_INIT(0, 0, 0, -1 << 16), + .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = -EINVAL, + }, + { + .name = "negative dst height", + .src = DRM_RECT_INIT(0, 0, 0, 1 << 16), + .dst = DRM_RECT_INIT(0, 0, 0, -1 << 16), + .min_range = 0, .max_range = INT_MAX, + .expected_scaling_factor = -EINVAL, + }, +}; + +KUNIT_ARRAY_PARAM(drm_rect_vscale, drm_rect_vscale_cases, drm_rect_scale_case_desc); + +static void drm_test_rect_calc_vscale(struct kunit *test) +{ + const struct drm_rect_scale_case *params = test->param_value; + int scaling_factor; + + scaling_factor = drm_rect_calc_vscale(¶ms->src, ¶ms->dst, + params->min_range, params->max_range); + + KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); +} + 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), @@ -421,6 +479,7 @@ static struct kunit_case drm_rect_tests[] = { KUNIT_CASE(drm_test_rect_clip_scaled_signed_vs_unsigned), KUNIT_CASE_PARAM(drm_test_rect_intersect, drm_rect_intersect_gen_params), KUNIT_CASE_PARAM(drm_test_rect_calc_hscale, drm_rect_hscale_gen_params), + KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_vscale_gen_params), { } }; From patchwork Tue Apr 4 18:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13200885 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 72591C6FD1D for ; Tue, 4 Apr 2023 18:42:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 920D710E766; Tue, 4 Apr 2023 18:42:35 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 13FB710E766 for ; Tue, 4 Apr 2023 18:42: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 4Prc7r4HcGz9swt; Tue, 4 Apr 2023 18:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1680633752; bh=QdD9QpG9dkNJj8fReBnyDvzkDFXKTPegFUNKJ79MWoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nh0mIkcGwO33dOyaXr8iAaDs3K9KJmK1uwW105YcbDWDlP3dS8kqzPI+RS1oHcH+H 0I5Fza5OnqeSijrfZ0VUjkb5tHWctHP6Vn9tHyNQx6XzkpvwjGNh6ozpaFtbzIQm8E AYKtihQ6ROSFBqWeLqGwZTXJ6YZmaCxeAaAvb55M= X-Riseup-User-ID: 57DF8B96F341B743AD08863AB65BC6B07F962D09E76E69C3AFB4D3792CFA949B Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4Prc7l73c4z1yjb; Tue, 4 Apr 2023 18:42:27 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 4/5] drm/tests: Add test cases for drm_rect_rotate() Date: Tue, 4 Apr 2023 15:41:57 -0300 Message-Id: <20230404184158.26290-5-arthurgrillo@riseup.net> In-Reply-To: <20230404184158.26290-1-arthurgrillo@riseup.net> References: <20230404184158.26290-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 a parameterized test for the drm_rect_rotate() to ensure correctness and prevent future regressions. All possible rotation modes are covered by the test. 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 30bb4d84f3a0..dca63552d289 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 @@ -472,6 +473,76 @@ static void drm_test_rect_calc_vscale(struct kunit *test) KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } +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_rotate_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_rotate_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), @@ -480,6 +551,7 @@ static struct kunit_case drm_rect_tests[] = { KUNIT_CASE_PARAM(drm_test_rect_intersect, drm_rect_intersect_gen_params), KUNIT_CASE_PARAM(drm_test_rect_calc_hscale, drm_rect_hscale_gen_params), KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_vscale_gen_params), + KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params), { } }; From patchwork Tue Apr 4 18:41:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Grillo X-Patchwork-Id: 13200886 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 90EBEC6FD1D for ; Tue, 4 Apr 2023 18:42:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B5FBC10E76B; Tue, 4 Apr 2023 18:42:40 +0000 (UTC) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 219BB10E769 for ; Tue, 4 Apr 2023 18:42: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 4Prc7x4nqdz9tG4; Tue, 4 Apr 2023 18:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1680633757; bh=JpaZ0SQl51V7z8ld+c7j18y1NfeZXdXo3cjc8A8YyjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5eDnWzdT9hP+CvayQE9qXdO3ZHHVWAFnHP1BlaKa4KhuzMeDhirhhuuRoPLElZQp LHsHLw8p5FEyXGLqvBMYSGTC37uDE7RHKbGGQppGkZYbyiqwaLflRDmCUUoR66c/zv pFwGymiEZkNK9ZsnYGIPYoJe7FMggHjHC/SxYlS4= X-Riseup-User-ID: 6CA6A8A777927615895A667E2BC9B853481FA2A5EB334F9EB93481CFC65EE4D7 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4Prc7s0q3Rz1yNK; Tue, 4 Apr 2023 18:42:32 +0000 (UTC) From: Arthur Grillo To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 5/5] drm/test: Add test cases for drm_rect_rotate_inv() Date: Tue, 4 Apr 2023 15:41:58 -0300 Message-Id: <20230404184158.26290-6-arthurgrillo@riseup.net> In-Reply-To: <20230404184158.26290-1-arthurgrillo@riseup.net> References: <20230404184158.26290-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 a parameterized test for the drm_rect_rotate_inv() to ensure its correctness and prevent future regressions. The test covers all rotation modes. It uses the same test cases from drm_test_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 dca63552d289..862b9435dcc6 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -543,6 +543,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), @@ -552,6 +562,7 @@ static struct kunit_case drm_rect_tests[] = { KUNIT_CASE_PARAM(drm_test_rect_calc_hscale, drm_rect_hscale_gen_params), KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_vscale_gen_params), 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), { } };