[PATCH v2 5/5] virpcitest: Introduce check for unbinded devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This just introduces the test for bug fixed in the previous patch.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/virpcitest.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/tests/virpcitest.c b/tests/virpcitest.c
index 8811add..5fb35ce 100644
--- a/tests/virpcitest.c
+++ b/tests/virpcitest.c
@@ -72,11 +72,12 @@ static int
 testVirPCIDeviceDetach(const void *oaque ATTRIBUTE_UNUSED)
 {
     int ret = -1;
-    virPCIDevicePtr dev;
+    virPCIDevicePtr dev = NULL, unbindedDev = NULL;
     virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
     int count;
 
     if (!(dev = virPCIDeviceNew(0, 0, 1, 0)) ||
+        !(unbindedDev = virPCIDeviceNew(0, 0, 3, 0)) ||
         !(activeDevs = virPCIDeviceListNew()) ||
         !(inactiveDevs = virPCIDeviceListNew()))
         goto cleanup;
@@ -84,7 +85,8 @@ testVirPCIDeviceDetach(const void *oaque ATTRIBUTE_UNUSED)
     CHECK_LIST_COUNT(activeDevs, 0);
     CHECK_LIST_COUNT(inactiveDevs, 0);
 
-    if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
+    if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0 ||
+        virPCIDeviceSetStubDriver(unbindedDev, "pci-stub") < 0)
         goto cleanup;
 
     if (virPCIDeviceDetach(dev, activeDevs, inactiveDevs) < 0)
@@ -93,9 +95,16 @@ testVirPCIDeviceDetach(const void *oaque ATTRIBUTE_UNUSED)
     CHECK_LIST_COUNT(activeDevs, 0);
     CHECK_LIST_COUNT(inactiveDevs, 1);
 
+    if (virPCIDeviceDetach(unbindedDev, activeDevs, inactiveDevs) < 0)
+        goto cleanup;
+
+    CHECK_LIST_COUNT(activeDevs, 0);
+    CHECK_LIST_COUNT(inactiveDevs, 2);
+
     ret = 0;
 cleanup:
     virPCIDeviceFree(dev);
+    virPCIDeviceFree(unbindedDev);
     virObjectUnref(activeDevs);
     virObjectUnref(inactiveDevs);
     return ret;
@@ -105,22 +114,29 @@ static int
 testVirPCIDeviceReattach(const void *oaque ATTRIBUTE_UNUSED)
 {
     int ret = -1;
-    virPCIDevicePtr dev = NULL;
+    virPCIDevicePtr dev = NULL, unbindedDev = NULL;
     virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
     int count;
 
     if (!(dev = virPCIDeviceNew(0, 0, 1, 0)) ||
+        !(unbindedDev = virPCIDeviceNew(0, 0, 3, 0)) ||
         !(activeDevs = virPCIDeviceListNew()) ||
         !(inactiveDevs = virPCIDeviceListNew()))
         goto cleanup;
 
     if (virPCIDeviceListAdd(inactiveDevs, dev) < 0) {
         virPCIDeviceFree(dev);
+        virPCIDeviceFree(unbindedDev);
+        goto cleanup;
+    }
+
+    if (virPCIDeviceListAdd(inactiveDevs, unbindedDev) < 0) {
+        virPCIDeviceFree(unbindedDev);
         goto cleanup;
     }
 
     CHECK_LIST_COUNT(activeDevs, 0);
-    CHECK_LIST_COUNT(inactiveDevs, 1);
+    CHECK_LIST_COUNT(inactiveDevs, 2);
 
     if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
         goto cleanup;
@@ -129,6 +145,12 @@ testVirPCIDeviceReattach(const void *oaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     CHECK_LIST_COUNT(activeDevs, 0);
+    CHECK_LIST_COUNT(inactiveDevs, 1);
+
+    if (virPCIDeviceReattach(unbindedDev, activeDevs, inactiveDevs) < 0)
+        goto cleanup;
+
+    CHECK_LIST_COUNT(activeDevs, 0);
     CHECK_LIST_COUNT(inactiveDevs, 0);
 
     ret = 0;
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]