[PATCH v3 2/4] rust: Enable test for macros::module
From: Ethan D. Twardy
Date: Thu Jul 04 2024 - 10:57:50 EST
Previously, this test was ignored due to a missing necessary dependency
on the `kernel` crate. Enable the test, and update it to remove the use
of a kernel parameter mechanism that was never merged.
Signed-off-by: Ethan D. Twardy <ethan.twardy@xxxxxxxxx>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
diff --git a/rust/Makefile b/rust/Makefile
index df389df4db9c..3ace8506ee8d 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -256,6 +256,7 @@ rusttest-prepare: FORCE
quiet_cmd_rustdoc_test_macros = RUSTDOC T $<
cmd_rustdoc_test_macros = \
+ export RUST_MODFILE=test.rs; \
OBJTREE=$(abspath $(objtree)) \
$(RUSTDOC) --test $(rust_common_flags) \
@$(objtree)/include/generated/rustc_cfg \
diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index 520eae5fd792..1c4ae5789cfa 100644
--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -26,9 +26,13 @@
///
/// # Examples
///
-/// ```ignore
+/// ```rust
+/// # #[macro_use] extern crate macros;
+/// # #[macro_use] extern crate kernel;
/// use kernel::prelude::*;
///
+/// struct MyModule(i32);
+///
/// module!{
/// type: MyModule,
/// name: "my_kernel_module",
@@ -37,22 +41,14 @@
/// license: "GPL",
/// }
///
-/// struct MyModule;
-///
/// impl kernel::Module for MyModule {
-/// fn init() -> Result<Self> {
-/// // If the parameter is writeable, then the kparam lock must be
-/// // taken to read the parameter:
-/// {
-/// let lock = THIS_MODULE.kernel_param_lock();
-/// pr_info!("i32 param is: {}\n", writeable_i32.read(&lock));
-/// }
-/// // If the parameter is read only, it can be read without locking
-/// // the kernel parameters:
-/// pr_info!("i32 param is: {}\n", my_i32.read());
-/// Ok(Self)
+/// fn init(module: &'static ThisModule) -> Result<Self> {
+/// let foo: i32 = 42;
+/// pr_info!("I contain: {}\n", foo);
+/// Ok(Self(foo))
/// }
/// }
+/// # fn main() {}
/// ```
///
/// # Supported argument types
--
2.44.2