summaryrefslogtreecommitdiff
path: root/drivers/gpu
diff options
context:
space:
mode:
authorEliot Courtney <ecourtney@nvidia.com>2026-08-27 17:51:50 +0900
committerAlexandre Courbot <acourbot@nvidia.com>2026-09-07 11:56:17 +0900
commit2c76c4ec9eb0c91f7b37795f83df8a34d4172285 (patch)
treeef10b40230dae94ec66b4b0464315d2272415f1b /drivers/gpu
parent5958450e98e52adb61c4967d67b76734ff9052c0 (diff)
gpu: nova-core: Add self-test assertion macros and config option
The existing assert! and assert_eq! macros cause a panic. For self tests in nova-core, it's inconvenient to cause a panic since these need to be run on actual hardware. Instead, define similar macros that log an error then return an Err. Also add the NOVA_CORE_SELFTESTS Kconfig option that gates the driver self-tests. Signed-off-by: Eliot Courtney <ecourtney@nvidia.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260827-pramin-split-v3-9-24b24d7afc52@nvidia.com Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/nova-core/Kconfig9
-rw-r--r--drivers/gpu/nova-core/nova_core.rs2
-rw-r--r--drivers/gpu/nova-core/selftest.rs64
3 files changed, 75 insertions, 0 deletions
diff --git a/drivers/gpu/nova-core/Kconfig b/drivers/gpu/nova-core/Kconfig
index f918f69e0599..cb7f0b00f796 100644
--- a/drivers/gpu/nova-core/Kconfig
+++ b/drivers/gpu/nova-core/Kconfig
@@ -15,3 +15,12 @@ config NOVA_CORE
This driver is work in progress and may not be functional.
If M is selected, the module will be called nova-core.
+
+config NOVA_CORE_SELFTESTS
+ bool "Nova Core driver self-tests"
+ depends on NOVA_CORE
+ default n
+ help
+ Build the driver self-tests and run them when the GPU is probed.
+
+ If unsure, say N.
diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
index 8f59cfa97017..1133c6ce5c55 100644
--- a/drivers/gpu/nova-core/nova_core.rs
+++ b/drivers/gpu/nova-core/nova_core.rs
@@ -23,6 +23,8 @@ mod mm;
mod num;
mod regs;
mod sbuffer;
+#[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
+mod selftest;
mod vbios;
mod vgpu;
diff --git a/drivers/gpu/nova-core/selftest.rs b/drivers/gpu/nova-core/selftest.rs
new file mode 100644
index 000000000000..f5b5965b7e6a
--- /dev/null
+++ b/drivers/gpu/nova-core/selftest.rs
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! Assertion macros for driver self-tests.
+//!
+//! Self-tests run against live hardware during probe, so a failed assertion should not panic. These
+//! macros log the failure on the device and fail the enclosing test by returning
+//! [`EIO`](kernel::error::code::EIO) instead.
+
+/// Like [`assert!`], but logs the failure via `dev` and fails the enclosing test instead of
+/// panicking.
+///
+/// As with [`assert!`], a custom message with format arguments can follow the condition.
+#[macro_export]
+macro_rules! selftest_assert {
+ ($dev:expr, $cond:expr $(,)?) => {
+ $crate::selftest_assert!($dev, $cond, "assertion failed: {}", ::core::stringify!($cond))
+ };
+ ($dev:expr, $cond:expr, $($arg:tt)+) => {{
+ if !$cond {
+ ::kernel::dev_err!(
+ $dev,
+ "Selftest: {}:{}: {}\n",
+ ::core::file!(),
+ ::core::line!(),
+ ::kernel::prelude::fmt!($($arg)+)
+ );
+ return Err(::kernel::error::code::EIO);
+ }
+ }};
+}
+
+/// Like [`assert_eq!`], but logs the failure via `dev` and fails the enclosing test instead of
+/// panicking.
+///
+/// As with [`assert_eq!`], a custom message with format arguments can follow the compared values.
+#[macro_export]
+macro_rules! selftest_assert_eq {
+ ($dev:expr, $left:expr, $right:expr $(,)?) => {
+ match (&$left, &$right) {
+ (left, right) => $crate::selftest_assert!(
+ $dev,
+ left == right,
+ "assertion `{} == {}` failed: left {:?}, right {:?}",
+ ::core::stringify!($left),
+ ::core::stringify!($right),
+ left,
+ right
+ ),
+ }
+ };
+ ($dev:expr, $left:expr, $right:expr, $($arg:tt)+) => {
+ match (&$left, &$right) {
+ (left, right) => $crate::selftest_assert!(
+ $dev,
+ left == right,
+ "assertion `left == right` failed: {}: left {:?}, right {:?}",
+ ::kernel::prelude::fmt!($($arg)+),
+ left,
+ right
+ ),
+ }
+ };
+}