
Chunyan Liu wrote:
Add unit test for hostdev common library. Current tests are based on virpcimock.
[...]
diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 49759b0..5676db7 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c
Your can drop the changes to this file, since they were added by 508b566e. Regards, Jim
@@ -149,7 +149,7 @@ static int pci_driver_handle_bind(const char *path); static int pci_driver_handle_unbind(const char *path); static int pci_driver_handle_new_id(const char *path); static int pci_driver_handle_remove_id(const char *path); - +static int pci_handle_drivers_probe(const char *path);
/* * Helper functions @@ -585,6 +585,8 @@ pci_driver_handle_change(int fd ATTRIBUTE_UNUSED, const char *path) } else if (STREQ(file, "remove_id")) { /* handle write to remove_id */ ret = pci_driver_handle_remove_id(path); + } else if (STREQ(file, "drivers_probe")) { + ret = pci_handle_drivers_probe(path); } else { /* yet not handled write */ ABORT("Not handled write to: %s", path); @@ -724,6 +726,16 @@ cleanup: return ret; }
+static int +pci_handle_drivers_probe(const char *path)
+{ + struct pciDevice *dev = pci_device_find_by_content(path); + + if (pci_device_autobind(dev) < 0) + ABORT("Unable to do driver reprobe."); + + return 0; +}
/* * Functions to load the symbols and init the environment @@ -760,6 +772,9 @@ init_syms(void) static void init_env(void) { + int fd = -1; + char *filepath; + if (fakesysfsdir) return;
@@ -791,6 +806,12 @@ init_env(void) MAKE_PCI_DEVICE("0005:90:01.0", 0x1033, 0x0035); MAKE_PCI_DEVICE("0005:90:01.1", 0x1033, 0x0035); MAKE_PCI_DEVICE("0005:90:01.2", 0x1033, 0x00e0); + + /* make file drivers_probe */ + if (virAsprintfQuiet(&filepath, "%s/drivers_probe", fakesysfsdir) < 0) + ABORT_OOM(); + if ((fd = realopen(filepath, O_CREAT|O_WRONLY, 0200)) < 0) + ABORT("Unable to create: %s", filepath); }