mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
43f68a4f9e
Multiple tests need to register a function to quiesce errors from libvirt when using a connection and doing negative tests. Each of those tests had a static function to do so. This can be replaced by a utility function that enables the errors when debug is enabled. This patch adds virtTestQuiesceLibvirtErrors() and refactors test that use private handlers.
73 lines
1.8 KiB
C
73 lines
1.8 KiB
C
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/utsname.h>
|
|
|
|
#include "internal.h"
|
|
#include "testutils.h"
|
|
#include "vircommand.h"
|
|
|
|
static int
|
|
mymain(void)
|
|
{
|
|
int id = 0;
|
|
bool ro = false;
|
|
virConnectPtr conn;
|
|
virDomainPtr dom;
|
|
int status;
|
|
virCommandPtr cmd;
|
|
struct utsname ut;
|
|
|
|
/* Skip test if xend is not running. Calling xend on a non-xen
|
|
kernel causes some versions of xend to issue a crash report, so
|
|
we first probe uname results. */
|
|
uname(&ut);
|
|
if (strstr(ut.release, "xen") == NULL)
|
|
return EXIT_AM_SKIP;
|
|
cmd = virCommandNewArgList("/usr/sbin/xend", "status", NULL);
|
|
if (virCommandRun(cmd, &status) != 0 || status != 0) {
|
|
virCommandFree(cmd);
|
|
return EXIT_AM_SKIP;
|
|
}
|
|
virCommandFree(cmd);
|
|
|
|
virtTestQuiesceLibvirtErrors(true);
|
|
|
|
conn = virConnectOpen(NULL);
|
|
if (conn == NULL) {
|
|
ro = true;
|
|
conn = virConnectOpenReadOnly(NULL);
|
|
}
|
|
if (conn == NULL) {
|
|
fprintf(stderr, "First virConnectOpen() failed\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
dom = virDomainLookupByID(conn, id);
|
|
if (dom == NULL) {
|
|
fprintf(stderr, "First lookup for domain %d failed\n", id);
|
|
return EXIT_FAILURE;
|
|
}
|
|
virDomainFree(dom);
|
|
virConnectClose(conn);
|
|
if (ro)
|
|
conn = virConnectOpenReadOnly(NULL);
|
|
else
|
|
conn = virConnectOpen(NULL);
|
|
if (conn == NULL) {
|
|
fprintf(stderr, "Second virConnectOpen() failed\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
dom = virDomainLookupByID(conn, id);
|
|
if (dom == NULL) {
|
|
fprintf(stderr, "Second lookup for domain %d failed\n", id);
|
|
return EXIT_FAILURE;
|
|
}
|
|
virDomainFree(dom);
|
|
virConnectClose(conn);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
VIRT_TEST_MAIN(mymain)
|