]> xenbits.xensource.com Git - libvirt.git/commitdiff
virpcitest: Introduce testVirPCIDeviceReattach
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 31 Oct 2013 10:57:56 +0000 (10:57 +0000)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 4 Nov 2013 16:28:51 +0000 (17:28 +0100)
This test will reattach the PCI device detached in the previous test.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tests/virpcitest.c

index 4f2191100609966dd7aa0cc375c229d951aafedf..45891a9577c984cb0ed6f3cc811d3403dd06a0c0 100644 (file)
@@ -100,6 +100,42 @@ cleanup:
 
 # define FAKESYSFSDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
 
+static int
+testVirPCIDeviceReattach(const void *oaque ATTRIBUTE_UNUSED)
+{
+    int ret = -1;
+    virPCIDevicePtr dev = NULL;
+    virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
+    int count;
+
+    if (!(dev = virPCIDeviceNew(0, 0, 1, 0)) ||
+        !(activeDevs = virPCIDeviceListNew()) ||
+        !(inactiveDevs = virPCIDeviceListNew()))
+        goto cleanup;
+
+    if (virPCIDeviceListAdd(inactiveDevs, dev) < 0) {
+        virPCIDeviceFree(dev);
+        goto cleanup;
+    }
+
+    CHECK_LIST_COUNT(activeDevs, 0);
+    CHECK_LIST_COUNT(inactiveDevs, 1);
+
+    if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
+        goto cleanup;
+
+    if (virPCIDeviceReattach(dev, activeDevs, inactiveDevs) < 0)
+        goto cleanup;
+
+    CHECK_LIST_COUNT(activeDevs, 0);
+    CHECK_LIST_COUNT(inactiveDevs, 0);
+
+    ret = 0;
+cleanup:
+    virObjectUnref(activeDevs);
+    virObjectUnref(inactiveDevs);
+    return ret;
+}
 static int
 mymain(void)
 {
@@ -126,6 +162,7 @@ mymain(void)
 
     DO_TEST(testVirPCIDeviceNew);
     DO_TEST(testVirPCIDeviceDetach);
+    DO_TEST(testVirPCIDeviceReattach);
 
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(fakesysfsdir);