On 6/26/25 10:47, Daniel P. Berrangé via Devel wrote: > From: Daniel P. Berrangé <berra...@redhat.com> > > The USB vendor/product is usually translated into a device/bus at > startup using the hostdev logic. We don't run the latter in the > unit test suite, but we can fake it by hardcoding a translation. > This demonstrates that we format the command line with the normal > device/bus properties, even when vendor/product is set. > > Signed-off-by: Daniel P. Berrangé <berra...@redhat.com> > --- > ...tdev-usb-vendor-product.x86_64-latest.args | 35 +++++++++++++++ > ...stdev-usb-vendor-product.x86_64-latest.xml | 44 +++++++++++++++++++ > .../hostdev-usb-vendor-product.xml | 36 +++++++++++++++ > tests/qemuxmlconftest.c | 18 ++++++++ > 4 files changed, 133 insertions(+) > create mode 100644 > tests/qemuxmlconfdata/hostdev-usb-vendor-product.x86_64-latest.args > create mode 100644 > tests/qemuxmlconfdata/hostdev-usb-vendor-product.x86_64-latest.xml > create mode 100644 tests/qemuxmlconfdata/hostdev-usb-vendor-product.xml >
Kudos for these test XMLs, but ... > diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c > index f74bd2bb7a..fe90f029d9 100644 > --- a/tests/qemuxmlconftest.c > +++ b/tests/qemuxmlconftest.c > @@ -474,6 +474,23 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv, > } > } > > + for (i = 0; i < vm->def->nhostdevs; i++) { > + virDomainHostdevDef *hostdev = vm->def->hostdevs[i]; > + > + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && > + hostdev->source.subsys.type == > VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { > + virDomainHostdevSubsysUSB *usb = &hostdev->source.subsys.u.usb; > + if (!usb->device && !usb->bus) { > + if (usb->vendor == 0x1234 && usb->product == 0x4321) { > + usb->bus = 42; > + usb->device = 0x1234; > + } else { > + g_assert_not_reached(); > + } > + } > + } > + } > + .. for this I think we can do a bit better. We already have virusbmock which would handle looking up USB devices in our fake USBSYS structure (tests/virusbtestdata/). But for that we would need slightly more code, so lets merge this and I'll post patches that use mocking. BTW: if anybody will want to try that on their own, they'll need the following patch to make chaining of our mocks actually work: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/BTFEENLIPAUH2DFE2GZMWNAT6LOWADH6/ > if (flags & FLAG_SLIRP_HELPER) { > for (i = 0; i < vm->def->nnets; i++) { > virDomainNetDef *net = vm->def->nets[i]; > @@ -2118,6 +2135,7 @@ mymain(void) > DO_TEST_CAPS_LATEST("hostdev-usb-address-device"); > DO_TEST_CAPS_LATEST("hostdev-usb-address-device-boot"); > DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-usb-duplicate"); > + DO_TEST_CAPS_LATEST("hostdev-usb-vendor-product"); > DO_TEST_CAPS_LATEST("hostdev-pci-address"); > DO_TEST_CAPS_LATEST("hostdev-pci-address-device"); > DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-pci-duplicate"); Reviewed-by: Michal Privoznik <mpriv...@redhat.com> Michal