[PATCH 2/4] rust: Enable test for macros::module

Ethan D. Twardy posted 4 patches 1 year, 5 months ago
There is a newer version of this series
[PATCH 2/4] rust: Enable test for macros::module
Posted by Ethan D. Twardy 1 year, 5 months ago
Previously, this test was ignored due to a missing necessary dependency
on the `kernel` crate.

Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>

diff --git a/rust/Makefile b/rust/Makefile
index de58f0cae23b..16abb8175494 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -264,6 +264,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..d8bd34c0ba89 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,15 @@
 ///     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
Re: [PATCH 2/4] rust: Enable test for macros::module
Posted by Alice Ryhl 1 year, 5 months ago
On Mon, Jun 24, 2024 at 5:04 AM Ethan D. Twardy <ethan.twardy@gmail.com> wrote:
>
> Previously, this test was ignored due to a missing necessary dependency
> on the `kernel` crate.
>
> Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>

It may be worth to call out in the commit message that you are
changing what the example does. (But the change is good - this form of
kernel parameters were never upstreamed.)

With the commit message updated:

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

Oh, also, you don't want an empty line between } and `# fn main() {}`
as it will show up as a weird empty line at the end of the example.

Alice
Re: [PATCH 2/4] rust: Enable test for macros::module
Posted by Ethan D. Twardy 1 year, 5 months ago
On Mon Jun 24, 2024 at 3:32 AM CDT, Alice Ryhl wrote:
> It may be worth to call out in the commit message that you are
> changing what the example does. (But the change is good - this form of
> kernel parameters were never upstreamed.)
>
> With the commit message updated:
>
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
>
> Oh, also, you don't want an empty line between } and `# fn main() {}`
> as it will show up as a weird empty line at the end of the example.
>
> Alice

I have these changes made locally and will send with v2. Thank you!