mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
objecteventtest: Don't overwrite @ret on failure
Our general pattern is to initialize @ret to -1 and set it to 0 only at the end of a function. Some functions in objecteventtest.c do not follow this pattern. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
@@ -347,7 +347,7 @@ testDomainDefine(const void *data)
|
|||||||
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
|
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
|
id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
|
||||||
VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
|
VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
|
||||||
@@ -357,12 +357,10 @@ testDomainDefine(const void *data)
|
|||||||
dom = virDomainDefineXML(test->conn, domainDef);
|
dom = virDomainDefineXML(test->conn, domainDef);
|
||||||
|
|
||||||
if (dom == NULL || virEventRunDefaultImpl() < 0) {
|
if (dom == NULL || virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,16 +368,14 @@ testDomainDefine(const void *data)
|
|||||||
virDomainUndefine(dom);
|
virDomainUndefine(dom);
|
||||||
|
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectDomainEventDeregisterAny(test->conn, id);
|
virConnectDomainEventDeregisterAny(test->conn, id);
|
||||||
if (dom != NULL)
|
if (dom != NULL)
|
||||||
@@ -458,7 +454,7 @@ testNetworkCreateXML(const void *data)
|
|||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
virNetworkPtr net;
|
virNetworkPtr net;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectNetworkEventRegisterAny(test->conn, NULL,
|
id = virConnectNetworkEventRegisterAny(test->conn, NULL,
|
||||||
VIR_NETWORK_EVENT_ID_LIFECYCLE,
|
VIR_NETWORK_EVENT_ID_LIFECYCLE,
|
||||||
@@ -467,15 +463,14 @@ testNetworkCreateXML(const void *data)
|
|||||||
net = virNetworkCreateXML(test->conn, networkDef);
|
net = virNetworkCreateXML(test->conn, networkDef);
|
||||||
|
|
||||||
if (!net || virEventRunDefaultImpl() < 0) {
|
if (!net || virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectNetworkEventDeregisterAny(test->conn, id);
|
virConnectNetworkEventDeregisterAny(test->conn, id);
|
||||||
if (net) {
|
if (net) {
|
||||||
@@ -492,7 +487,7 @@ testNetworkDefine(const void *data)
|
|||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
virNetworkPtr net;
|
virNetworkPtr net;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectNetworkEventRegisterAny(test->conn, NULL,
|
id = virConnectNetworkEventRegisterAny(test->conn, NULL,
|
||||||
VIR_NETWORK_EVENT_ID_LIFECYCLE,
|
VIR_NETWORK_EVENT_ID_LIFECYCLE,
|
||||||
@@ -503,12 +498,10 @@ testNetworkDefine(const void *data)
|
|||||||
net = virNetworkDefineXML(test->conn, networkDef);
|
net = virNetworkDefineXML(test->conn, networkDef);
|
||||||
|
|
||||||
if (!net || virEventRunDefaultImpl() < 0) {
|
if (!net || virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,16 +509,15 @@ testNetworkDefine(const void *data)
|
|||||||
virNetworkUndefine(net);
|
virNetworkUndefine(net);
|
||||||
|
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectNetworkEventDeregisterAny(test->conn, id);
|
virConnectNetworkEventDeregisterAny(test->conn, id);
|
||||||
if (net)
|
if (net)
|
||||||
@@ -540,7 +532,7 @@ testNetworkStartStopEvent(const void *data)
|
|||||||
const objecteventTest *test = data;
|
const objecteventTest *test = data;
|
||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
if (!test->net)
|
if (!test->net)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -553,15 +545,15 @@ testNetworkStartStopEvent(const void *data)
|
|||||||
virNetworkDestroy(test->net);
|
virNetworkDestroy(test->net);
|
||||||
|
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.startEvents != 1 || counter.stopEvents != 1 ||
|
if (counter.startEvents != 1 || counter.stopEvents != 1 ||
|
||||||
counter.unexpectedEvents > 0) {
|
counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectNetworkEventDeregisterAny(test->conn, id);
|
virConnectNetworkEventDeregisterAny(test->conn, id);
|
||||||
|
|
||||||
@@ -575,7 +567,7 @@ testStoragePoolCreateXML(const void *data)
|
|||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
virStoragePoolPtr pool;
|
virStoragePoolPtr pool;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
||||||
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
||||||
@@ -584,15 +576,14 @@ testStoragePoolCreateXML(const void *data)
|
|||||||
pool = virStoragePoolCreateXML(test->conn, storagePoolDef, 0);
|
pool = virStoragePoolCreateXML(test->conn, storagePoolDef, 0);
|
||||||
|
|
||||||
if (!pool || virEventRunDefaultImpl() < 0) {
|
if (!pool || virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
||||||
if (pool) {
|
if (pool) {
|
||||||
@@ -609,7 +600,7 @@ testStoragePoolDefine(const void *data)
|
|||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
virStoragePoolPtr pool;
|
virStoragePoolPtr pool;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
||||||
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
||||||
@@ -620,12 +611,10 @@ testStoragePoolDefine(const void *data)
|
|||||||
pool = virStoragePoolDefineXML(test->conn, storagePoolDef, 0);
|
pool = virStoragePoolDefineXML(test->conn, storagePoolDef, 0);
|
||||||
|
|
||||||
if (!pool || virEventRunDefaultImpl() < 0) {
|
if (!pool || virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,16 +622,14 @@ testStoragePoolDefine(const void *data)
|
|||||||
virStoragePoolUndefine(pool);
|
virStoragePoolUndefine(pool);
|
||||||
|
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
||||||
if (pool)
|
if (pool)
|
||||||
@@ -656,15 +643,13 @@ testStoragePoolStartStopEvent(const void *data)
|
|||||||
{
|
{
|
||||||
const objecteventTest *test = data;
|
const objecteventTest *test = data;
|
||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
int refreshCounter;
|
int refreshCounter = 0;
|
||||||
int id1, id2;
|
int id1, id2;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
if (!test->pool)
|
if (!test->pool)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
refreshCounter = 0;
|
|
||||||
|
|
||||||
id1 = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
|
id1 = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
|
||||||
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
||||||
VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
|
VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
|
||||||
@@ -678,16 +663,15 @@ testStoragePoolStartStopEvent(const void *data)
|
|||||||
virStoragePoolDestroy(test->pool);
|
virStoragePoolDestroy(test->pool);
|
||||||
|
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.startEvents != 1 || counter.stopEvents != 1 ||
|
if (counter.startEvents != 1 || counter.stopEvents != 1 ||
|
||||||
refreshCounter != 1 || counter.unexpectedEvents > 0) {
|
refreshCounter != 1 || counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectStoragePoolEventDeregisterAny(test->conn, id1);
|
virConnectStoragePoolEventDeregisterAny(test->conn, id1);
|
||||||
virConnectStoragePoolEventDeregisterAny(test->conn, id2);
|
virConnectStoragePoolEventDeregisterAny(test->conn, id2);
|
||||||
@@ -700,7 +684,7 @@ testStoragePoolBuild(const void *data)
|
|||||||
const objecteventTest *test = data;
|
const objecteventTest *test = data;
|
||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
||||||
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
||||||
@@ -710,15 +694,14 @@ testStoragePoolBuild(const void *data)
|
|||||||
virStoragePoolBuild(test->pool, 0);
|
virStoragePoolBuild(test->pool, 0);
|
||||||
|
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.createdEvents != 1) {
|
if (counter.createdEvents != 1) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -730,7 +713,7 @@ testStoragePoolDelete(const void *data)
|
|||||||
const objecteventTest *test = data;
|
const objecteventTest *test = data;
|
||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
|
||||||
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
|
||||||
@@ -740,15 +723,14 @@ testStoragePoolDelete(const void *data)
|
|||||||
virStoragePoolDelete(test->pool, 0);
|
virStoragePoolDelete(test->pool, 0);
|
||||||
|
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.deletedEvents != 1) {
|
if (counter.deletedEvents != 1) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
virConnectStoragePoolEventDeregisterAny(test->conn, id);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -760,7 +742,7 @@ testNodeDeviceCreateXML(const void *data)
|
|||||||
lifecycleEventCounter counter = { 0 };
|
lifecycleEventCounter counter = { 0 };
|
||||||
virNodeDevicePtr dev;
|
virNodeDevicePtr dev;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
id = virConnectNodeDeviceEventRegisterAny(test->conn, NULL,
|
id = virConnectNodeDeviceEventRegisterAny(test->conn, NULL,
|
||||||
VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
|
VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
|
||||||
@@ -770,16 +752,15 @@ testNodeDeviceCreateXML(const void *data)
|
|||||||
virNodeDeviceDestroy(dev);
|
virNodeDeviceDestroy(dev);
|
||||||
|
|
||||||
if (!dev || virEventRunDefaultImpl() < 0) {
|
if (!dev || virEventRunDefaultImpl() < 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter.createdEvents != 1 || counter.deletedEvents != 1 ||
|
if (counter.createdEvents != 1 || counter.deletedEvents != 1 ||
|
||||||
counter.unexpectedEvents > 0) {
|
counter.unexpectedEvents > 0) {
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectNodeDeviceEventDeregisterAny(test->conn, id);
|
virConnectNodeDeviceEventDeregisterAny(test->conn, id);
|
||||||
if (dev)
|
if (dev)
|
||||||
|
|||||||
Reference in New Issue
Block a user