From: nelsonbogado99 <nelosonbrizue99@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org,
"Maíra Canal" <mairacanal@riseup.net>,
"Arthur Grillo" <arthurgrillo@riseup.net>,
"Javier Martinez Canillas" <javierm@redhat.com>,
"Nelson Bogado" <nelosonbrizue99@gmail.com>
Subject: [PATCH] drm/tests: Add test case for drm_rect_clip_scaled()
Date: Wed, 14 Jun 2023 13:54:31 -0400 [thread overview]
Message-ID: <20230614175431.6496-1-nelosonbrizue99@gmail.com> (raw)
From: Nelson Bogado <nelosonbrizue99@gmail.com>
To evaluate the behavior of the drm_rect_clip_scaled() helper function
with misplaced rectangles and improve the robustness and quality of it.
The new test was executed using the following command:
$ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/tests/
[01:48:12] ================== drm_rect (10 subtests) ==================
...
[01:48:12] [PASSED] drm_test_rect_clip_scaled_out_of_bounds
Signed-off-by: Nelson Bogado <nelosonbrizue99@gmail.com>
---
drivers/gpu/drm/tests/drm_rect_test.c | 53 +++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
index 76332cd2ead8..b3bfdd420123 100644
--- a/drivers/gpu/drm/tests/drm_rect_test.c
+++ b/drivers/gpu/drm/tests/drm_rect_test.c
@@ -209,6 +209,58 @@ 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");
}
+static void drm_test_rect_clip_scaled_out_of_bounds(struct kunit *test)
+{
+ /* Definition of the rectangles and visible variables */
+ struct drm_rect src, dst, clip;
+ bool visible;
+
+ /*
+ * Both rectangles are completely out of bounds, initialize the src,
+ * dst and clip rectangles with specific coordinates and sizes.
+ */
+ drm_rect_init(&src, -10, -10, -5, -5);
+ drm_rect_init(&dst, -20, -20, -15, -15);
+ drm_rect_init(&clip, 0, 0, 100, 100);
+
+ /* Function call drm_rect_clip_scaled to determine visibility */
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ /* Check expected results */
+ KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination should not be visible\n");
+ KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
+
+ /*
+ * Only source rectangle is out of bounds, reinitialize the src,
+ * dst and clip rectangles with new values.
+ */
+ drm_rect_init(&src, -10, -10, -5, -5);
+ drm_rect_init(&dst, 0, 0, 10, 10);
+ drm_rect_init(&clip, 0, 0, 100, 100);
+
+ /* Function call drm_rect_clip_scaled to determine visibility */
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ /* Check expected results */
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n\n");
+ KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
+
+ /*
+ * Only source rectangle is out of bounds, reinitialize the src,
+ * dst and clip rectangles with new values.
+ */
+ drm_rect_init(&src, 0, 0, 10, 10);
+ drm_rect_init(&dst, -10, -10, -5, -5);
+ drm_rect_init(&clip, 0, 0, 100, 100);
+
+ /* Function call drm_rect_clip_scaled to determine visibility */
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ /* Check expected results */
+ KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination should not be visible\n");
+ 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;
@@ -511,6 +563,7 @@ static struct kunit_case drm_rect_tests[] = {
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(drm_test_rect_clip_scaled_out_of_bounds),
KUNIT_CASE_PARAM(drm_test_rect_intersect, drm_rect_intersect_gen_params),
KUNIT_CASE_PARAM(drm_test_rect_calc_hscale, drm_rect_scale_gen_params),
KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_scale_gen_params),
--
2.40.1
next reply other threads:[~2023-06-14 17:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-14 17:54 nelsonbogado99 [this message]
2023-06-21 18:33 ` Arthur Grillo Queiroz Cabral
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230614175431.6496-1-nelosonbrizue99@gmail.com \
--to=nelosonbrizue99@gmail.com \
--cc=arthurgrillo@riseup.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mairacanal@riseup.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®