提交 ee07c980 编写于 作者: A Andrea Bolognani

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.
上级 ee4cfb56
...@@ -253,7 +253,7 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void) ...@@ -253,7 +253,7 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void)
} }
static int static int
testVirHostdevPreparePCIHostdevs_managed(void) testVirHostdevPreparePCIHostdevs_managed(bool mixed)
{ {
int ret = -1; int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
...@@ -270,7 +270,13 @@ testVirHostdevPreparePCIHostdevs_managed(void) ...@@ -270,7 +270,13 @@ testVirHostdevPreparePCIHostdevs_managed(void)
hostdevs, nhostdevs, 0) < 0) hostdevs, nhostdevs, 0) < 0)
goto cleanup; goto cleanup;
CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); 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 */ /* Test conflict */
active_count = virPCIDeviceListCount(mgr->activePCIHostdevs); active_count = virPCIDeviceListCount(mgr->activePCIHostdevs);
...@@ -304,7 +310,7 @@ testVirHostdevPreparePCIHostdevs_managed(void) ...@@ -304,7 +310,7 @@ testVirHostdevPreparePCIHostdevs_managed(void)
} }
static int static int
testVirHostdevReAttachPCIHostdevs_managed(void) testVirHostdevReAttachPCIHostdevs_managed(bool mixed)
{ {
int ret = -1; int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
...@@ -328,7 +334,12 @@ testVirHostdevReAttachPCIHostdevs_managed(void) ...@@ -328,7 +334,12 @@ testVirHostdevReAttachPCIHostdevs_managed(void)
virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, virHostdevReAttachPCIDevices(mgr, drv_name, dom_name,
hostdevs, nhostdevs, NULL); hostdevs, nhostdevs, NULL);
CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); 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; ret = 0;
...@@ -431,6 +442,31 @@ testVirHostdevUpdateActivePCIHostdevs(void) ...@@ -431,6 +442,31 @@ testVirHostdevUpdateActivePCIHostdevs(void)
return ret; return ret;
} }
/**
* 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: * testVirHostdevRoundtripUnmanaged:
* @opaque: unused * @opaque: unused
...@@ -479,9 +515,9 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED) ...@@ -479,9 +515,9 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED)
int ret = -1; int ret = -1;
if (virHostdevHostSupportsPassthroughKVM()) { if (virHostdevHostSupportsPassthroughKVM()) {
if (testVirHostdevPreparePCIHostdevs_managed() < 0) if (testVirHostdevPreparePCIHostdevs_managed(false) < 0)
goto out; goto out;
if (testVirHostdevReAttachPCIHostdevs_managed() < 0) if (testVirHostdevReAttachPCIHostdevs_managed(false) < 0)
goto out; goto out;
} }
...@@ -491,6 +527,40 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED) ...@@ -491,6 +527,40 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED)
return ret; return ret;
} }
/**
* 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: * testVirHostdevOther:
* @opaque: unused * @opaque: unused
...@@ -546,8 +616,10 @@ mymain(void) ...@@ -546,8 +616,10 @@ mymain(void)
if (myInit() < 0) if (myInit() < 0)
fprintf(stderr, "Init data structures failed."); fprintf(stderr, "Init data structures failed.");
DO_TEST(testVirHostdevRoundtripNoGuest);
DO_TEST(testVirHostdevRoundtripUnmanaged); DO_TEST(testVirHostdevRoundtripUnmanaged);
DO_TEST(testVirHostdevRoundtripManaged); DO_TEST(testVirHostdevRoundtripManaged);
DO_TEST(testVirHostdevRoundtripMixed);
DO_TEST(testVirHostdevOther); DO_TEST(testVirHostdevOther);
myCleanup(); myCleanup();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册