summaryrefslogtreecommitdiff
path: root/tests/virhostdevtest.c
diff options
context:
space:
mode:
authorAndrea Bolognani <abologna@redhat.com>2016-03-18 18:03:53 +0100
committerAndrea Bolognani <abologna@redhat.com>2016-03-23 11:38:20 +0100
commitee07c9802b82e98ee32ad0b3389bcf5d3307bd51 (patch)
treec89d28d95bf4c4035f7da0cee5935cbf2fb5dce3 /tests/virhostdevtest.c
parentee4cfb56436b50345b072c706b87aff82e06d760 (diff)
downloadlibvirt-ee07c9802b82e98ee32ad0b3389bcf5d3307bd51.tar.gz
tests: hostdev: Add more tests
Ensure the code behaves properly even for situations that were not being considered before, such as simply detaching devices from the host without attaching them to a guest and attaching devices as managed even though they had already been manually detached from the host.
Diffstat (limited to 'tests/virhostdevtest.c')
-rw-r--r--tests/virhostdevtest.c84
1 files changed, 78 insertions, 6 deletions
diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c
index 5eb2e7eb04..610b02a4ec 100644
--- a/tests/virhostdevtest.c
+++ b/tests/virhostdevtest.c
@@ -253,7 +253,7 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void)
}
static int
-testVirHostdevPreparePCIHostdevs_managed(void)
+testVirHostdevPreparePCIHostdevs_managed(bool mixed)
{
int ret = -1;
size_t active_count, inactive_count, i;
@@ -270,7 +270,13 @@ testVirHostdevPreparePCIHostdevs_managed(void)
hostdevs, nhostdevs, 0) < 0)
goto cleanup;
CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs);
- CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
+ /* If testing a mixed roundtrip, devices are already in the inactive list
+ * before we start and are removed from it as soon as we attach them to
+ * the guest */
+ if (mixed)
+ CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nhostdevs);
+ else
+ CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
/* Test conflict */
active_count = virPCIDeviceListCount(mgr->activePCIHostdevs);
@@ -304,7 +310,7 @@ testVirHostdevPreparePCIHostdevs_managed(void)
}
static int
-testVirHostdevReAttachPCIHostdevs_managed(void)
+testVirHostdevReAttachPCIHostdevs_managed(bool mixed)
{
int ret = -1;
size_t active_count, inactive_count, i;
@@ -328,7 +334,12 @@ testVirHostdevReAttachPCIHostdevs_managed(void)
virHostdevReAttachPCIDevices(mgr, drv_name, dom_name,
hostdevs, nhostdevs, NULL);
CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs);
- CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
+ /* If testing a mixed roundtrip, devices are added back to the inactive
+ * list as soon as we detach from the guest */
+ if (mixed)
+ CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostdevs);
+ else
+ CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
ret = 0;
@@ -432,6 +443,31 @@ testVirHostdevUpdateActivePCIHostdevs(void)
}
/**
+ * testVirHostdevRoundtripNoGuest:
+ * @opaque: unused
+ *
+ * Perform a roundtrip without ever assigning devices to the guest.
+ *
+ * 1. Detach devices from the host
+ * 2. Reattach devices to the host
+ */
+static int
+testVirHostdevRoundtripNoGuest(const void *opaque ATTRIBUTE_UNUSED)
+{
+ int ret = -1;
+
+ if (testVirHostdevDetachPCINodeDevice() < 0)
+ goto out;
+ if (testVirHostdevReAttachPCINodeDevice() < 0)
+ goto out;
+
+ ret = 0;
+
+ out:
+ return ret;
+}
+
+/**
* testVirHostdevRoundtripUnmanaged:
* @opaque: unused
*
@@ -479,9 +515,9 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED)
int ret = -1;
if (virHostdevHostSupportsPassthroughKVM()) {
- if (testVirHostdevPreparePCIHostdevs_managed() < 0)
+ if (testVirHostdevPreparePCIHostdevs_managed(false) < 0)
goto out;
- if (testVirHostdevReAttachPCIHostdevs_managed() < 0)
+ if (testVirHostdevReAttachPCIHostdevs_managed(false) < 0)
goto out;
}
@@ -492,6 +528,40 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED)
}
/**
+ * testVirHostdevRoundtripMixed:
+ * @opaque: unused
+ *
+ * Perform a roundtrip with managed devices but manually detach the devices
+ * from the host first.
+ *
+ * 1. Detach devices from the host
+ * 2. Attach devices to the guest as managed
+ * 3. Detach devices from the guest as managed
+ * 4. Reattach devices to the host
+ */
+static int
+testVirHostdevRoundtripMixed(const void *opaque ATTRIBUTE_UNUSED)
+{
+ int ret = -1;
+
+ if (testVirHostdevDetachPCINodeDevice() < 0)
+ goto out;
+ if (virHostdevHostSupportsPassthroughKVM()) {
+ if (testVirHostdevPreparePCIHostdevs_managed(true) < 0)
+ goto out;
+ if (testVirHostdevReAttachPCIHostdevs_managed(true) < 0)
+ goto out;
+ }
+ if (testVirHostdevReAttachPCINodeDevice() < 0)
+ goto out;
+
+ ret = 0;
+
+ out:
+ return ret;
+}
+
+/**
* testVirHostdevOther:
* @opaque: unused
*
@@ -546,8 +616,10 @@ mymain(void)
if (myInit() < 0)
fprintf(stderr, "Init data structures failed.");
+ DO_TEST(testVirHostdevRoundtripNoGuest);
DO_TEST(testVirHostdevRoundtripUnmanaged);
DO_TEST(testVirHostdevRoundtripManaged);
+ DO_TEST(testVirHostdevRoundtripMixed);
DO_TEST(testVirHostdevOther);
myCleanup();