Skip to content

Commit 8d3f507

Browse files
AmateurECEojeda
authored andcommitted
rust: enable macros::module! tests
Previously, these tests were ignored due to a missing necessary dependency on the `kernel` crate. Enable the tests, and update them: for both, add the parameter to `init()`; for the first one, remove the use of a kernel parameter mechanism that was never merged. Signed-off-by: Ethan D. Twardy <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: #1076 Link: https://lore.kernel.org/r/[email protected] [ Rebased (moved the `export` to the `rustdoc_test` rule, enable the firmware example too). Removed `export` for `RUST_MODFILE`. Removed unneeded `rust` language in examples, as well as `#[macro_use]` `extern`s. Reworded accordingly. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent b2c261f commit 8d3f507

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

rust/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ rusttestlib-uapi: $(src)/uapi/lib.rs FORCE
145145

146146
quiet_cmd_rustdoc_test = RUSTDOC T $<
147147
cmd_rustdoc_test = \
148+
RUST_MODFILE=test.rs \
148149
OBJTREE=$(abspath $(objtree)) \
149150
$(RUSTDOC) --test $(rust_common_flags) \
150151
@$(objtree)/include/generated/rustc_cfg \

rust/macros/lib.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use proc_macro::TokenStream;
3030
///
3131
/// # Examples
3232
///
33-
/// ```ignore
33+
/// ```
3434
/// use kernel::prelude::*;
3535
///
3636
/// module!{
@@ -42,22 +42,16 @@ use proc_macro::TokenStream;
4242
/// alias: ["alternate_module_name"],
4343
/// }
4444
///
45-
/// struct MyModule;
45+
/// struct MyModule(i32);
4646
///
4747
/// impl kernel::Module for MyModule {
48-
/// fn init() -> Result<Self> {
49-
/// // If the parameter is writeable, then the kparam lock must be
50-
/// // taken to read the parameter:
51-
/// {
52-
/// let lock = THIS_MODULE.kernel_param_lock();
53-
/// pr_info!("i32 param is: {}\n", writeable_i32.read(&lock));
54-
/// }
55-
/// // If the parameter is read only, it can be read without locking
56-
/// // the kernel parameters:
57-
/// pr_info!("i32 param is: {}\n", my_i32.read());
58-
/// Ok(Self)
48+
/// fn init(_module: &'static ThisModule) -> Result<Self> {
49+
/// let foo: i32 = 42;
50+
/// pr_info!("I contain: {}\n", foo);
51+
/// Ok(Self(foo))
5952
/// }
6053
/// }
54+
/// # fn main() {}
6155
/// ```
6256
///
6357
/// ## Firmware
@@ -69,7 +63,7 @@ use proc_macro::TokenStream;
6963
/// build an initramfs uses this information to put the firmware files into
7064
/// the initramfs image.
7165
///
72-
/// ```ignore
66+
/// ```
7367
/// use kernel::prelude::*;
7468
///
7569
/// module!{
@@ -84,10 +78,11 @@ use proc_macro::TokenStream;
8478
/// struct MyDeviceDriverModule;
8579
///
8680
/// impl kernel::Module for MyDeviceDriverModule {
87-
/// fn init() -> Result<Self> {
81+
/// fn init(_module: &'static ThisModule) -> Result<Self> {
8882
/// Ok(Self)
8983
/// }
9084
/// }
85+
/// # fn main() {}
9186
/// ```
9287
///
9388
/// # Supported argument types

0 commit comments

Comments
 (0)