提交 50e66887 编写于 作者: M Michal Privoznik

virhostdevtest: Drop most of 'cleanup' and 'out' labels

In this test there is this macro CHECK_LIST_COUNT() which checks
if a list of PCI devices contains expected count. If it doesn't
an error is reported and 'goto cleanup' is invoked. There's no
real reason for that as even since its introduction there is no
cleanup done and all 'cleanup' labels contain nothing but
'return'.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 9409f6b7
...@@ -41,7 +41,7 @@ VIR_LOG_INIT("tests.hostdevtest"); ...@@ -41,7 +41,7 @@ VIR_LOG_INIT("tests.hostdevtest");
virReportError(VIR_ERR_INTERNAL_ERROR, \ virReportError(VIR_ERR_INTERNAL_ERROR, \
"Unexpected count of items in " #list ": %zu, " \ "Unexpected count of items in " #list ": %zu, " \
"expecting %zu", actualCount, (size_t) cnt); \ "expecting %zu", actualCount, (size_t) cnt); \
goto cleanup; \ return -1; \
} \ } \
} while (0) } while (0)
...@@ -132,7 +132,6 @@ myInit(void) ...@@ -132,7 +132,6 @@ myInit(void)
static int static int
testVirHostdevPreparePCIHostdevs_unmanaged(void) testVirHostdevPreparePCIHostdevs_unmanaged(void)
{ {
int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
for (i = 0; i < nhostdevs; i++) for (i = 0; i < nhostdevs; i++)
...@@ -145,7 +144,7 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) ...@@ -145,7 +144,7 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void)
VIR_DEBUG("Test 0 hostdevs"); VIR_DEBUG("Test 0 hostdevs");
if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid,
NULL, 0, 0) < 0) NULL, 0, 0) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
...@@ -153,7 +152,7 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) ...@@ -153,7 +152,7 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void)
VIR_DEBUG("Test >=1 unmanaged hostdevs"); VIR_DEBUG("Test >=1 unmanaged hostdevs");
if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid,
hostdevs, nhostdevs, 0) < 0) hostdevs, nhostdevs, 0) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nhostdevs); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nhostdevs);
...@@ -163,35 +162,30 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) ...@@ -163,35 +162,30 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void)
VIR_DEBUG("Test: prepare same hostdevs for same driver/domain again"); VIR_DEBUG("Test: prepare same hostdevs for same driver/domain again");
if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid,
&hostdevs[0], 1, 0) == 0) &hostdevs[0], 1, 0) == 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain again"); VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain again");
if (virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid, if (virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid,
&hostdevs[1], 1, 0) == 0) &hostdevs[1], 1, 0) == 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again"); VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again");
if (virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid, if (virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid,
&hostdevs[2], 1, 0) == 0) &hostdevs[2], 1, 0) == 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testVirHostdevReAttachPCIHostdevs_unmanaged(void) testVirHostdevReAttachPCIHostdevs_unmanaged(void)
{ {
int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
for (i = 0; i < nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
...@@ -215,17 +209,12 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void) ...@@ -215,17 +209,12 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void)
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostdevs); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostdevs);
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testVirHostdevPreparePCIHostdevs_managed(bool mixed) testVirHostdevPreparePCIHostdevs_managed(bool mixed)
{ {
int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
for (i = 0; i < nhostdevs; i++) for (i = 0; i < nhostdevs; i++)
...@@ -238,7 +227,7 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed) ...@@ -238,7 +227,7 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed)
VIR_DEBUG("Test >=1 hostdevs"); VIR_DEBUG("Test >=1 hostdevs");
if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid,
hostdevs, nhostdevs, 0) < 0) hostdevs, nhostdevs, 0) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs);
/* If testing a mixed roundtrip, devices are already in the inactive list /* 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 * before we start and are removed from it as soon as we attach them to
...@@ -254,35 +243,30 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed) ...@@ -254,35 +243,30 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed)
VIR_DEBUG("Test: prepare same hostdevs for same driver/domain again"); VIR_DEBUG("Test: prepare same hostdevs for same driver/domain again");
if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid,
&hostdevs[0], 1, 0) == 0) &hostdevs[0], 1, 0) == 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain again"); VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain again");
if (virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid, if (virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid,
&hostdevs[1], 1, 0) == 0) &hostdevs[1], 1, 0) == 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again"); VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again");
if (virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid, if (virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid,
&hostdevs[2], 1, 0) == 0) &hostdevs[2], 1, 0) == 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testVirHostdevReAttachPCIHostdevs_managed(bool mixed) testVirHostdevReAttachPCIHostdevs_managed(bool mixed)
{ {
int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
for (i = 0; i < nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
...@@ -311,82 +295,63 @@ testVirHostdevReAttachPCIHostdevs_managed(bool mixed) ...@@ -311,82 +295,63 @@ testVirHostdevReAttachPCIHostdevs_managed(bool mixed)
else else
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testVirHostdevDetachPCINodeDevice(void) testVirHostdevDetachPCINodeDevice(void)
{ {
int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
for (i = 0; i < nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
active_count = virPCIDeviceListCount(mgr->activePCIHostdevs); active_count = virPCIDeviceListCount(mgr->activePCIHostdevs);
inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs); inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs);
if (virHostdevPCINodeDeviceDetach(mgr, dev[i]) < 0) if (virHostdevPCINodeDeviceDetach(mgr, dev[i]) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + 1); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + 1);
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testVirHostdevResetPCINodeDevice(void) testVirHostdevResetPCINodeDevice(void)
{ {
int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
for (i = 0; i < nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
active_count = virPCIDeviceListCount(mgr->activePCIHostdevs); active_count = virPCIDeviceListCount(mgr->activePCIHostdevs);
inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs); inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs);
if (virHostdevPCINodeDeviceReset(mgr, dev[i]) < 0) if (virHostdevPCINodeDeviceReset(mgr, dev[i]) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testVirHostdevReAttachPCINodeDevice(void) testVirHostdevReAttachPCINodeDevice(void)
{ {
int ret = -1;
size_t active_count, inactive_count, i; size_t active_count, inactive_count, i;
for (i = 0; i < nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
active_count = virPCIDeviceListCount(mgr->activePCIHostdevs); active_count = virPCIDeviceListCount(mgr->activePCIHostdevs);
inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs); inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs);
if (virHostdevPCINodeDeviceReAttach(mgr, dev[i]) < 0) if (virHostdevPCINodeDeviceReAttach(mgr, dev[i]) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - 1); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - 1);
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testVirHostdevUpdateActivePCIHostdevs(void) testVirHostdevUpdateActivePCIHostdevs(void)
{ {
int ret = -1;
size_t active_count, inactive_count; size_t active_count, inactive_count;
active_count = virPCIDeviceListCount(mgr->activePCIHostdevs); active_count = virPCIDeviceListCount(mgr->activePCIHostdevs);
...@@ -395,21 +360,18 @@ testVirHostdevUpdateActivePCIHostdevs(void) ...@@ -395,21 +360,18 @@ testVirHostdevUpdateActivePCIHostdevs(void)
VIR_DEBUG("Test 0 hostdevs"); VIR_DEBUG("Test 0 hostdevs");
if (virHostdevUpdateActivePCIDevices(mgr, NULL, 0, if (virHostdevUpdateActivePCIDevices(mgr, NULL, 0,
drv_name, dom_name) < 0) drv_name, dom_name) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
VIR_DEBUG("Test >=1 hostdevs"); VIR_DEBUG("Test >=1 hostdevs");
if (virHostdevUpdateActivePCIDevices(mgr, hostdevs, nhostdevs, if (virHostdevUpdateActivePCIDevices(mgr, hostdevs, nhostdevs,
drv_name, dom_name) < 0) drv_name, dom_name) < 0)
goto cleanup; return -1;
CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs);
CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count);
ret = 0; return 0;
cleanup:
return ret;
} }
/** /**
...@@ -424,17 +386,12 @@ testVirHostdevUpdateActivePCIHostdevs(void) ...@@ -424,17 +386,12 @@ testVirHostdevUpdateActivePCIHostdevs(void)
static int static int
testVirHostdevRoundtripNoGuest(const void *opaque ATTRIBUTE_UNUSED) testVirHostdevRoundtripNoGuest(const void *opaque ATTRIBUTE_UNUSED)
{ {
int ret = -1;
if (testVirHostdevDetachPCINodeDevice() < 0) if (testVirHostdevDetachPCINodeDevice() < 0)
goto out; return -1;
if (testVirHostdevReAttachPCINodeDevice() < 0) if (testVirHostdevReAttachPCINodeDevice() < 0)
goto out; return -1;
ret = 0;
out: return 0;
return ret;
} }
/** /**
...@@ -451,21 +408,16 @@ testVirHostdevRoundtripNoGuest(const void *opaque ATTRIBUTE_UNUSED) ...@@ -451,21 +408,16 @@ testVirHostdevRoundtripNoGuest(const void *opaque ATTRIBUTE_UNUSED)
static int static int
testVirHostdevRoundtripUnmanaged(const void *opaque ATTRIBUTE_UNUSED) testVirHostdevRoundtripUnmanaged(const void *opaque ATTRIBUTE_UNUSED)
{ {
int ret = -1;
if (testVirHostdevDetachPCINodeDevice() < 0) if (testVirHostdevDetachPCINodeDevice() < 0)
goto out; return -1;
if (testVirHostdevPreparePCIHostdevs_unmanaged() < 0) if (testVirHostdevPreparePCIHostdevs_unmanaged() < 0)
goto out; return -1;
if (testVirHostdevReAttachPCIHostdevs_unmanaged() < 0) if (testVirHostdevReAttachPCIHostdevs_unmanaged() < 0)
goto out; return -1;
if (testVirHostdevReAttachPCINodeDevice() < 0) if (testVirHostdevReAttachPCINodeDevice() < 0)
goto out; return -1;
ret = 0; return 0;
out:
return ret;
} }
/** /**
...@@ -480,17 +432,12 @@ testVirHostdevRoundtripUnmanaged(const void *opaque ATTRIBUTE_UNUSED) ...@@ -480,17 +432,12 @@ testVirHostdevRoundtripUnmanaged(const void *opaque ATTRIBUTE_UNUSED)
static int static int
testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED) testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED)
{ {
int ret = -1;
if (testVirHostdevPreparePCIHostdevs_managed(false) < 0) if (testVirHostdevPreparePCIHostdevs_managed(false) < 0)
goto out; return -1;
if (testVirHostdevReAttachPCIHostdevs_managed(false) < 0) if (testVirHostdevReAttachPCIHostdevs_managed(false) < 0)
goto out; return -1;
ret = 0;
out: return 0;
return ret;
} }
/** /**
...@@ -508,21 +455,16 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED) ...@@ -508,21 +455,16 @@ testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED)
static int static int
testVirHostdevRoundtripMixed(const void *opaque ATTRIBUTE_UNUSED) testVirHostdevRoundtripMixed(const void *opaque ATTRIBUTE_UNUSED)
{ {
int ret = -1;
if (testVirHostdevDetachPCINodeDevice() < 0) if (testVirHostdevDetachPCINodeDevice() < 0)
goto out; return -1;
if (testVirHostdevPreparePCIHostdevs_managed(true) < 0) if (testVirHostdevPreparePCIHostdevs_managed(true) < 0)
goto out; return -1;
if (testVirHostdevReAttachPCIHostdevs_managed(true) < 0) if (testVirHostdevReAttachPCIHostdevs_managed(true) < 0)
goto out; return -1;
if (testVirHostdevReAttachPCINodeDevice() < 0) if (testVirHostdevReAttachPCINodeDevice() < 0)
goto out; return -1;
ret = 0; return 0;
out:
return ret;
} }
/** /**
...@@ -537,17 +479,12 @@ testVirHostdevRoundtripMixed(const void *opaque ATTRIBUTE_UNUSED) ...@@ -537,17 +479,12 @@ testVirHostdevRoundtripMixed(const void *opaque ATTRIBUTE_UNUSED)
static int static int
testVirHostdevOther(const void *opaque ATTRIBUTE_UNUSED) testVirHostdevOther(const void *opaque ATTRIBUTE_UNUSED)
{ {
int ret = -1;
if (testVirHostdevResetPCINodeDevice() < 0) if (testVirHostdevResetPCINodeDevice() < 0)
goto out; return -1;
if (testVirHostdevUpdateActivePCIHostdevs() < 0) if (testVirHostdevUpdateActivePCIHostdevs() < 0)
goto out; return -1;
ret = 0;
out: return 0;
return ret;
} }
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册