mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
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>
This commit is contained in:
parent
5958450e98
commit
2c76c4ec9e
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
mod num;
|
||||
mod regs;
|
||||
mod sbuffer;
|
||||
#[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
|
||||
mod selftest;
|
||||
mod vbios;
|
||||
mod vgpu;
|
||||
|
||||
|
|
|
|||
64
drivers/gpu/nova-core/selftest.rs
Normal file
64
drivers/gpu/nova-core/selftest.rs
Normal file
|
|
@ -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
|
||||
),
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user