build: expand rule to cover testsuite

The bulk of this patch was done with:

sed -i 's/\(\bfree *(/VIR_FREE(/g' tests/*.c

followed by fixing the few compile errors that resulted.

* cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation):
Remove tests from exemption.
* tests/testutils.h: Add common header.
* tests/commandhelper.c: Fix offenders.
* tests/cputest.c: Likewise.
* tests/domainsnapshotxml2xmltest.c: Likewise.
* tests/interfacexml2xmltest.c: Likewise.
* tests/networkxml2argvtest.c: Likewise.
* tests/networkxml2xmltest.c: Likewise.
* tests/nodedevxml2xmltest.c: Likewise.
* tests/nodeinfotest.c: Likewise.
* tests/nwfilterxml2xmltest.c: Likewise.
* tests/qemuargv2xmltest.c: Likewise.
* tests/qemuxml2argvtest.c: Likewise.
* tests/qemuxml2xmltest.c: Likewise.
* tests/qemuxmlnstest.c: Likewise.
* tests/qparamtest.c: Likewise.
* tests/sexpr2xmltest.c: Likewise.
* tests/storagepoolxml2xmltest.c: Likewise.
* tests/storagevolxml2xmltest.c: Likewise.
* tests/testutils.c: Likewise.
* tests/virshtest.c: Likewise.
* tests/xencapstest.c: Likewise.
* tests/xmconfigtest.c: Likewise.
* tests/xml2sexprtest.c: Likewise.
This commit is contained in:
Eric Blake 2012-02-02 16:16:43 -07:00
parent a7cfd709f4
commit 8fe454ce90
24 changed files with 134 additions and 131 deletions

2
cfg.mk
View File

@ -744,7 +744,7 @@ exclude_file_name_regexp--sc_prohibit_nonreentrant = \
^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$)
exclude_file_name_regexp--sc_prohibit_raw_allocation = \
^(src/util/memory\.[ch]|(examples|python|tests)/.*)$$
^(src/util/memory\.[ch]|(examples|python)/.*)$$
exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$

View File

@ -1,7 +1,7 @@
/*
* commandhelper.c: Auxiliary program for commandtest
*
* Copyright (C) 2010-2011 Red Hat, Inc.
* Copyright (C) 2010-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -42,8 +42,8 @@ static int envsort(const void *a, const void *b) {
char *akey = strndup(astr, aeq - astr);
char *bkey = strndup(bstr, beq - bstr);
int ret = strcmp(akey, bkey);
free(akey);
free(bkey);
VIR_FREE(akey);
VIR_FREE(bkey);
return ret;
}

View File

@ -104,7 +104,7 @@ cpuTestLoadXML(const char *arch, const char *name)
cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
free(xml);
VIR_FREE(xml);
return cpu;
}
@ -129,7 +129,7 @@ cpuTestLoadMultiXML(const char *arch,
goto error;
n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
if (n <= 0 || !(cpus = calloc(n, sizeof(virCPUDefPtr))))
if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0))
goto error;
for (i = 0; i < n; i++) {
@ -142,8 +142,8 @@ cpuTestLoadMultiXML(const char *arch,
*count = n;
cleanup:
free(xml);
free(nodes);
VIR_FREE(xml);
VIR_FREE(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
return cpus;
@ -152,7 +152,7 @@ error:
if (cpus) {
for (i = 0; i < n; i++)
virCPUDefFree(cpus[i]);
free(cpus);
VIR_FREE(cpus);
cpus = NULL;
}
goto cleanup;
@ -190,9 +190,9 @@ cpuTestCompareXML(const char *arch,
ret = 0;
cleanup:
free(xml);
free(expected);
free(actual);
VIR_FREE(xml);
VIR_FREE(expected);
VIR_FREE(actual);
return ret;
}
@ -381,10 +381,10 @@ cleanup:
if (cpus) {
for (i = 0; i < ncpus; i++)
virCPUDefFree(cpus[i]);
free(cpus);
VIR_FREE(cpus);
}
virCPUDefFree(baseline);
free(result);
VIR_FREE(result);
return ret;
}
@ -414,7 +414,7 @@ cpuTestUpdate(const void *arg)
cleanup:
virCPUDefFree(host);
virCPUDefFree(cpu);
free(result);
VIR_FREE(result);
return ret;
}
@ -473,11 +473,13 @@ static int
cpuTestRun(const char *name, const struct data *data)
{
char *label = NULL;
char *tmp;
if (virAsprintf(&label, "CPU %s(%s): %s", apis[data->api], data->arch, name) < 0)
return -1;
free(virtTestLogContentAndReset());
tmp = virtTestLogContentAndReset();
VIR_FREE(tmp);
if (virtTestRun(label, 1, cpuTest[data->api], data) < 0) {
if (virTestGetDebug()) {
@ -485,14 +487,14 @@ cpuTestRun(const char *name, const struct data *data)
if ((log = virtTestLogContentAndReset()) &&
strlen(log) > 0)
fprintf(stderr, "\n%s\n", log);
free(log);
VIR_FREE(log);
}
free(label);
VIR_FREE(label);
return -1;
}
free(label);
VIR_FREE(label);
return 0;
}
@ -513,7 +515,7 @@ mymain(void)
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
cpuMapOverride(map) < 0) {
free(map);
VIR_FREE(map);
return EXIT_FAILURE;
}
@ -632,7 +634,7 @@ mymain(void)
DO_TEST_GUESTDATA("x86", "host", "host+host-model-nofallback",
models, "Penryn", -1);
free(map);
VIR_FREE(map);
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@ -51,8 +51,8 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
ret = 0;
fail:
free(inXmlData);
free(actual);
VIR_FREE(inXmlData);
VIR_FREE(actual);
virDomainSnapshotDefFree(def);
return ret;
}
@ -77,7 +77,7 @@ testCompareXMLToXMLHelper(const void *data)
ret = testCompareXMLToXMLFiles(xml_in, info->uuid, info->internal);
cleanup:
free(xml_in);
VIR_FREE(xml_in);
return ret;
}

View File

@ -39,8 +39,8 @@ testCompareXMLToXMLFiles(const char *xml)
ret = 0;
fail:
free(xmlData);
free(actual);
VIR_FREE(xmlData);
VIR_FREE(actual);
virInterfaceDefFree(dev);
return ret;
}
@ -57,7 +57,7 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(xml);
free (xml);
VIR_FREE(xml);
return result;
}

View File

@ -91,9 +91,9 @@ static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
ret = 0;
fail:
free(inXmlData);
free(outArgvData);
free(actual);
VIR_FREE(inXmlData);
VIR_FREE(outArgvData);
VIR_FREE(actual);
VIR_FREE(pidfile);
virCommandFree(cmd);
virNetworkObjFree(obj);
@ -118,8 +118,8 @@ testCompareXMLToArgvHelper(const void *data)
result = testCompareXMLToArgvFiles(inxml, outxml);
cleanup:
free(inxml);
free(outxml);
VIR_FREE(inxml);
VIR_FREE(outxml);
return result;
}

View File

@ -42,9 +42,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
ret = 0;
fail:
free(inXmlData);
free(outXmlData);
free(actual);
VIR_FREE(inXmlData);
VIR_FREE(outXmlData);
VIR_FREE(actual);
virNetworkDefFree(dev);
return ret;
}
@ -72,8 +72,8 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(inxml, outxml, info->flags);
cleanup:
free(inxml);
free(outxml);
VIR_FREE(inxml);
VIR_FREE(outxml);
return result;
}

View File

@ -38,8 +38,8 @@ testCompareXMLToXMLFiles(const char *xml)
ret = 0;
fail:
free(xmlData);
free(actual);
VIR_FREE(xmlData);
VIR_FREE(actual);
virNodeDeviceDefFree(dev);
return ret;
}
@ -56,7 +56,7 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(xml);
free(xml);
VIR_FREE(xml);
return result;
}

View File

@ -81,8 +81,8 @@ linuxTestCompareFiles(const char *cpuinfofile,
ret = 0;
fail:
free(expectData);
free(actualData);
VIR_FREE(expectData);
VIR_FREE(actualData);
return ret;
}
@ -117,9 +117,9 @@ linuxTestNodeInfo(const void *data)
result = linuxTestCompareFiles(cpuinfo, sysfs_cpuinfo, output);
cleanup:
free(cpuinfo);
free(output);
free(sysfs_cpuinfo);
VIR_FREE(cpuinfo);
VIR_FREE(output);
VIR_FREE(sysfs_cpuinfo);
return result;
}

View File

@ -55,9 +55,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
ret = 0;
fail:
free(inXmlData);
free(outXmlData);
free(actual);
VIR_FREE(inXmlData);
VIR_FREE(outXmlData);
VIR_FREE(actual);
virNWFilterDefFree(dev);
return ret;
}
@ -85,8 +85,8 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning);
cleanup:
free(inxml);
free(outxml);
VIR_FREE(inxml);
VIR_FREE(outxml);
return result;
}

View File

@ -52,10 +52,10 @@ static int testCompareXMLToArgvFiles(const char *xml,
if ((log = virtTestLogContentAndReset()) == NULL)
goto fail;
if ((*log != '\0') != expect_warning) {
free(log);
VIR_FREE(log);
goto fail;
}
free(log);
VIR_FREE(log);
if (!(actualxml = virDomainDefFormat(vmdef, 0)))
goto fail;
@ -72,9 +72,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
ret = 0;
fail:
free(expectxml);
free(actualxml);
free(cmd);
VIR_FREE(expectxml);
VIR_FREE(actualxml);
VIR_FREE(cmd);
virDomainDefFree(vmdef);
return ret;
}
@ -103,8 +103,8 @@ testCompareXMLToArgvHelper(const void *data)
result = testCompareXMLToArgvFiles(xml, args, !!info->extraFlags);
cleanup:
free(xml);
free(args);
VIR_FREE(xml);
VIR_FREE(args);
return result;
}
@ -192,8 +192,8 @@ mymain(void)
driver.vncTLSx509certdir = strdup("/etc/pki/tls/qemu");
DO_TEST("graphics-vnc-tls");
driver.vncSASL = driver.vncTLSx509verify = driver.vncTLS = 0;
free(driver.vncSASLdir);
free(driver.vncTLSx509certdir);
VIR_FREE(driver.vncSASLdir);
VIR_FREE(driver.vncTLSx509certdir);
driver.vncSASLdir = driver.vncTLSx509certdir = NULL;
DO_TEST("graphics-sdl");
@ -238,7 +238,7 @@ mymain(void)
DO_TEST_FULL("qemu-ns-no-env", 1, NULL);
free(driver.stateDir);
VIR_FREE(driver.stateDir);
virCapabilitiesFree(driver.caps);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);

View File

@ -120,7 +120,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
if (!(emulator = strdup(vmdef->emulator + 1)))
goto out;
free(vmdef->emulator);
VIR_FREE(vmdef->emulator);
vmdef->emulator = NULL;
if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s",
abs_srcdir, emulator) < 0)
@ -164,8 +164,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
qemuDomainPCIAddressSetFree(pciaddrs);
}
free(virtTestLogContentAndReset());
log = virtTestLogContentAndReset();
VIR_FREE(log);
virResetLastError();
/* We do not call qemuCapsExtractVersionInfo() before calling
@ -233,10 +233,10 @@ static int testCompareXMLToArgvFiles(const char *xml,
ret = 0;
out:
free(log);
free(emulator);
free(expectargv);
free(actualargv);
VIR_FREE(log);
VIR_FREE(emulator);
VIR_FREE(expectargv);
VIR_FREE(actualargv);
virCommandFree(cmd);
virDomainDefFree(vmdef);
virUnrefConnect(conn);
@ -275,8 +275,8 @@ testCompareXMLToArgvHelper(const void *data)
info->expectFailure);
cleanup:
free(xml);
free(args);
VIR_FREE(xml);
VIR_FREE(args);
return result;
}
@ -307,7 +307,7 @@ mymain(void)
return EXIT_FAILURE;
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
cpuMapOverride(map) < 0) {
free(map);
VIR_FREE(map);
return EXIT_FAILURE;
}
@ -499,8 +499,8 @@ mymain(void)
driver.vncTLSx509certdir = strdup("/etc/pki/tls/qemu");
DO_TEST("graphics-vnc-tls", false, NONE);
driver.vncSASL = driver.vncTLSx509verify = driver.vncTLS = 0;
free(driver.vncSASLdir);
free(driver.vncTLSx509certdir);
VIR_FREE(driver.vncSASLdir);
VIR_FREE(driver.vncTLSx509certdir);
driver.vncSASLdir = driver.vncTLSx509certdir = NULL;
DO_TEST("graphics-sdl", false, NONE);
@ -738,9 +738,9 @@ mymain(void)
DO_TEST("pseries-vio-address-clash", true, QEMU_CAPS_DRIVE,
QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
free(driver.stateDir);
VIR_FREE(driver.stateDir);
virCapabilitiesFree(driver.caps);
free(map);
VIR_FREE(map);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@ -48,9 +48,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
ret = 0;
fail:
free(inXmlData);
free(outXmlData);
free(actual);
VIR_FREE(inXmlData);
VIR_FREE(outXmlData);
VIR_FREE(actual);
virDomainDefFree(def);
return ret;
}
@ -81,8 +81,8 @@ testCompareXMLToXMLHelper(const void *data)
}
cleanup:
free(xml_in);
free(xml_out);
VIR_FREE(xml_in);
VIR_FREE(xml_out);
return ret;
}

View File

@ -69,7 +69,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
if (!(emulator = strdup(vmdef->emulator + 1)))
goto fail;
free(vmdef->emulator);
VIR_FREE(vmdef->emulator);
vmdef->emulator = NULL;
if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s",
abs_srcdir, emulator) < 0)
@ -107,7 +107,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
}
free(virtTestLogContentAndReset());
log = virtTestLogContentAndReset();
VIR_FREE(log);
virResetLastError();
/* We do not call qemuCapsExtractVersionInfo() before calling
@ -159,10 +160,10 @@ static int testCompareXMLToArgvFiles(const char *xml,
ret = 0;
fail:
free(log);
free(emulator);
free(expectargv);
free(actualargv);
VIR_FREE(log);
VIR_FREE(emulator);
VIR_FREE(expectargv);
VIR_FREE(actualargv);
virCommandFree(cmd);
virDomainDefFree(vmdef);
virUnrefConnect(conn);
@ -198,8 +199,8 @@ testCompareXMLToArgvHelper(const void *data)
info->json, info->expectError);
cleanup:
free(xml);
free(args);
VIR_FREE(xml);
VIR_FREE(args);
return result;
}
@ -231,7 +232,7 @@ mymain(void)
return EXIT_FAILURE;
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
cpuMapOverride(map) < 0) {
free(map);
VIR_FREE(map);
return EXIT_FAILURE;
}
@ -275,9 +276,9 @@ mymain(void)
DO_TEST("qemu-ns-commandline-ns0", false, NONE);
DO_TEST("qemu-ns-commandline-ns1", false, NONE);
free(driver.stateDir);
VIR_FREE(driver.stateDir);
virCapabilitiesFree(driver.caps);
free(map);
VIR_FREE(map);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@ -71,7 +71,7 @@ qparamFormatTest(const void *data)
ret = 0;
fail:
free(output);
VIR_FREE(output);
free_qparam_set(actual);
return ret;
}

View File

@ -67,9 +67,9 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
ret = 0;
fail:
free(xmlData);
free(sexprData);
free(gotxml);
VIR_FREE(xmlData);
VIR_FREE(sexprData);
VIR_FREE(gotxml);
virDomainDefFree(def);
if (conn)
virUnrefConnect(conn);
@ -101,8 +101,8 @@ testCompareHelper(const void *data)
result = testCompareFiles(xml, args, info->version);
cleanup:
free(xml);
free(args);
VIR_FREE(xml);
VIR_FREE(args);
return result;
}

View File

@ -41,9 +41,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
ret = 0;
fail:
free(inXmlData);
free(outXmlData);
free(actual);
VIR_FREE(inXmlData);
VIR_FREE(outXmlData);
VIR_FREE(actual);
virStoragePoolDefFree(dev);
return ret;
}
@ -65,8 +65,8 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(inxml, outxml);
cleanup:
free(inxml);
free(outxml);
VIR_FREE(inxml);
VIR_FREE(outxml);
return result;
}

View File

@ -49,10 +49,10 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
ret = 0;
fail:
free(poolXmlData);
free(inXmlData);
free(outXmlData);
free(actual);
VIR_FREE(poolXmlData);
VIR_FREE(inXmlData);
VIR_FREE(outXmlData);
VIR_FREE(actual);
virStoragePoolDefFree(pool);
virStorageVolDefFree(dev);
return ret;
@ -84,9 +84,9 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(poolxml, inxml, outxml);
cleanup:
free(poolxml);
free(inxml);
free(outxml);
VIR_FREE(poolxml);
VIR_FREE(inxml);
VIR_FREE(outxml);
return result;
}

View File

@ -128,8 +128,7 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
fprintf(stderr, "%2d) %-65s ... ", testCounter, title);
}
if (nloops > 1 && (ts = calloc(nloops,
sizeof(double)))==NULL)
if (nloops > 1 && (VIR_ALLOC_N(ts, nloops) < 0))
return -1;
for (i=0; i < nloops; i++) {
@ -181,7 +180,7 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
}
}
free(ts);
VIR_FREE(ts);
return ret;
}
@ -236,7 +235,7 @@ virtTestLoadFile(const char *file, char **buf)
if (ferror(fp)) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
VIR_FORCE_FCLOSE(fp);
free(*buf);
VIR_FREE(*buf);
return -1;
}
}
@ -512,7 +511,7 @@ virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED)
if (symbols[i])
fprintf(stderr, " TRACE: %s\n", symbols[i]);
}
free(symbols);
VIR_FREE(symbols);
}
}
#endif

View File

@ -1,7 +1,7 @@
/*
* utils.c: test utils
*
* Copyright (C) 2005, 2008-2011 Red Hat, Inc.
* Copyright (C) 2005, 2008-2012 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@ -12,6 +12,7 @@
# define __VIT_TEST_UTILS_H__
# include <stdio.h>
# include "memory.h"
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */

