]> www.infradead.org Git - users/hch/misc.git/commitdiff
rust: kernel: remove support for unused host `#[test]`s
authorMiguel Ojeda <ojeda@kernel.org>
Sat, 26 Jul 2025 18:07:50 +0000 (20:07 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Sun, 24 Aug 2025 13:29:51 +0000 (15:29 +0200)
Since commit 028df914e546 ("rust: str: convert `rusttest` tests into
KUnit"), we do not have anymore host `#[test]`s that run in the host.

Moreover, we do not plan to add any new ones -- tests should generally
run within KUnit, since there they are built the same way the kernel
does. While we may want to have some way to define tests that can also
be run outside the kernel, we still want to test within the kernel too
[1], and thus would likely use a custom syntax anyway to define them.

Thus simplify the `rusttest` target by removing support for host
`#[test]`s for the `kernel` crate.

This still maintains the support for the `macros` crate, even though we
do not have any such tests there.

Link: https://lore.kernel.org/rust-for-linux/CABVgOS=AKHSfifp0S68K3jgNZAkALBr=7iFb=niryG5WDxjSrg@mail.gmail.com/
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/r/20250726180750.2735836-1-ojeda@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/Makefile
rust/kernel/alloc.rs
rust/kernel/error.rs
rust/kernel/lib.rs

index 4263462b84709fdddae4cc4de3da2aeee1ee5109..a934946bbf2137e710618993c06222310c747b10 100644 (file)
@@ -238,7 +238,7 @@ quiet_cmd_rustc_test = $(RUSTC_OR_CLIPPY_QUIET) T  $<
        $(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
                $(rustc_test_run_flags)
 
-rusttest: rusttest-macros rusttest-kernel
+rusttest: rusttest-macros
 
 rusttest-macros: private rustc_target_flags = --extern proc_macro \
        --extern macros --extern kernel --extern pin_init
@@ -248,13 +248,6 @@ rusttest-macros: $(src)/macros/lib.rs \
        +$(call if_changed,rustc_test)
        +$(call if_changed,rustdoc_test)
 
-rusttest-kernel: private rustc_target_flags = --extern ffi --extern pin_init \
-    --extern build_error --extern macros --extern bindings --extern uapi
-rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \
-    rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
-    rusttestlib-uapi rusttestlib-pin_init FORCE
-       +$(call if_changed,rustc_test)
-
 ifdef CONFIG_CC_IS_CLANG
 bindgen_c_flags = $(c_flags)
 else
index 907301334d8c111eb26719ad89700a289e03f037..25a2df50f59a895cc3935b6b1bf1d7bb31a20f8e 100644 (file)
@@ -2,16 +2,16 @@
 
 //! Implementation of the kernel's memory allocation infrastructure.
 
-#[cfg(not(any(test, testlib)))]
+#[cfg(not(testlib))]
 pub mod allocator;
 pub mod kbox;
 pub mod kvec;
 pub mod layout;
 
-#[cfg(any(test, testlib))]
+#[cfg(testlib)]
 pub mod allocator_test;
 
-#[cfg(any(test, testlib))]
+#[cfg(testlib)]
 pub use self::allocator_test as allocator;
 
 pub use self::kbox::Box;
index a41de293dcd11bef96d6808b5a4b06f4f3d0aa0a..67da2d118e656f1bbd0af52df1ad36b14e6aa583 100644 (file)
@@ -158,7 +158,7 @@ impl Error {
     }
 
     /// Returns a string representing the error, if one exists.
-    #[cfg(not(any(test, testlib)))]
+    #[cfg(not(testlib))]
     pub fn name(&self) -> Option<&'static CStr> {
         // SAFETY: Just an FFI call, there are no extra safety requirements.
         let ptr = unsafe { bindings::errname(-self.0.get()) };
@@ -175,7 +175,7 @@ impl Error {
     /// When `testlib` is configured, this always returns `None` to avoid the dependency on a
     /// kernel function so that tests that use this (e.g., by calling [`Result::unwrap`]) can still
     /// run in userspace.
-    #[cfg(any(test, testlib))]
+    #[cfg(testlib)]
     pub fn name(&self) -> Option<&'static CStr> {
         None
     }
index ed53169e795c0badf548025a57f946fa18bc73e3..821e74eee1bb06ec2b81cf13e536add12c7ba083 100644 (file)
@@ -206,7 +206,7 @@ impl ThisModule {
     }
 }
 
-#[cfg(not(any(testlib, test)))]
+#[cfg(not(testlib))]
 #[panic_handler]
 fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
     pr_emerg!("{}\n", info);