mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 16:56:26 +00:00
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 <ethan.twardy@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://github.com/Rust-for-Linux/linux/issues/1076 Link: https://lore.kernel.org/r/20240704145607.17732-3-ethan.twardy@gmail.com [ 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 <ojeda@kernel.org>
This commit is contained in:
parent
b2c261fa86
commit
8d3f50795a
@ -145,6 +145,7 @@ rusttestlib-uapi: $(src)/uapi/lib.rs FORCE
|
||||
|
||||
quiet_cmd_rustdoc_test = RUSTDOC T $<
|
||||
cmd_rustdoc_test = \
|
||||
RUST_MODFILE=test.rs \
|
||||
OBJTREE=$(abspath $(objtree)) \
|
||||
$(RUSTDOC) --test $(rust_common_flags) \
|
||||
@$(objtree)/include/generated/rustc_cfg \
|
||||
|
@ -30,7 +30,7 @@
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```ignore
|
||||
/// ```
|
||||
/// use kernel::prelude::*;
|
||||
///
|
||||
/// module!{
|
||||
@ -42,22 +42,16 @@
|
||||
/// alias: ["alternate_module_name"],
|
||||
/// }
|
||||
///
|
||||
/// struct MyModule;
|
||||
/// struct MyModule(i32);
|
||||
///
|
||||
/// 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() {}
|
||||
/// ```
|
||||
///
|
||||
/// ## Firmware
|
||||
@ -69,7 +63,7 @@
|
||||
/// build an initramfs uses this information to put the firmware files into
|
||||
/// the initramfs image.
|
||||
///
|
||||
/// ```ignore
|
||||
/// ```
|
||||
/// use kernel::prelude::*;
|
||||
///
|
||||
/// module!{
|
||||
@ -84,10 +78,11 @@
|
||||
/// struct MyDeviceDriverModule;
|
||||
///
|
||||
/// impl kernel::Module for MyDeviceDriverModule {
|
||||
/// fn init() -> Result<Self> {
|
||||
/// fn init(_module: &'static ThisModule) -> Result<Self> {
|
||||
/// Ok(Self)
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// # Supported argument types
|
||||
|
Loading…
Reference in New Issue
Block a user