mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
tests: Use libvirt properly with initialization and error dispatching
We were using "complicated" error printing in virnetservertest even though we could've just dispatched the error. Also add some good practices that might come in handy (the code may fail without proper initialization and event loop). Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
73ad20e936
commit
38788a3209
@ -119,6 +119,8 @@ testCreateServer(const char *host, int family)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (!srv)
|
||||||
|
virDispatchError(NULL);
|
||||||
virObjectUnref(cln1);
|
virObjectUnref(cln1);
|
||||||
virObjectUnref(cln2);
|
virObjectUnref(cln2);
|
||||||
virObjectUnref(svc1);
|
virObjectUnref(svc1);
|
||||||
@ -235,14 +237,8 @@ static int testExecRestart(const void *opaque)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
virErrorPtr err = virGetLastError();
|
virDispatchError(NULL);
|
||||||
/* Rather be safe, we have lot of missing errors */
|
|
||||||
if (err)
|
|
||||||
fprintf(stderr, "%s\n", err->message);
|
|
||||||
else
|
|
||||||
fprintf(stderr, "%s\n", "Unknown error");
|
|
||||||
}
|
|
||||||
fail:
|
fail:
|
||||||
VIR_FREE(infile);
|
VIR_FREE(infile);
|
||||||
VIR_FREE(outfile);
|
VIR_FREE(outfile);
|
||||||
@ -264,6 +260,12 @@ mymain(void)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (virInitialize() < 0 ||
|
||||||
|
virEventRegisterDefaultImpl() < 0) {
|
||||||
|
virDispatchError(NULL);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Hack to make it easier to generate new JSON files when
|
/* Hack to make it easier to generate new JSON files when
|
||||||
* the RPC classes change. Just set this env var, save
|
* the RPC classes change. Just set this env var, save
|
||||||
* the generated JSON, and replace the file descriptor
|
* the generated JSON, and replace the file descriptor
|
||||||
|
Loading…
Reference in New Issue
Block a user