diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_faux.rs index de131fce491a..6db3124ed3a9 100644 --- a/samples/rust/rust_driver_faux.rs +++ b/samples/rust/rust_driver_faux.rs @@ -2,8 +2,10 @@ //! Rust faux device sample. +use core::cell::Cell; use kernel::{ faux, + fmt, prelude::*, Module, // }; @@ -20,6 +22,20 @@ struct SampleModule { _reg: faux::Registration, } +struct Status<'a>(&'a Cell); + +impl fmt::Display for Status<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.set(self.0.get() + 1); + f.write_str("ready") + } +} + +fn read_status<'a>(reads: &Cell, formats: &'a Cell) -> Status<'a> { + reads.set(reads.get() + 1); + Status(formats) +} + impl Module for SampleModule { fn init(_module: &'static ThisModule) -> Result { pr_info!("Initialising Rust Faux Device Sample\n"); @@ -30,6 +46,28 @@ fn init(_module: &'static ThisModule) -> Result { dev_info!(fdev, "Hello from faux device!\n"); dev_dbg!(fdev, "foobar\n"); + let reads = Cell::new(0); + let formats = Cell::new(0); + pr_debug!("dyndbg repro pr: {}\n", read_status(&reads, &formats)); + pr_info!( + "dyndbg repro pr: args={} fmt={}\n", + reads.get(), + formats.get() + ); + + reads.set(0); + formats.set(0); + dev_dbg!( + fdev, + "dyndbg repro dev: {}\n", + read_status(&reads, &formats) + ); + pr_info!( + "dyndbg repro dev: args={} fmt={}\n", + reads.get(), + formats.get() + ); + Ok(Self { _reg: reg }) } } -- 2.53.0