diff options
author | Martin Kletzander <mkletzan@redhat.com> | 2015-06-15 10:41:17 +0200 |
---|---|---|
committer | Martin Kletzander <mkletzan@redhat.com> | 2015-06-15 17:13:00 +0200 |
commit | 38788a3209c5d7d2cece261ae128fb07bb348ce7 (patch) | |
tree | c79d4383e51cb87400bf9139a2ba6a1bd12afcc9 | |
parent | 73ad20e936b0fc9fac59efb66e6f77a5739aab4b (diff) | |
download | libvirt-38788a3209c5d7d2cece261ae128fb07bb348ce7.tar.gz |
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>
-rw-r--r-- | tests/virnetservertest.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/virnetservertest.c b/tests/virnetservertest.c index e8e91f867e..d546f87764 100644 --- a/tests/virnetservertest.c +++ b/tests/virnetservertest.c @@ -119,6 +119,8 @@ testCreateServer(const char *host, int family) goto error; cleanup: + if (!srv) + virDispatchError(NULL); virObjectUnref(cln1); virObjectUnref(cln2); virObjectUnref(svc1); @@ -235,14 +237,8 @@ static int testExecRestart(const void *opaque) ret = 0; cleanup: - if (ret < 0) { - virErrorPtr err = virGetLastError(); - /* Rather be safe, we have lot of missing errors */ - if (err) - fprintf(stderr, "%s\n", err->message); - else - fprintf(stderr, "%s\n", "Unknown error"); - } + if (ret < 0) + virDispatchError(NULL); fail: VIR_FREE(infile); VIR_FREE(outfile); @@ -264,6 +260,12 @@ mymain(void) { int ret = 0; + if (virInitialize() < 0 || + virEventRegisterDefaultImpl() < 0) { + virDispatchError(NULL); + return EXIT_FAILURE; + } + /* Hack to make it easier to generate new JSON files when * the RPC classes change. Just set this env var, save * the generated JSON, and replace the file descriptor |