]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: tests: add Kconfig for KUnit test
authorYury Norov <ynorov@nvidia.com>
Fri, 17 Apr 2026 03:15:28 +0000 (23:15 -0400)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 8 Jun 2026 00:30:33 +0000 (02:30 +0200)
There are 6 individual Rust KUnit test suites (plus the doctests one). 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>
Reviewed-by: David Gow <david@davidgow.net>
Acked-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260417031531.315281-3-ynorov@nvidia.com
[ Fixed capitalization. Used singular for "API" for consistency.
  Reworded to clarify these are suites and that there exists
  the doctests one (which is the biggest at the moment by
  far). - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
init/Kconfig
rust/kernel/Kconfig.test [new file with mode: 0644]
rust/kernel/alloc/allocator.rs
rust/kernel/alloc/kvec.rs
rust/kernel/bitmap.rs
rust/kernel/kunit.rs
rust/kernel/str.rs
rust/kernel/sync/atomic/predefine.rs

index 7ef3fa222ca329d2c0f6b8c6153636e278885f56..bf1281569678d700a4587e491328b8468858cd00 100644 (file)
@@ -2213,6 +2213,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 (file)
index 0000000..3a8208b
--- /dev/null
@@ -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 API" 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 API" 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
index 562e41925ada533b0d443b3e7e9ad2fca740a773..cd4203f27aed0645b0fc0941dc700be501478474 100644 (file)
@@ -265,6 +265,7 @@ unsafe impl Allocator for KVmalloc {
     }
 }
 
+#[cfg(CONFIG_RUST_ALLOCATOR_KUNIT_TEST)]
 #[macros::kunit_tests(rust_allocator)]
 mod tests {
     use super::*;
index 6f35484387de9d39710cf44ec8e58bac9dc9a0cc..f7af62835aa84a3e4ca904e40c5456ac4aaa9280 100644 (file)
@@ -1508,6 +1508,7 @@ impl<'vec, T> Drop for DrainAll<'vec, T> {
     }
 }
 
+#[cfg(CONFIG_RUST_KVEC_KUNIT_TEST)]
 #[macros::kunit_tests(rust_kvec)]
 mod tests {
     use super::*;
index 894043c9e460b37c5b8de5bde470fe68647f6cf7..b27e0ec80d643da5d5510ee79e24493323e61b72 100644 (file)
@@ -499,6 +499,7 @@ impl Bitmap {
     }
 }
 
+#[cfg(CONFIG_RUST_BITMAP_KUNIT_TEST)]
 #[macros::kunit_tests(rust_kernel_bitmap)]
 mod tests {
     use super::*;
index a1edf7491579b1bffaba1f092c93c5b3c5f7fb03..cdee5f27bd7fa4ce9d3786cd6631b3da67204fac 100644 (file)
@@ -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::*;
index 8311d91549e15e56aaa08edd50f21e85b1be85a9..a435674f05eabf286a314d9d24938558e84cd9c6 100644 (file)
@@ -415,6 +415,7 @@ macro_rules! c_str {
     }};
 }
 
+#[cfg(CONFIG_RUST_STR_KUNIT_TEST)]
 #[kunit_tests(rust_kernel_str)]
 mod tests {
     use super::*;
index 84fcd7cfcb73cd1eb57f1d59eef95e089892d3d7..7468153429e18994e784e160123a4059359bdadb 100644 (file)
@@ -154,6 +154,7 @@ unsafe impl super::AtomicAdd<usize> for usize {
     }
 }
 
+#[cfg(CONFIG_RUST_ATOMICS_KUNIT_TEST)]
 #[macros::kunit_tests(rust_atomics)]
 mod tests {
     use super::super::*;