* [PATCH 0/3] rust: add Kconfig.test
@ 2026-04-17 3:15 Yury Norov
2026-04-17 3:15 ` [PATCH 1/3] rust: tests: drop 'use crate' in bitmap and atomic KUnit tests Yury Norov
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Yury Norov @ 2026-04-17 3:15 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Jonathan Corbet, Shuah Khan, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Burak Emir,
Yury Norov, Brendan Higgins, David Gow, Rae Moar, Will Deacon,
Peter Zijlstra, Mark Rutland, Nathan Chancellor, Kees Cook,
Nicolas Schier, Thomas Weißschuh, Thomas Gleixner,
Douglas Anderson, Shakeel Butt, Christian Brauner, Randy Dunlap,
Tamir Duberstein, rust-for-linux, linux-doc, linux-kernel,
linux-kselftest, kunit-dev
Cc: Yury Norov
There are 6 individual Rust KUnit tests. All the tests are compiled
unconditionally now, which adds ~200 kB to the kernel image on my
x86_64 buld. As Rust matures, this bloating will inevitably grow.
Add Kconfig.test, which provides a RUST_KUNIT_TESTS menu, and all
individual tests under it.
Yury Norov (3):
rust: tests: drop 'use crate' in bitmap and atomic KUnit tests
rust: testing: add Kconfig for KUnit test
Documentation: rust: testing: add Kconfig guidance
Documentation/rust/testing.rst | 5 ++-
init/Kconfig | 2 +
rust/kernel/Kconfig.test | 76 ++++++++++++++++++++++++++++
rust/kernel/alloc/allocator.rs | 1 +
rust/kernel/alloc/kvec.rs | 1 +
rust/kernel/bitmap.rs | 5 +--
rust/kernel/kunit.rs | 1 +
rust/kernel/str.rs | 1 +
rust/kernel/sync/atomic/predefine.rs | 5 +--
9 files changed, 79 insertions(+), 7 deletions(-)
create mode 100644 rust/kernel/Kconfig.test
--
2.51.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] rust: tests: drop 'use crate' in bitmap and atomic KUnit tests
2026-04-17 3:15 [PATCH 0/3] rust: add Kconfig.test Yury Norov
@ 2026-04-17 3:15 ` Yury Norov
2026-04-17 9:00 ` David Gow
2026-04-17 3:15 ` [PATCH 2/3] rust: testing: add Kconfig for KUnit test Yury Norov
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Yury Norov @ 2026-04-17 3:15 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Jonathan Corbet, Shuah Khan, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Burak Emir,
Yury Norov, Brendan Higgins, David Gow, Rae Moar, Will Deacon,
Peter Zijlstra, Mark Rutland, Nathan Chancellor, Kees Cook,
Nicolas Schier, Thomas Weißschuh, Thomas Gleixner,
Douglas Anderson, Shakeel Butt, Christian Brauner, Randy Dunlap,
Tamir Duberstein, rust-for-linux, linux-doc, linux-kernel,
linux-kselftest, kunit-dev
Cc: Yury Norov
The following patch makes usage of macros::kunit_tests crate conditional
on the corresponding configs. When the configs are disabled, compiler
warns on unused crate. So, embed it in unit test declaration.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
rust/kernel/bitmap.rs | 4 +---
rust/kernel/sync/atomic/predefine.rs | 4 +---
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
index 83d7dea99137..894043c9e460 100644
--- a/rust/kernel/bitmap.rs
+++ b/rust/kernel/bitmap.rs
@@ -499,9 +499,7 @@ pub fn next_zero_bit(&self, start: usize) -> Option<usize> {
}
}
-use macros::kunit_tests;
-
-#[kunit_tests(rust_kernel_bitmap)]
+#[macros::kunit_tests(rust_kernel_bitmap)]
mod tests {
use super::*;
use kernel::alloc::flags::GFP_KERNEL;
diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs
index 1d53834fcb12..84fcd7cfcb73 100644
--- a/rust/kernel/sync/atomic/predefine.rs
+++ b/rust/kernel/sync/atomic/predefine.rs
@@ -154,9 +154,7 @@ fn rhs_into_delta(rhs: usize) -> isize_atomic_repr {
}
}
-use crate::macros::kunit_tests;
-
-#[kunit_tests(rust_atomics)]
+#[macros::kunit_tests(rust_atomics)]
mod tests {
use super::super::*;
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] rust: testing: add Kconfig for KUnit test
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 3:15 ` Yury Norov
2026-04-17 9:00 ` David Gow
2026-04-17 3:15 ` [PATCH 3/3] Documentation: rust: testing: add Kconfig guidance Yury Norov
2026-04-17 14:11 ` [PATCH 0/3] rust: add Kconfig.test Gary Guo
3 siblings, 1 reply; 8+ messages in thread
From: Yury Norov @ 2026-04-17 3:15 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Jonathan Corbet, Shuah Khan, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Burak Emir,
Yury Norov, Brendan Higgins, David Gow, Rae Moar, Will Deacon,
Peter Zijlstra, Mark Rutland, Nathan Chancellor, Kees Cook,
Nicolas Schier, Thomas Weißschuh, Thomas Gleixner,
Douglas Anderson, Shakeel Butt, Christian Brauner, Randy Dunlap,
Tamir Duberstein, rust-for-linux, linux-doc, linux-kernel,
linux-kselftest, kunit-dev
Cc: Yury Norov
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] Documentation: rust: testing: add Kconfig guidance
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 3:15 ` [PATCH 2/3] rust: testing: add Kconfig for KUnit test Yury Norov
@ 2026-04-17 3:15 ` Yury Norov
2026-04-17 9:00 ` David Gow
2026-04-17 14:11 ` [PATCH 0/3] rust: add Kconfig.test Gary Guo
3 siblings, 1 reply; 8+ messages in thread
From: Yury Norov @ 2026-04-17 3:15 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Jonathan Corbet, Shuah Khan, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Burak Emir,
Yury Norov, Brendan Higgins, David Gow, Rae Moar, Will Deacon,
Peter Zijlstra, Mark Rutland, Nathan Chancellor, Kees Cook,
Nicolas Schier, Thomas Weißschuh, Thomas Gleixner,
Douglas Anderson, Shakeel Butt, Christian Brauner, Randy Dunlap,
Tamir Duberstein, rust-for-linux, linux-doc, linux-kernel,
linux-kselftest, kunit-dev
Cc: Yury Norov
Now that rust KUnit tests are protected with Kconfig, update the
documentation to mention it.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
Documentation/rust/testing.rst | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/Documentation/rust/testing.rst b/Documentation/rust/testing.rst
index f43cb77bcc69..24de173471b2 100644
--- a/Documentation/rust/testing.rst
+++ b/Documentation/rust/testing.rst
@@ -141,10 +141,13 @@ These tests are introduced by the ``kunit_tests`` procedural macro, which takes
the name of the test suite as an argument.
For instance, assume we want to test the function ``f`` from the documentation
-tests section. We could write, in the same file where we have our function:
+tests section. We could write, in the same file where we have our function.
+Each test is protected with the corresponding Kconfig option, see
+rust/kernel/Kconfig.test.
.. code-block:: rust
+ #[cfg(CONFIG_RUST_MYMOD_KUNIT_TEST)]
#[kunit_tests(rust_kernel_mymod)]
mod tests {
use super::*;
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] Documentation: rust: testing: add Kconfig guidance
2026-04-17 3:15 ` [PATCH 3/3] Documentation: rust: testing: add Kconfig guidance Yury Norov
@ 2026-04-17 9:00 ` David Gow
0 siblings, 0 replies; 8+ messages in thread
From: David Gow @ 2026-04-17 9:00 UTC (permalink / raw)
To: Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Jonathan Corbet, Shuah Khan,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Burak Emir, Yury Norov, Brendan Higgins,
Rae Moar, Will Deacon, Peter Zijlstra, Mark Rutland,
Nathan Chancellor, Kees Cook, Nicolas Schier,
Thomas Weißschuh, Thomas Gleixner, Douglas Anderson,
Shakeel Butt, Christian Brauner, Randy Dunlap, Tamir Duberstein,
rust-for-linux, linux-doc, linux-kernel, linux-kselftest,
kunit-dev
Le 17/04/2026 à 11:15 AM, Yury Norov a écrit :
> Now that rust KUnit tests are protected with Kconfig, update the
> documentation to mention it.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
Looks good to me.
Reviewed-by: David Gow <david@davidgow.net>
Cheers,
-- David
> Documentation/rust/testing.rst | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/rust/testing.rst b/Documentation/rust/testing.rst
> index f43cb77bcc69..24de173471b2 100644
> --- a/Documentation/rust/testing.rst
> +++ b/Documentation/rust/testing.rst
> @@ -141,10 +141,13 @@ These tests are introduced by the ``kunit_tests`` procedural macro, which takes
> the name of the test suite as an argument.
>
> For instance, assume we want to test the function ``f`` from the documentation
> -tests section. We could write, in the same file where we have our function:
> +tests section. We could write, in the same file where we have our function.
> +Each test is protected with the corresponding Kconfig option, see
> +rust/kernel/Kconfig.test.
>
> .. code-block:: rust
>
> + #[cfg(CONFIG_RUST_MYMOD_KUNIT_TEST)]
> #[kunit_tests(rust_kernel_mymod)]
> mod tests {
> use super::*;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] rust: testing: add Kconfig for KUnit test
2026-04-17 3:15 ` [PATCH 2/3] rust: testing: add Kconfig for KUnit test Yury Norov
@ 2026-04-17 9:00 ` David Gow
0 siblings, 0 replies; 8+ messages in thread
From: David Gow @ 2026-04-17 9:00 UTC (permalink / raw)
To: Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Jonathan Corbet, Shuah Khan,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Burak Emir, Yury Norov, Brendan Higgins,
Rae Moar, Will Deacon, Peter Zijlstra, Mark Rutland,
Nathan Chancellor, Kees Cook, Nicolas Schier,
Thomas Weißschuh, Thomas Gleixner, Douglas Anderson,
Shakeel Butt, Christian Brauner, Randy Dunlap, Tamir Duberstein,
rust-for-linux, linux-doc, linux-kernel, linux-kselftest,
kunit-dev
Le 17/04/2026 à 11:15 AM, Yury Norov a écrit :
> 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.
I think this makes a lot of sense for tests within the kernel crate (and
any other 'system' crates). Individual drivers probably should still
keep their Kconfig options under the corresponding subsystem.
>
> 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.
>
I think it's fine to leave this as implicitly part of rust/, personally.
Still, this looks good.
Reviewed-by: David Gow <david@davidgow.net>
Cheers,
-- David
> 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::*;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] rust: tests: drop 'use crate' in bitmap and atomic KUnit tests
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
0 siblings, 0 replies; 8+ messages in thread
From: David Gow @ 2026-04-17 9:00 UTC (permalink / raw)
To: Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Jonathan Corbet, Shuah Khan,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Burak Emir, Yury Norov, Brendan Higgins,
Rae Moar, Will Deacon, Peter Zijlstra, Mark Rutland,
Nathan Chancellor, Kees Cook, Nicolas Schier,
Thomas Weißschuh, Thomas Gleixner, Douglas Anderson,
Shakeel Butt, Christian Brauner, Randy Dunlap, Tamir Duberstein,
rust-for-linux, linux-doc, linux-kernel, linux-kselftest,
kunit-dev
Le 17/04/2026 à 11:15 AM, Yury Norov a écrit :
> The following patch makes usage of macros::kunit_tests crate conditional
> on the corresponding configs. When the configs are disabled, compiler
> warns on unused crate. So, embed it in unit test declaration.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
Looks good to me!
Reviewed-by: David Gow <david@davidgow.net>
Cheers,
-- David
> rust/kernel/bitmap.rs | 4 +---
> rust/kernel/sync/atomic/predefine.rs | 4 +---
> 2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
> index 83d7dea99137..894043c9e460 100644
> --- a/rust/kernel/bitmap.rs
> +++ b/rust/kernel/bitmap.rs
> @@ -499,9 +499,7 @@ pub fn next_zero_bit(&self, start: usize) -> Option<usize> {
> }
> }
>
> -use macros::kunit_tests;
> -
> -#[kunit_tests(rust_kernel_bitmap)]
> +#[macros::kunit_tests(rust_kernel_bitmap)]
> mod tests {
> use super::*;
> use kernel::alloc::flags::GFP_KERNEL;
> diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs
> index 1d53834fcb12..84fcd7cfcb73 100644
> --- a/rust/kernel/sync/atomic/predefine.rs
> +++ b/rust/kernel/sync/atomic/predefine.rs
> @@ -154,9 +154,7 @@ fn rhs_into_delta(rhs: usize) -> isize_atomic_repr {
> }
> }
>
> -use crate::macros::kunit_tests;
> -
> -#[kunit_tests(rust_atomics)]
> +#[macros::kunit_tests(rust_atomics)]
> mod tests {
> use super::super::*;
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] rust: add Kconfig.test
2026-04-17 3:15 [PATCH 0/3] rust: add Kconfig.test Yury Norov
` (2 preceding siblings ...)
2026-04-17 3:15 ` [PATCH 3/3] Documentation: rust: testing: add Kconfig guidance Yury Norov
@ 2026-04-17 14:11 ` Gary Guo
3 siblings, 0 replies; 8+ messages in thread
From: Gary Guo @ 2026-04-17 14:11 UTC (permalink / raw)
To: Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Jonathan Corbet, Shuah Khan,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Burak Emir, Yury Norov, Brendan Higgins,
David Gow, Rae Moar, Will Deacon, Peter Zijlstra, Mark Rutland,
Nathan Chancellor, Kees Cook, Nicolas Schier,
Thomas Weißschuh, Thomas Gleixner, Douglas Anderson,
Shakeel Butt, Christian Brauner, Randy Dunlap, Tamir Duberstein,
rust-for-linux, linux-doc, linux-kernel, linux-kselftest,
kunit-dev
On Fri Apr 17, 2026 at 4:15 AM BST, Yury Norov wrote:
> There are 6 individual Rust KUnit tests. All the tests are compiled
> unconditionally now, which adds ~200 kB to the kernel image on my
> x86_64 buld. As Rust matures, this bloating will inevitably grow.
>
> Add Kconfig.test, which provides a RUST_KUNIT_TESTS menu, and all
> individual tests under it.
>
> Yury Norov (3):
> rust: tests: drop 'use crate' in bitmap and atomic KUnit tests
> rust: testing: add Kconfig for KUnit test
> Documentation: rust: testing: add Kconfig guidance
Acked-by: Gary Guo <gary@garyguo.net>
>
> Documentation/rust/testing.rst | 5 ++-
> init/Kconfig | 2 +
> rust/kernel/Kconfig.test | 76 ++++++++++++++++++++++++++++
> rust/kernel/alloc/allocator.rs | 1 +
> rust/kernel/alloc/kvec.rs | 1 +
> rust/kernel/bitmap.rs | 5 +--
> rust/kernel/kunit.rs | 1 +
> rust/kernel/str.rs | 1 +
> rust/kernel/sync/atomic/predefine.rs | 5 +--
> 9 files changed, 79 insertions(+), 7 deletions(-)
> create mode 100644 rust/kernel/Kconfig.test
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-04-17 14:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/3] rust: testing: add Kconfig for KUnit test Yury Norov
2026-04-17 9:00 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox