From 29b1e859e31960fb3e923636f4e6d97c1b30f429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Sun, 20 Oct 2019 13:49:46 +0200 Subject: [PATCH] tests: use g_strdup instead of VIR_STRDUP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- tests/bhyvexml2argvmock.c | 6 +-- tests/commandtest.c | 5 +-- tests/cputest.c | 4 +- tests/domaincapstest.c | 13 +++--- tests/nssmock.c | 3 +- tests/openvzutilstest.c | 5 ++- tests/qemublocktest.c | 3 +- tests/qemudomaincheckpointxml2xmltest.c | 9 ++-- tests/qemufirmwaretest.c | 3 +- tests/qemuhotplugtest.c | 8 +--- tests/qemumemlocktest.c | 5 +-- tests/qemumonitorjsontest.c | 3 +- tests/qemumonitortestutils.c | 32 ++++++-------- tests/qemusecuritymock.c | 6 +-- tests/qemuvhostusertest.c | 3 +- tests/qemuxml2argvtest.c | 55 ++++++++----------------- tests/qemuxml2xmltest.c | 5 +-- tests/scsihosttest.c | 5 +-- tests/securityselinuxlabeltest.c | 8 +--- tests/securityselinuxtest.c | 13 +++--- tests/storagebackendsheepdogtest.c | 6 +-- tests/testutils.c | 3 +- tests/testutilsqemu.c | 31 +++++--------- tests/vboxsnapshotxmltest.c | 4 +- tests/viralloctest.c | 3 +- tests/vircgrouptest.c | 5 +-- tests/virfilecachetest.c | 7 +--- tests/virfirewalltest.c | 8 ++-- tests/virhostdevtest.c | 8 +--- tests/virnetmessagetest.c | 11 ++--- tests/virpcimock.c | 19 +++++---- tests/virpcitest.c | 5 +-- tests/virscsitest.c | 5 +-- tests/virstoragetest.c | 6 +-- tests/virstringtest.c | 9 ++-- tests/virtestmock.c | 3 +- tests/virusbmock.c | 4 +- tests/vmx2xmltest.c | 3 +- tests/xml2vmxtest.c | 3 +- 39 files changed, 115 insertions(+), 222 deletions(-) diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c index 717ceb4847..b0d38187f9 100644 --- a/tests/bhyvexml2argvmock.c +++ b/tests/bhyvexml2argvmock.c @@ -34,8 +34,7 @@ int virNetDevTapCreateInBridgePort(const char *brname G_GNUC_UNUSED, unsigned int fakeflags G_GNUC_UNUSED) { VIR_FREE(*ifname); - if (VIR_STRDUP(*ifname, "vnet0") < 0) - return -1; + *ifname = g_strdup("vnet0"); return 0; } @@ -43,8 +42,7 @@ char *virNetDevTapGetRealDeviceName(char *name G_GNUC_UNUSED) { char *fakename; - if (VIR_STRDUP(fakename, "faketapdev") < 0) - return NULL; + fakename = g_strdup("faketapdev"); return fakename; } diff --git a/tests/commandtest.c b/tests/commandtest.c index e79baa2946..6ff2039ab1 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -686,10 +686,7 @@ static int test17(const void *unused G_GNUC_UNUSED) goto cleanup; } VIR_FREE(outbuf); - if (VIR_STRDUP(outbuf, "should not be leaked") < 0) { - puts("test framework failure"); - goto cleanup; - } + outbuf = g_strdup("should not be leaked"); virCommandSetErrorBuffer(cmd, &errbuf); if (errbuf != NULL) { diff --git a/tests/cputest.c b/tests/cputest.c index ab68c3b4af..83b494857f 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -492,9 +492,11 @@ cpuTestMakeQEMUCaps(const struct data *data) if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true))) goto error; - if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, "host") < 0) + if (VIR_ALLOC(cpu) < 0) goto cleanup; + cpu->model = g_strdup("host"); + if (ARCH_IS_S390(data->arch)) fail_no_props = false; diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 07bc99cc03..61bc019671 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -36,11 +36,11 @@ fillStringValues(virDomainCapsStringValuesPtr values, ...) va_start(list, values); while ((str = va_arg(list, const char *))) { - if (VIR_REALLOC_N(values->values, values->nvalues + 1) < 0 || - VIR_STRDUP(values->values[values->nvalues], str) < 0) { + if (VIR_REALLOC_N(values->values, values->nvalues + 1) < 0) { ret = -1; break; } + values->values[values->nvalues] = g_strdup(str); values->nvalues++; } va_end(list); @@ -95,9 +95,7 @@ fillQemuCaps(virDomainCapsPtr domCaps, if (machine) { VIR_FREE(domCaps->machine); - if (VIR_STRDUP(domCaps->machine, - virQEMUCapsGetCanonicalMachine(qemuCaps, machine)) < 0) - goto cleanup; + domCaps->machine = g_strdup(virQEMUCapsGetCanonicalMachine(qemuCaps, machine)); } if (!domCaps->machine) @@ -153,9 +151,8 @@ fillXenCaps(virDomainCapsPtr domCaps) if (VIR_ALLOC(firmwares[0]) < 0 || VIR_ALLOC(firmwares[1]) < 0) goto cleanup; - if (VIR_STRDUP(firmwares[0]->name, "/usr/lib/xen/boot/hvmloader") < 0 || - VIR_STRDUP(firmwares[1]->name, "/usr/lib/xen/boot/ovmf.bin") < 0) - goto cleanup; + firmwares[0]->name = g_strdup("/usr/lib/xen/boot/hvmloader"); + firmwares[1]->name = g_strdup("/usr/lib/xen/boot/ovmf.bin"); if (libxlMakeDomainCapabilities(domCaps, firmwares, 2) < 0) goto cleanup; diff --git a/tests/nssmock.c b/tests/nssmock.c index 230044275a..ea4b26ffab 100644 --- a/tests/nssmock.c +++ b/tests/nssmock.c @@ -62,8 +62,7 @@ getrealpath(char **newpath, return -1; } } else { - if (VIR_STRDUP_QUIET(*newpath, path) < 0) - return -1; + *newpath = g_strdup(path); } return 0; diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index 1fcd4d2caa..c15ce9a47b 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -99,10 +99,11 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) " \n" "\n"; - if (!(def = virDomainDefNew()) || - VIR_STRDUP(def->os.init, "/sbin/init") < 0) + if (!(def = virDomainDefNew())) goto cleanup; + def->os.init = g_strdup("/sbin/init"); + def->virtType = VIR_DOMAIN_VIRT_OPENVZ; def->os.type = VIR_DOMAIN_OSTYPE_EXE; diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 0f073682ca..a8d2f57c6e 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -161,8 +161,7 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src) return -1; srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; - if (VIR_STRDUP(srcpriv->secinfo->s.aes.username, src->auth->username) < 0) - return -1; + srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username); if (virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias", NULLSTR(src->nodestorage)) < 0) diff --git a/tests/qemudomaincheckpointxml2xmltest.c b/tests/qemudomaincheckpointxml2xmltest.c index f6eb1f69b2..4540f15ddd 100644 --- a/tests/qemudomaincheckpointxml2xmltest.c +++ b/tests/qemudomaincheckpointxml2xmltest.c @@ -63,8 +63,7 @@ testCompareXMLToXMLFiles(const char *inxml, if (flags & TEST_PARENT) { if (def->parent.parent_name) return -1; - if (VIR_STRDUP(def->parent.parent_name, "1525111885") < 0) - return -1; + def->parent.parent_name = g_strdup("1525111885"); } if (flags & TEST_VDA_BITMAP) { virDomainCheckpointDiskDefPtr disk; @@ -76,13 +75,11 @@ testCompareXMLToXMLFiles(const char *inxml, return -1; if (!disk->name) { disk->type = VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; - if (VIR_STRDUP(disk->name, "vda") < 0) - return -1; + disk->name = g_strdup("vda"); } else if (STRNEQ(disk->name, "vda")) { return -1; } - if (VIR_STRDUP(disk->bitmap, def->parent.name) < 0) - return -1; + disk->bitmap = g_strdup(def->parent.name); } if (flags & TEST_SIZE) { def->disks[0].size = 1048576; diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c index 9287ea554b..ad7ed7a384 100644 --- a/tests/qemufirmwaretest.c +++ b/tests/qemufirmwaretest.c @@ -70,8 +70,7 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED) }; const size_t nexpected = G_N_ELEMENTS(expected); - if (VIR_STRDUP(fakehome, abs_srcdir "/qemufirmwaredata/home/user/.config") < 0) - return -1; + fakehome = g_strdup(abs_srcdir "/qemufirmwaredata/home/user/.config"); setenv("XDG_CONFIG_HOME", fakehome, 1); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index d3da08875a..4ff2b38c83 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -597,10 +597,7 @@ mymain(void) struct testQemuHotplugCpuParams cpudata; char *fakerootdir; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - fprintf(stderr, "Out of memory\n"); - abort(); - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { fprintf(stderr, "Cannot create fakerootdir"); @@ -622,8 +619,7 @@ mymain(void) VIR_FREE(driver.config->spiceListen); VIR_FREE(driver.config->vncListen); /* some dummy values from 'config file' */ - if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0) - return EXIT_FAILURE; + driver.config->spicePassword = g_strdup("123456"); if (!(driver.domainEventState = virObjectEventStateNew())) return EXIT_FAILURE; diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index c9484ac9cb..490e2ef11f 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -61,10 +61,7 @@ mymain(void) char *fakerootdir; virQEMUCapsPtr qemuCaps = NULL; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - fprintf(stderr, "Out of memory\n"); - abort(); - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { fprintf(stderr, "Cannot create fakerootdir"); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index f754e4d94b..c0eee921cf 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2165,8 +2165,7 @@ testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *opaque) return -1; expectedInfo = (virDomainBlockIoTuneInfo) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, NULL, 15, 16, 17, 18, 19, 20}; - if (VIR_STRDUP(expectedInfo.group_name, "group14") < 0) - return -1; + expectedInfo.group_name = g_strdup("group14"); if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0 || qemuMonitorTestAddItemParams(test, "block_set_io_throttle", diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 6b3aa97e39..fb76bf185d 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -604,11 +604,8 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, if (VIR_ALLOC(data) < 0) return -1; - if (VIR_STRDUP(data->command_name, command_name) < 0 || - VIR_STRDUP(data->response, response) < 0) { - qemuMonitorTestHandlerDataFree(data); - return -1; - } + data->command_name = g_strdup(command_name); + data->response = g_strdup(response); return qemuMonitorTestAddHandler(test, qemuMonitorTestProcessCommandDefault, @@ -692,9 +689,8 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test, if (VIR_ALLOC(data) < 0) return -1; - if (VIR_STRDUP(data->response, response) < 0 || - VIR_STRDUP(data->cmderr, cmderr) < 0) - goto error; + data->response = g_strdup(response); + data->cmderr = g_strdup(cmderr); data->command_name = virJSONStringReformat(command, false); if (!data->command_name) @@ -868,9 +864,8 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test, if (VIR_ALLOC(data) < 0) goto error; - if (VIR_STRDUP(data->command_name, cmdname) < 0 || - VIR_STRDUP(data->response, response) < 0) - goto error; + data->command_name = g_strdup(cmdname); + data->response = g_strdup(response); while ((argname = va_arg(args, char *))) { size_t i; @@ -885,9 +880,8 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test, if (VIR_EXPAND_N(data->args, data->nargs, 1)) goto error; - if (VIR_STRDUP(data->args[i].argname, argname) < 0 || - VIR_STRDUP(data->args[i].argval, argval) < 0) - goto error; + data->args[i].argname = g_strdup(argname); + data->args[i].argval = g_strdup(argval); } va_end(args); @@ -984,10 +978,9 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test, if (VIR_ALLOC(data) < 0) goto error; - if (VIR_STRDUP(data->command_name, cmdname) < 0 || - VIR_STRDUP(data->response, response) < 0 || - VIR_STRDUP(data->expectArgs, cmdargs) < 0) - goto error; + data->command_name = g_strdup(cmdname); + data->response = g_strdup(response); + data->expectArgs = g_strdup(cmdargs); if (apostrophe) { char *tmp = data->expectArgs; @@ -1065,8 +1058,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, return NULL; } - if (VIR_STRDUP(tmpdir_template, "/tmp/libvirt_XXXXXX") < 0) - goto error; + tmpdir_template = g_strdup("/tmp/libvirt_XXXXXX"); if (!(test->tmpdir = mkdtemp(tmpdir_template))) { virReportSystemError(errno, "%s", diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 8b857b0cc1..50435bbd02 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -146,8 +146,7 @@ virFileGetXAttrQuiet(const char *path, goto cleanup; } - if (VIR_STRDUP(*value, val) < 0) - goto cleanup; + *value = g_strdup(val); ret = 0; cleanup: @@ -194,8 +193,7 @@ int virFileSetXAttr(const char *path, char *val; key = get_key(path, name); - if (VIR_STRDUP(val, value) < 0) - return -1; + val = g_strdup(value); virMutexLock(&m); init_syms(); diff --git a/tests/qemuvhostusertest.c b/tests/qemuvhostusertest.c index 0ee96d9ecc..3e1890a88f 100644 --- a/tests/qemuvhostusertest.c +++ b/tests/qemuvhostusertest.c @@ -68,8 +68,7 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED) }; const size_t nexpected = G_N_ELEMENTS(expected); - if (VIR_STRDUP(fakehome, abs_srcdir "/qemuvhostuserdata/home/user/.config") < 0) - return -1; + fakehome = g_strdup(abs_srcdir "/qemuvhostuserdata/home/user/.config"); setenv("XDG_CONFIG_HOME", fakehome, 1); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 7bbc44451d..122e14b071 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -43,8 +43,7 @@ fakeSecretGetValue(virSecretPtr obj G_GNUC_UNUSED, unsigned int internalFlags G_GNUC_UNUSED) { char *secret; - if (VIR_STRDUP(secret, "AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A") < 0) - return NULL; + secret = g_strdup("AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A"); *value_size = strlen(secret); return (unsigned char *) secret; } @@ -517,9 +516,7 @@ testCompareXMLToArgv(const void *data) switch (vm->def->tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path); - if (VIR_STRDUP(vm->def->tpm->data.emulator.source.data.file.path, - "/dev/test") < 0) - goto cleanup; + vm->def->tpm->data.emulator.source.data.file.path = g_strdup("/dev/test"); vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_FILE; break; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: @@ -620,10 +617,7 @@ mymain(void) char *fakerootdir; virHashTablePtr capslatest = NULL; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - fprintf(stderr, "Out of memory\n"); - abort(); - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { fprintf(stderr, "Cannot create fakerootdir"); @@ -648,43 +642,33 @@ mymain(void) driver.privileged = true; VIR_FREE(driver.config->defaultTLSx509certdir); - if (VIR_STRDUP_QUIET(driver.config->defaultTLSx509certdir, "/etc/pki/qemu") < 0) - return EXIT_FAILURE; + driver.config->defaultTLSx509certdir = g_strdup("/etc/pki/qemu"); VIR_FREE(driver.config->vncTLSx509certdir); - if (VIR_STRDUP_QUIET(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc") < 0) - return EXIT_FAILURE; + driver.config->vncTLSx509certdir = g_strdup("/etc/pki/libvirt-vnc"); VIR_FREE(driver.config->spiceTLSx509certdir); - if (VIR_STRDUP_QUIET(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0) - return EXIT_FAILURE; + driver.config->spiceTLSx509certdir = g_strdup("/etc/pki/libvirt-spice"); VIR_FREE(driver.config->chardevTLSx509certdir); - if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509certdir, "/etc/pki/libvirt-chardev") < 0) - return EXIT_FAILURE; + driver.config->chardevTLSx509certdir = g_strdup("/etc/pki/libvirt-chardev"); VIR_FREE(driver.config->vxhsTLSx509certdir); - if (VIR_STRDUP_QUIET(driver.config->vxhsTLSx509certdir, "/etc/pki/libvirt-vxhs/dummy,path") < 0) - return EXIT_FAILURE; + driver.config->vxhsTLSx509certdir = g_strdup("/etc/pki/libvirt-vxhs/dummy,path"); VIR_FREE(driver.config->nbdTLSx509certdir); - if (VIR_STRDUP_QUIET(driver.config->nbdTLSx509certdir, "/etc/pki/libvirt-nbd/dummy,path") < 0) - return EXIT_FAILURE; + driver.config->nbdTLSx509certdir = g_strdup("/etc/pki/libvirt-nbd/dummy,path"); VIR_FREE(driver.config->hugetlbfs); if (VIR_ALLOC_N(driver.config->hugetlbfs, 2) < 0) return EXIT_FAILURE; driver.config->nhugetlbfs = 2; - if (VIR_STRDUP(driver.config->hugetlbfs[0].mnt_dir, "/dev/hugepages2M") < 0 || - VIR_STRDUP(driver.config->hugetlbfs[1].mnt_dir, "/dev/hugepages1G") < 0) - return EXIT_FAILURE; + driver.config->hugetlbfs[0].mnt_dir = g_strdup("/dev/hugepages2M"); + driver.config->hugetlbfs[1].mnt_dir = g_strdup("/dev/hugepages1G"); driver.config->hugetlbfs[0].size = 2048; driver.config->hugetlbfs[0].deflt = true; driver.config->hugetlbfs[1].size = 1048576; driver.config->spiceTLS = 1; - if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0) - return EXIT_FAILURE; + driver.config->spicePassword = g_strdup("123456"); VIR_FREE(driver.config->memoryBackingDir); - if (VIR_STRDUP_QUIET(driver.config->memoryBackingDir, "/var/lib/libvirt/qemu/ram") < 0) - return EXIT_FAILURE; + driver.config->memoryBackingDir = g_strdup("/var/lib/libvirt/qemu/ram"); VIR_FREE(driver.config->nvramDir); - if (VIR_STRDUP(driver.config->nvramDir, "/var/lib/libvirt/qemu/nvram") < 0) - return EXIT_FAILURE; + driver.config->nvramDir = g_strdup("/var/lib/libvirt/qemu/nvram"); capslatest = testQemuGetLatestCaps(); if (!capslatest) @@ -1222,9 +1206,7 @@ mymain(void) DO_TEST("graphics-vnc-tls", QEMU_CAPS_VNC, QEMU_CAPS_DEVICE_CIRRUS_VGA); DO_TEST_CAPS_VER("graphics-vnc-tls", "2.4.0"); DO_TEST_CAPS_LATEST("graphics-vnc-tls"); - if (VIR_STRDUP_QUIET(driver.config->vncTLSx509secretUUID, - "6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea") < 0) - return EXIT_FAILURE; + driver.config->vncTLSx509secretUUID = g_strdup("6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea"); DO_TEST_CAPS_LATEST("graphics-vnc-tls-secret"); VIR_FREE(driver.config->vncTLSx509secretUUID); driver.config->vncSASL = driver.config->vncTLSx509verify = driver.config->vncTLS = 0; @@ -1407,11 +1389,8 @@ mymain(void) QEMU_CAPS_DEVICE_ISA_SERIAL, QEMU_CAPS_OBJECT_TLS_CREDS_X509); VIR_FREE(driver.config->chardevTLSx509certdir); - if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509certdir, "/etc/pki/libvirt-chardev") < 0) - return EXIT_FAILURE; - if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509secretUUID, - "6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea") < 0) - return EXIT_FAILURE; + driver.config->chardevTLSx509certdir = g_strdup("/etc/pki/libvirt-chardev"); + driver.config->chardevTLSx509secretUUID = g_strdup("6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea"); DO_TEST("serial-tcp-tlsx509-secret-chardev", QEMU_CAPS_OBJECT_SECRET, QEMU_CAPS_DEVICE_ISA_SERIAL, diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 4c7ba98367..e7c029a74d 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -157,10 +157,7 @@ mymain(void) if (!capslatest) return EXIT_FAILURE; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - fprintf(stderr, "Out of memory\n"); - abort(); - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { fprintf(stderr, "Cannot create fakerootdir"); diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c index c1a7e2d603..35c7d93376 100644 --- a/tests/scsihosttest.c +++ b/tests/scsihosttest.c @@ -253,10 +253,7 @@ mymain(void) char *fakerootdir = NULL; char *fakesysfsdir = NULL; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - fprintf(stderr, "Out of memory\n"); - goto cleanup; - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { fprintf(stderr, "Cannot create fakerootdir"); diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 6f9b5c0e70..9156403c51 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -144,10 +144,7 @@ testSELinuxLoadFileList(const char *testname, abs_builddir, line) < 0) goto cleanup; if (*tmp != '\0' && *tmp != '\n') { - if (VIR_STRDUP(context, tmp) < 0) { - VIR_FREE(file); - goto cleanup; - } + context = g_strdup(tmp); tmp = strchr(context, '\n'); if (tmp) @@ -270,8 +267,7 @@ testSELinuxCheckLabels(testSELinuxFile *files, size_t nfiles) if (errno == ENODATA) { /* nothing to do */ } else if (errno == EOPNOTSUPP) { - if (VIR_STRDUP(ctx, "EOPNOTSUPP") < 0) - return -1; + ctx = g_strdup("EOPNOTSUPP"); } else { virReportSystemError(errno, "Cannot read label on %s", diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index 5dccb708d8..6c8314de6b 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -77,17 +77,14 @@ testBuildDomainDef(bool dynamic, if (VIR_ALLOC(secdef) < 0) goto error; - if (VIR_STRDUP(secdef->model, "selinux") < 0) - goto error; + secdef->model = g_strdup("selinux"); secdef->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC : VIR_DOMAIN_SECLABEL_STATIC; - if (label && - VIR_STRDUP(secdef->label, label) < 0) - goto error; + if (label) + secdef->label = g_strdup(label); - if (baselabel && - VIR_STRDUP(secdef->baselabel, baselabel) < 0) - goto error; + if (baselabel) + secdef->baselabel = g_strdup(baselabel); def->seclabels[0] = secdef; def->nseclabels++; diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c index 6504881920..a5403e7136 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -63,8 +63,7 @@ test_node_info_parser(const void *opaque) if (!(pool = virStoragePoolDefParseFile(data->poolxml))) return -1; - if (VIR_STRDUP(output, test.output) < 0) - return -1; + output = g_strdup(test.output); if (virStorageBackendSheepdogParseNodeInfo(pool, output) != test.expected_return) @@ -95,8 +94,7 @@ test_vdi_list_parser(const void *opaque) if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0))) return -1; - if (VIR_STRDUP(output, test.output) < 0) - return -1; + output = g_strdup(test.output); if (virStorageBackendSheepdogParseVdiList(vol, output) != test.expected_return) diff --git a/tests/testutils.c b/tests/testutils.c index 1c89d503d9..a141abc91b 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -816,8 +816,7 @@ virTestSetEnvPath(void) virAsprintf(&new_path, "%s:%s", abs_builddir, path) < 0) goto cleanup; } else { - if (VIR_STRDUP(new_path, abs_builddir) < 0) - goto cleanup; + new_path = g_strdup(abs_builddir); } if (new_path && diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index e6eca5cb2e..0faa9cb84a 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -74,8 +74,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines) "pc-0.11", "pc", "pc-0.10", "isapc" }; - if (VIR_STRDUP(canonical, x86_machines[0]) < 0) - return NULL; + canonical = g_strdup(x86_machines[0]); machines = virCapabilitiesAllocMachines(x86_machines, G_N_ELEMENTS(x86_machines)); @@ -503,9 +502,8 @@ virCapsPtr testQemuCapsInit(void) goto cleanup; caps->host.nsecModels = 1; - if (VIR_STRDUP(caps->host.secModels[0].model, "none") < 0 || - VIR_STRDUP(caps->host.secModels[0].doi, "0") < 0) - goto cleanup; + caps->host.secModels[0].model = g_strdup("none"); + caps->host.secModels[0].doi = g_strdup("0"); if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) || !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) || @@ -710,29 +708,22 @@ int qemuTestDriverInit(virQEMUDriver *driver) /* Overwrite some default paths so it's consistent for tests. */ VIR_FREE(driver->config->libDir); VIR_FREE(driver->config->channelTargetDir); - if (VIR_STRDUP(driver->config->libDir, "/tmp/lib") < 0 || - VIR_STRDUP(driver->config->channelTargetDir, "/tmp/channel") < 0) - goto error; + driver->config->libDir = g_strdup("/tmp/lib"); + driver->config->channelTargetDir = g_strdup("/tmp/channel"); if (!mkdtemp(statedir)) { virFilePrintf(stderr, "Cannot create fake stateDir"); goto error; } - if (VIR_STRDUP(driver->config->stateDir, statedir) < 0) { - rmdir(statedir); - goto error; - } + driver->config->stateDir = g_strdup(statedir); if (!mkdtemp(configdir)) { virFilePrintf(stderr, "Cannot create fake configDir"); goto error; } - if (VIR_STRDUP(driver->config->configDir, configdir) < 0) { - rmdir(configdir); - goto error; - } + driver->config->configDir = g_strdup(configdir); driver->caps = testQemuCapsInit(); if (!driver->caps) @@ -827,10 +818,9 @@ testQemuGetLatestCapsForArch(const char *arch, while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) { VIR_FREE(tmp); - if ((rc = VIR_STRDUP(tmp, STRSKIP(ent->d_name, "caps_"))) < 0) - goto cleanup; + tmp = g_strdup(STRSKIP(ent->d_name, "caps_")); - if (rc == 0) + if (!tmp) continue; if (!virStringStripSuffix(tmp, fullsuffix)) @@ -1051,8 +1041,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info, bool stripmachinealiases = false; if (STREQ(capsver, "latest")) { - if (VIR_STRDUP(capsfile, virHashLookup(capslatest, capsarch)) < 0) - goto cleanup; + capsfile = g_strdup(virHashLookup(capslatest, capsarch)); stripmachinealiases = true; } else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml", TEST_QEMU_CAPS_PATH, capsver, capsarch) < 0) { diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c index c70d7ab100..3d6171e266 100644 --- a/tests/vboxsnapshotxmltest.c +++ b/tests/vboxsnapshotxmltest.c @@ -58,9 +58,7 @@ testCompareXMLtoXMLFiles(const char *xml) int ret = -1; virVBoxSnapshotConfMachinePtr machine = NULL; - if (VIR_STRDUP(pathResult, - abs_builddir "/vboxsnapshotxmldata/testResult.vbox") < 0) - return -1; + pathResult = g_strdup(abs_builddir "/vboxsnapshotxmldata/testResult.vbox"); if (virFileMakePath(abs_builddir "/vboxsnapshotxmldata") < 0) goto cleanup; diff --git a/tests/viralloctest.c b/tests/viralloctest.c index 75e639675b..c52483998b 100644 --- a/tests/viralloctest.c +++ b/tests/viralloctest.c @@ -409,8 +409,7 @@ testDispose(const void *opaque G_GNUC_UNUSED) VIR_DISPOSE_N(nums, nnums); - if (VIR_STRDUP(str, "test") < 0) - return -1; + str = g_strdup("test"); VIR_DISPOSE_STRING(str); diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index cecb15ae5b..cec07580ac 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -992,10 +992,7 @@ initFakeFS(const char *mode, { char *fakerootdir; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - fprintf(stderr, "Out of memory\n"); - abort(); - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { fprintf(stderr, "Cannot create fakerootdir"); diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c index e3c6401934..6d280b3bec 100644 --- a/tests/virfilecachetest.c +++ b/tests/virfilecachetest.c @@ -71,14 +71,9 @@ testFileCacheObjNew(const char *data) if (!(obj = virObjectNew(testFileCacheObjClass))) return NULL; - if (VIR_STRDUP(obj->data, data) < 0) - goto error; + obj->data = g_strdup(data); return obj; - - error: - virObjectUnref(obj); - return NULL; } diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index 824e9f46c2..a5323a4256 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -961,19 +961,17 @@ testFirewallQueryHook(const char *const*args, const char *input G_GNUC_UNUSED, char **output, char **error G_GNUC_UNUSED, - int *status, + int *status G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { if (STREQ(args[0], IPTABLES_PATH) && STREQ(args[1], "-L")) { - if (VIR_STRDUP(*output, TEST_FILTER_TABLE_LIST) < 0) - *status = 127; + *output = g_strdup(TEST_FILTER_TABLE_LIST); } else if (STREQ(args[0], IPTABLES_PATH) && STREQ(args[1], "-t") && STREQ(args[2], "nat") && STREQ(args[3], "-L")) { - if (VIR_STRDUP(*output, TEST_NAT_TABLE_LIST) < 0) - *status = 127; + *output = g_strdup(TEST_NAT_TABLE_LIST); } } diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 8e21d3eae4..1f3f730433 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -117,8 +117,7 @@ myInit(void) goto cleanup; if ((mgr->activeSCSIHostdevs = virSCSIDeviceListNew()) == NULL) goto cleanup; - if (VIR_STRDUP(mgr->stateDir, TEST_STATE_DIR) < 0) - goto cleanup; + mgr->stateDir = g_strdup(TEST_STATE_DIR); if (virFileMakePath(mgr->stateDir) < 0) goto cleanup; @@ -501,10 +500,7 @@ mymain(void) int ret = 0; g_autofree char *fakerootdir = NULL; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - fprintf(stderr, "Out of memory\n"); - abort(); - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { fprintf(stderr, "Cannot create fakerootdir"); diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index 53544abbdb..b0a01e8b9d 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -228,15 +228,16 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) err.level = VIR_ERR_ERROR; if (VIR_ALLOC(err.message) < 0 || - VIR_STRDUP(*err.message, "Hello World") < 0 || VIR_ALLOC(err.str1) < 0 || - VIR_STRDUP(*err.str1, "One") < 0 || VIR_ALLOC(err.str2) < 0 || - VIR_STRDUP(*err.str2, "Two") < 0 || - VIR_ALLOC(err.str3) < 0 || - VIR_STRDUP(*err.str3, "Three") < 0) + VIR_ALLOC(err.str3) < 0) goto cleanup; + *err.message = g_strdup("Hello World"); + *err.str1 = g_strdup("One"); + *err.str2 = g_strdup("Two"); + *err.str3 = g_strdup("Three"); + err.int1 = 1; err.int2 = 2; diff --git a/tests/virpcimock.c b/tests/virpcimock.c index ba4256e2fb..d7dc0b00f0 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -289,8 +289,7 @@ getrealpath(char **newpath, return -1; } } else { - if (VIR_STRDUP_QUIET(*newpath, path) < 0) - return -1; + *newpath = g_strdup(path); } return 0; @@ -324,12 +323,12 @@ add_fd(int fd, const char *path) fd, path, cb.fd, cb.path); } - if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0 || - VIR_STRDUP_QUIET(callbacks[nCallbacks].path, path) < 0) { + if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0) { errno = ENOMEM; goto cleanup; } + callbacks[nCallbacks].path = g_strdup(path); callbacks[nCallbacks++].fd = fd; ret = 0; cleanup: @@ -477,10 +476,11 @@ pci_device_new_from_stub(const struct pciDevice *data) struct stat sb; bool configSrcExists = false; - if (!(devid = pci_address_format(&data->addr)) || - VIR_STRDUP_QUIET(id, devid) < 0) + if (!(devid = pci_address_format(&data->addr))) ABORT_OOM(); + id = g_strdup(devid); + /* Replace ':' with '-' to create the config filename from the * device ID. The device ID cannot be used directly as filename * because it contains ':' and Windows does not allow ':' in @@ -724,9 +724,10 @@ pci_driver_new(const char *name, ...) int vendor, device; g_autofree char *driverpath = NULL; - if (VIR_ALLOC_QUIET(driver) < 0 || - VIR_STRDUP_QUIET(driver->name, name) < 0 || - !(driverpath = pci_driver_get_path(driver, NULL, true))) + if (VIR_ALLOC_QUIET(driver) < 0) + ABORT_OOM(); + driver->name = g_strdup(name); + if (!(driverpath = pci_driver_get_path(driver, NULL, true))) ABORT_OOM(); if (virFileMakePath(driverpath) < 0) diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 4078dc4c69..de2ffc7d41 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -328,10 +328,7 @@ mymain(void) int ret = 0; char *fakerootdir; - if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { - VIR_TEST_DEBUG("Out of memory"); - abort(); - } + fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (!mkdtemp(fakerootdir)) { VIR_TEST_DEBUG("Cannot create fakerootdir"); diff --git a/tests/virscsitest.c b/tests/virscsitest.c index d4019e82f7..99374cc80c 100644 --- a/tests/virscsitest.c +++ b/tests/virscsitest.c @@ -222,10 +222,7 @@ mymain(void) VIR_FREE(virscsi_prefix); - if (VIR_STRDUP(virscsi_prefix, tmpdir) < 0) { - ret = -1; - goto cleanup; - } + virscsi_prefix = g_strdup(tmpdir); if (virTestRun("test1", test1, NULL) < 0) ret = -1; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 5d3edbc854..8f1d93fa5a 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -102,8 +102,7 @@ testStorageFileGetMetadata(const char *path, } } - if (VIR_STRDUP(def->path, path) < 0) - return NULL; + def->path = g_strdup(path); if (virStorageFileGetMetadata(def, uid, gid, false) < 0) return NULL; @@ -480,8 +479,7 @@ testPathCanonicalizeReadlink(const char *path, for (i = 0; i < G_N_ELEMENTS(testPathCanonicalizeSymlinks); i++) { if (STREQ(path, testPathCanonicalizeSymlinks[i][0])) { - if (VIR_STRDUP(*linkpath, testPathCanonicalizeSymlinks[i][1]) < 0) - return -1; + *linkpath = g_strdup(testPathCanonicalizeSymlinks[i][1]); return 0; } diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 5d010f7f59..1e408f2757 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -718,8 +718,7 @@ static int testStripIPv6Brackets(const void *args) int ret = -1; char *res = NULL; - if (VIR_STRDUP(res, data->string) < 0) - goto cleanup; + res = g_strdup(data->string); virStringStripIPv6Brackets(res); @@ -742,8 +741,7 @@ static int testStripControlChars(const void *args) int ret = -1; char *res = NULL; - if (VIR_STRDUP(res, data->string) < 0) - goto cleanup; + res = g_strdup(data->string); virStringStripControlChars(res); @@ -772,8 +770,7 @@ static int testFilterChars(const void *args) int ret = -1; char *res = NULL; - if (VIR_STRDUP(res, data->string) < 0) - goto cleanup; + res = g_strdup(data->string); virStringFilterChars(res, data->valid); diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 9fe774836b..e0f9c6c2a1 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -122,8 +122,7 @@ checkPath(const char *path, } else { /* Yeah, our worst nightmares just became true. Path does * not exist. Cut off the last component and retry. */ - if (VIR_STRDUP_QUIET(crippledPath, relPath ? relPath : path) < 0) - goto error; + crippledPath = g_strdup(relPath ? relPath : path); virFileRemoveLastComponent(crippledPath); diff --git a/tests/virusbmock.c b/tests/virusbmock.c index f35ad407ad..cace140725 100644 --- a/tests/virusbmock.c +++ b/tests/virusbmock.c @@ -56,8 +56,8 @@ static char *get_fake_path(const char *real_path) if ((p = STRSKIP(real_path, USB_SYSFS)) && virAsprintfQuiet(&path, "%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p) < 0) goto error; - else if (!p && VIR_STRDUP_QUIET(path, real_path) < 0) - goto error; + else if (!p) + path = g_strdup(real_path); return path; diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 4c5d41aee5..706fec7bac 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -142,8 +142,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED) if (STRPREFIX(fileName, "/vmfs/volumes/")) { /* Found absolute path referencing a file inside a datastore */ - if (VIR_STRDUP(copyOfFileName, fileName) < 0) - goto cleanup; + copyOfFileName = g_strdup(fileName); /* Expected format: '/vmfs/volumes//' */ if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL || diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 0cfdb1facf..42ab4ed929 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -153,8 +153,7 @@ testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED) if (STRPREFIX(src, "[")) { /* Found potential datastore path */ - if (VIR_STRDUP(copyOfDatastorePath, src) < 0) - goto cleanup; + copyOfDatastorePath = g_strdup(src); /* Expected format: '[] ' where is optional */ if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp == ']' ||