From: Munique Feitoza <muniquefeitoz4@gmail.com>
To: Lyude Paul <lyude.paul@maintainer.cc>,
Danilo Krummrich <dakr@kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
Munique Feitoza <muniquefeitoz4@gmail.com>
Subject: [PATCH 1/2] drm/nouveau: add KUnit tests for dispnv50 head helpers
Date: Sun, 6 Dec 2026 05:50:42 -0300 [thread overview]
Message-ID: <20261206085043.76059-2-muniquefeitoz4@gmail.com> (raw)
In-Reply-To: <20261206085043.76059-1-muniquefeitoz4@gmail.com>
Add CONFIG_DRM_NOUVEAU_KUNIT_TEST and initial KUnit test suite for
dispnv50 head mode and view calculations (nv50_head_atomic_check_mode()
and nv50_head_atomic_check_view()).
Signed-off-by: Munique Feitoza <muniquefeitoz4@gmail.com>
---
drivers/gpu/drm/nouveau/Kbuild | 1 +
drivers/gpu/drm/nouveau/Kconfig | 10 +
drivers/gpu/drm/nouveau/dispnv50/head.c | 7 +-
drivers/gpu/drm/nouveau/dispnv50/head.h | 10 +
drivers/gpu/drm/nouveau/tests/Makefile | 11 +
.../gpu/drm/nouveau/tests/nv50_head_test.c | 260 ++++++++++++++++++
6 files changed, 297 insertions(+), 2 deletions(-)
create mode 100644 drivers/gpu/drm/nouveau/tests/Makefile
create mode 100644 drivers/gpu/drm/nouveau/tests/nv50_head_test.c
diff --git a/drivers/gpu/drm/nouveau/Kbuild b/drivers/gpu/drm/nouveau/Kbuild
index 385d24530d1e60..cee8616bdad649 100644
--- a/drivers/gpu/drm/nouveau/Kbuild
+++ b/drivers/gpu/drm/nouveau/Kbuild
@@ -72,3 +72,4 @@ nouveau-y += nvc0_fence.o
nouveau-y += gv100_fence.o
obj-$(CONFIG_DRM_NOUVEAU) += nouveau.o
+obj-$(CONFIG_DRM_NOUVEAU_KUNIT_TEST) += tests/
diff --git a/drivers/gpu/drm/nouveau/Kconfig b/drivers/gpu/drm/nouveau/Kconfig
index 3b5757aed9c842..7bf606213a633b 100644
--- a/drivers/gpu/drm/nouveau/Kconfig
+++ b/drivers/gpu/drm/nouveau/Kconfig
@@ -120,3 +120,13 @@ config DRM_NOUVEAU_SIL164
help
Support for sil164 and similar single-link (or dual-link
when used in pairs) TMDS transmitters.
+
+config DRM_NOUVEAU_KUNIT_TEST
+ tristate "KUnit tests for Nouveau" if !KUNIT_ALL_TESTS
+ depends on DRM_NOUVEAU && KUNIT
+ default KUNIT_ALL_TESTS
+ help
+ This builds KUnit unit tests for the Nouveau DRM driver, covering
+ dispnv50 head mode and view calculations without requiring physical
+ NVIDIA GPU hardware. This option is not useful for distributions
+ or general kernels, only for kernel developers working on Nouveau.
diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.c b/drivers/gpu/drm/nouveau/dispnv50/head.c
index 6a3a93de0cbfe7..a297a59953a9bd 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/head.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/head.c
@@ -33,6 +33,7 @@
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_edid.h>
+#include <kunit/visibility.h>
#include <drm/drm_vblank.h>
#include "nouveau_connector.h"
@@ -123,7 +124,7 @@ nv50_head_atomic_check_dither(struct nv50_head_atom *armh,
asyh->set.dither = true;
}
-static void
+VISIBLE_IF_KUNIT void
nv50_head_atomic_check_view(struct nv50_head_atom *armh,
struct nv50_head_atom *asyh,
struct nouveau_conn_atom *asyc)
@@ -220,6 +221,7 @@ nv50_head_atomic_check_view(struct nv50_head_atom *armh,
asyh->set.view = true;
}
+EXPORT_SYMBOL_IF_KUNIT(nv50_head_atomic_check_view);
static int
nv50_head_atomic_check_lut(struct nv50_head *head,
@@ -279,7 +281,7 @@ nv50_head_atomic_check_lut(struct nv50_head *head,
return 0;
}
-static void
+VISIBLE_IF_KUNIT void
nv50_head_atomic_check_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
{
struct drm_display_mode *mode = &asyh->state.adjusted_mode;
@@ -328,6 +330,7 @@ nv50_head_atomic_check_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
asyh->set.or = head->func->or != NULL;
asyh->set.mode = true;
}
+EXPORT_SYMBOL_IF_KUNIT(nv50_head_atomic_check_mode);
static int
nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state)
diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.h b/drivers/gpu/drm/nouveau/dispnv50/head.h
index 8bd2fcb1eff5eb..dbfc8aa9f87dc4 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/head.h
+++ b/drivers/gpu/drm/nouveau/dispnv50/head.h
@@ -27,6 +27,16 @@ void nv50_head_flush_set_wndw(struct nv50_head *head, struct nv50_head_atom *asy
void nv50_head_flush_clr(struct nv50_head *head,
struct nv50_head_atom *asyh, bool flush);
+#if IS_ENABLED(CONFIG_KUNIT)
+struct nouveau_conn_atom;
+
+void nv50_head_atomic_check_view(struct nv50_head_atom *armh,
+ struct nv50_head_atom *asyh,
+ struct nouveau_conn_atom *asyc);
+void nv50_head_atomic_check_mode(struct nv50_head *head,
+ struct nv50_head_atom *asyh);
+#endif
+
struct nv50_head_func {
int (*view)(struct nv50_head *, struct nv50_head_atom *);
int (*mode)(struct nv50_head *, struct nv50_head_atom *);
diff --git a/drivers/gpu/drm/nouveau/tests/Makefile b/drivers/gpu/drm/nouveau/tests/Makefile
new file mode 100644
index 00000000000000..e9e16933295a6a
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/tests/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+ccflags-y += -I $(src)/../include
+ccflags-y += -I $(src)/../include/nvkm
+ccflags-y += -I $(src)/../nvkm
+ccflags-y += -I $(src)/..
+
+nouveau-kunit-tests-y := \
+ nv50_head_test.o
+
+obj-$(CONFIG_DRM_NOUVEAU_KUNIT_TEST) += nouveau-kunit-tests.o
diff --git a/drivers/gpu/drm/nouveau/tests/nv50_head_test.c b/drivers/gpu/drm/nouveau/tests/nv50_head_test.c
new file mode 100644
index 00000000000000..a54a2cebfed3a6
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/tests/nv50_head_test.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <kunit/test.h>
+
+#include <drm/drm_connector.h>
+#include <drm/drm_modes.h>
+
+#include "../dispnv50/head.h"
+#include "../nouveau_connector.h"
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static const struct nv50_head_func test_head_func_with_or = {
+ .or = (void *)0x1,
+};
+
+static struct drm_display_mode make_1080p_mode(void)
+{
+ return (struct drm_display_mode) {
+ .clock = 148500,
+ .hdisplay = 1920,
+ .hsync_start = 2008,
+ .hsync_end = 2052,
+ .htotal = 2200,
+ .vdisplay = 1080,
+ .vsync_start = 1084,
+ .vsync_end = 1089,
+ .vtotal = 1125,
+ .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
+ };
+}
+
+static void nv50_head_test_mode_progressive(struct kunit *test)
+{
+ struct nv50_head *head;
+ struct nv50_head_atom *asyh;
+
+ head = kunit_kzalloc(test, sizeof(*head), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, head);
+ asyh = kunit_kzalloc(test, sizeof(*asyh), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, asyh);
+
+ head->func = &test_head_func_with_or;
+ asyh->state.adjusted_mode = make_1080p_mode();
+
+ nv50_head_atomic_check_mode(head, asyh);
+
+ KUNIT_EXPECT_EQ(test, asyh->mode.h.active, 2200);
+ KUNIT_EXPECT_EQ(test, asyh->mode.h.synce, 2052 - 2008 - 1);
+ KUNIT_EXPECT_EQ(test, asyh->mode.h.blanke, 2200 - 2008 - 1);
+ KUNIT_EXPECT_EQ(test, asyh->mode.h.blanks, (2200 - 2008 - 1) + 1920);
+
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.active, 1125);
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.synce, 1089 - 1084 - 1);
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.blanke, 1125 - 1084 - 1);
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.blanks, (1125 - 1084 - 1) + 1080);
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2e, 0);
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2s, 1);
+
+ KUNIT_EXPECT_FALSE(test, asyh->mode.interlace);
+ KUNIT_EXPECT_EQ(test, asyh->mode.clock, 148500);
+ KUNIT_EXPECT_FALSE(test, asyh->or.nhsync);
+ KUNIT_EXPECT_FALSE(test, asyh->or.nvsync);
+ KUNIT_EXPECT_TRUE(test, asyh->set.or);
+ KUNIT_EXPECT_TRUE(test, asyh->set.mode);
+}
+
+static void nv50_head_test_mode_interlaced_neg_sync(struct kunit *test)
+{
+ struct nv50_head *head;
+ struct nv50_head_atom *asyh;
+ struct drm_display_mode mode = make_1080p_mode();
+
+ head = kunit_kzalloc(test, sizeof(*head), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, head);
+ asyh = kunit_kzalloc(test, sizeof(*asyh), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, asyh);
+
+ head->func = &test_head_func_with_or;
+ mode.flags = DRM_MODE_FLAG_INTERLACE |
+ DRM_MODE_FLAG_NHSYNC |
+ DRM_MODE_FLAG_NVSYNC;
+ asyh->state.adjusted_mode = mode;
+
+ nv50_head_atomic_check_mode(head, asyh);
+
+ KUNIT_EXPECT_TRUE(test, asyh->mode.interlace);
+ /* CRTC_INTERLACE_HALVE_V halves vertical timings before doubling */
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2e,
+ (1125 / 2) + ((1125 / 2) - (1084 / 2) - 1));
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2s,
+ asyh->mode.v.blank2e + (1080 / 2));
+ KUNIT_EXPECT_EQ(test, asyh->mode.v.active, ((1125 / 2) * 2) + 1);
+ KUNIT_EXPECT_TRUE(test, asyh->or.nhsync);
+ KUNIT_EXPECT_TRUE(test, asyh->or.nvsync);
+}
+
+static void alloc_view_fixtures(struct kunit *test,
+ struct drm_connector **conn,
+ struct nv50_head_atom **armh,
+ struct nv50_head_atom **asyh,
+ struct nouveau_conn_atom **asyc)
+{
+ *conn = kunit_kzalloc(test, sizeof(**conn), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, *conn);
+ *armh = kunit_kzalloc(test, sizeof(**armh), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, *armh);
+ *asyh = kunit_kzalloc(test, sizeof(**asyh), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, *asyh);
+ *asyc = kunit_kzalloc(test, sizeof(**asyc), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, *asyc);
+ (*asyc)->state.connector = *conn;
+}
+
+static void nv50_head_test_view_scale_none(struct kunit *test)
+{
+ struct drm_connector *conn;
+ struct nv50_head_atom *armh, *asyh;
+ struct nouveau_conn_atom *asyc;
+
+ alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+ asyc->scaler.mode = DRM_MODE_SCALE_NONE;
+ asyc->scaler.full = false;
+
+ asyh->state.mode = (struct drm_display_mode) {
+ .hdisplay = 1280,
+ .vdisplay = 720,
+ .vtotal = 750,
+ };
+ asyh->state.adjusted_mode = make_1080p_mode();
+
+ nv50_head_atomic_check_view(armh, asyh, asyc);
+
+ KUNIT_EXPECT_EQ(test, asyh->view.iW, 1280);
+ KUNIT_EXPECT_EQ(test, asyh->view.iH, 720);
+ KUNIT_EXPECT_EQ(test, asyh->view.oW, 1280);
+ KUNIT_EXPECT_EQ(test, asyh->view.oH, 720);
+ KUNIT_EXPECT_TRUE(test, asyh->set.view);
+}
+
+static void nv50_head_test_view_scale_center(struct kunit *test)
+{
+ struct drm_connector *conn;
+ struct nv50_head_atom *armh, *asyh;
+ struct nouveau_conn_atom *asyc;
+
+ alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+ asyc->scaler.mode = DRM_MODE_SCALE_CENTER;
+
+ /* Smaller input than output: centered 1:1 */
+ asyh->state.mode = (struct drm_display_mode) {
+ .hdisplay = 800,
+ .vdisplay = 600,
+ .vtotal = 628,
+ };
+ asyh->state.adjusted_mode = make_1080p_mode();
+
+ nv50_head_atomic_check_view(armh, asyh, asyc);
+
+ KUNIT_EXPECT_EQ(test, asyh->view.iW, 800);
+ KUNIT_EXPECT_EQ(test, asyh->view.iH, 600);
+ KUNIT_EXPECT_EQ(test, asyh->view.oW, 800);
+ KUNIT_EXPECT_EQ(test, asyh->view.oH, 600);
+
+ /* Larger input than output: clamped to output dimensions */
+ asyh->state.mode = (struct drm_display_mode) {
+ .hdisplay = 2560,
+ .vdisplay = 1440,
+ .vtotal = 1481,
+ };
+
+ nv50_head_atomic_check_view(armh, asyh, asyc);
+
+ KUNIT_EXPECT_EQ(test, asyh->view.oW, 1920);
+ KUNIT_EXPECT_EQ(test, asyh->view.oH, 1080);
+}
+
+static void nv50_head_test_view_scale_aspect(struct kunit *test)
+{
+ struct drm_connector *conn;
+ struct nv50_head_atom *armh, *asyh;
+ struct nouveau_conn_atom *asyc;
+
+ alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+ asyc->scaler.mode = DRM_MODE_SCALE_ASPECT;
+
+ /* 4:3 input on 16:9 output -> letterbox left/right (1440x1080) */
+ asyh->state.mode = (struct drm_display_mode) {
+ .hdisplay = 800,
+ .vdisplay = 600,
+ .vtotal = 628,
+ };
+ asyh->state.adjusted_mode = make_1080p_mode();
+
+ nv50_head_atomic_check_view(armh, asyh, asyc);
+
+ KUNIT_EXPECT_EQ(test, asyh->view.oW, 1440);
+ KUNIT_EXPECT_EQ(test, asyh->view.oH, 1080);
+
+ /* 16:9 input on 4:3 output -> letterbox top/bottom (1024x576) */
+ asyh->state.mode = make_1080p_mode();
+ asyh->state.adjusted_mode = (struct drm_display_mode) {
+ .hdisplay = 1024,
+ .vdisplay = 768,
+ .vtotal = 806,
+ };
+
+ nv50_head_atomic_check_view(armh, asyh, asyc);
+
+ KUNIT_EXPECT_EQ(test, asyh->view.oW, 1024);
+ KUNIT_EXPECT_EQ(test, asyh->view.oH, 576);
+}
+
+static void nv50_head_test_view_underscan_and_3d(struct kunit *test)
+{
+ struct drm_connector *conn;
+ struct nv50_head_atom *armh, *asyh;
+ struct nouveau_conn_atom *asyc;
+
+ alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+ asyc->scaler.mode = DRM_MODE_SCALE_FULLSCREEN;
+ asyc->scaler.underscan.mode = UNDERSCAN_ON;
+ asyc->scaler.underscan.hborder = 40;
+ asyc->scaler.underscan.vborder = 20;
+
+ asyh->state.mode = (struct drm_display_mode) {
+ .hdisplay = 1920,
+ .vdisplay = 1080,
+ .vtotal = 1125,
+ .flags = DRM_MODE_FLAG_3D_FRAME_PACKING,
+ };
+ asyh->state.adjusted_mode = make_1080p_mode();
+
+ nv50_head_atomic_check_view(armh, asyh, asyc);
+
+ KUNIT_EXPECT_EQ(test, asyh->view.iW, 1920);
+ KUNIT_EXPECT_EQ(test, asyh->view.iH, 1080 + 1125);
+ KUNIT_EXPECT_EQ(test, asyh->view.oW, 1920 - 80);
+ KUNIT_EXPECT_EQ(test, asyh->view.oH, 1080 - 40);
+}
+
+static struct kunit_case nv50_head_test_cases[] = {
+ KUNIT_CASE(nv50_head_test_mode_progressive),
+ KUNIT_CASE(nv50_head_test_mode_interlaced_neg_sync),
+ KUNIT_CASE(nv50_head_test_view_scale_none),
+ KUNIT_CASE(nv50_head_test_view_scale_center),
+ KUNIT_CASE(nv50_head_test_view_scale_aspect),
+ KUNIT_CASE(nv50_head_test_view_underscan_and_3d),
+ { }
+};
+
+static struct kunit_suite nv50_head_test_suite = {
+ .name = "nouveau-nv50-head",
+ .test_cases = nv50_head_test_cases,
+};
+
+kunit_test_suite(nv50_head_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for Nouveau dispnv50 head helpers");
+MODULE_LICENSE("GPL");
--
2.56.1
next prev parent reply other threads:[~2026-12-06 8:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 8:50 [PATCH 0/2] drm/nouveau: add initial KUnit test suite Munique Feitoza
2026-12-06 8:50 ` Munique Feitoza [this message]
2026-12-06 8:50 ` [PATCH 2/2] drm/nouveau: add KUnit tests for gt215_pll_calc() Munique Feitoza
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=20261206085043.76059-2-muniquefeitoz4@gmail.com \
--to=muniquefeitoz4@gmail.com \
--cc=airlied@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude.paul@maintainer.cc \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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®