From: Yury Norov <ynorov@nvidia.com>
To: "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>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Burak Emir" <bqe@google.com>,
"Yury Norov" <yury.norov@gmail.com>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <david@davidgow.net>,
"Rae Moar" <raemoar63@gmail.com>, "Will Deacon" <will@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Nathan Chancellor" <nathan@kernel.org>,
"Kees Cook" <kees@kernel.org>, "Nicolas Schier" <nsc@kernel.org>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Thomas Gleixner" <tglx@kernel.org>,
"Douglas Anderson" <dianders@chromium.org>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Christian Brauner" <brauner@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Tamir Duberstein" <tamird@kernel.org>,
rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com
Cc: Yury Norov <ynorov@nvidia.com>
Subject: [PATCH 2/3] rust: testing: add Kconfig for KUnit test
Date: Thu, 16 Apr 2026 23:15:28 -0400 [thread overview]
Message-ID: <20260417031531.315281-3-ynorov@nvidia.com> (raw)
In-Reply-To: <20260417031531.315281-1-ynorov@nvidia.com>
There are 6 individual Rust KUnit tests. All the tests are compiled
unconditionally now, which adds ~200 kB to the kernel image for me
on x86_64. As Rust matures, this bloating will inevitably grow.
Add Kconfig.test which includes a RUST_KUNIT_TESTS menu, and all
individual tests under it.
As usual, new tests are all enabled if KUNIT_ALL_TESTS=y.
Suggested-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
This doesn't create a new entry in MAINTAINERS for the Kconfig.test,
so the new file just follows the implicit rule for the rust/ directory.
Please let me know if the explicit entry is needed.
init/Kconfig | 2 +
rust/kernel/Kconfig.test | 76 ++++++++++++++++++++++++++++
rust/kernel/alloc/allocator.rs | 1 +
rust/kernel/alloc/kvec.rs | 1 +
rust/kernel/bitmap.rs | 1 +
rust/kernel/kunit.rs | 1 +
rust/kernel/str.rs | 1 +
rust/kernel/sync/atomic/predefine.rs | 1 +
8 files changed, 84 insertions(+)
create mode 100644 rust/kernel/Kconfig.test
diff --git a/init/Kconfig b/init/Kconfig
index 43875ef36752..4af544514e6c 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2208,6 +2208,8 @@ config RUST
If unsure, say N.
+source "rust/kernel/Kconfig.test"
+
config RUSTC_VERSION_TEXT
string
depends on RUST
diff --git a/rust/kernel/Kconfig.test b/rust/kernel/Kconfig.test
new file mode 100644
index 000000000000..a05243696a01
--- /dev/null
+++ b/rust/kernel/Kconfig.test
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: GPL-2.0-only
+menuconfig RUST_KUNIT_TESTS
+ bool "Rust KUnit tests"
+ depends on KUNIT && RUST
+ default KUNIT_ALL_TESTS
+ help
+ This menu collects all options for Rust Kunit tests.
+ See Documentation/rust/testing.rst for how to protect
+ unit tests with these options.
+
+ Say Y here to enable Rust KUnit tests.
+
+ If unsure, say N.
+
+if RUST_KUNIT_TESTS
+config RUST_ALLOCATOR_KUNIT_TEST
+ bool "KUnit tests for Rust allocator API" if !KUNIT_ALL_TESTS
+ default KUNIT_ALL_TESTS
+ help
+ This option enables KUnit tests for the Rust allocator API.
+ These are only for development and testing, not for regular
+ kernel use cases.
+
+ If unsure, say N.
+
+config RUST_KVEC_KUNIT_TEST
+ bool "KUnit tests for Rust KVEC API" if !KUNIT_ALL_TESTS
+ default KUNIT_ALL_TESTS
+ help
+ This option enables KUnit tests for the Rust KVEC API.
+ These are only for development and testing, not for
+ regular kernel use cases.
+
+ If unsure, say N.
+
+config RUST_BITMAP_KUNIT_TEST
+ bool "KUnit tests for Rust bitmap API" if !KUNIT_ALL_TESTS
+ default KUNIT_ALL_TESTS
+ help
+ This option enables KUnit tests for the Rust bitmap API.
+ These are only for development and testing, not for regular
+ kernel use cases.
+
+ If unsure, say N.
+
+config RUST_KUNIT_SELFTEST
+ bool "KUnit selftests for Rust" if !KUNIT_ALL_TESTS
+ default KUNIT_ALL_TESTS
+ help
+ This option enables KUnit selftests. These are only
+ for development and testing, not for regular kernel
+ use cases.
+
+ If unsure, say N.
+
+config RUST_STR_KUNIT_TEST
+ bool "KUnit tests for Rust strings APIs" if !KUNIT_ALL_TESTS
+ default KUNIT_ALL_TESTS
+ help
+ This option enables KUnit tests for the Rust strings API.
+ These are only for development and testing, not for regular
+ kernel use cases.
+
+ If unsure, say N.
+
+config RUST_ATOMICS_KUNIT_TEST
+ bool "KUnit tests for Rust atomics APIs" if !KUNIT_ALL_TESTS
+ default KUNIT_ALL_TESTS
+ help
+ This option enables KUnit tests for the Rust atomics API.
+ These are only for development and testing, not for regular
+ kernel use cases.
+
+ If unsure, say N.
+
+endif
diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs
index 63bfb91b3671..0d3434bca867 100644
--- a/rust/kernel/alloc/allocator.rs
+++ b/rust/kernel/alloc/allocator.rs
@@ -251,6 +251,7 @@ unsafe fn realloc(
}
}
+#[cfg(CONFIG_RUST_ALLOCATOR_KUNIT_TEST)]
#[macros::kunit_tests(rust_allocator)]
mod tests {
use super::*;
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index ac8d6f763ae8..563c760c8105 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -1351,6 +1351,7 @@ fn drop(&mut self) {
}
}
+#[cfg(CONFIG_RUST_KVEC_KUNIT_TEST)]
#[macros::kunit_tests(rust_kvec)]
mod tests {
use super::*;
diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
index 894043c9e460..b27e0ec80d64 100644
--- a/rust/kernel/bitmap.rs
+++ b/rust/kernel/bitmap.rs
@@ -499,6 +499,7 @@ pub fn next_zero_bit(&self, start: usize) -> Option<usize> {
}
}
+#[cfg(CONFIG_RUST_BITMAP_KUNIT_TEST)]
#[macros::kunit_tests(rust_kernel_bitmap)]
mod tests {
use super::*;
diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
index a1edf7491579..cdee5f27bd7f 100644
--- a/rust/kernel/kunit.rs
+++ b/rust/kernel/kunit.rs
@@ -329,6 +329,7 @@ pub fn in_kunit_test() -> bool {
!unsafe { bindings::kunit_get_current_test() }.is_null()
}
+#[cfg(CONFIG_RUST_KUNIT_SELFTEST)]
#[kunit_tests(rust_kernel_kunit)]
mod tests {
use super::*;
diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 8311d91549e1..a435674f05ea 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -415,6 +415,7 @@ macro_rules! c_str {
}};
}
+#[cfg(CONFIG_RUST_STR_KUNIT_TEST)]
#[kunit_tests(rust_kernel_str)]
mod tests {
use super::*;
diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs
index 84fcd7cfcb73..7468153429e1 100644
--- a/rust/kernel/sync/atomic/predefine.rs
+++ b/rust/kernel/sync/atomic/predefine.rs
@@ -154,6 +154,7 @@ fn rhs_into_delta(rhs: usize) -> isize_atomic_repr {
}
}
+#[cfg(CONFIG_RUST_ATOMICS_KUNIT_TEST)]
#[macros::kunit_tests(rust_atomics)]
mod tests {
use super::super::*;
--
2.51.0
next prev parent reply other threads:[~2026-04-17 3:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 3:15 [PATCH 0/3] rust: add Kconfig.test Yury Norov
2026-04-17 3:15 ` [PATCH 1/3] rust: tests: drop 'use crate' in bitmap and atomic KUnit tests Yury Norov
2026-04-17 9:00 ` David Gow
2026-04-17 3:15 ` Yury Norov [this message]
2026-04-17 9:00 ` [PATCH 2/3] rust: testing: add Kconfig for KUnit test David Gow
2026-04-17 3:15 ` [PATCH 3/3] Documentation: rust: testing: add Kconfig guidance Yury Norov
2026-04-17 9:00 ` David Gow
2026-04-17 14:11 ` [PATCH 0/3] rust: add Kconfig.test Gary Guo
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=20260417031531.315281-3-ynorov@nvidia.com \
--to=ynorov@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=bqe@google.com \
--cc=brauner@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=david@davidgow.net \
--cc=dianders@chromium.org \
--cc=gary@garyguo.net \
--cc=kees@kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=mark.rutland@arm.com \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=raemoar63@gmail.com \
--cc=rdunlap@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=will@kernel.org \
--cc=yury.norov@gmail.com \
/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