View File

@ -76,7 +76,7 @@ testCompareOutputLit(const char *expectData,
result = 0;
cleanup:
free(actualData);
VIR_FREE(actualData);
return result;
}
@ -388,7 +388,7 @@ mymain(void)
# undef DO_TEST
free(custom_uri);
VIR_FREE(custom_uri);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@ -54,11 +54,11 @@ testCompareFiles(const char *hostmachine, const char *xml_rel,
ret = 0;
fail:
free(expectxml);
free(actualxml);
free(xml);
free(cpuinfo);
free(capabilities);
VIR_FREE(expectxml);
VIR_FREE(actualxml);
VIR_FREE(xml);
VIR_FREE(cpuinfo);
VIR_FREE(capabilities);
VIR_FORCE_FCLOSE(fp1);
VIR_FORCE_FCLOSE(fp2);

View File

@ -87,9 +87,9 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
ret = 0;
fail:
free(xmlData);
free(xmcfgData);
free(gotxmcfgData);
VIR_FREE(xmlData);
VIR_FREE(xmcfgData);
VIR_FREE(gotxmcfgData);
if (conf)
virConfFree(conf);
virDomainDefFree(def);
@ -179,8 +179,8 @@ testCompareHelper(const void *data)
result = testCompareFormatXML(cfg, xml, info->version);
cleanup:
free(xml);
free(cfg);
VIR_FREE(xml);
VIR_FREE(cfg);
return result;
}

View File

@ -46,9 +46,9 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
ret = 0;
fail:
free(xmlData);
free(sexprData);
free(gotsexpr);
VIR_FREE(xmlData);
VIR_FREE(sexprData);
VIR_FREE(gotsexpr);
virDomainDefFree(def);
return ret;
@ -79,8 +79,8 @@ testCompareHelper(const void *data)
result = testCompareFiles(xml, args, info->version);
cleanup:
free(xml);
free(args);
VIR_FREE(xml);
VIR_FREE(args);
return result;
}