]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Adapt to VIR_STRDUP and VIR_STRNDUP in tests/*
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 3 May 2013 12:52:21 +0000 (14:52 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 10 May 2013 09:54:29 +0000 (11:54 +0200)
16 files changed:
tests/commandhelper.c
tests/commandtest.c
tests/openvzutilstest.c
tests/qemumonitortestutils.c
tests/qemuxml2argvtest.c
tests/qemuxmlnstest.c
tests/securityselinuxhelper.c
tests/securityselinuxlabeltest.c
tests/securityselinuxtest.c
tests/storagebackendsheepdogtest.c
tests/testutils.c
tests/testutilsqemu.c
tests/vircgrouptest.c
tests/virnetmessagetest.c
tests/vmx2xmltest.c
tests/xml2vmxtest.c

index 92f031fd41d4ff73ed017be504b613b53880504d..d0b97184a670c4839f403967103f351df0cc99db 100644 (file)
@@ -31,6 +31,7 @@
 #include "viralloc.h"
 #include "virfile.h"
 #include "testutils.h"
+#include "virstring.h"
 
 #ifndef WIN32
 
@@ -42,9 +43,13 @@ static int envsort(const void *a, const void *b) {
     const char *bstr = *bstrptr;
     char *aeq = strchr(astr, '=');
     char *beq = strchr(bstr, '=');
-    char *akey = strndup(astr, aeq - astr);
-    char *bkey = strndup(bstr, beq - bstr);
-    int ret = strcmp(akey, bkey);
+    char *akey;
+    char *bkey;
+    int ret;
+
+    ignore_value(VIR_STRNDUP_QUIET(akey, astr, aeq - astr));
+    ignore_value(VIR_STRNDUP_QUIET(bkey, bstr, beq - bstr));
+    ret = strcmp(akey, bkey);
     VIR_FREE(akey);
     VIR_FREE(bkey);
     return ret;
index 68398aca336a27a86f9a7c73b55a359048c749b0..ec69dbda1d10a1dd5aa0a0b4da4972f4cff3d42d 100644 (file)
@@ -685,7 +685,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
         goto cleanup;
     }
     VIR_FREE(outbuf);
-    if ((outbuf = strdup("should not be leaked")) == NULL) {
+    if (VIR_STRDUP(outbuf, "should not be leaked") < 0) {
         puts("test framework failure");
         goto cleanup;
     }
index be0c74cbd53b7cb65ad91359e1c69f349156faaa..48500177c55bf6a154d08ec0755bed304073f674 100644 (file)
@@ -13,6 +13,8 @@
 # include "openvz/openvz_conf.h"
 # include "virstring.h"
 
+# define VIR_FROM_THIS VIR_FROM_OPENVZ
+
 static int
 testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile,
                    const char *ext ATTRIBUTE_UNUSED)
@@ -103,8 +105,8 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
         "</domain>\n";
 
     if (VIR_ALLOC(def) < 0 ||
-        !(def->os.type = strdup("exe")) ||
-        !(def->os.init = strdup("/sbin/init")))
+        VIR_STRDUP(def->os.type, "exe") < 0 ||
+        VIR_STRDUP(def->os.init, "/sbin/init") < 0)
         goto cleanup;
 
     def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
index c24a37fb99f3dec6b84343f065b398abd413c19e..df09802b5c7b60ef276c50d520707e993a2d3846 100644 (file)
@@ -159,10 +159,8 @@ static int qemuMonitorTestProcessCommandText(qemuMonitorTestPtr test,
     char *cmdname;
     int ret = -1;
 
-    if (!(cmdname = strdup(cmdstr))) {
-        virReportOOMError();
+    if (VIR_STRDUP(cmdname, cmdstr) < 0)
         return -1;
-    }
     if (!(tmp = strchr(cmdname, ' '))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Cannot find command name in '%s'", cmdstr);
@@ -407,9 +405,9 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
     if (VIR_ALLOC(item) < 0)
         goto no_memory;
 
-    if (!(item->command_name = strdup(command_name)) ||
-        !(item->response = strdup(response)))
-        goto no_memory;
+    if (VIR_STRDUP(item->command_name, command_name) < 0 ||
+        VIR_STRDUP(item->response, response) < 0)
+        goto error;
 
     virMutexLock(&test->lock);
     if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) {
@@ -424,6 +422,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
 
 no_memory:
     virReportOOMError();
+error:
     qemuMonitorTestItemFree(item);
     return -1;
 }
@@ -467,8 +466,8 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
         return NULL;
     }
 
-    if (!(tmpdir_template = strdup("/tmp/libvirt_XXXXXX")))
-        goto no_memory;
+    if (VIR_STRDUP(tmpdir_template, "/tmp/libvirt_XXXXXX") < 0)
+        goto error;
 
     if (!(test->tmpdir = mkdtemp(tmpdir_template))) {
         virReportSystemError(errno, "%s",
index b1bf9dbc2a43569204c01e2aad17b055c192a0cb..bd1cc68cfa76cd0e52afd71c7bf59dc8db57d032 100644 (file)
@@ -23,6 +23,8 @@
 
 # include "testutilsqemu.h"
 
+# define VIR_FROM_THIS VIR_FROM_QEMU
+
 static const char *abs_top_srcdir;
 static virQEMUDriver driver;
 
@@ -32,10 +34,9 @@ fakeSecretGetValue(virSecretPtr obj ATTRIBUTE_UNUSED,
                    unsigned int fakeflags ATTRIBUTE_UNUSED,
                    unsigned int internalFlags ATTRIBUTE_UNUSED)
 {
-    char *secret = strdup("AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A");
-    if (!secret) {
+    char *secret;
+    if (VIR_STRDUP(secret, "AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A") < 0)
         return NULL;
-    }
     *value_size = strlen(secret);
     return (unsigned char *) secret;
 }
@@ -129,7 +130,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
     if (STREQ(vmdef->os.machine, "pc") &&
         STREQ(vmdef->emulator, "/usr/bin/qemu-system-x86_64")) {
         VIR_FREE(vmdef->os.machine);
-        if (!(vmdef->os.machine = strdup("pc-0.11")))
+        if (VIR_STRDUP(vmdef->os.machine, "pc-0.11") < 0)
             goto out;
     }
 
@@ -288,10 +289,10 @@ mymain(void)
     VIR_FREE(driver.config->vncListen);
 
     VIR_FREE(driver.config->vncTLSx509certdir);
-    if ((driver.config->vncTLSx509certdir = strdup("/etc/pki/libvirt-vnc")) == NULL)
+    if (VIR_STRDUP_QUIET(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc") < 0)
         return EXIT_FAILURE;
     VIR_FREE(driver.config->spiceTLSx509certdir);
-    if ((driver.config->spiceTLSx509certdir = strdup("/etc/pki/libvirt-spice")) == NULL)
+    if (VIR_STRDUP_QUIET(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0)
         return EXIT_FAILURE;
 
     if ((driver.caps = testQemuCapsInit()) == NULL)
@@ -299,16 +300,16 @@ mymain(void)
     if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
         return EXIT_FAILURE;
     VIR_FREE(driver.config->stateDir);
-    if ((driver.config->stateDir = strdup("/nowhere")) == NULL)
+    if (VIR_STRDUP_QUIET(driver.config->stateDir, "/nowhere") < 0)
         return EXIT_FAILURE;
     VIR_FREE(driver.config->hugetlbfsMount);
-    if ((driver.config->hugetlbfsMount = strdup("/dev/hugepages")) == NULL)
+    if (VIR_STRDUP_QUIET(driver.config->hugetlbfsMount, "/dev/hugepages") < 0)
         return EXIT_FAILURE;
     VIR_FREE(driver.config->hugepagePath);
-    if ((driver.config->hugepagePath = strdup("/dev/hugepages/libvirt/qemu")) == NULL)
+    if (VIR_STRDUP_QUIET(driver.config->hugepagePath, "/dev/hugepages/libvirt/qemu") < 0)
         return EXIT_FAILURE;
     driver.config->spiceTLS = 1;
-    if (!(driver.config->spicePassword = strdup("123456")))
+    if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
         return EXIT_FAILURE;
     if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
         cpuMapOverride(map) < 0) {
@@ -601,7 +602,7 @@ mymain(void)
 
     driver.config->vncSASL = 1;
     VIR_FREE(driver.config->vncSASLdir);
-    driver.config->vncSASLdir = strdup("/root/.sasl2");
+    ignore_value(VIR_STRDUP(driver.config->vncSASLdir, "/root/.sasl2"));
     DO_TEST("graphics-vnc-sasl", QEMU_CAPS_VNC, QEMU_CAPS_VGA);
     driver.config->vncTLS = 1;
     driver.config->vncTLSx509verify = 1;
index cd493e37e1bad227992f8a07fa50d7125bde8eef..952b8e2375122a732362cccb01c61f53ab73fb19 100644 (file)
@@ -21,6 +21,8 @@
 # include "testutilsqemu.h"
 # include "virstring.h"
 
+# define VIR_FROM_THIS VIR_FROM_QEMU
+
 static const char *abs_top_srcdir;
 static virQEMUDriver driver;
 
@@ -68,7 +70,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
      * detects such paths, strips the extra '/' and makes the path absolute.
      */
     if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
