提交 cbbb9baa 编写于 作者: M Michal Privoznik

objecteventtest: Check for virNetwork* return values

Lets not give a bad example and check for return values of
virNetwork* APIs called within the test. Even though it's
unlikely that any API will fail, it can happen. We're connected
to the test driver after all, and our API sequence is correct. So
test driver should fail only in case of bug or OOM.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 dd7bfb2c
......@@ -417,7 +417,7 @@ testNetworkCreateXML(const void *data)
&counter, NULL);
net = virNetworkCreateXML(test->conn, networkDef);
if (virEventRunDefaultImpl() < 0) {
if (!net || virEventRunDefaultImpl() < 0) {
ret = -1;
goto cleanup;
}
......@@ -429,10 +429,10 @@ testNetworkCreateXML(const void *data)
cleanup:
virConnectNetworkEventDeregisterAny(test->conn, id);
virNetworkDestroy(net);
virNetworkFree(net);
if (net) {
virNetworkDestroy(net);
virNetworkFree(net);
}
return ret;
}
......@@ -455,7 +455,7 @@ testNetworkDefine(const void *data)
/* Make sure the define event is triggered */
net = virNetworkDefineXML(test->conn, networkDef);
if (virEventRunDefaultImpl() < 0) {
if (!net || virEventRunDefaultImpl() < 0) {
ret = -1;
goto cleanup;
}
......@@ -481,7 +481,8 @@ testNetworkDefine(const void *data)
cleanup:
virConnectNetworkEventDeregisterAny(test->conn, id);
virNetworkFree(net);
if (net)
virNetworkFree(net);
return ret;
}
......@@ -494,6 +495,9 @@ testNetworkStartStopEvent(const void *data)
int id;
int ret = 0;
if (!test->net)
return -1;
lifecycleEventCounter_reset(&counter);
id = virConnectNetworkEventRegisterAny(test->conn, test->net,
......@@ -509,7 +513,7 @@ testNetworkStartStopEvent(const void *data)
}
if (counter.startEvents != 1 || counter.stopEvents != 1 ||
counter.unexpectedEvents > 0) {
counter.unexpectedEvents > 0) {
ret = -1;
goto cleanup;
}
......@@ -567,13 +571,16 @@ mymain(void)
ret = EXIT_FAILURE;
/* Define a test network */
test.net = virNetworkDefineXML(test.conn, networkDef);
if (!(test.net = virNetworkDefineXML(test.conn, networkDef)))
ret = EXIT_FAILURE;
if (virtTestRun("Network start stop events ", testNetworkStartStopEvent, &test) < 0)
ret = EXIT_FAILURE;
/* Cleanup */
virNetworkUndefine(test.net);
virNetworkFree(test.net);
if (test.net) {
virNetworkUndefine(test.net);
virNetworkFree(test.net);
}
virConnectClose(test.conn);
virEventRemoveTimeout(timer);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册