hughsie / libgusb

GUsb is a GObject wrapper for libusb1
GNU Lesser General Public License v2.1
25 stars 21 forks source link

Save device events when required #69

Closed hughsie closed 2 years ago

hughsie commented 2 years ago

This allows us to simulate an entire context of devices, simulating responses as if the hardware is connected. This allows building rich device-specific unit tests in programs like fwupd, without having to have the hardware attached.

benzea commented 2 years ago

Heh, I guess this is the easy way compared to me going through umockdev and emulating ioctl's :-)

hughsie commented 2 years ago

@benzea it also allows us to load entire contexts of devices easily, e.g. when you do a firmware update the device disconnects and reconnects as a different VID/PID.

benzea commented 2 years ago

True, doing that is quite painful in umockdev as you need to add/remove the device manually.

hughsie commented 2 years ago

@benzea I'd appreciate some high level review of the event collection API if that's okay?

hughsie commented 2 years ago

I'll merge as fwupd now depends on this functionality, but I'm 100% open to modifying the JSON output or the API before we do the 0.4.0 release.

benzea commented 2 years ago

Heh, now I am wondering if a usbmon recording includes enough information to add/remove a device in umockdev dynamically ... that could be a fun hack, but I don't think I'll get around to play with that.

hughsie commented 2 years ago

I have to admit, g_usb_context_load makes me a bit nervous as you seem to have the whole libusb hotplug machinery running underneath still.

Ya, I know what you mean. The reason I did this is that in fwupd I do actually want to use the physical devices alongside the emulated ones.

benzea commented 2 years ago

but but, it is a cute dragon! :-)

One thing I realised, You are setting enumeration_done = TRUE, which means that the behaviour is different whether you load before or after enumerate. If you run it before loading, you will see existing devices. If not, you'll only see newly plugged host devices.