-        if (!(emulator = strdup(vmdef->emulator + 1)))
+        if (VIR_STRDUP(emulator, vmdef->emulator + 1) < 0)
             goto fail;
         VIR_FREE(vmdef->emulator);
         vmdef->emulator = NULL;
index 647b84156c11a7fbe3e0e8bb311a3142d2c791bc..a82ca6d7e1843c242c224f6a5723065a9fdad6ce 100644 (file)
@@ -28,6 +28,7 @@
 # include <attr/xattr.h>
 #endif
 
+#include "virstring.h"
 
 /*
  * The kernel policy will not allow us to arbitrarily change
@@ -43,9 +44,7 @@ int getcon_raw(security_context_t *context)
         errno = EINVAL;
         return -1;
     }
-    if (!(*context = strdup(getenv("FAKE_CONTEXT"))))
-        return -1;
-    return 0;
+    return VIR_STRDUP_QUIET(*context, getenv("FAKE_CONTEXT"));
 }
 
 int getcon(security_context_t *context)
@@ -65,9 +64,7 @@ int getpidcon_raw(pid_t pid, security_context_t *context)
         errno = EINVAL;
         return -1;
     }
-    if (!(*context = strdup(getenv("FAKE_CONTEXT"))))
-        return -1;
-    return 0;
+    return VIR_STRDUP_QUIET(*context, getenv("FAKE_CONTEXT"));
 }
 
 int getpidcon(pid_t pid, security_context_t *context)
index e270a765c3a67de6b07e85c63efb6917b99a100b..275ca9361bdce389cfd77152e51d57136b3252cc 100644 (file)
@@ -116,10 +116,9 @@ testSELinuxLoadFileList(const char *testname,
             goto cleanup;
         }
         if (*tmp != '\0' && *tmp != '\n') {
-            if (!(context = strdup(tmp))) {
+            if (VIR_STRDUP(context, tmp) < 0) {
                 VIR_FREE(line);
                 VIR_FREE(file);
-                virReportOOMError();
                 goto cleanup;
             }
 
index dd4cd11270ac1a93ef8ad735a1cf11d978777109..0d56769cc80f783ee88f0a319031d2ef09a939ee 100644 (file)
@@ -81,17 +81,18 @@ testBuildDomainDef(bool dynamic,
     def->seclabels[0]->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC : VIR_DOMAIN_SECLABEL_STATIC;
 
     if (label &&
-        !(def->seclabels[0]->label = strdup(label)))
-        goto no_memory;
+        VIR_STRDUP(def->seclabels[0]->label, label) < 0)
+        goto error;
 
     if (baselabel &&
-        !(def->seclabels[0]->baselabel = strdup(baselabel)))
-        goto no_memory;
+        VIR_STRDUP(def->seclabels[0]->baselabel, baselabel) < 0)
+        goto error;
 
     return def;
 
 no_memory:
     virReportOOMError();
+error:
     virDomainDefFree(def);
     return NULL;
 }
index 9b43a6d7bb96b842cccade422ce4da5b044397a1..39b2299b9fd16bb29b1e0c743ede425ae6e81241 100644 (file)
@@ -57,8 +57,7 @@ test_node_info_parser(collie_test test, char *poolxml)
     if (!(pool = virStoragePoolDefParseString(poolXmlData)))
         goto cleanup;
 
-    output = strdup(test.output);
-    if (!output)
+    if (VIR_STRDUP(output, test.output) < 0)
         goto cleanup;
 
     if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
@@ -102,8 +101,7 @@ test_vdi_list_parser(collie_test test, char *poolxml, char *volxml)
     if (!(vol = virStorageVolDefParseString(pool, volXmlData)))
         goto cleanup;
 
-    output = strdup(test.output);
-    if (!output)
+    if (VIR_STRDUP(output, test.output) < 0)
         goto cleanup;
 
     if (virStorageBackendSheepdogParseVdiList(vol, output) !=
index b0806defb8ea8a8675bffad8aa74bab7c864cce3..222c01690b5db59fdd35371de149dd220865e49e 100644 (file)
@@ -512,7 +512,9 @@ virtTestLogContentAndReset(void)
     if (virBufferError(&testLog.buf))
         return NULL;
     ret = virBufferContentAndReset(&testLog.buf);
-    return ret ? ret : strdup("");
+    if (!ret)
+        ignore_value(VIR_STRDUP(ret, ""));
+    return ret;
 }
 
 #if TEST_OOM_TRACE
index fba17a361c71c1fe813815338d94a8359b1b43b8..45ca6fe12416bebcd4219af53cd465043a5669c2 100644 (file)
@@ -8,6 +8,9 @@
 # include "cpu_conf.h"
 # include "qemu/qemu_driver.h"
 # include "qemu/qemu_domain.h"
+# include "virstring.h"
+
+# define VIR_FROM_THIS VIR_FROM_QEMU
 
 static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
 {
@@ -38,7 +41,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines)
         "pc-0.11", "pc", "pc-0.10", "isapc"
     };
 
-    if ((canonical = strdup(x86_machines[0])) == NULL)
+    if (VIR_STRDUP(canonical, x86_machines[0]) < 0)
         return NULL;
 
     machines = virCapabilitiesAllocMachines(x86_machines,
index 4777fae8473e5a504b24f01fe939ba3e3f01a1e3..75acfcb58e368ecf520ef66ddaad8c33b177f03b 100644 (file)
@@ -501,7 +501,7 @@ mymain(void)
     int ret = 0;
     char *fakesysfsdir;
 
-    if (!(fakesysfsdir = strdup(FAKESYSFSDIRTEMPLATE))) {
+    if (VIR_STRDUP_QUIET(fakesysfsdir, FAKESYSFSDIRTEMPLATE) < 0) {
         fprintf(stderr, "Out of memory\n");
         abort();
     }
index fabeffd19b24b7607e56a2220460bc0870d703b5..062c3ff6b3b3bce15c7e219793ab3d10555d8b6a 100644 (file)
@@ -27,7 +27,7 @@
 #include "virerror.h"
 #include "viralloc.h"
 #include "virlog.h"
-
+#include "virstring.h"
 #include "rpc/virnetmessage.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
@@ -236,18 +236,15 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED)
     err.domain = VIR_FROM_RPC;
     err.level = VIR_ERR_ERROR;
 
-    if (VIR_ALLOC(err.message) < 0)
-        goto cleanup;
-    *err.message = strdup("Hello World");
-    if (VIR_ALLOC(err.str1) < 0)
-        goto cleanup;
-    *err.str1 = strdup("One");
-    if (VIR_ALLOC(err.str2) < 0)
-        goto cleanup;
-    *err.str2 = strdup("Two");
-    if (VIR_ALLOC(err.str3) < 0)
+    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)
         goto cleanup;
-    *err.str3 = strdup("Three");
 
     err.int1 = 1;
     err.int2 = 2;
index bd7cbc6a0bf4f5ac08e373fc7e7c923e43371256..c9616de2e746d2c2ed859c3e431fd6bd4a778236 100644 (file)
@@ -13,6 +13,8 @@
 # include "vmx/vmx.h"
 # include "virstring.h"
 
+# define VIR_FROM_THIS VIR_FROM_VMWARE
+
 static virCapsPtr caps;
 static virDomainXMLOptionPtr xmlopt;
 static virVMXContext ctx;
@@ -159,11 +161,8 @@ testParseVMXFileName(const char *fileName, void *opaque ATTRIBUTE_UNUSED)
 
     if (STRPREFIX(fileName, "/vmfs/volumes/")) {
         /* Found absolute path referencing a file inside a datastore */
