virpcitest: Test virPCIDeviceDetach

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@redhat.com>
This commit is contained in:
Michal Privoznik
2013-11-04 17:28:48 +01:00
parent d770618842
commit 25527ae25c
4 changed files with 654 additions and 5 deletions
+42
View File
@@ -57,6 +57,47 @@ cleanup:
return ret;
}
# define CHECK_LIST_COUNT(list, cnt) \
if ((count = virPCIDeviceListCount(list)) != cnt) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
"Unexpected count of items in " #list ": %d, " \
"expecting " #cnt, count); \
goto cleanup; \
}
static int
testVirPCIDeviceDetach(const void *oaque ATTRIBUTE_UNUSED)
{
int ret = -1;
virPCIDevicePtr dev;
virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
int count;
if (!(dev = virPCIDeviceNew(0, 0, 1, 0)) ||
!(activeDevs = virPCIDeviceListNew()) ||
!(inactiveDevs = virPCIDeviceListNew()))
goto cleanup;
CHECK_LIST_COUNT(activeDevs, 0);
CHECK_LIST_COUNT(inactiveDevs, 0);
if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
goto cleanup;
if (virPCIDeviceDetach(dev, activeDevs, inactiveDevs) < 0)
goto cleanup;
CHECK_LIST_COUNT(activeDevs, 0);
CHECK_LIST_COUNT(inactiveDevs, 1);
ret = 0;
cleanup:
virPCIDeviceFree(dev);
virObjectUnref(activeDevs);
virObjectUnref(inactiveDevs);
return ret;
}
# define FAKESYSFSDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
static int
@@ -84,6 +125,7 @@ mymain(void)
} while (0)
DO_TEST(testVirPCIDeviceNew);
DO_TEST(testVirPCIDeviceDetach);
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakesysfsdir);