/* Not strictly a virCommand test, but this is the easiest place
* to test this lower-level interface. It takes a double fork to
* test virProcessExitWithStatus. */
- int ret = -1;
int status = -1;
pid_t pid;
if ((pid = virFork()) < 0)
- goto cleanup;
+ return -1;
if (pid == 0) {
if ((pid = virFork()) < 0)
_exit(EXIT_FAILURE);
}
if (virProcessWait(pid, &status, true) < 0)
- goto cleanup;
+ return -1;
if (!WIFEXITED(status) || WEXITSTATUS(status) != 42) {
printf("Unexpected status %d\n", status);
- goto cleanup;
+ return -1;
}
if ((pid = virFork()) < 0)
- goto cleanup;
+ return -1;
if (pid == 0) {
if ((pid = virFork()) < 0)
_exit(EXIT_FAILURE);
}
if (virProcessWait(pid, &status, true) < 0)
- goto cleanup;
+ return -1;
if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL) {
printf("Unexpected status %d\n", status);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int test25(const void *unused G_GNUC_UNUSED)
return EXIT_AM_SKIP;
}
- ret = -1;
- goto cleanup;
+ return EXIT_FAILURE;
}
basefile = g_strdup_printf("%s/networkxml2firewalldata/base.args", abs_srcdir);
- if (virTestLoadFile(basefile, &baseargs) < 0) {
- ret = -1;
- goto cleanup;
- }
+ if (virTestLoadFile(basefile, &baseargs) < 0)
+ return EXIT_FAILURE;
DO_TEST("nat-default");
DO_TEST("nat-tftp");
DO_TEST("nat-ipv6");
DO_TEST("route-default");
- cleanup:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
{
const struct testNSSData *data = opaque;
const bool existent = data->hostname && data->ipAddr && data->ipAddr[0];
- int ret = -1;
struct hostent resolved;
char buf[BUF_SIZE] = { 0 };
char **addrList;
virReportError(VIR_ERR_INTERNAL_ERROR,
"Resolving of %s failed due to internal error",
data->hostname);
- goto cleanup;
+ return -1;
} else if (rv == NSS_STATUS_NOTFOUND) {
/* Resolving failed. Should it? */
if (!existent)
- ret = 0;
+ return 0;
else
virReportError(VIR_ERR_INTERNAL_ERROR,
"Resolving of %s failed",
data->hostname);
- goto cleanup;
+ return -1;
}
/* Resolving succeeded. Should it? */
virReportError(VIR_ERR_INTERNAL_ERROR,
"Resolving of %s succeeded but was expected to fail",
data->hostname);
- goto cleanup;
+ return -1;
}
/* Now lets see if resolved address match our expectations. */
if (!resolved.h_name) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
"resolved.h_name empty");
- goto cleanup;
+ return -1;
}
if (data->af != AF_UNSPEC &&
virReportError(VIR_ERR_INTERNAL_ERROR,
"Expected AF_INET (%d) got %d",
data->af, resolved.h_addrtype);
- goto cleanup;
+ return -1;
}
if ((resolved.h_addrtype == AF_INET && resolved.h_length != 4) ||
"Expected %d bytes long address, got %d",
resolved.h_addrtype == AF_INET ? 4 : 16,
resolved.h_length);
- goto cleanup;
+ return -1;
}
if (!resolved.h_addr_list) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
"resolved.h_addr_list empty");
- goto cleanup;
+ return -1;
}
addrList = resolved.h_addr_list;
if (!(ipAddr = virSocketAddrFormat(&sa))) {
/* error reported by helper */
- goto cleanup;
+ return -1;
}
if (STRNEQ_NULLABLE(data->ipAddr[i], ipAddr)) {
"Unexpected address %s, expecting %s",
ipAddr, NULLSTR(data->ipAddr[i]));
VIR_FREE(ipAddr);
- goto cleanup;
+ return -1;
}
VIR_FREE(ipAddr);
virReportError(VIR_ERR_INTERNAL_ERROR,
"Expected %s address, got NULL",
data->ipAddr[i]);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
return EXIT_AM_SKIP;
}
- ret = -1;
- goto cleanup;
+ return EXIT_FAILURE;
}
if (virTestRun("ebiptablesAllTeardown",
NULL) < 0)
ret = -1;
- cleanup:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
const char *name,
const char *value)
{
- int ret = -1;
virNWFilterVarValuePtr val;
if ((val = virHashLookup(vars, name)) == NULL) {
val = virNWFilterVarValueCreateSimpleCopyValue(value);
if (!val)
- goto cleanup;
+ return -1;
if (virHashUpdateEntry(vars, name, val) < 0) {
virNWFilterVarValueFree(val);
- goto cleanup;
+ return -1;
}
} else {
if (virNWFilterVarValueAddValueCopy(val, value) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+
+ return 0;
}
static int testSetDefaultParameters(virHashTablePtr vars)
fprintf(stderr, "iptables/ip6tables/ebtables tools not present");
return EXIT_AM_SKIP;
}
- ret = -1;
- goto cleanup;
+ return EXIT_FAILURE;
}
DO_TEST("ah");
DO_TEST("udplite-ipv6");
DO_TEST("vlan");
- cleanup:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
virDomainObjPtr *vm,
const char *domxml)
{
- int ret = -1;
qemuDomainObjPrivatePtr priv = NULL;
const unsigned int parseFlags = 0;
if (!(*vm = virDomainObjNew(xmlopt)))
- goto cleanup;
+ return -1;
priv = (*vm)->privateData;
if (!(priv->qemuCaps = virQEMUCapsNew()))
- goto cleanup;
+ return -1;
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI);
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE);
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_CIRRUS_VGA);
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0)
- goto cleanup;
+ return -1;
if (!((*vm)->def = virDomainDefParseString(domxml,
driver.caps,
driver.xmlopt,
NULL,
parseFlags)))
- goto cleanup;
+ return -1;
if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps,
&driver, *vm, true) < 0) {
- goto cleanup;
+ return -1;
}
if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0)
- goto cleanup;
+ return -1;
(*vm)->def->id = QEMU_HOTPLUG_TEST_DOMAIN_ID;
if (qemuDomainSetPrivatePaths(&driver, *vm) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
virDomainObjPtr vm,
virCapsPtr caps)
{
- int ret = -1;
-
if (!caps)
- goto cleanup;
+ return -1;
virQEMUCapsSetArch(info->qemuCaps, vm->def->os.arch);
if (testAddCPUModels(info->qemuCaps,
!!(info->flags & FLAG_SKIP_LEGACY_CPUS)) < 0)
- goto cleanup;
+ return -1;
virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
VIR_DOMAIN_VIRT_KVM);
virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
VIR_DOMAIN_VIRT_QEMU);
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int testAuthLookup(const void *args)
{
- int ret = -1;
const struct ConfigLookupData *data = args;
const char *actual = NULL;
int rv;
&actual);
if (rv < 0)
- goto cleanup;
+ return -1;
if (data->expect) {
if (!actual ||
data->expect, data->hostname,
data->service, data->credname,
NULLSTR(actual));
- goto cleanup;
+ return -1;
}
} else {
if (actual) {
data->hostname,
data->service, data->credname,
actual);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int make_controller_v1(const char *path, mode_t mode)
{
- int ret = -1;
const char *controller;
if (!STRPREFIX(path, fakesysfscgroupdir)) {
return symlink("cpu,cpuacct", path);
if (real_mkdir(path, mode) < 0)
- goto cleanup;
+ return -1;
# define MAKE_FILE(name, value) \
do { \
if (make_file(path, name, value) < 0) \
- goto cleanup; \
+ return -1; \
} while (0)
if (STRPREFIX(controller, "cpu,cpuacct")) {
} else {
errno = EINVAL;
- goto cleanup;
+ return -1;
}
# undef MAKE_FILE
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
* unaligned access. */
char array[] = { 1, 2, 3, 4, 5, 6, 7, 8,
0x89, 0x8a, 0x8b, 0x8c, 0x8d };
- int ret = -1;
if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
- goto cleanup;
+ return -1;
if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
- goto cleanup;
+ return -1;
if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
- goto cleanup;
+ return -1;
if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
- goto cleanup;
+ return -1;
if (virReadBufInt32BE(array) != 0x01020304U)
- goto cleanup;
+ return -1;
if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
- goto cleanup;
+ return -1;
if (virReadBufInt32LE(array) != 0x04030201U)
- goto cleanup;
+ return -1;
if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
- goto cleanup;
+ return -1;
if (virReadBufInt16BE(array) != 0x0102U)
- goto cleanup;
+ return -1;
if (virReadBufInt16BE(array + 11) != 0x8c8dU)
- goto cleanup;
+ return -1;
if (virReadBufInt16LE(array) != 0x0201U)
- goto cleanup;
+ return -1;
if (virReadBufInt16LE(array + 11) != 0x8d8cU)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
/* Unsigned char should work without cast, even if unaligned access. */
unsigned char array[] = { 1, 2, 3, 4, 5, 6, 7, 8,
0x89, 0x8a, 0x8b, 0x8c, 0x8d };
- int ret = -1;
if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
- goto cleanup;
+ return -1;
if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
- goto cleanup;
+ return -1;
if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
- goto cleanup;
+ return -1;
if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
- goto cleanup;
+ return -1;
if (virReadBufInt32BE(array) != 0x01020304U)
- goto cleanup;
+ return -1;
if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
- goto cleanup;
+ return -1;
if (virReadBufInt32LE(array) != 0x04030201U)
- goto cleanup;
+ return -1;
if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
- goto cleanup;
+ return -1;
if (virReadBufInt16BE(array) != 0x0102U)
- goto cleanup;
+ return -1;
if (virReadBufInt16BE(array + 11) != 0x8c8dU)
- goto cleanup;
+ return -1;
if (virReadBufInt16LE(array) != 0x0201U)
- goto cleanup;
+ return -1;
if (virReadBufInt16LE(array + 11) != 0x8d8cU)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
static int testKeycodeMapping(const void *data G_GNUC_UNUSED)
{
- int ret = -1;
int got;
#define TRANSLATE(from, to, val, want) \
val)) != want) { \
fprintf(stderr, "Translating %d from %s to %s, got %d want %d\n", \
val, #from, #to, got, want); \
- goto cleanup; \
+ return -1; \
} \
} while (0)
#undef TRANSLATE
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int testKeycodeStrings(const void *data G_GNUC_UNUSED)
{
- int ret = -1;
int got;
#define TRANSLATE(from, str, want) \
str)) != want) { \
fprintf(stderr, "Converting %s from %s, got %d want %d\n", \
str, #from, got, want); \
- goto cleanup; \
+ return -1; \
} \
} while (0)
#undef TRANSLATE
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
#define DO_TEST_FLUSH_PROLOGUE \
do { \
if (!(mgr = virMacMapNew(NULL))) { \
- ret = -1; \
- goto cleanup; \
+ return EXIT_FAILURE; \
} \
} while (0)
DO_TEST_FLUSH("dom1", "9e:89:49:99:51:0e", "89:b4:3f:08:88:2c", "54:0b:4c:e2:0a:39");
DO_TEST_FLUSH("dom1", "bb:88:07:19:51:9d", "b7:f1:1a:40:a2:95", "88:94:39:a3:90:b4");
DO_TEST_FLUSH_EPILOGUE("complex");
- cleanup:
+
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
static int
testVirNetDevGetLinkInfo(const void *opaque)
{
- int ret = -1;
const struct testVirNetDevGetLinkInfoData *data = opaque;
virNetDevIfLink lnk;
if (virNetDevGetLinkInfo(data->ifname, &lnk) < 0)
- goto cleanup;
+ return -1;
if (lnk.state != data->state) {
fprintf(stderr,
"Fetched link state (%s) doesn't match the expected one (%s)",
virNetDevIfStateTypeToString(lnk.state),
virNetDevIfStateTypeToString(data->state));
- goto cleanup;
+ return -1;
}
if (lnk.speed != data->speed) {
fprintf(stderr,
"Fetched link speed (%u) doesn't match the expected one (%u)",
lnk.speed, data->speed);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
static int
add_fd(int fd, const char *path)
{
- int ret = -1;
size_t i;
if (find_fd(fd, &i)) {
if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0) {
errno = ENOMEM;
- goto cleanup;
+ return -1;
}
callbacks[nCallbacks].path = g_strdup(path);
callbacks[nCallbacks++].fd = fd;
- ret = 0;
- cleanup:
- return ret;
+
+ return 0;
}
static int
remove_fd(int fd)
{
- int ret = -1;
size_t i;
if (find_fd(fd, &i)) {
struct fdCallback cb = callbacks[i];
if (pci_driver_handle_change(cb.fd, cb.path) < 0)
- goto cleanup;
+ return -1;
VIR_FREE(cb.path);
if (VIR_DELETE_ELEMENT(callbacks, i, nCallbacks) < 0) {
errno = EINVAL;
- goto cleanup;
+ return -1;
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
pci_driver_handle_bind(const char *path)
{
- int ret = -1;
struct pciDevice *dev = pci_device_find_by_content(path);
struct pciDriver *driver = pci_driver_find_by_path(path);
if (!driver || !dev) {
/* No driver, no device or failing driver requested */
errno = ENODEV;
- goto cleanup;
+ return -1;
}
- ret = pci_driver_bind(driver, dev);
- cleanup:
- return ret;
+ return pci_driver_bind(driver, dev);
}
static int
pci_driver_handle_unbind(const char *path)
{
- int ret = -1;
struct pciDevice *dev = pci_device_find_by_content(path);
if (!dev || !dev->driver) {
/* No device, device not binded or failing driver requested */
errno = ENODEV;
- goto cleanup;
+ return -1;
}
- ret = pci_driver_unbind(dev->driver, dev);
- cleanup:
- return ret;
+ return pci_driver_unbind(dev->driver, dev);
}
virPCIDevicePtr dev;
if (!(dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function)))
- goto cleanup;
+ return -1;
if (virPCIDeviceIsAssignable(dev, true))
ret = 0;
virPCIDeviceFree(dev);
- cleanup:
return ret;
}
static int testPolkitAuthSuccess(const void *opaque G_GNUC_UNUSED)
{
- int ret = -1;
-
if (virPolkitCheckAuth("org.libvirt.test.success",
THE_PID,
THE_TIME,
THE_UID,
NULL,
true) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
static int testPolkitAuthDenied(const void *opaque G_GNUC_UNUSED)
{
- int ret = -1;
int rv;
virErrorPtr err;
if (rv == 0) {
fprintf(stderr, "Unexpected auth success\n");
- goto cleanup;
+ return -1;
} else if (rv != -2) {
- goto cleanup;
+ return -1;
}
err = virGetLastError();
if (!err || !strstr(err->message,
_("access denied by policy"))) {
fprintf(stderr, "Incorrect error response\n");
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int testPolkitAuthChallenge(const void *opaque G_GNUC_UNUSED)
{
- int ret = -1;
int rv;
virErrorPtr err;
if (rv == 0) {
fprintf(stderr, "Unexpected auth success\n");
- goto cleanup;
+ return -1;
} else if (rv != -2) {
- goto cleanup;
+ return -1;
}
err = virGetLastError();
err->code != VIR_ERR_AUTH_UNAVAILABLE ||
!strstr(err->message, _("no polkit agent available to authenticate"))) {
fprintf(stderr, "Incorrect error response\n");
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int testPolkitAuthCancelled(const void *opaque G_GNUC_UNUSED)
{
- int ret = -1;
int rv;
virErrorPtr err;
if (rv == 0) {
fprintf(stderr, "Unexpected auth success\n");
- goto cleanup;
+ return -1;
} else if (rv != -2) {
- goto cleanup;
+ return -1;
}
err = virGetLastError();
if (!err || !strstr(err->message,
_("user cancelled authentication process"))) {
fprintf(stderr, "Incorrect error response\n");
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int testPolkitAuthDetailsSuccess(const void *opaque G_GNUC_UNUSED)
{
- int ret = -1;
const char *details[] = {
"org.libvirt.test.person", "Fred",
NULL,
THE_UID,
details,
true) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
static int testPolkitAuthDetailsDenied(const void *opaque G_GNUC_UNUSED)
{
- int ret = -1;
int rv;
virErrorPtr err;
const char *details[] = {
if (rv == 0) {
fprintf(stderr, "Unexpected auth success\n");
- goto cleanup;
+ return -1;
} else if (rv != -2) {
- goto cleanup;
+ return -1;
}
err = virGetLastError();
if (!err || !strstr(err->message,
_("access denied by policy"))) {
fprintf(stderr, "Incorrect error response\n");
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int testStreq(const void *args)
{
const struct testStreqData *data = args;
- int ret = -1;
bool equal = true;
bool streq_rv, strneq_rv;
size_t i;
virFilePrintf(stderr,
"STREQ not working correctly. Expected %d got %d",
(int) equal, (int) streq_rv);
- goto cleanup;
+ return -1;
}
if (strneq_rv == equal) {
virFilePrintf(stderr,
"STRNEQ not working correctly. Expected %d got %d",
(int) equal, (int) strneq_rv);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
struct testSplitData {
const char *sortrlist[] = {
"turducken", "tasty", "goat", "chicken", "astro",
};
- int ret = -1;
size_t i;
qsort(randlist, G_N_ELEMENTS(randlist), sizeof(randlist[0]),
if (STRNEQ(randlist[i], sortlist[i])) {
fprintf(stderr, "sortlist[%zu] '%s' != randlist[%zu] '%s'\n",
i, sortlist[i], i, randlist[i]);
- goto cleanup;
+ return -1;
}
if (STRNEQ(randrlist[i], sortrlist[i])) {
fprintf(stderr, "sortrlist[%zu] '%s' != randrlist[%zu] '%s'\n",
i, sortrlist[i], i, randrlist[i]);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}