On Thu, Oct 31, 2013 at 11:23:39AM +0000, Michal Privoznik wrote:
This commit introduces yet another test under virpcitest:
virPCIDeviceDetach. However, in order to be able to do this, the
virpcimock needs to be extended to model the kernel behavior on PCI
device binding and unbinding (create 'driver' symlinks under the device
tree, check for device ID in driver's ID table, etc.)
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
cfg.mk | 2 +-
tests/Makefile.am | 10 +-
tests/virpcimock.c | 603 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
tests/virpcitest.c | 42 ++++
4 files changed, 652 insertions(+), 5 deletions(-)
[...]
diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index d545361..2adc337 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
[...]
+static int
+pci_driver_handle_unbind(const char *path)
+{
+ int ret = -1;
+ struct pciDevice *dev = pci_device_find_by_content(path);
+
+ if (!dev || !dev->driver) {
+ /* This should never happen (TM) */
+ errno = ENODEV;
+ goto cleanup;
+ }
+
I spoke too soon, this function might check whether the driver is what
the device is really binded to and error out if not.
+ ret = pci_driver_unbind(dev->driver, dev);
than this one can be called only with 'dev'.
But since we are not testing/emulating faulty kernel behaviour, this
is not necesarily needed. However it would be nice to have cleaned up
so it's easier to read for others when adding more tests.
Martin