-        copyOfFileName = strdup(fileName);
-
-        if (copyOfFileName == NULL) {
+        if (VIR_STRDUP(copyOfFileName, fileName) < 0)
             goto cleanup;
-        }
 
         /* Expected format: '/vmfs/volumes/<datastore>/<path>' */
         if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||
@@ -177,7 +176,7 @@ testParseVMXFileName(const char *fileName, void *opaque ATTRIBUTE_UNUSED)
             goto cleanup;
     } else if (STRPREFIX(fileName, "/")) {
         /* Found absolute path referencing a file outside a datastore */
-        src = strdup(fileName);
+        ignore_value(VIR_STRDUP(src, fileName));
     } else if (strchr(fileName, '/') != NULL) {
         /* Found relative path, this is not supported */
         src = NULL;
index 38b5a4de49aa96a6746f9afc4357b941f702df3f..0dffebd38b05d3d9d7ec07f0e0c9d6c0dd029aef 100644 (file)
@@ -13,6 +13,8 @@
 # include "vmx/vmx.h"
 # include "virstring.h"
 
+# define VIR_FROM_THIS VIR_FROM_VMWARE
+
 static virCapsPtr caps;
 static virVMXContext ctx;
 static virDomainXMLOptionPtr xmlopt;
@@ -169,11 +171,8 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
 
     if (STRPREFIX(src, "[")) {
         /* Found potential datastore path */
-        copyOfDatastorePath = strdup(src);
-
-        if (copyOfDatastorePath == NULL) {
+        if (VIR_STRDUP(copyOfDatastorePath, src) < 0)
             goto cleanup;
-        }
 
         /* Expected format: '[<datastore>] <path>' where <path> is optional */
         if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp == ']' ||
@@ -194,7 +193,7 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
             goto cleanup;
     } else if (STRPREFIX(src, "/")) {
         /* Found absolute path */
-        absolutePath = strdup(src);
+        ignore_value(VIR_STRDUP(absolutePath, src));
     } else {
         /* Found relative path, this is not supported */
         goto cleanup;