On Wed, Oct 23, 2024 at 10:37:03AM -0500, Rob Herring wrote: > On Wed, Oct 23, 2024 at 08:59:48AM +0200, Danilo Krummrich wrote: > > On Tue, Oct 22, 2024 at 07:04:08PM -0500, Rob Herring wrote: > > > On Tue, Oct 22, 2024 at 11:31:53PM +0200, Danilo Krummrich wrote: > > > > Add a sample Rust platform driver illustrating the usage of the platform > > > > bus abstractions. > > > > > > > > This driver probes through either a match of device / driver name or a > > > > match within the OF ID table. > > > > > > I know if rust compiles it works, but how does one actually use/test > > > this? (I know ways, but I might be in the minority. :) ) > > > > For testing a name match I just used platform_device_register_simple() in a > > separate module. > > > > Probing through the OF table is indeed a bit more tricky. Since I was too lazy > > to pull out a random ARM device of my cupboard I just used QEMU on x86 and did > > what drivers/of/unittest.c does. If you're smart you can also just enable those > > unit tests and change the compatible string to "unittest". :) > > > > > > > > The DT unittests already define test platform devices. I'd be happy to > > > add a device node there. Then you don't have to muck with the DT on some > > > device and it even works on x86 or UML. > > > > Sounds good, I'll add one in there for this sample driver -- any preferences? > > I gave this a spin and added the patch below in. Feel free to squash it > into this one. Looks good -- it only works if the sample driver is built-in though, but I think that should be fine. > > 8<---------------------------------------------------------------- > From: "Rob Herring (Arm)" <robh@xxxxxxxxxx> > Date: Wed, 23 Oct 2024 10:29:47 -0500 > Subject: [PATCH] of: unittest: Add a platform device node for rust platform > driver sample > > Signed-off-by: Rob Herring (Arm) <robh@xxxxxxxxxx> > > diff --git a/drivers/of/unittest-data/tests-platform.dtsi b/drivers/of/unittest-data/tests-platform.dtsi > index fa39611071b3..575ea260a877 100644 > --- a/drivers/of/unittest-data/tests-platform.dtsi > +++ b/drivers/of/unittest-data/tests-platform.dtsi > @@ -33,6 +33,11 @@ dev@100 { > reg = <0x100>; > }; > }; > + > + test-device@2 { > + compatible = "test,rust-device"; > + reg = <0x2>; > + }; > }; > }; > }; > diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs > index 55caaaa4f216..5cf4a8f86c13 100644 > --- a/samples/rust/rust_driver_platform.rs > +++ b/samples/rust/rust_driver_platform.rs > @@ -15,7 +15,7 @@ struct SampleDriver { > MODULE_OF_TABLE, > <SampleDriver as platform::Driver>::IdInfo, > [( > - of::DeviceId::new(c_str!("redhat,rust-sample-platform-driver")), > + of::DeviceId::new(c_str!("test,rust-device")), > Info(42) > )] > ); >