From: Albert Esteve <aesteve@redhat.com>
To: "Rob Herring" <robh@kernel.org>,
"Saravana Kannan" <saravanak@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>
Cc: devicetree@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
Albert Esteve <aesteve@redhat.com>,
mripard@kernel.org
Subject: [PATCH 5/5] rust: drm: add KUnit tests for panel
Date: Mon, 17 Aug 2026 13:40:50 +0200 [thread overview]
Message-ID: <20260817-drm_panel_bindings-v1-5-1f974508a31c@redhat.com> (raw)
In-Reply-To: <20260817-drm_panel_bindings-v1-0-1f974508a31c@redhat.com>
Add a test module to verify basic data type conversions
and layout. The tests covers:
- PanelOrientation and ConnectorType: TryFrom conversion for valid
values and also out-of-range invalid inputs.
- PanelContainer: layout invariants (offset, alignment, size) on which
Panel::new relies on for memory access.
Tests are gated on CONFIG_RUST_DRM_PANEL_KUNIT_TEST.
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
rust/kernel/Kconfig.test | 10 ++++++
rust/kernel/drm/panel.rs | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+)
diff --git a/rust/kernel/Kconfig.test b/rust/kernel/Kconfig.test
index e6a5c7a795f0f..397b916dca0d4 100644
--- a/rust/kernel/Kconfig.test
+++ b/rust/kernel/Kconfig.test
@@ -83,4 +83,14 @@ config RUST_BITFIELD_KUNIT_TEST
If unsure, say N.
+config RUST_DRM_PANEL_KUNIT_TEST
+ bool "KUnit tests for Rust panel API" if !KUNIT_ALL_TESTS
+ default KUNIT_ALL_TESTS
+ help
+ This option enables KUnit tests for the Rust panel API.
+ These are only for development and testing, not for regular
+ kernel use cases.
+
+ If unsure, say N.
+
endif
diff --git a/rust/kernel/drm/panel.rs b/rust/kernel/drm/panel.rs
index 8f87774e06ed7..3da203c39edd6 100644
--- a/rust/kernel/drm/panel.rs
+++ b/rust/kernel/drm/panel.rs
@@ -595,3 +595,90 @@ pub(crate) const fn build() -> &'static bindings::drm_panel_funcs {
&Self::VTABLE
}
}
+
+#[cfg(CONFIG_RUST_DRM_PANEL_KUNIT_TEST)]
+#[macros::kunit_tests(rust_kernel_drm_panel)]
+mod tests {
+ use super::*;
+ use core::mem::{align_of, offset_of, size_of, ManuallyDrop, MaybeUninit};
+
+ struct TestData {
+ _ptr: *const u8,
+ _byte: u8,
+ }
+
+ #[test]
+ fn panel_orientation() {
+ // Test valid values.
+ assert!(matches!(
+ PanelOrientation::try_from(-1),
+ Ok(PanelOrientation::Unknown)
+ ));
+ assert!(matches!(
+ PanelOrientation::try_from(0),
+ Ok(PanelOrientation::Normal)
+ ));
+ assert!(matches!(
+ PanelOrientation::try_from(1),
+ Ok(PanelOrientation::BottomUp)
+ ));
+ assert!(matches!(
+ PanelOrientation::try_from(2),
+ Ok(PanelOrientation::LeftUp)
+ ));
+ assert!(matches!(
+ PanelOrientation::try_from(3),
+ Ok(PanelOrientation::RightUp)
+ ));
+
+ // Test invalid values.
+ assert!(PanelOrientation::try_from(4).is_err());
+ assert!(PanelOrientation::try_from(-2).is_err());
+ }
+
+ #[test]
+ fn connector_type() {
+ // Test valid values.
+ assert!(matches!(
+ ConnectorType::try_from(0),
+ Ok(ConnectorType::Unknown)
+ ));
+ assert!(matches!(
+ ConnectorType::try_from(10),
+ Ok(ConnectorType::DisplayPort)
+ ));
+ assert!(matches!(
+ ConnectorType::try_from(14),
+ Ok(ConnectorType::eDP)
+ ));
+ assert!(matches!(
+ ConnectorType::try_from(16),
+ Ok(ConnectorType::DSI)
+ ));
+ assert!(matches!(
+ ConnectorType::try_from(20),
+ Ok(ConnectorType::USB)
+ ));
+
+ // Test invalid values.
+ assert!(ConnectorType::try_from(21).is_err());
+ }
+
+ #[test]
+ fn panel_container_layout() {
+ assert_eq!(offset_of!(PanelContainer<TestData>, data), 0);
+
+ assert_eq!(size_of::<ManuallyDrop<TestData>>(), size_of::<TestData>());
+
+ let panel_offset = offset_of!(PanelContainer<TestData>, panel);
+ assert_eq!(
+ panel_offset % align_of::<MaybeUninit<bindings::drm_panel>>(),
+ 0
+ );
+
+ assert!(
+ size_of::<PanelContainer<TestData>>()
+ >= panel_offset + size_of::<bindings::drm_panel>()
+ );
+ }
+}
--
2.55.0
next prev parent reply other threads:[~2026-08-17 11:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 11:40 [PATCH 0/5] rust: drm: add panel bindings Albert Esteve
2026-08-17 11:40 ` [PATCH 1/5] rust: of: add Node type Albert Esteve
2026-08-17 11:49 ` sashiko-bot
2026-08-17 15:18 ` Rob Herring
2026-08-18 7:20 ` Albert Esteve
2026-08-17 11:40 ` [PATCH 2/5] rust: drm: add connector abstraction Albert Esteve
2026-08-17 11:46 ` sashiko-bot
2026-08-17 11:40 ` [PATCH 3/5] rust: drm: add panel consumer abstractions Albert Esteve
2026-08-17 11:51 ` sashiko-bot
2026-08-17 11:40 ` [PATCH 4/5] rust: drm: add panel producer abstractions Albert Esteve
2026-08-17 11:53 ` sashiko-bot
2026-08-17 11:40 ` Albert Esteve [this message]
2026-08-17 11:52 ` [PATCH 5/5] rust: drm: add KUnit tests for panel sashiko-bot
2026-08-18 11:45 ` [PATCH 0/5] rust: drm: add panel bindings Maxime Ripard
2026-08-18 12:43 ` Albert Esteve
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=20260817-drm_panel_bindings-v1-5-1f974508a31c@redhat.com \
--to=aesteve@redhat.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mripard@kernel.org \
--cc=ojeda@kernel.org \
--cc=robh@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=saravanak@kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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