tests: Use g_strdup_printf() instead of virAsprintf()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-10-22 15:26:14 +02:00
parent 06030f05bb
commit 4fa804c0c7
87 changed files with 483 additions and 859 deletions

View File

@ -106,15 +106,13 @@ testCompareXMLToArgvHelper(const void *data)
char *xml = NULL;
char *args = NULL;
if (virAsprintf(&xml, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&args, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.args",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/bhyveargv2xmldata/bhyveargv2xml-%s.xml",
abs_srcdir, info->name);
args = g_strdup_printf("%s/bhyveargv2xmldata/bhyveargv2xml-%s.args",
abs_srcdir, info->name);
result = testCompareXMLToArgvFiles(xml, args, info->flags);
cleanup:
VIR_FREE(xml);
VIR_FREE(args);
return result;

View File

@ -119,19 +119,17 @@ testCompareXMLToArgvHelper(const void *data)
char *xml = NULL;
char *args = NULL, *ldargs = NULL, *dmargs = NULL;
if (virAsprintf(&xml, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&args, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
abs_srcdir, info->name) < 0 ||
virAsprintf(&ldargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.ldargs",
abs_srcdir, info->name) < 0 ||
virAsprintf(&dmargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.devmap",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
abs_srcdir, info->name);
args = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
abs_srcdir, info->name);
ldargs = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.ldargs",
abs_srcdir, info->name);
dmargs = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.devmap",
abs_srcdir, info->name);
ret = testCompareXMLToArgvFiles(xml, args, ldargs, dmargs, info->flags);
cleanup:
VIR_FREE(xml);
VIR_FREE(args);
VIR_FREE(ldargs);

View File

@ -31,11 +31,10 @@ testCompareXMLToXMLHelper(const void *data)
bool is_different = info->flags & FLAG_IS_DIFFERENT;
int ret = -1;
if (virAsprintf(&xml_in, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&xml_out, "%s/bhyvexml2xmloutdata/bhyvexml2xmlout-%s.xml",
abs_srcdir, info->name) < 0)
goto cleanup;
xml_in = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
abs_srcdir, info->name);
xml_out = g_strdup_printf("%s/bhyvexml2xmloutdata/bhyvexml2xmlout-%s.xml",
abs_srcdir, info->name);
ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in,
is_different ? xml_out : xml_in,
@ -49,7 +48,6 @@ testCompareXMLToXMLHelper(const void *data)
virResetLastError();
}
cleanup:
VIR_FREE(xml_in);
VIR_FREE(xml_out);
return ret;

View File

@ -67,11 +67,8 @@ static int checkoutput(const char *testname,
char *actualname = NULL;
char *actuallog = NULL;
if (virAsprintf(&expectname, "%s/commanddata/%s.log", abs_srcdir,
testname) < 0)
goto cleanup;
if (virAsprintf(&actualname, "%s/commandhelper.log", abs_builddir) < 0)
goto cleanup;
expectname = g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, testname);
actualname = g_strdup_printf("%s/commandhelper.log", abs_builddir);
if (virFileReadAll(expectname, 1024*64, &expectlog) < 0) {
fprintf(stderr, "cannot read %s\n", expectname);
@ -86,8 +83,7 @@ static int checkoutput(const char *testname,
if (prefix) {
char *tmp = NULL;
if (virAsprintf(&tmp, "%s%s", prefix, expectlog) < 0)
goto cleanup;
tmp = g_strdup_printf("%s%s", prefix, expectlog);
VIR_FREE(expectlog);
expectlog = tmp;
@ -595,8 +591,7 @@ static int test15(const void *unused G_GNUC_UNUSED)
char *cwd = NULL;
int ret = -1;
if (virAsprintf(&cwd, "%s/commanddata", abs_srcdir) < 0)
goto cleanup;
cwd = g_strdup_printf("%s/commanddata", abs_srcdir);
virCommandSetWorkingDirectory(cmd, cwd);
virCommandSetUmask(cmd, 002);
@ -815,8 +810,7 @@ static int test20(const void *unused G_GNUC_UNUSED)
sigaction(SIGPIPE, &sig_action, NULL);
if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0)
goto cleanup;
buf = g_strdup_printf("1\n%100000d\n", 2);
virCommandSetInputBuffer(cmd, buf);
if (virCommandRun(cmd, NULL) < 0) {
@ -1174,13 +1168,10 @@ static int test27(const void *unused G_GNUC_UNUSED)
buffer2[buflen - 2] = '\n';
buffer2[buflen - 1] = 0;
if (virAsprintf(&outexpect, TEST27_OUTEXPECT_TEMP,
buffer0, buffer1, buffer2) < 0 ||
virAsprintf(&errexpect, TEST27_ERREXPECT_TEMP,
buffer0, buffer1, buffer2) < 0) {
printf("Could not virAsprintf expected output\n");
goto cleanup;
}
outexpect = g_strdup_printf(TEST27_OUTEXPECT_TEMP,
buffer0, buffer1, buffer2);
errexpect = g_strdup_printf(TEST27_ERREXPECT_TEMP,
buffer0, buffer1, buffer2);
if (pipe(pipe1) < 0 || pipe(pipe2) < 0) {
printf("Could not create pipe: %s\n", g_strerror(errno));

View File

@ -75,9 +75,8 @@ cpuTestLoadXML(virArch arch, const char *name)
xmlXPathContextPtr ctxt = NULL;
virCPUDefPtr cpu = NULL;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
abs_srcdir, virArchToString(arch), name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
virArchToString(arch), name);
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
goto cleanup;
@ -105,9 +104,8 @@ cpuTestLoadMultiXML(virArch arch,
int n;
size_t i;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
abs_srcdir, virArchToString(arch), name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
virArchToString(arch), name);
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
goto cleanup;
@ -150,9 +148,8 @@ cpuTestCompareXML(virArch arch,
char *actual = NULL;
int ret = -1;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
abs_srcdir, virArchToString(arch), name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
virArchToString(arch), name);
if (!(actual = virCPUDefFormat(cpu, NULL)))
goto cleanup;
@ -341,8 +338,7 @@ cpuTestBaseline(const void *arg)
suffix = "migratable";
else
suffix = "result";
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
goto cleanup;
result = g_strdup_printf("%s-%s", data->name, suffix);
if (cpuTestCompareXML(data->arch, baseline, result) < 0)
goto cleanup;
@ -395,8 +391,7 @@ cpuTestUpdate(const void *arg)
if (virCPUUpdate(host->arch, cpu, migHost) < 0)
goto cleanup;
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
goto cleanup;
result = g_strdup_printf("%s+%s", data->host, data->name);
ret = cpuTestCompareXML(data->arch, cpu, result);
@ -481,9 +476,8 @@ cpuTestMakeQEMUCaps(const struct data *data)
bool fail_no_props = true;
char *json = NULL;
if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json",
abs_srcdir, virArchToString(data->arch), data->host) < 0)
goto error;
json = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.json", abs_srcdir,
virArchToString(data->arch), data->host);
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
goto error;
@ -585,9 +579,8 @@ cpuTestCPUID(bool guest, const void *arg)
char *result = NULL;
virDomainCapsCPUModelsPtr models = NULL;
if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml",
abs_srcdir, virArchToString(data->arch), data->host) < 0)
goto cleanup;
hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
virArchToString(data->arch), data->host);
if (virTestLoadFile(hostFile, &host) < 0 ||
!(hostData = virCPUDataParse(host)))
@ -618,10 +611,7 @@ cpuTestCPUID(bool guest, const void *arg)
if (cpuDecode(cpu, hostData, models) < 0)
goto cleanup;
if (virAsprintf(&result, "cpuid-%s-%s",
data->host,
guest ? "guest" : "host") < 0)
goto cleanup;
result = g_strdup_printf("cpuid-%s-%s", data->host, guest ? "guest" : "host");
ret = cpuTestCompareXML(data->arch, cpu, result);
@ -663,17 +653,12 @@ cpuTestCompareSignature(const struct data *data,
signature = virCPUx86DataGetSignature(hostData, &family, &model, &stepping);
if (virAsprintf(&result, "%s/cputestdata/%s-cpuid-%s.sig",
abs_srcdir, virArchToString(data->arch), data->host) < 0)
return -1;
result = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.sig", abs_srcdir,
virArchToString(data->arch), data->host);
if (virAsprintf(&sigStr,
"%1$06lx\n"
"family: %2$3u (0x%2$02x)\n"
"model: %3$3u (0x%3$02x)\n"
"stepping: %4$3u (0x%4$02x)\n",
signature, family, model, stepping) < 0)
return -1;
sigStr = g_strdup_printf("%1$06lx\n" "family: %2$3u (0x%2$02x)\n"
"model: %3$3u (0x%3$02x)\n" "stepping: %4$3u (0x%4$02x)\n",
signature, family, model, stepping);
return virTestCompareToFile(sigStr, result);
}
@ -688,9 +673,8 @@ cpuTestCPUIDSignature(const void *arg)
char *host = NULL;
int ret = -1;
if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml",
abs_srcdir, virArchToString(data->arch), data->host) < 0)
goto cleanup;
hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
virArchToString(data->arch), data->host);
if (virTestLoadFile(hostFile, &host) < 0 ||
!(hostData = virCPUDataParse(host)))
@ -813,24 +797,24 @@ cpuTestUpdateLive(const void *arg)
virDomainCapsCPUModelsPtr models = NULL;
int ret = -1;
if (virAsprintf(&cpuFile, "cpuid-%s-guest", data->host) < 0 ||
!(cpu = cpuTestLoadXML(data->arch, cpuFile)))
cpuFile = g_strdup_printf("cpuid-%s-guest", data->host);
if (!(cpu = cpuTestLoadXML(data->arch, cpuFile)))
goto cleanup;
if (virAsprintf(&enabledFile, "%s/cputestdata/%s-cpuid-%s-enabled.xml",
abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
virTestLoadFile(enabledFile, &enabled) < 0 ||
enabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-enabled.xml",
abs_srcdir, virArchToString(data->arch), data->host);
if (virTestLoadFile(enabledFile, &enabled) < 0 ||
!(enabledData = virCPUDataParse(enabled)))
goto cleanup;
if (virAsprintf(&disabledFile, "%s/cputestdata/%s-cpuid-%s-disabled.xml",
abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
virTestLoadFile(disabledFile, &disabled) < 0 ||
disabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-disabled.xml",
abs_srcdir, virArchToString(data->arch), data->host);
if (virTestLoadFile(disabledFile, &disabled) < 0 ||
!(disabledData = virCPUDataParse(disabled)))
goto cleanup;
if (virAsprintf(&expectedFile, "cpuid-%s-json", data->host) < 0 ||
!(expected = cpuTestLoadXML(data->arch, expectedFile)))
expectedFile = g_strdup_printf("cpuid-%s-json", data->host);
if (!(expected = cpuTestLoadXML(data->arch, expectedFile)))
goto cleanup;
/* In case the host CPU signature does not exactly match any CPU model from
@ -902,8 +886,7 @@ cpuTestJSONCPUID(const void *arg)
char *result = NULL;
int ret = -1;
if (virAsprintf(&result, "cpuid-%s-json", data->host) < 0)
goto cleanup;
result = g_strdup_printf("cpuid-%s-json", data->host);
if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
goto cleanup;
@ -1024,11 +1007,8 @@ mymain(void)
tmp = virTestLogContentAndReset(); \
VIR_FREE(tmp); \
\
if (virAsprintf(&testLabel, "%s(%s): %s", \
#api, virArchToString(arch), name) < 0) { \
ret = -1; \
break; \
} \
testLabel = g_strdup_printf("%s(%s): %s", #api, \
virArchToString(arch), name); \
\
if (virTestRun(testLabel, api, &data) < 0) { \
if (virTestGetDebug()) { \
@ -1068,12 +1048,9 @@ mymain(void)
suffix = " (expanded)"; \
if ((flags) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) \
suffix = " (migratable)"; \
if (virAsprintf(&label, "%s%s", name, suffix) < 0) { \
ret = -1; \
} else { \
DO_TEST(arch, cpuTestBaseline, label, NULL, \
"baseline-" name, NULL, flags, result); \
} \
label = g_strdup_printf("%s%s", name, suffix); \
DO_TEST(arch, cpuTestBaseline, label, NULL, \
"baseline-" name, NULL, flags, result); \
VIR_FREE(label); \
} while (0)

View File

@ -88,9 +88,8 @@ fillQemuCaps(virDomainCapsPtr domCaps,
fakeHostCPU(caps, domCaps->arch) < 0)
goto cleanup;
if (virAsprintf(&path, "%s/%s.%s.xml",
TEST_QEMU_CAPS_PATH, name, arch) < 0 ||
!(qemuCaps = qemuTestParseCapabilities(caps, path)))
path = g_strdup_printf("%s/%s.%s.xml", TEST_QEMU_CAPS_PATH, name, arch);
if (!(qemuCaps = qemuTestParseCapabilities(caps, path)))
goto cleanup;
if (machine) {
@ -217,9 +216,7 @@ test_virDomainCapsFormat(const void *opaque)
char *domCapsXML = NULL;
int ret = -1;
if (virAsprintf(&path, "%s/domaincapsdata/%s.xml",
abs_srcdir, data->name) < 0)
goto cleanup;
path = g_strdup_printf("%s/domaincapsdata/%s.xml", abs_srcdir, data->name);
if (!(domCaps = virDomainCapsNew(data->emulator, data->machine,
virArchFromString(data->arch),
@ -407,10 +404,7 @@ mymain(void)
#define DO_TEST_BHYVE(Name, Emulator, BhyveCaps, Type) \
do { \
char *name = NULL; \
if (virAsprintf(&name, "bhyve_%s.x86_64", Name) < 0) { \
ret = -1; \
break; \
} \
name = g_strdup_printf("bhyve_%s.x86_64", Name); \
struct testData data = { \
.name = name, \
.emulator = Emulator, \

View File

@ -46,9 +46,8 @@ static int testGetFilesystem(const void *opaque)
const struct testGetFilesystemData *data = opaque;
virDomainFSDefPtr fsdef;
if (virAsprintf(&filename, "%s/domainconfdata/%s.xml",
abs_srcdir, data->filename) < 0)
goto cleanup;
filename = g_strdup_printf("%s/domainconfdata/%s.xml", abs_srcdir,
data->filename);
if (!(def = virDomainDefParseFile(filename, caps, xmlopt, NULL, 0)))
goto cleanup;

View File

@ -343,11 +343,7 @@ mymain(void)
{
int ret = 0;
if (virAsprintf(&fchost_prefix, "%s/%s", abs_srcdir,
"fchostdata/fc_host/") < 0) {
ret = -1;
goto cleanup;
}
fchost_prefix = g_strdup_printf("%s/%s", abs_srcdir, "fchostdata/fc_host/");
if (virTestRun("virVHBAPathExists", test1, NULL) < 0)
ret = -1;
@ -377,7 +373,6 @@ mymain(void)
test11_xml) < 0)
ret = -1;
cleanup:
VIR_FREE(fchost_prefix);
return ret;
}

View File

@ -62,8 +62,7 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
for (i = 0; i < PATTERN_LEN; i++)
pattern[i] = i;
if (virAsprintf(&file, "%s/input.data", scratchdir) < 0)
goto cleanup;
file = g_strdup_printf("%s/input.data", scratchdir);
if ((fd = open(file, O_CREAT|O_WRONLY|O_EXCL, 0600)) < 0)
goto cleanup;
@ -194,8 +193,7 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
for (i = 0; i < PATTERN_LEN; i++)
pattern[i] = i;
if (virAsprintf(&file, "%s/input.data", scratchdir) < 0)
goto cleanup;
file = g_strdup_printf("%s/input.data", scratchdir);
if (!(st = virStreamNew(conn, flags)))
goto cleanup;

View File

@ -29,17 +29,15 @@ testCompareXMLToXMLHelper(const void *data)
char *xml_out = NULL;
int ret = -1;
if (virAsprintf(&xml_in, "%s/genericxml2xmlindata/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&xml_out, "%s/genericxml2xmloutdata/%s.xml",
abs_srcdir, info->name) < 0)
goto cleanup;
xml_in = g_strdup_printf("%s/genericxml2xmlindata/%s.xml",
abs_srcdir, info->name);
xml_out = g_strdup_printf("%s/genericxml2xmloutdata/%s.xml",
abs_srcdir, info->name);
ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
info->different ? xml_out : xml_in,
!info->inactive_only, 0,
info->expectResult);
cleanup:
VIR_FREE(xml_in);
VIR_FREE(xml_out);
return ret;

View File

@ -50,9 +50,8 @@ testCompareXMLToXMLHelper(const void *data)
int result = -1;
char *xml = NULL;
if (virAsprintf(&xml, "%s/interfaceschemadata/%s.xml",
abs_srcdir, (const char*)data) < 0)
return -1;
xml = g_strdup_printf("%s/interfaceschemadata/%s.xml", abs_srcdir,
(const char *)data);
result = testCompareXMLToXMLFiles(xml);

View File

@ -151,15 +151,11 @@ testCompareXMLToDomConfigHelper(const void *data)
char *xmlfile = NULL;
char *jsonfile = NULL;
if (virAsprintf(&xmlfile, "%s/libxlxml2domconfigdata/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&jsonfile, "%s/libxlxml2domconfigdata/%s.json",
abs_srcdir, info->name) < 0)
goto cleanup;
xmlfile = g_strdup_printf("%s/libxlxml2domconfigdata/%s.xml", abs_srcdir, info->name);
jsonfile = g_strdup_printf("%s/libxlxml2domconfigdata/%s.json", abs_srcdir, info->name);
ret = testCompareXMLToDomConfig(xmlfile, jsonfile);
cleanup:
VIR_FREE(xmlfile);
VIR_FREE(jsonfile);
return ret;

View File

@ -71,15 +71,13 @@ testCompareXMLToConfigHelperLegacy(const void *data)
char *xml = NULL;
char *config = NULL;
if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s.config",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name);
config = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.config",
abs_srcdir, info->name);
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
cleanup:
VIR_FREE(xml);
VIR_FREE(config);
return result;
@ -93,15 +91,13 @@ testCompareXMLToConfigHelperV3(const void *data)
char *xml = NULL;
char *config = NULL;
if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s-v3.config",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name);
config = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s-v3.config",
abs_srcdir, info->name);
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
cleanup:
VIR_FREE(xml);
VIR_FREE(config);
return result;

View File

@ -34,18 +34,16 @@ testCompareXMLToXMLHelper(const void *data)
char *xml_out = NULL;
int ret = -1;
if (virAsprintf(&xml_in, "%s/lxcxml2xmldata/lxc-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&xml_out, "%s/lxcxml2xmloutdata/lxc-%s.xml",
abs_srcdir, info->name) < 0)
goto cleanup;
xml_in = g_strdup_printf("%s/lxcxml2xmldata/lxc-%s.xml",
abs_srcdir, info->name);
xml_out = g_strdup_printf("%s/lxcxml2xmloutdata/lxc-%s.xml",
abs_srcdir, info->name);
ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
info->different ? xml_out : xml_in,
!info->inactive_only,
info->parse_flags,
TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS);
cleanup:
VIR_FREE(xml_in);
VIR_FREE(xml_out);
return ret;

View File

@ -86,16 +86,11 @@ testCompareXMLToConfHelper(const void *data)
char *inxml = NULL;
char *outconf = NULL;
if (virAsprintf(&inxml, "%s/networkxml2confdata/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outconf, "%s/networkxml2confdata/%s.conf",
abs_srcdir, info->name) < 0) {
goto cleanup;
}
inxml = g_strdup_printf("%s/networkxml2confdata/%s.xml", abs_srcdir, info->name);
outconf = g_strdup_printf("%s/networkxml2confdata/%s.conf", abs_srcdir, info->name);
result = testCompareXMLToConfFiles(inxml, outconf, info->caps);
cleanup:
VIR_FREE(inxml);
VIR_FREE(outconf);

View File

@ -114,15 +114,13 @@ testCompareXMLToIPTablesHelper(const void *data)
char *xml = NULL;
char *args = NULL;
if (virAsprintf(&xml, "%s/networkxml2firewalldata/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&args, "%s/networkxml2firewalldata/%s-%s.args",
abs_srcdir, info->name, RULESTYPE) < 0)
goto cleanup;
xml = g_strdup_printf("%s/networkxml2firewalldata/%s.xml",
abs_srcdir, info->name);
args = g_strdup_printf("%s/networkxml2firewalldata/%s-%s.args",
abs_srcdir, info->name, RULESTYPE);
result = testCompareXMLToArgvFiles(xml, args, info->baseargs);
cleanup:
VIR_FREE(xml);
VIR_FREE(args);
return result;
@ -166,11 +164,7 @@ mymain(void)
goto cleanup;
}
if (virAsprintf(&basefile, "%s/networkxml2firewalldata/base.args",
abs_srcdir) < 0) {
ret = -1;
goto cleanup;
}
basefile = g_strdup_printf("%s/networkxml2firewalldata/base.args", abs_srcdir);
if (virTestLoadFile(basefile, &baseargs) < 0) {
ret = -1;

View File

@ -90,17 +90,12 @@ testCompareXMLToXMLHelper(const void *data)
char *inxml = NULL;
char *outxml = NULL;
if (virAsprintf(&inxml, "%s/networkxml2xmlin/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outxml, "%s/networkxml2xmlout/%s.xml",
abs_srcdir, info->name) < 0) {
goto cleanup;
}
inxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcdir, info->name);
outxml = g_strdup_printf("%s/networkxml2xmlout/%s.xml", abs_srcdir, info->name);
result = testCompareXMLToXMLFiles(inxml, outxml, info->flags,
info->expectResult);
cleanup:
VIR_FREE(inxml);
VIR_FREE(outxml);

View File

@ -82,20 +82,17 @@ testCompareXMLToXMLHelper(const void *data)
char *updatexml = NULL;
char *outxml = NULL;
if (virAsprintf(&netxml, "%s/networkxml2xmlin/%s.xml",
abs_srcdir, info->netxml) < 0 ||
virAsprintf(&updatexml, "%s/networkxml2xmlupdatein/%s.xml",
abs_srcdir, info->updatexml) < 0 ||
virAsprintf(&outxml, "%s/networkxml2xmlupdateout/%s.xml",
abs_srcdir, info->outxml) < 0) {
goto cleanup;
}
netxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml",
abs_srcdir, info->netxml);
updatexml = g_strdup_printf("%s/networkxml2xmlupdatein/%s.xml",
abs_srcdir, info->updatexml);
outxml = g_strdup_printf("%s/networkxml2xmlupdateout/%s.xml",
abs_srcdir, info->outxml);
result = testCompareXMLToXMLFiles(netxml, updatexml, outxml, info->flags,
info->command, info->section,
info->parentIndex, info->expectFailure);
cleanup:
VIR_FREE(netxml);
VIR_FREE(updatexml);
VIR_FREE(outxml);

View File

@ -72,9 +72,8 @@ testCompareXMLToXMLHelper(const void *data)
int result = -1;
char *xml = NULL;
if (virAsprintf(&xml, "%s/nodedevschemadata/%s.xml",
abs_srcdir, (const char*)data) < 0)
return -1;
xml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
(const char *)data);
result = testCompareXMLToXMLFiles(xml);

View File

@ -55,12 +55,9 @@ getrealpath(char **newpath,
const char *path)
{
if (STRPREFIX(path, LEASEDIR)) {
if (virAsprintfQuiet(newpath, "%s/nssdata/%s",
abs_srcdir,
path + strlen(LEASEDIR)) < 0) {
errno = ENOMEM;
return -1;
}
*newpath = g_strdup_printf("%s/nssdata/%s",
abs_srcdir,
path + strlen(LEASEDIR));
} else {
*newpath = g_strdup(path);
}

View File

@ -243,9 +243,8 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPtr inc,
int ret = -1;
char *xml;
if (virAsprintf(&xml, "%s/nwfilterxml2firewalldata/%s.xml",
abs_srcdir, inc->filterref) < 0)
return -1;
xml = g_strdup_printf("%s/nwfilterxml2firewalldata/%s.xml", abs_srcdir,
inc->filterref);
/* create a temporary hashmap for depth-first tree traversal */
if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params,
@ -426,15 +425,13 @@ testCompareXMLToIPTablesHelper(const void *data)
char *xml = NULL;
char *args = NULL;
if (virAsprintf(&xml, "%s/nwfilterxml2firewalldata/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&args, "%s/nwfilterxml2firewalldata/%s-%s.args",
abs_srcdir, info->name, RULESTYPE) < 0)
goto cleanup;
xml = g_strdup_printf("%s/nwfilterxml2firewalldata/%s.xml",
abs_srcdir, info->name);
args = g_strdup_printf("%s/nwfilterxml2firewalldata/%s-%s.args",
abs_srcdir, info->name, RULESTYPE);
result = testCompareXMLToArgvFiles(xml, args);
cleanup:
VIR_FREE(xml);
VIR_FREE(args);
return result;

View File

@ -62,16 +62,11 @@ testCompareXMLToXMLHelper(const void *data)
char *inxml = NULL;
char *outxml = NULL;
if (virAsprintf(&inxml, "%s/nwfilterxml2xmlin/%s.xml",
abs_srcdir, tp->name) < 0 ||
virAsprintf(&outxml, "%s/nwfilterxml2xmlout/%s.xml",
abs_srcdir, tp->name) < 0) {
goto cleanup;
}
inxml = g_strdup_printf("%s/nwfilterxml2xmlin/%s.xml", abs_srcdir, tp->name);
outxml = g_strdup_printf("%s/nwfilterxml2xmlout/%s.xml", abs_srcdir, tp->name);
result = testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning);
cleanup:
VIR_FREE(inxml);
VIR_FREE(outxml);

View File

@ -17,7 +17,8 @@ static int
testLocateConfFile(int vpsid G_GNUC_UNUSED, char **conffile,
const char *ext G_GNUC_UNUSED)
{
return virAsprintf(conffile, "%s/openvzutilstest.conf", abs_srcdir);
*conffile = g_strdup_printf("%s/openvzutilstest.conf", abs_srcdir);
return 0;
}
struct testConfigParam {
@ -40,8 +41,7 @@ testReadConfigParam(const void *data G_GNUC_UNUSED)
char *conf = NULL;
char *value = NULL;
if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0)
return -1;
conf = g_strdup_printf("%s/openvzutilstest.conf", abs_srcdir);
for (i = 0; i < G_N_ELEMENTS(configParams); ++i) {
if (openvzReadConfigParam(conf, configParams[i].param,

View File

@ -183,9 +183,7 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOptionPtr xmlopt,
if (!(ret_test = qemuMonitorTestNewAgent(xmlopt)))
return -1;
if (virAsprintf(&domain_filename, "%s/qemuagentdata/fsinfo.xml",
abs_srcdir) < 0)
goto cleanup;
domain_filename = g_strdup_printf("%s/qemuagentdata/fsinfo.xml", abs_srcdir);
if (!(ret_def = virDomainDefParseFile(domain_filename, driver.caps, xmlopt,
NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE)))

View File

@ -82,8 +82,7 @@ testBackingXMLjsonXML(const void *args)
if (!(propsstr = virJSONValueToString(wrapper, false)))
return -1;
if (virAsprintf(&protocolwrapper, "json:%s", propsstr) < 0)
return -1;
protocolwrapper = g_strdup_printf("json:%s", propsstr);
if (virStorageSourceNewFromBackingAbsolute(protocolwrapper,
&jsonsrc) < 0) {
@ -163,9 +162,8 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src)
srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username);
if (virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias",
NULLSTR(src->nodestorage)) < 0)
return -1;
srcpriv->secinfo->s.aes.alias = g_strdup_printf("%s-secalias",
NULLSTR(src->nodestorage));
}
if (src->encryption) {
@ -173,9 +171,8 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src)
return -1;
srcpriv->encinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
if (virAsprintf(&srcpriv->encinfo->s.aes.alias, "%s-encalias",
NULLSTR(src->nodeformat)) < 0)
return -1;
srcpriv->encinfo->s.aes.alias = g_strdup_printf("%s-encalias",
NULLSTR(src->nodeformat));
}
return 0;
@ -197,9 +194,7 @@ testQemuDiskXMLToProps(const void *opaque)
char *xmlstr = NULL;
int ret = -1;
if (virAsprintf(&xmlpath, "%s%s.xml",
testQemuDiskXMLToJSONPath, data->name) < 0)
goto cleanup;
xmlpath = g_strdup_printf("%s%s.xml", testQemuDiskXMLToJSONPath, data->name);
if (virTestLoadFile(xmlpath, &xmlstr) < 0)
goto cleanup;
@ -316,9 +311,7 @@ testQemuDiskXMLToPropsValidateFile(const void *opaque)
if (data->fail)
return EXIT_AM_SKIP;
if (virAsprintf(&jsonpath, "%s%s.json",
testQemuDiskXMLToJSONPath, data->name) < 0)
goto cleanup;
jsonpath = g_strdup_printf("%s%s.json", testQemuDiskXMLToJSONPath, data->name);
for (i = 0; i < data->nprops; i++) {
char *jsonstr;
@ -364,9 +357,7 @@ testQemuImageCreateLoadDiskXML(const char *name,
g_autofree char *xmlpath = NULL;
virStorageSourcePtr ret = NULL;
if (virAsprintf(&xmlpath, "%s%s.xml",
testQemuImageCreatePath, name) < 0)
return NULL;
xmlpath = g_strdup_printf("%s%s.xml", testQemuImageCreatePath, name);
if (!(doc = virXMLParseFileCtxt(xmlpath, &ctxt)))
return NULL;
@ -462,9 +453,7 @@ testQemuImageCreate(const void *opaque)
virBufferTrim(&actualbuf, "\n", -1);
virBufferAddLit(&actualbuf, "\n");
if (virAsprintf(&jsonpath, "%s%s.json",
testQemuImageCreatePath, data->name) < 0)
return -1;
jsonpath = g_strdup_printf("%s%s.json", testQemuImageCreatePath, data->name);
if (!(actual = virBufferContentAndReset(&actualbuf)))
return -1;
@ -485,9 +474,8 @@ testQemuDiskXMLToPropsValidateFileSrcOnly(const void *opaque)
if (data->fail)
return EXIT_AM_SKIP;
if (virAsprintf(&jsonpath, "%s%s-srconly.json",
testQemuDiskXMLToJSONPath, data->name) < 0)
return -1;
jsonpath = g_strdup_printf("%s%s-srconly.json", testQemuDiskXMLToJSONPath,
data->name);
for (i = 0; i < data->npropssrc; i++) {
g_autofree char *jsonstr = NULL;

View File

@ -79,13 +79,12 @@ testQemuCaps(const void *opaque)
unsigned int fakeMicrocodeVersion = 0;
const char *p;
if (virAsprintf(&repliesFile, "%s/%s_%s.%s.%s",
data->inputDir, data->prefix, data->version,
data->archName, data->suffix) < 0 ||
virAsprintf(&capsFile, "%s/%s_%s.%s.xml",
data->outputDir, data->prefix, data->version,
data->archName) < 0)
goto cleanup;
repliesFile = g_strdup_printf("%s/%s_%s.%s.%s",
data->inputDir, data->prefix, data->version,
data->archName, data->suffix);
capsFile = g_strdup_printf("%s/%s_%s.%s.xml",
data->outputDir, data->prefix, data->version,
data->archName);
if (!(mon = qemuMonitorTestNewFromFileFull(repliesFile, &data->driver, NULL,
NULL)))
@ -150,10 +149,9 @@ testQemuCapsCopy(const void *opaque)
virQEMUCapsPtr copy = NULL;
char *actual = NULL;
if (virAsprintf(&capsFile, "%s/%s_%s.%s.xml",
data->outputDir, data->prefix, data->version,
data->archName) < 0)
goto cleanup;
capsFile = g_strdup_printf("%s/%s_%s.%s.xml",
data->outputDir, data->prefix, data->version,
data->archName);
if (!(caps = virCapabilitiesNew(virArchFromString(data->archName),
false, false)))
@ -195,10 +193,8 @@ doCapsTest(const char *inputDir,
g_autofree char *title = NULL;
g_autofree char *copyTitle = NULL;
if (virAsprintf(&title, "%s (%s)", version, archName) < 0 ||
virAsprintf(&copyTitle, "copy %s (%s)", version, archName) < 0) {
return -1;
}
title = g_strdup_printf("%s (%s)", version, archName);
copyTitle = g_strdup_printf("copy %s (%s)", version, archName);
data->inputDir = inputDir;
data->prefix = prefix;

View File

@ -103,8 +103,7 @@ testGetCaps(char *capsData, const testQemuData *data)
virArch arch = virArchFromString(data->archName);
g_autofree char *binary = NULL;
if (virAsprintf(&binary, "/usr/bin/qemu-system-%s", data->archName) < 0)
goto error;
binary = g_strdup_printf("/usr/bin/qemu-system-%s", data->archName);
if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) {
fprintf(stderr, "failed to parse qemu capabilities flags");
@ -143,14 +142,11 @@ testQemuCapsXML(const void *opaque)
char *capsXml = NULL;
virCapsPtr capsProvided = NULL;
if (virAsprintf(&xmlFile, "%s/caps.%s.xml",
data->outputDir, data->archName) < 0)
goto cleanup;
xmlFile = g_strdup_printf("%s/caps.%s.xml", data->outputDir, data->archName);
if (virAsprintf(&capsFile, "%s/%s_%s.%s.%s",
data->inputDir, data->prefix, data->version,
data->archName, data->suffix) < 0)
goto cleanup;
capsFile = g_strdup_printf("%s/%s_%s.%s.%s",
data->inputDir, data->prefix, data->version,
data->archName, data->suffix);
if (virTestLoadFile(capsFile, &capsData) < 0)
goto cleanup;
@ -186,8 +182,7 @@ doCapsTest(const char *inputDir,
testQemuDataPtr data = (testQemuDataPtr) opaque;
g_autofree char *title = NULL;
if (virAsprintf(&title, "%s (%s)", version, archName) < 0)
return -1;
title = g_strdup_printf("%s (%s)", version, archName);
data->inputDir = inputDir;
data->prefix = prefix;

View File

@ -120,9 +120,8 @@ testCheckpointPostParse(virDomainMomentDefPtr def)
if (def->creationTime)
return -1;
def->creationTime = mocktime;
if (!def->name &&
virAsprintf(&def->name, "%lld", def->creationTime) < 0)
return -1;
if (!def->name)
def->name = g_strdup_printf("%lld", def->creationTime);
return 0;
}

View File

@ -105,9 +105,8 @@ testSnapshotPostParse(virDomainMomentDefPtr def)
if (def->creationTime)
return -1;
def->creationTime = mocktime;
if (!def->name &&
virAsprintf(&def->name, "%lld", def->creationTime) < 0)
return -1;
if (!def->name)
def->name = g_strdup_printf("%lld", def->creationTime);
return 0;
}

View File

@ -24,9 +24,7 @@ testParseFormatFW(const void *opaque)
g_autofree char *expected = NULL;
g_autofree char *actual = NULL;
if (virAsprintf(&path, "%s/qemufirmwaredata/%s",
abs_srcdir, filename) < 0)
return -1;
path = g_strdup_printf("%s/qemufirmwaredata/%s", abs_srcdir, filename);
if (!(fw = qemuFirmwareParse(path)))
return -1;

View File

@ -245,15 +245,13 @@ testQemuHotplug(const void *data)
qemuMonitorTestPtr test_mon = NULL;
qemuDomainObjPrivatePtr priv = NULL;
if (virAsprintf(&domain_filename, "%s/qemuhotplugtestdomains/qemuhotplug-%s.xml",
abs_srcdir, test->domain_filename) < 0 ||
virAsprintf(&device_filename, "%s/qemuhotplugtestdevices/qemuhotplug-%s.xml",
abs_srcdir, test->device_filename) < 0 ||
virAsprintf(&result_filename,
"%s/qemuhotplugtestdomains/qemuhotplug-%s+%s.xml",
abs_srcdir, test->domain_filename,
test->device_filename) < 0)
goto cleanup;
domain_filename = g_strdup_printf("%s/qemuhotplugtestdomains/qemuhotplug-%s.xml",
abs_srcdir, test->domain_filename);
device_filename = g_strdup_printf("%s/qemuhotplugtestdevices/qemuhotplug-%s.xml",
abs_srcdir, test->device_filename);
result_filename = g_strdup_printf("%s/qemuhotplugtestdomains/qemuhotplug-%s+%s.xml",
abs_srcdir, test->domain_filename,
test->device_filename);
if (virTestLoadFile(domain_filename, &domain_xml) < 0 ||
virTestLoadFile(device_filename, &device_xml) < 0)
@ -409,19 +407,17 @@ testQemuHotplugCpuPrepare(const char *test,
char *prefix = NULL;
struct testQemuHotplugCpuData *data = NULL;
if (virAsprintf(&prefix, "%s/qemuhotplugtestcpus/%s", abs_srcdir, test) < 0)
return NULL;
prefix = g_strdup_printf("%s/qemuhotplugtestcpus/%s", abs_srcdir, test);
if (VIR_ALLOC(data) < 0)
goto error;
data->modern = modern;
if (virAsprintf(&data->file_xml_dom, "%s-domain.xml", prefix) < 0 ||
virAsprintf(&data->file_xml_res_live, "%s-result-live.xml", prefix) < 0 ||
virAsprintf(&data->file_xml_res_conf, "%s-result-conf.xml", prefix) < 0 ||
virAsprintf(&data->file_json_monitor, "%s-monitor.json", prefix) < 0)
goto error;
data->file_xml_dom = g_strdup_printf("%s-domain.xml", prefix);
data->file_xml_res_live = g_strdup_printf("%s-result-live.xml", prefix);
data->file_xml_res_conf = g_strdup_printf("%s-result-conf.xml", prefix);
data->file_json_monitor = g_strdup_printf("%s-monitor.json", prefix);
if (virTestLoadFile(data->file_xml_dom, &data->xml_dom) < 0)
goto error;

View File

@ -34,9 +34,8 @@ testCompareMemLock(const void *data)
char *xml = NULL;
int ret = -1;
if (virAsprintf(&xml, "%s/qemumemlockdata/qemumemlock-%s.xml",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/qemumemlockdata/qemumemlock-%s.xml", abs_srcdir,
info->name);
if (!(def = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, NULL,
VIR_DOMAIN_DEF_PARSE_INACTIVE))) {

View File

@ -66,9 +66,8 @@ qemuMigParamsTestXML2XML(const void *opaque)
char *actualXML = NULL;
int ret = -1;
if (virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml",
abs_srcdir, data->name) < 0)
goto cleanup;
xmlFile = g_strdup_printf("%s/qemumigparamsdata/%s.xml", abs_srcdir,
data->name);
if (!(doc = virXMLParseFileCtxt(xmlFile, &ctxt)))
goto cleanup;
@ -110,11 +109,10 @@ qemuMigParamsTestXML(const void *opaque)
char *actualXML = NULL;
int ret = -1;
if (virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply",
abs_srcdir, data->name) < 0 ||
virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml",
abs_srcdir, data->name) < 0)
goto cleanup;
replyFile = g_strdup_printf("%s/qemumigparamsdata/%s.reply",
abs_srcdir, data->name);
xmlFile = g_strdup_printf("%s/qemumigparamsdata/%s.xml",
abs_srcdir, data->name);
if (!(mon = qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true)))
goto cleanup;
@ -161,11 +159,10 @@ qemuMigParamsTestJSON(const void *opaque)
char *actualJSON = NULL;
int ret = -1;
if (virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply",
abs_srcdir, data->name) < 0 ||
virAsprintf(&jsonFile, "%s/qemumigparamsdata/%s.json",
abs_srcdir, data->name) < 0)
goto cleanup;
replyFile = g_strdup_printf("%s/qemumigparamsdata/%s.reply",
abs_srcdir, data->name);
jsonFile = g_strdup_printf("%s/qemumigparamsdata/%s.json",
abs_srcdir, data->name);
if (!(mon = qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true)))
goto cleanup;

View File

@ -796,11 +796,9 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
if (!reply)
reply = "";
if (virAsprintf(&jsonreply, "{\"return\": {%s}}", reply) < 0)
goto cleanup;
jsonreply = g_strdup_printf("{\"return\": {%s}}", reply);
if (virAsprintf(&fulllabel, "qemuMonitorJSONTestAttachChardev(%s)", label) < 0)
goto cleanup;
fulllabel = g_strdup_printf("qemuMonitorJSONTestAttachChardev(%s)", label);
data.chr = chr;
data.fail = fail;
@ -2459,13 +2457,10 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema)))
return -1;
if (virAsprintf(&jsonFile,
"%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.json",
abs_srcdir, data->name) < 0 ||
virAsprintf(&dataFile,
"%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.data",
abs_srcdir, data->name) < 0)
goto cleanup;
jsonFile = g_strdup_printf("%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.json",
abs_srcdir, data->name);
dataFile = g_strdup_printf("%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.data",
abs_srcdir, data->name);
if (virTestLoadFile(jsonFile, &jsonStr) < 0)
goto cleanup;
@ -2712,16 +2707,12 @@ testQemuMonitorCPUInfo(const void *opaque)
if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema)))
return -1;
if (virAsprintf(&queryCpusFile,
"%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-cpus.json",
abs_srcdir, data->name) < 0 ||
virAsprintf(&queryHotpluggableFile,
"%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-hotplug.json",
abs_srcdir, data->name) < 0 ||
virAsprintf(&dataFile,
"%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s.data",
abs_srcdir, data->name) < 0)
goto cleanup;
queryCpusFile = g_strdup_printf("%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-cpus.json",
abs_srcdir, data->name);
queryHotpluggableFile = g_strdup_printf("%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-hotplug.json",
abs_srcdir, data->name);
dataFile = g_strdup_printf("%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s.data",
abs_srcdir, data->name);
if (virTestLoadFile(queryCpusFile, &queryCpusStr) < 0)
goto cleanup;
@ -2816,9 +2807,8 @@ testBlockNodeNameDetect(const void *opaque)
virBuffer buf = VIR_BUFFER_INITIALIZER;
int ret = -1;
if (virAsprintf(&resultFile, "%s/%s%s.result",
abs_srcdir, pathprefix, testname) < 0)
goto cleanup;
resultFile = g_strdup_printf("%s/%s%s.result", abs_srcdir, pathprefix,
testname);
if (!(namedNodesJson = virTestLoadFileJSON(pathprefix, testname,
"-named-nodes.json", NULL)))
@ -2958,13 +2948,10 @@ testQueryJobs(const void *opaque)
if (!test)
return -1;
if (virAsprintf(&filenameJSON,
abs_srcdir "/qemumonitorjsondata/query-jobs-%s.json",
data->name) < 0 ||
virAsprintf(&filenameResult,
abs_srcdir "/qemumonitorjsondata/query-jobs-%s.result",
data->name) < 0)
goto cleanup;
filenameJSON = g_strdup_printf(abs_srcdir "/qemumonitorjsondata/query-jobs-%s.json",
data->name);
filenameResult = g_strdup_printf(abs_srcdir "/qemumonitorjsondata/query-jobs-%s.result",
data->name);
if (virTestLoadFile(filenameJSON, &fileJSON) < 0)
goto cleanup;

View File

@ -143,11 +143,8 @@ qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test,
}
/* format the JSON error message */
if (virAsprintf(&jsonmsg, "{ \"error\": "
" { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }",
escapemsg) < 0)
return -1;
jsonmsg = g_strdup_printf("{ \"error\": " " { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }", escapemsg);
return qemuMonitorTestAddResponse(test, jsonmsg);
}
@ -159,8 +156,7 @@ qemuMonitorTestAddUnexpectedErrorResponse(qemuMonitorTestPtr test,
{
g_autofree char *msg = NULL;
if (virAsprintf(&msg, "unexpected command: '%s'", command) < 0)
return -1;
msg = g_strdup_printf("unexpected command: '%s'", command);
return qemuMonitorTestAddErrorResponse(test, msg);
}
@ -173,9 +169,8 @@ qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTestPtr test,
{
g_autofree char *msg = NULL;
if (virAsprintf(&msg, "expected command '%s' got '%s'",
expectedcommand, actualcommand) < 0)
return -1;
msg = g_strdup_printf("expected command '%s' got '%s'", expectedcommand,
actualcommand);
return qemuMonitorTestAddErrorResponse(test, msg);
}
@ -194,11 +189,8 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
if (virVasprintf(&msg, errmsg, msgargs) < 0)
goto cleanup;
if (virAsprintf(&jsonmsg, "{ \"error\": "
" { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }",
msg) < 0)
goto cleanup;
jsonmsg = g_strdup_printf("{ \"error\": " " { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }", msg);
ret = qemuMonitorTestAddResponse(test, jsonmsg);
@ -528,8 +520,7 @@ qemuMonitorTestProcessCommandDefaultValidate(qemuMonitorTestPtr test,
if (STREQ(cmdname, "device_add"))
return 0;
if (virAsprintf(&schemapath, "%s/arg-type", cmdname) < 0)
return -1;
schemapath = g_strdup_printf("%s/arg-type", cmdname);
if (virQEMUQAPISchemaPathGet(schemapath, test->qapischema, &schemaroot) < 0 ||
!schemaroot) {
@ -647,8 +638,7 @@ qemuMonitorTestProcessCommandVerbatim(qemuMonitorTestPtr test,
ret = qemuMonitorTestAddResponse(test, data->response);
} else {
if (data->cmderr) {
if (virAsprintf(&errmsg, "%s: %s", data->cmderr, cmdstr) < 0)
return -1;
errmsg = g_strdup_printf("%s: %s", data->cmderr, cmdstr);
ret = qemuMonitorTestAddErrorResponse(test, errmsg);
} else {
@ -739,8 +729,7 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTestPtr test,
goto cleanup;
}
if (virAsprintf(&retmsg, "{\"return\":%llu}", id) < 0)
goto cleanup;
retmsg = g_strdup_printf("{\"return\":%llu}", id);
ret = qemuMonitorTestAddResponse(test, retmsg);
@ -1066,8 +1055,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
tmpdir_template = NULL;
if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
goto error;
path = g_strdup_printf("%s/qemumonitorjsontest.sock", test->tmpdir);
if (vm) {
test->vm = virObjectRef(vm);
@ -1295,9 +1283,7 @@ qemuMonitorTestFullAddItem(qemuMonitorTestPtr test,
char *cmderr;
int ret;
if (virAsprintf(&cmderr, "wrong expected command in %s:%zu: ",
filename, line) < 0)
return -1;
cmderr = g_strdup_printf("wrong expected command in %s:%zu: ", filename, line);
ret = qemuMonitorTestAddItemVerbatim(test, command, cmderr, response);

View File

@ -117,10 +117,7 @@ get_key(const char *path,
{
char *ret;
if (virAsprintf(&ret, "%s:%s", path, name) < 0) {
fprintf(stderr, "Unable to create hash table key\n");
abort();
}
ret = g_strdup_printf("%s:%s", path, name);
return ret;
}

View File

@ -45,8 +45,7 @@ prepareObjects(virQEMUDriverPtr driver,
g_autofree char *domxml = NULL;
g_autofree char *latestCapsFile = NULL;
if (virAsprintf(&filename, "%s/qemuxml2argvdata/%s.xml", abs_srcdir, xmlname) < 0)
return -1;
filename = g_strdup_printf("%s/qemuxml2argvdata/%s.xml", abs_srcdir, xmlname);
if (virTestLoadFile(filename, &domxml) < 0)
return -1;

View File

@ -24,9 +24,7 @@ testParseFormatVU(const void *opaque)
g_autofree char *expected = NULL;
g_autofree char *actual = NULL;
if (virAsprintf(&path, "%s/qemuvhostuserdata/%s",
abs_srcdir, filename) < 0)
return -1;
path = g_strdup_printf("%s/qemuvhostuserdata/%s", abs_srcdir, filename);
if (!(vu = qemuVhostUserParse(path)))
return -1;

View File

@ -106,11 +106,8 @@ fakeStoragePoolLookupByName(virConnectPtr conn,
virStoragePoolPtr ret = NULL;
if (STRNEQ(name, "inactive")) {
if (virAsprintf(&xmlpath, "%s/%s%s.xml",
abs_srcdir,
STORAGE_POOL_XML_PATH,
name) < 0)
return NULL;
xmlpath = g_strdup_printf("%s/%s%s.xml", abs_srcdir,
STORAGE_POOL_XML_PATH, name);
if (!virFileExists(xmlpath)) {
virReportError(VIR_ERR_NO_STORAGE_POOL,
@ -190,7 +187,7 @@ fakeStorageVolGetPath(virStorageVolPtr vol)
{
char *ret = NULL;
ignore_value(virAsprintf(&ret, "/some/%s/device/%s", vol->key, vol->name));
ret = g_strdup_printf("/some/%s/device/%s", vol->key, vol->name);
return ret;
}
@ -208,11 +205,8 @@ fakeStoragePoolGetXMLDesc(virStoragePoolPtr pool,
return NULL;
}
if (virAsprintf(&xmlpath, "%s/%s%s.xml",
abs_srcdir,
STORAGE_POOL_XML_PATH,
pool->name) < 0)
return NULL;
xmlpath = g_strdup_printf("%s/%s%s.xml", abs_srcdir, STORAGE_POOL_XML_PATH,
pool->name);
if (virTestLoadFile(xmlpath, &xmlbuf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@ -594,18 +588,14 @@ testCompareXMLToArgv(const void *data)
return ret;
}
static int
static void
testInfoSetPaths(struct testQemuInfo *info,
const char *suffix)
{
if (virAsprintf(&info->infile, "%s/qemuxml2argvdata/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&info->outfile, "%s/qemuxml2argvdata/%s%s.args",
abs_srcdir, info->name, suffix ? suffix : "") < 0) {
return -1;
}
return 0;
info->infile = g_strdup_printf("%s/qemuxml2argvdata/%s.xml",
abs_srcdir, info->name);
info->outfile = g_strdup_printf("%s/qemuxml2argvdata/%s%s.args",
abs_srcdir, info->name, suffix ? suffix : "");
}
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
@ -713,10 +703,7 @@ mymain(void)
if (testQemuInfoSetArgs(&info, capslatest, \
__VA_ARGS__, ARG_END) < 0) \
return EXIT_FAILURE; \
if (testInfoSetPaths(&info, _suffix) < 0) { \
VIR_TEST_DEBUG("Failed to generate paths for '%s'", _name); \
return EXIT_FAILURE; \
} \
testInfoSetPaths(&info, _suffix); \
if (virTestRun("QEMU XML-2-ARGV " _name _suffix, \
testCompareXMLToArgv, &info) < 0) \
ret = -1; \

View File

@ -98,48 +98,31 @@ testInfoSetPaths(struct testQemuInfo *info,
VIR_FREE(info->infile);
VIR_FREE(info->outfile);
if (virAsprintf(&info->infile, "%s/qemuxml2argvdata/%s.xml",
abs_srcdir, info->name) < 0)
goto error;
info->infile = g_strdup_printf("%s/qemuxml2argvdata/%s.xml", abs_srcdir,
info->name);
if (virAsprintf(&info->outfile,
"%s/qemuxml2xmloutdata/%s-%s%s.xml",
abs_srcdir, info->name,
when == WHEN_ACTIVE ? "active" : "inactive",
suffix) < 0)
goto error;
info->outfile = g_strdup_printf("%s/qemuxml2xmloutdata/%s-%s%s.xml",
abs_srcdir, info->name,
when == WHEN_ACTIVE ? "active" : "inactive", suffix);
if (!virFileExists(info->outfile)) {
VIR_FREE(info->outfile);
if (virAsprintf(&info->outfile,
"%s/qemuxml2xmloutdata/%s%s.xml",
abs_srcdir, info->name, suffix) < 0)
goto error;
info->outfile = g_strdup_printf("%s/qemuxml2xmloutdata/%s%s.xml",
abs_srcdir, info->name, suffix);
}
return 0;
error:
testQemuInfoClear(info);
return -1;
}
static const char *statusPath = abs_srcdir "/qemustatusxml2xmldata/";
static int
static void
testInfoSetStatusPaths(struct testQemuInfo *info)
{
if (virAsprintf(&info->infile, "%s%s-in.xml", statusPath, info->name) < 0 ||
virAsprintf(&info->outfile, "%s%s-out.xml", statusPath, info->name) < 0)
goto error;
return 0;
error:
testQemuInfoClear(info);
return -1;
info->infile = g_strdup_printf("%s%s-in.xml", statusPath, info->name);
info->outfile = g_strdup_printf("%s%s-out.xml", statusPath, info->name);
}
@ -1286,11 +1269,11 @@ mymain(void)
if (testQemuInfoSetArgs(&info, capslatest, \
ARG_QEMU_CAPS, QEMU_CAPS_LAST, \
ARG_END) < 0 || \
qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0 || \
testInfoSetStatusPaths(&info) < 0) { \
qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
VIR_TEST_DEBUG("Failed to generate status test data for '%s'", _name); \
return -1; \
} \
testInfoSetStatusPaths(&info); \
\
if (virTestRun("QEMU status XML-2-XML " _name, \
testCompareStatusXMLToXMLFiles, &info) < 0) \

View File

@ -72,13 +72,10 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
int ret = -1;
int fd = -1;
if (virAsprintfQuiet(&unique_id_path, "%s/devices/pci0000:00/%s/unique_id",
fakesysfsdir, devicepath) < 0 ||
virAsprintfQuiet(&link_path, "%s/class/scsi_host/%s",
fakesysfsdir, hostname) < 0) {
fprintf(stderr, "Out of memory\n");
goto cleanup;
}
unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id",
fakesysfsdir, devicepath);
link_path = g_strdup_printf("%s/class/scsi_host/%s",
fakesysfsdir, hostname);
/* Rather than create path & file, temporarily snip off the file to
* create the path
@ -208,9 +205,7 @@ testVirFindSCSIHostByPCI(const void *data G_GNUC_UNUSED)
char *ret_host = NULL;
int ret = -1;
if (virAsprintf(&path_addr, "%s/%s", abs_srcdir,
"sysfs/class/scsi_host") < 0)
goto cleanup;
path_addr = g_strdup_printf("%s/%s", abs_srcdir, "sysfs/class/scsi_host");
if (!(ret_host = virSCSIHostFindByPCI(TEST_SCSIHOST_CLASS_PATH,
pci_addr1, unique_id1)) ||
@ -260,21 +255,14 @@ mymain(void)
goto cleanup;
}
if (virAsprintfQuiet(&fakesysfsdir, "%s/sys", fakerootdir) < 0) {
fprintf(stderr, "Out of memory\n");
goto cleanup;
}
fakesysfsdir = g_strdup_printf("%s/sys", fakerootdir);
if (init_scsihost_sysfs(fakesysfsdir) < 0) {
fprintf(stderr, "Failed to create fakesysfs='%s'\n", fakesysfsdir);
goto cleanup;
}
if (virAsprintfQuiet(&scsihost_class_path, "%s/class/scsi_host",
fakesysfsdir) < 0) {
fprintf(stderr, "Out of memory\n");
goto cleanup;
}
scsihost_class_path = g_strdup_printf("%s/class/scsi_host", fakesysfsdir);
VIR_DEBUG("Reading from '%s'", scsihost_class_path);
if (virTestRun("testVirReadSCSIUniqueId",

View File

@ -44,18 +44,14 @@ testCompareXMLToXMLHelper(const void *data)
char *outxml = NULL;
const struct testInfo *info = data;
if (virAsprintf(&inxml, "%s/secretxml2xmlin/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outxml, "%s/secretxml2xml%s/%s.xml",
abs_srcdir,
info->different ? "out" : "in",
info->name) < 0) {
goto cleanup;
}
inxml = g_strdup_printf("%s/secretxml2xmlin/%s.xml", abs_srcdir, info->name);
outxml = g_strdup_printf("%s/secretxml2xml%s/%s.xml",
abs_srcdir,
info->different ? "out" : "in",
info->name);
result = testCompareXMLToXMLFiles(inxml, outxml);
cleanup:
VIR_FREE(inxml);
VIR_FREE(outxml);

View File

@ -60,9 +60,7 @@ testUserXattrEnabled(void)
ssize_t len;
const char *con_value = "system_u:object_r:svirt_image_t:s0:c41,c264";
char *path = NULL;
if (virAsprintf(&path, "%s/securityselinuxlabeldata/testxattr",
abs_builddir) < 0)
goto cleanup;
path = g_strdup_printf("%s/securityselinuxlabeldata/testxattr", abs_builddir);
if (virFileMakePath(abs_builddir "/securityselinuxlabeldata") < 0 ||
virFileTouch(path, 0600) < 0)
@ -90,9 +88,7 @@ testSELinuxMungePath(char **path)
{
char *tmp;
if (virAsprintf(&tmp, "%s/securityselinuxlabeldata%s",
abs_builddir, *path) < 0)
return -1;
tmp = g_strdup_printf("%s/securityselinuxlabeldata%s", abs_builddir, *path);
VIR_FREE(*path);
*path = tmp;
@ -112,9 +108,8 @@ testSELinuxLoadFileList(const char *testname,
*files = NULL;
*nfiles = 0;
if (virAsprintf(&path, "%s/securityselinuxlabeldata/%s.txt",
abs_srcdir, testname) < 0)
goto cleanup;
path = g_strdup_printf("%s/securityselinuxlabeldata/%s.txt", abs_srcdir,
testname);
if (!(fp = fopen(path, "r")))
goto cleanup;
@ -140,9 +135,8 @@ testSELinuxLoadFileList(const char *testname,
*tmp = '\0';
tmp++;
if (virAsprintf(&file, "%s/securityselinuxlabeldata%s",
abs_builddir, line) < 0)
goto cleanup;
file = g_strdup_printf("%s/securityselinuxlabeldata%s", abs_builddir,
line);
if (*tmp != '\0' && *tmp != '\n') {
context = g_strdup(tmp);
@ -178,9 +172,8 @@ testSELinuxLoadDef(const char *testname)
virDomainDefPtr def = NULL;
size_t i;
if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml",
abs_srcdir, testname) < 0)
goto cleanup;
xmlfile = g_strdup_printf("%s/securityselinuxlabeldata/%s.xml", abs_srcdir,
testname);
if (!(def = virDomainDefParseFile(xmlfile, driver.caps, driver.xmlopt,
NULL, 0)))

View File

@ -158,13 +158,11 @@ mymain(void)
collie_test *test = node_info_tests;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/pool-sheepdog.xml",
abs_srcdir) < 0)
goto cleanup;
poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/pool-sheepdog.xml",
abs_srcdir);
if (virAsprintf(&volxml, "%s/storagevolxml2xmlin/vol-sheepdog.xml",
abs_srcdir) < 0)
goto cleanup;
volxml = g_strdup_printf("%s/storagevolxml2xmlin/vol-sheepdog.xml",
abs_srcdir);
#define DO_TEST_NODE(collie) \
do { \
@ -202,7 +200,6 @@ mymain(void)
++test;
}
cleanup:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -62,10 +62,8 @@ test_virStoragePoolCapsFormat(const void *opaque)
if (!(poolCaps = virStoragePoolCapsNew(driverCaps)))
return -1;
if (virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml",
abs_srcdir, data->filename) < 0) {
return -1;
}
path = g_strdup_printf("%s/storagepoolcapsschemadata/poolcaps-%s.xml",
abs_srcdir, data->filename);
if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps)))
return -1;

View File

@ -108,14 +108,11 @@ testCompareXMLToArgvHelper(const void *data)
g_autofree char *poolxml = NULL;
g_autofree char *cmdline = NULL;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool) < 0)
return -1;
poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s.xml", abs_srcdir,
info->pool);
if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s%s.argv",
abs_srcdir, info->pool, info->platformSuffix) < 0 &&
!info->shouldFail)
return -1;
cmdline = g_strdup_printf("%s/storagepoolxml2argvdata/%s%s.argv",
abs_srcdir, info->pool, info->platformSuffix);
return testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline);
}

View File

@ -39,11 +39,10 @@ testCompareXMLToXMLHelper(const void *data)
g_autofree char *inxml = NULL;
g_autofree char *outxml = NULL;
if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, (const char*)data) < 0 ||
virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml",
abs_srcdir, (const char*)data) < 0)
return -1;
inxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, (const char*)data);
outxml = g_strdup_printf("%s/storagepoolxml2xmlout/%s.xml",
abs_srcdir, (const char*)data);
return testCompareXMLToXMLFiles(inxml, outxml);
}

View File

@ -109,17 +109,13 @@ testCompareXMLToArgvFiles(bool shouldFail,
} else {
char *createCmdline = actualCmdline;
g_autofree char *cvtCmdline = NULL;
int rc;
if (!(cvtCmdline = virCommandToString(cmd, false)))
goto cleanup;
rc = virAsprintf(&actualCmdline, "%s\n%s",
createCmdline, cvtCmdline);
actualCmdline = g_strdup_printf("%s\n%s", createCmdline, cvtCmdline);
VIR_FREE(createCmdline);
if (rc < 0)
goto cleanup;
}
if (convertStep == VIR_STORAGE_VOL_ENCRYPT_NONE)
@ -162,23 +158,18 @@ testCompareXMLToArgvHelper(const void *data)
g_autofree char *inputvolxml = NULL;
g_autofree char *cmdline = NULL;
if (info->inputvol &&
virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->inputvol) < 0)
return -1;
if (info->inputpool &&
virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->inputpool) < 0)
return -1;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool) < 0 ||
virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->vol) < 0) {
return -1;
}
if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv",
abs_srcdir, info->cmdline) < 0 && !info->shouldFail)
return -1;
if (info->inputvol)
inputvolxml = g_strdup_printf("%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->inputvol);
if (info->inputpool)
inputpoolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->inputpool);
poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool);
volxml = g_strdup_printf("%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->vol);
cmdline = g_strdup_printf("%s/storagevolxml2argvdata/%s.argv",
abs_srcdir, info->cmdline);
return testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
inputpoolxml, inputvolxml,

View File

@ -50,13 +50,12 @@ testCompareXMLToXMLHelper(const void *data)
g_autofree char *inxml = NULL;
g_autofree char *outxml = NULL;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool) < 0 ||
virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml",
abs_srcdir, info->name) < 0)
return -1;
poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool);
inxml = g_strdup_printf("%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->name);
outxml = g_strdup_printf("%s/storagevolxml2xmlout/%s.xml",
abs_srcdir, info->name);
return testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags);
}

View File

@ -90,16 +90,14 @@ sysinfotest_run(const char *test,
testdata.func = func;
if ((decoder &&
virAsprintf(&testdata.decoder, "%s/%s", abs_srcdir, decoder) < 0) ||
(sysinfo &&
virAsprintf(&testdata.sysinfo, "%s/%s", abs_srcdir, sysinfo) < 0) ||
(cpuinfo &&
virAsprintf(&testdata.cpuinfo, "%s/%s", abs_srcdir, cpuinfo) < 0) ||
(expected &&
virAsprintf(&testdata.expected, "%s/%s", abs_srcdir, expected) < 0)) {
goto error;
}
if (decoder)
testdata.decoder = g_strdup_printf("%s/%s", abs_srcdir, decoder);
if (sysinfo)
testdata.sysinfo = g_strdup_printf("%s/%s", abs_srcdir, sysinfo);
if (cpuinfo)
testdata.cpuinfo = g_strdup_printf("%s/%s", abs_srcdir, cpuinfo);
if (expected)
testdata.expected = g_strdup_printf("%s/%s", abs_srcdir, expected);
if (virTestRun(test, testSysinfo, &testdata) < 0)
goto error;

View File

@ -404,8 +404,7 @@ virTestRewrapFile(const char *filename)
return -1;
}
if (virAsprintf(&script, "%s/test-wrap-argv.pl", abs_srcdir) < 0)
goto cleanup;
script = g_strdup_printf("%s/test-wrap-argv.pl", abs_srcdir);
cmd = virCommandNewArgList(perl, script, "--in-place", filename, NULL);
if (virCommandRun(cmd, NULL) < 0)
@ -664,8 +663,7 @@ virTestCompareToFile(const char *actual,
if (filecontentLen > 0 &&
filecontent[filecontentLen - 1] == '\n' &&
(cmpcontentLen == 0 || cmpcontent[cmpcontentLen - 1] != '\n')) {
if (virAsprintf(&fixedcontent, "%s\n", cmpcontent) < 0)
goto failure;
fixedcontent = g_strdup_printf("%s\n", cmpcontent);
cmpcontent = fixedcontent;
}
}
@ -691,11 +689,9 @@ virTestCompareToULL(unsigned long long expect,
g_autofree char *expectStr = NULL;
g_autofree char *actualStr = NULL;
if (virAsprintf(&expectStr, "%llu", expect) < 0)
return -1;
expectStr = g_strdup_printf("%llu", expect);
if (virAsprintf(&actualStr, "%llu", actual) < 0)
return -1;
actualStr = g_strdup_printf("%llu", actual);
return virTestCompareToString(expectStr, actualStr);
}
@ -810,9 +806,8 @@ virTestSetEnvPath(void)
char *new_path = NULL;
if (path) {
if (strstr(path, abs_builddir) != path &&
virAsprintf(&new_path, "%s:%s", abs_builddir, path) < 0)
goto cleanup;
if (strstr(path, abs_builddir) != path)
new_path = g_strdup_printf("%s:%s", abs_builddir, path);
} else {
new_path = g_strdup(abs_builddir);
}

View File

@ -137,9 +137,8 @@ int virTestMain(int argc,
} \
if (!preload) { \
newenv = (char *) lib; \
} else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) { \
perror("virAsprintf"); \
return EXIT_FAILURE; \
} else { \
newenv = g_strdup_printf("%s:%s", lib, preload); \
} \
setenv(PRELOAD_VAR, newenv, 1); \
FORCE_FLAT_NAMESPACE \

View File

@ -809,8 +809,7 @@ testQemuGetLatestCapsForArch(const char *arch,
const char *maxname = NULL;
char *ret = NULL;
if (virAsprintf(&fullsuffix, "%s.%s", arch, suffix) < 0)
goto cleanup;
fullsuffix = g_strdup_printf("%s.%s", arch, suffix);
if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0)
goto cleanup;
@ -846,7 +845,7 @@ testQemuGetLatestCapsForArch(const char *arch,
goto cleanup;
}
ignore_value(virAsprintf(&ret, "%s/%s", TEST_QEMU_CAPS_PATH, maxname));
ret = g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
cleanup:
VIR_FREE(tmp);
@ -1064,10 +1063,8 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
if (STREQ(capsver, "latest")) {
capsfile = g_strdup(virHashLookup(capslatest, capsarch));
stripmachinealiases = true;
} else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml",
TEST_QEMU_CAPS_PATH, capsver, capsarch) < 0) {
goto cleanup;
}
} else capsfile = g_strdup_printf("%s/caps_%s.%s.xml",
TEST_QEMU_CAPS_PATH, capsver, capsarch);
if (!(qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(capsarch),
capsfile))) {

View File

@ -99,9 +99,8 @@ testCompareXMLToXMLHelper(const void *data)
int result = -1;
char *xml = NULL;
if (virAsprintf(&xml, "%s/vboxsnapshotxmldata/%s.vbox",
abs_srcdir, (const char*)data) < 0)
return -1;
xml = g_strdup_printf("%s/vboxsnapshotxmldata/%s.vbox", abs_srcdir,
(const char *)data);
result = testCompareXMLtoXMLFiles(xml);

View File

@ -45,13 +45,11 @@ test_virCapabilities(const void *opaque)
char *resctrl = NULL;
int ret = -1;
if (virAsprintf(&system, "%s/vircaps2xmldata/linux-%s/system",
abs_srcdir, data->filename) < 0)
goto cleanup;
system = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir,
data->filename);
if (virAsprintf(&resctrl, "%s/vircaps2xmldata/linux-%s/resctrl",
abs_srcdir, data->filename) < 0)
goto cleanup;
resctrl = g_strdup_printf("%s/vircaps2xmldata/linux-%s/resctrl", abs_srcdir,
data->filename);
virFileWrapperAddPrefix("/sys/devices/system", system);
virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl);
@ -69,9 +67,8 @@ test_virCapabilities(const void *opaque)
if (!(capsXML = virCapabilitiesFormatXML(caps)))
goto cleanup;
if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s-%s.xml",
abs_srcdir, archStr, data->filename) < 0)
goto cleanup;
path = g_strdup_printf("%s/vircaps2xmldata/vircaps-%s-%s.xml", abs_srcdir,
archStr, data->filename);
if (virTestCompareToFile(capsXML, path) < 0)
goto cleanup;

View File

@ -376,9 +376,8 @@ static void init_sysfs(void)
VIR_FREE(fakesysfscgroupdir);
if (virAsprintfQuiet(&fakesysfscgroupdir, "%s%s",
fakerootdir, SYSFS_CGROUP_PREFIX) < 0)
abort();
fakesysfscgroupdir = g_strdup_printf("%s%s",
fakerootdir, SYSFS_CGROUP_PREFIX);
if (virFileMakePath(fakesysfscgroupdir) < 0) {
fprintf(stderr, "Cannot create %s\n", fakesysfscgroupdir);
@ -459,10 +458,8 @@ FILE *fopen(const char *path, const char *mode)
errno = EACCES;
return NULL;
}
if (virAsprintfQuiet(&filepath, "%s/vircgroupdata/%s.%s",
abs_srcdir, filename, type) < 0) {
abort();
}
filepath = g_strdup_printf("%s/vircgroupdata/%s.%s",
abs_srcdir, filename, type);
rc = real_fopen(filepath, mode);
free(filepath);
return rc;

View File

@ -189,10 +189,7 @@ testCgroupDetectMounts(const void *args)
setenv("VIR_CGROUP_MOCK_FILENAME", data->file, 1);
if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed",
abs_srcdir, data->file) < 0) {
goto cleanup;
}
parsed = g_strdup_printf("%s/vircgroupdata/%s.parsed", abs_srcdir, data->file);
if (virCgroupNewSelf(&group) < 0) {
if (data->fail)

View File

@ -39,11 +39,8 @@ static int testConfRoundTrip(const void *opaque)
char *srcfile = NULL;
char *dstfile = NULL;
if (virAsprintf(&srcfile, "%s/virconfdata/%s.conf",
abs_srcdir, name) < 0 ||
virAsprintf(&dstfile, "%s/virconfdata/%s.out",
abs_srcdir, name) < 0)
goto cleanup;
srcfile = g_strdup_printf("%s/virconfdata/%s.conf", abs_srcdir, name);
dstfile = g_strdup_printf("%s/virconfdata/%s.out", abs_srcdir, name);
if (VIR_ALLOC_N_QUIET(buffer, len) < 0) {
fprintf(stderr, "out of memory\n");

View File

@ -188,7 +188,7 @@ canonicalize_file_name(const char *path)
char *ret;
if ((p = STRSKIP(path, "/some/symlink")))
ignore_value(virAsprintfQuiet(&ret, "/gluster%s", p));
ret = g_strdup_printf("/gluster%s", p);
else
ret = g_strdup(path);

View File

@ -325,8 +325,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED)
bool actual;
int ret = -1;
if (virAsprintf(&mtabFile, abs_srcdir "/virfiledata/%s", data->mtabFile) < 0)
return -1;
mtabFile = g_strdup_printf(abs_srcdir "/virfiledata/%s", data->mtabFile);
if (setenv("LIBVIRT_MTAB", mtabFile, 1) < 0) {
fprintf(stderr, "Unable to set env variable\n");

View File

@ -124,9 +124,7 @@ virMockStatRedirect(const char *path, char **newpath)
if (!tmp)
continue;
if (virAsprintfQuiet(newpath, "%s%s", overrides[i], tmp) < 0)
return -1;
*newpath = g_strdup_printf("%s%s", overrides[i], tmp);
break;
}

View File

@ -55,13 +55,11 @@ linuxTestCompareFiles(const char *cpuinfofile,
}
VIR_FORCE_FCLOSE(cpuinfo);
if (virAsprintf(&actualData,
"CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, "
"Cores: %u, Threads: %u\n",
nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo),
nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets,
nodeinfo.cores, nodeinfo.threads) < 0)
goto fail;
actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, "
"Cores: %u, Threads: %u\n",
nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo),
nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets,
nodeinfo.cores, nodeinfo.threads);
if (virTestCompareToFile(actualData, outputfile) < 0)
goto fail;
@ -177,20 +175,17 @@ linuxTestHostCPU(const void *opaque)
struct linuxTestHostCPUData *data = (struct linuxTestHostCPUData *) opaque;
const char *archStr = virArchToString(data->arch);
if (virAsprintf(&sysfs_prefix, "%s/virhostcpudata/linux-%s",
abs_srcdir, data->testName) < 0 ||
virAsprintf(&cpuinfo, "%s/virhostcpudata/linux-%s-%s.cpuinfo",
abs_srcdir, archStr, data->testName) < 0 ||
virAsprintf(&output, "%s/virhostcpudata/linux-%s-%s.expected",
abs_srcdir, archStr, data->testName) < 0) {
goto cleanup;
}
sysfs_prefix = g_strdup_printf("%s/virhostcpudata/linux-%s",
abs_srcdir, data->testName);
cpuinfo = g_strdup_printf("%s/virhostcpudata/linux-%s-%s.cpuinfo",
abs_srcdir, archStr, data->testName);
output = g_strdup_printf("%s/virhostcpudata/linux-%s-%s.expected",
abs_srcdir, archStr, data->testName);
virFileWrapperAddPrefix(SYSFS_SYSTEM_PATH, sysfs_prefix);
result = linuxTestCompareFiles(cpuinfo, data->arch, output);
virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH);
cleanup:
VIR_FREE(cpuinfo);
VIR_FREE(output);
VIR_FREE(sysfs_prefix);
@ -211,16 +206,14 @@ linuxTestNodeCPUStats(const void *data)
char *cpustatfile = NULL;
char *outfile = NULL;
if (virAsprintf(&cpustatfile, "%s/virhostcpudata/linux-cpustat-%s.stat",
abs_srcdir, testData->name) < 0 ||
virAsprintf(&outfile, "%s/virhostcpudata/linux-cpustat-%s.out",
abs_srcdir, testData->name) < 0)
goto fail;
cpustatfile = g_strdup_printf("%s/virhostcpudata/linux-cpustat-%s.stat",
abs_srcdir, testData->name);
outfile = g_strdup_printf("%s/virhostcpudata/linux-cpustat-%s.out",
abs_srcdir, testData->name);
result = linuxCPUStatsCompareFiles(cpustatfile,
testData->ncpus,
outfile);
fail:
VIR_FREE(cpustatfile);
VIR_FREE(outfile);
return result;

View File

@ -26,11 +26,10 @@ testJSONFromFile(const void *data)
g_autofree char *outfile = NULL;
g_autofree char *actual = NULL;
if (virAsprintf(&infile, "%s/virjsondata/parse-%s-in.json",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outfile, "%s/virjsondata/parse-%s-out.json",
abs_srcdir, info->name) < 0)
return -1;
infile = g_strdup_printf("%s/virjsondata/parse-%s-in.json",
abs_srcdir, info->name);
outfile = g_strdup_printf("%s/virjsondata/parse-%s-out.json",
abs_srcdir, info->name);
if (virTestLoadFile(infile, &indata) < 0)
return -1;
@ -114,11 +113,10 @@ testJSONAddRemove(const void *data)
g_autofree char *outfile = NULL;
g_autofree char *actual = NULL;
if (virAsprintf(&infile, "%s/virjsondata/add-remove-%s-in.json",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outfile, "%s/virjsondata/add-remove-%s-out.json",
abs_srcdir, info->name) < 0)
return -1;
infile = g_strdup_printf("%s/virjsondata/add-remove-%s-in.json",
abs_srcdir, info->name);
outfile = g_strdup_printf("%s/virjsondata/add-remove-%s-out.json",
abs_srcdir, info->name);
if (virTestLoadFile(infile, &indata) < 0)
return -1;
@ -350,11 +348,10 @@ testJSONDeflatten(const void *data)
g_autofree char *outfile = NULL;
g_autofree char *actual = NULL;
if (virAsprintf(&infile, "%s/virjsondata/deflatten-%s-in.json",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outfile, "%s/virjsondata/deflatten-%s-out.json",
abs_srcdir, info->name) < 0)
return -1;
infile = g_strdup_printf("%s/virjsondata/deflatten-%s-in.json",
abs_srcdir, info->name);
outfile = g_strdup_printf("%s/virjsondata/deflatten-%s-out.json",
abs_srcdir, info->name);
if (virTestLoadFile(infile, &indata) < 0)
return -1;

View File

@ -41,9 +41,7 @@ testMACLookup(const void *opaque)
char *file = NULL;
int ret = -1;
if (virAsprintf(&file, "%s/virmacmaptestdata/%s.json",
abs_srcdir, data->file) < 0)
goto cleanup;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
if (!(mgr = virMacMapNew(file)))
goto cleanup;
@ -94,9 +92,7 @@ testMACRemove(const void *opaque)
char *file = NULL;
int ret = -1;
if (virAsprintf(&file, "%s/virmacmaptestdata/%s.json",
abs_srcdir, data->file) < 0)
goto cleanup;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
if (!(mgr = virMacMapNew(file)))
goto cleanup;
@ -131,9 +127,7 @@ testMACFlush(const void *opaque)
char *str = NULL;
int ret = -1;
if (virAsprintf(&file, "%s/virmacmaptestdata/%s.json",
abs_srcdir, data->file) < 0)
goto cleanup;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
if (virMacMapDumpStr(data->mgr, &str) < 0)
goto cleanup;

View File

@ -295,13 +295,11 @@ static int testExecRestart(const void *opaque)
goto cleanup;
}
if (virAsprintf(&infile, "%s/virnetdaemondata/input-data-%s.json",
abs_srcdir, data->jsonfile) < 0)
goto cleanup;
infile = g_strdup_printf("%s/virnetdaemondata/input-data-%s.json", abs_srcdir,
data->jsonfile);
if (virAsprintf(&outfile, "%s/virnetdaemondata/output-data-%s.json",
abs_srcdir, data->jsonfile) < 0)
goto cleanup;
outfile = g_strdup_printf("%s/virnetdaemondata/output-data-%s.json",
abs_srcdir, data->jsonfile);
if (virFileReadAll(infile, 8192, &injsonstr) < 0)
goto cleanup;

View File

@ -30,12 +30,8 @@ virNetDevSysfsFile(char **pf_sysfs_device_link,
const char *ifname,
const char *file)
{
if (virAsprintfQuiet(pf_sysfs_device_link, "%s/%s/%s",
NET_DEV_TEST_DATA_PREFIX, ifname, file) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
*pf_sysfs_device_link = g_strdup_printf("%s/%s/%s",
NET_DEV_TEST_DATA_PREFIX, ifname, file);
return 0;
}
#else

View File

@ -38,9 +38,8 @@ testInterfaceParseStats(const void *opaque)
g_autofree char *buf = NULL;
virDomainInterfaceStatsStruct actual;
if (virAsprintf(&filename, "%s/virnetdevopenvswitchdata/%s",
abs_srcdir, data->filename) < 0)
return -1;
filename = g_strdup_printf("%s/virnetdevopenvswitchdata/%s", abs_srcdir,
data->filename);
if (virFileReadAll(filename, 1024, &buf) < 0)
return -1;

View File

@ -196,8 +196,7 @@ testSocketAccept(const void *opaque)
VIR_WARN("Failed to create temporary directory");
goto cleanup;
}
if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0)
goto cleanup;
path = g_strdup_printf("%s/test.sock", tmpdir);
if (virNetSocketNewListenUNIX(path, 0700, -1, getegid(), &usock) < 0)
goto cleanup;
@ -321,8 +320,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
VIR_WARN("Failed to create temporary directory");
goto cleanup;
}
if (virAsprintf(&path, "%s/test.sock", tmpdir) < 0)
goto cleanup;
path = g_strdup_printf("%s/test.sock", tmpdir);
if (virNetSocketNewListenUNIX(path, 0700, -1, getegid(), &lsock) < 0)
goto cleanup;

View File

@ -66,13 +66,11 @@ testCompareXMLToXMLHelper(const void *data)
int ret = -1;
char *xml = NULL;
if (virAsprintf(&xml, "%s/virnetworkportxml2xmldata/%s.xml",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir,
info->name);
ret = testCompareXMLToXMLFiles(xml);
cleanup:
VIR_FREE(xml);
return ret;

View File

@ -43,8 +43,7 @@ virNumaIsAvailable(void)
if (numa_avail < 0) {
char *sysfs_node_path = NULL;
if (virAsprintfQuiet(&sysfs_node_path, "%s/node", SYSFS_SYSTEM_PATH) < 0)
return false;
sysfs_node_path = g_strdup_printf("%s/node", SYSFS_SYSTEM_PATH);
numa_avail = virFileExists(sysfs_node_path);

View File

@ -72,14 +72,11 @@ testCompareXMLToXMLHelper(const void *data)
const test_parms *tp = data;
char *xml = NULL;
if (virAsprintf(&xml, "%s/virnwfilterbindingxml2xmldata/%s.xml",
abs_srcdir, tp->name) < 0) {
goto cleanup;
}
xml = g_strdup_printf("%s/virnwfilterbindingxml2xmldata/%s.xml", abs_srcdir,
tp->name);
result = testCompareXMLToXMLFiles(xml);
cleanup:
VIR_FREE(xml);
return result;

View File

@ -186,8 +186,7 @@ make_file(const char *path,
if (value && len == -1)
len = strlen(value);
if (virAsprintfQuiet(&filepath, "%s/%s", path, name) < 0)
ABORT_OOM();
filepath = g_strdup_printf("%s/%s", path, name);
if ((fd = real_open(filepath, O_CREAT|O_WRONLY, 0666)) < 0)
ABORT("Unable to open: %s", filepath);
@ -204,8 +203,7 @@ make_dir(const char *path,
{
g_autofree char *dirpath = NULL;
if (virAsprintfQuiet(&dirpath, "%s/%s", path, name) < 0)
ABORT_OOM();
dirpath = g_strdup_printf("%s/%s", path, name);
if (virFileMakePath(dirpath) < 0)
ABORT("Unable to create: %s", dirpath);
@ -218,8 +216,7 @@ make_symlink(const char *path,
{
g_autofree char *filepath = NULL;
if (virAsprintfQuiet(&filepath, "%s/%s", path, name) < 0)
ABORT_OOM();
filepath = g_strdup_printf("%s/%s", path, name);
if (symlink(target, filepath) < 0)
ABORT("Unable to create symlink filepath -> target");
@ -235,10 +232,7 @@ pci_read_file(const char *path,
int fd = -1;
g_autofree char *newpath = NULL;
if (virAsprintfQuiet(&newpath, "%s/%s", fakerootdir, path) < 0) {
errno = ENOMEM;
goto cleanup;
}
newpath = g_strdup_printf("%s/%s", fakerootdir, path);
if ((fd = real_open(newpath, O_RDWR)) < 0)
goto cleanup;
@ -275,19 +269,13 @@ getrealpath(char **newpath,
init_env();
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
if (virAsprintfQuiet(newpath, "%s/sys/bus/pci/%s",
fakerootdir,
path + strlen(SYSFS_PCI_PREFIX)) < 0) {
errno = ENOMEM;
return -1;
}
*newpath = g_strdup_printf("%s/sys/bus/pci/%s",
fakerootdir,
path + strlen(SYSFS_PCI_PREFIX));
} else if (pathPrefixIsMocked(path)) {
if (virAsprintfQuiet(newpath, "%s/%s",
fakerootdir,
path) < 0) {
errno = ENOMEM;
return -1;
}
*newpath = g_strdup_printf("%s/%s",
fakerootdir,
path);
} else {
*newpath = g_strdup(path);
}
@ -368,9 +356,9 @@ pci_address_format(struct pciDeviceAddress const *addr)
{
char *ret;
ignore_value(virAsprintfQuiet(&ret, ADDR_STR_FMT,
addr->domain, addr->bus,
addr->device, addr->function));
ret = g_strdup_printf(ADDR_STR_FMT,
addr->domain, addr->bus,
addr->device, addr->function);
return ret;
}
@ -405,13 +393,13 @@ pci_device_get_path(const struct pciDevice *dev,
* and then they are just symlinked to /sys/bus/pci/devices/
*/
if (file) {
ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s/%s",
prefix, dev->addr.domain, dev->addr.bus,
devid, file));
ret = g_strdup_printf("%s/sys/devices/pci%04x:%02x/%s/%s",
prefix, dev->addr.domain, dev->addr.bus,
devid, file);
} else {
ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s",
prefix, dev->addr.domain, dev->addr.bus,
devid));
ret = g_strdup_printf("%s/sys/devices/pci%04x:%02x/%s",
prefix, dev->addr.domain, dev->addr.bus,
devid);
}
return ret;
@ -427,9 +415,8 @@ pci_device_create_iommu(const struct pciDevice *dev,
char tmp[256];
size_t i;
if (virAsprintfQuiet(&iommuPath, "%s/sys/kernel/iommu_groups/%d/devices/",
fakerootdir, dev->iommuGroup) < 0)
ABORT_OOM();
iommuPath = g_strdup_printf("%s/sys/kernel/iommu_groups/%d/devices/",
fakerootdir, dev->iommuGroup);
if (virFileMakePath(iommuPath) < 0)
ABORT("Unable to create: %s", iommuPath);
@ -492,11 +479,11 @@ pci_device_new_from_stub(const struct pciDevice *data)
c = strchr(c, ':');
}
if (VIR_ALLOC_QUIET(dev) < 0 ||
virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config",
abs_srcdir, id) < 0)
if (VIR_ALLOC_QUIET(dev) < 0)
ABORT_OOM();
configSrc = g_strdup_printf("%s/virpcitestdata/%s.config", abs_srcdir, id);
memcpy(dev, data, sizeof(*dev));
if (!(devpath = pci_device_get_path(dev, NULL, true)))
@ -557,8 +544,7 @@ pci_device_new_from_stub(const struct pciDevice *data)
ABORT("@tmp overflow");
}
if (virAsprintfQuiet(&devsympath, "%s" SYSFS_PCI_PREFIX "devices", fakerootdir) < 0)
ABORT_OOM();
devsympath = g_strdup_printf("%s" SYSFS_PCI_PREFIX "devices", fakerootdir);
make_symlink(devsympath, devid, tmp);
@ -639,12 +625,9 @@ pci_vfio_release_iommu(struct pciDevice *device)
pciIommuGroups[i]->nDevicesBoundToVFIO--;
if (!pciIommuGroups[i]->nDevicesBoundToVFIO) {
if (virAsprintfQuiet(&vfiopath, "%s/dev/vfio/%d",
fakerootdir,
device->iommuGroup) < 0) {
errno = ENOMEM;
return -1;
}
vfiopath = g_strdup_printf("%s/dev/vfio/%d",
fakerootdir,
device->iommuGroup);
if (unlink(vfiopath) < 0)
return -1;
@ -668,12 +651,9 @@ pci_vfio_lock_iommu(struct pciDevice *device)
continue;
if (pciIommuGroups[i]->nDevicesBoundToVFIO == 0) {
if (virAsprintfQuiet(&vfiopath, "%s/dev/vfio/%d",
fakerootdir,
device->iommuGroup) < 0) {
errno = ENOMEM;
goto cleanup;
}
vfiopath = g_strdup_printf("%s/dev/vfio/%d",
fakerootdir,
device->iommuGroup);
if ((fd = real_open(vfiopath, O_CREAT)) < 0)
goto cleanup;
@ -705,11 +685,11 @@ pci_driver_get_path(const struct pciDriver *driver,
prefix = fakerootdir;
if (file) {
ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s/%s",
prefix, driver->name, file));
ret = g_strdup_printf("%s" SYSFS_PCI_PREFIX "drivers/%s/%s",
prefix, driver->name, file);
} else {
ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s",
prefix, driver->name));
ret = g_strdup_printf("%s" SYSFS_PCI_PREFIX "drivers/%s",
prefix, driver->name);
}
return ret;
@ -991,9 +971,7 @@ init_env(void)
if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR")))
ABORT("Missing LIBVIRT_FAKE_ROOT_DIR env variable\n");
if (virAsprintfQuiet(&tmp, "%s%s",
fakerootdir, SYSFS_PCI_PREFIX) < 0)
ABORT_OOM();
tmp = g_strdup_printf("%s%s", fakerootdir, SYSFS_PCI_PREFIX);
if (virFileMakePath(tmp) < 0)
ABORT("Unable to create: %s", tmp);
@ -1004,8 +982,7 @@ init_env(void)
/* Create /dev/vfio/ dir and /dev/vfio/vfio file */
VIR_FREE(tmp);
if (virAsprintfQuiet(&tmp, "%s/dev/vfio", fakerootdir) < 0)
ABORT_OOM();
tmp = g_strdup_printf("%s/dev/vfio", fakerootdir);
if (virFileMakePath(tmp) < 0)
ABORT("Unable to create: %s", tmp);

View File

@ -349,11 +349,8 @@ mymain(void)
domain, bus, slot, function, NULL \
}; \
char *label = NULL; \
if (virAsprintf(&label, "%s(%04x:%02x:%02x.%x)", \
#fnc, domain, bus, slot, function) < 0) { \
ret = -1; \
break; \
} \
label = g_strdup_printf("%s(%04x:%02x:%02x.%x)", \
#fnc, domain, bus, slot, function); \
if (virTestRun(label, fnc, &data) < 0) \
ret = -1; \
VIR_FREE(label); \
@ -365,12 +362,9 @@ mymain(void)
domain, bus, slot, function, driver \
}; \
char *label = NULL; \
if (virAsprintf(&label, "PCI driver %04x:%02x:%02x.%x is %s", \
domain, bus, slot, function, \
NULLSTR(driver)) < 0) { \
ret = -1; \
break; \
} \
label = g_strdup_printf("PCI driver %04x:%02x:%02x.%x is %s", \
domain, bus, slot, function, \
NULLSTR(driver)); \
if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \
&data) < 0) \
ret = -1; \

View File

@ -53,8 +53,9 @@ uint64_t virRandomBits(int nbits)
int virRandomGenerateWWN(char **wwn,
const char *virt_type G_GNUC_UNUSED)
{
return virAsprintf(wwn, "5100000%09llx",
(unsigned long long)virRandomBits(36));
*wwn = g_strdup_printf("5100000%09llx",
(unsigned long long)virRandomBits(36));
return 0;
}

View File

@ -26,17 +26,14 @@ test_virResctrlGetUnused(const void *opaque)
char *schemata_file;
virCapsPtr caps = NULL;
if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system",
abs_srcdir, data->filename) < 0)
goto cleanup;
system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir,
data->filename);
if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl",
abs_srcdir, data->filename) < 0)
goto cleanup;
resctrl_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/resctrl",
abs_srcdir, data->filename);
if (virAsprintf(&schemata_file, "%s/virresctrldata/%s.schemata",
abs_srcdir, data->filename) < 0)
goto cleanup;
schemata_file = g_strdup_printf("%s/virresctrldata/%s.schemata", abs_srcdir,
data->filename);
virFileWrapperAddPrefix("/sys/devices/system", system_dir);
virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir);

View File

@ -87,12 +87,9 @@ testSchemaDir(const char *schema,
if (ent->d_name[0] == '.')
continue;
if (virAsprintf(&xml_path, "%s/%s", dir_path, ent->d_name) < 0)
goto cleanup;
xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name);
if (virAsprintf(&test_name, "Checking %s against %s",
ent->d_name, schema) < 0)
goto cleanup;
test_name = g_strdup_printf("Checking %s against %s", ent->d_name, schema);
data.xml_path = xml_path;
if (virTestRun(test_name, testSchemaFile, &data) < 0)
@ -105,7 +102,6 @@ testSchemaDir(const char *schema,
if (rc < 0)
ret = -1;
cleanup:
VIR_FREE(test_name);
VIR_FREE(xml_path);
VIR_DIR_CLOSE(dir);
@ -124,16 +120,12 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr validator, ...)
va_start(args, validator);
while ((dir = va_arg(args, char *))) {
if (virAsprintf(&dir_path, "%s/%s", abs_srcdir, dir) < 0) {
ret = -1;
goto cleanup;
}
dir_path = g_strdup_printf("%s/%s", abs_srcdir, dir);
if (testSchemaDir(schema, validator, dir_path) < 0)
ret = -1;
VIR_FREE(dir_path);
}
cleanup:
VIR_FREE(dir_path);
va_end(args);
return ret;
@ -147,9 +139,8 @@ testSchemaGrammar(const void *opaque)
char *schema_path;
int ret = -1;
if (virAsprintf(&schema_path, "%s/docs/schemas/%s",
abs_top_srcdir, data->schema) < 0)
return -1;
schema_path = g_strdup_printf("%s/docs/schemas/%s", abs_top_srcdir,
data->schema);
if (!(data->validator = virXMLValidatorInit(schema_path)))
goto cleanup;

View File

@ -167,11 +167,9 @@ create_symlink(const char *tmpdir, const char *src_name, const char *dst_name)
char *src_path = NULL;
char *dst_path = NULL;
if (virAsprintf(&src_path, "%s/%s", virscsi_prefix, src_name) < 0)
goto cleanup;
src_path = g_strdup_printf("%s/%s", virscsi_prefix, src_name);
if (virAsprintf(&dst_path, "%s/%s", tmpdir, dst_name) < 0)
goto cleanup;
dst_path = g_strdup_printf("%s/%s", tmpdir, dst_name);
if (symlink(src_path, dst_path) < 0) {
VIR_WARN("Failed to create symlink '%s' to '%s'", src_path, dst_path);
@ -194,10 +192,7 @@ mymain(void)
char *tmpdir = NULL;
char template[] = "/tmp/libvirt_XXXXXX";
if (virAsprintf(&virscsi_prefix, "%s" VIR_SCSI_DATA, abs_srcdir) < 0) {
ret = -1;
goto cleanup;
}
virscsi_prefix = g_strdup_printf("%s" VIR_SCSI_DATA, abs_srcdir);
tmpdir = mkdtemp(template);

View File

@ -252,9 +252,8 @@ mymain(void)
{
int ret = 0;
if (virAsprintf(&custom_uri, "test://%s/../examples/xml/test/testnode.xml",
abs_srcdir) < 0)
return EXIT_FAILURE;
custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml",
abs_srcdir);
if (virTestRun("virsh list (default)",
testCompareListDefault, NULL) != 0)

View File

@ -136,13 +136,12 @@ testPrepImages(void)
compat = true;
VIR_FREE(buf);
if (virAsprintf(&absraw, "%s/raw", datadir) < 0 ||
virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 ||
virAsprintf(&abswrap, "%s/wrap", datadir) < 0 ||
virAsprintf(&absqed, "%s/qed", datadir) < 0 ||
virAsprintf(&absdir, "%s/dir", datadir) < 0 ||
virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0)
goto cleanup;
absraw = g_strdup_printf("%s/raw", datadir);
absqcow2 = g_strdup_printf("%s/qcow2", datadir);
abswrap = g_strdup_printf("%s/wrap", datadir);
absqed = g_strdup_printf("%s/qed", datadir);
absdir = g_strdup_printf("%s/dir", datadir);
abslink2 = g_strdup_printf("%s/sub/link2", datadir);
if (virFileMakePath(datadir "/sub") < 0) {
fprintf(stderr, "unable to create directory %s\n", datadir "/sub");
@ -158,8 +157,8 @@ testPrepImages(void)
goto cleanup;
}
if (virAsprintf(&buf, "%1024d", 0) < 0 ||
virFileWriteStr("raw", buf, 0600) < 0) {
buf = g_strdup_printf("%1024d", 0);
if (virFileWriteStr("raw", buf, 0600) < 0) {
fprintf(stderr, "unable to create raw file\n");
goto cleanup;
}
@ -320,30 +319,26 @@ testStorageChain(const void *args)
return -1;
}
if (virAsprintf(&expect,
testStorageChainFormat, i,
NULLSTR(data->files[i]->path),
NULLSTR(data->files[i]->expBackingStoreRaw),
data->files[i]->expCapacity,
data->files[i]->expEncrypted,
NULLSTR(data->files[i]->pathRel),
data->files[i]->type,
data->files[i]->format,
virStorageNetProtocolTypeToString(data->files[i]->protocol),
NULLSTR(data->files[i]->hostname)) < 0 ||
virAsprintf(&actual,
testStorageChainFormat, i,
NULLSTR(elt->path),
NULLSTR(elt->backingStoreRaw),
elt->capacity,
!!elt->encryption,
NULLSTR(elt->relPath),
elt->type,
elt->format,
virStorageNetProtocolTypeToString(elt->protocol),
NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)) < 0) {
return -1;
}
expect = g_strdup_printf(testStorageChainFormat, i,
NULLSTR(data->files[i]->path),
NULLSTR(data->files[i]->expBackingStoreRaw),
data->files[i]->expCapacity,
data->files[i]->expEncrypted,
NULLSTR(data->files[i]->pathRel),
data->files[i]->type,
data->files[i]->format,
virStorageNetProtocolTypeToString(data->files[i]->protocol),
NULLSTR(data->files[i]->hostname));
actual = g_strdup_printf(testStorageChainFormat, i,
NULLSTR(elt->path),
NULLSTR(elt->backingStoreRaw),
elt->capacity,
!!elt->encryption,
NULLSTR(elt->relPath),
elt->type,
elt->format,
virStorageNetProtocolTypeToString(elt->protocol),
NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL));
if (STRNEQ(expect, actual)) {
virTestDifference(stderr, expect, actual);
return -1;

View File

@ -109,9 +109,8 @@ checkPath(const char *path,
char *relPath = NULL;
char *crippledPath = NULL;
if (path[0] != '/' &&
virAsprintfQuiet(&relPath, "./%s", path) < 0)
goto error;
if (path[0] != '/')
relPath = g_strdup_printf("./%s", path);
/* Le sigh. virFileCanonicalizePath() expects @path to exist, otherwise
* it will return an error. So if we are called over an non-existent
@ -141,9 +140,6 @@ checkPath(const char *path,
VIR_FREE(fullPath);
return;
error:
fprintf(stderr, "Out of memory\n");
abort();
}

View File

@ -53,17 +53,12 @@ static char *get_fake_path(const char *real_path)
const char *p = NULL;
char *path = NULL;
if ((p = STRSKIP(real_path, USB_SYSFS)) &&
virAsprintfQuiet(&path, "%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p) < 0)
goto error;
if ((p = STRSKIP(real_path, USB_SYSFS)))
path = g_strdup_printf("%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p);
else if (!p)
path = g_strdup(real_path);
return path;
error:
errno = ENOMEM;
return NULL;
}
DIR *opendir(const char *name)

View File

@ -52,10 +52,8 @@ static int testDeviceFileActor(virUSBDevicePtr dev,
char *str = NULL;
int ret = 0;
if (virAsprintf(&str, USB_DEVFS "%03d/%03d",
virUSBDeviceGetBus(dev),
virUSBDeviceGetDevno(dev)) < 0)
return -1;
str = g_strdup_printf(USB_DEVFS "%03d/%03d", virUSBDeviceGetBus(dev),
virUSBDeviceGetDevno(dev));
if (STRNEQ(path, str)) {
virReportError(VIR_ERR_INTERNAL_ERROR,

View File

@ -43,9 +43,7 @@ testVerStrParse(const void *data)
unsigned long version;
int vmware_type;
if (virAsprintf(&path, "%s/vmwareverdata/%s.txt", abs_srcdir,
info->name) < 0)
return -1;
path = g_strdup_printf("%s/vmwareverdata/%s.txt", abs_srcdir, info->name);
if (virTestLoadFile(path, &databuf) < 0)
goto cleanup;

View File

@ -114,16 +114,13 @@ testCompareHelper(const void *data)
char *vmx = NULL;
char *xml = NULL;
if (virAsprintf(&vmx, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
info->input) < 0 ||
virAsprintf(&xml, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
info->output) < 0) {
goto cleanup;
}
vmx = g_strdup_printf("%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
info->input);
xml = g_strdup_printf("%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
info->output);
ret = testCompareFiles(vmx, xml);
cleanup:
VIR_FREE(vmx);
VIR_FREE(xml);
@ -151,9 +148,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED)
goto cleanup;
}
if (virAsprintf(&src, "[%s] %s", datastoreName,
directoryAndFileName) < 0)
goto cleanup;
src = g_strdup_printf("[%s] %s", datastoreName, directoryAndFileName);
} else if (STRPREFIX(fileName, "/")) {
/* Found absolute path referencing a file outside a datastore */
src = g_strdup(fileName);
@ -162,8 +157,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED)
src = NULL;
} else {
/* Found single file name referencing a file inside a datastore */
if (virAsprintf(&src, "[datastore] directory/%s", fileName) < 0)
goto cleanup;
src = g_strdup_printf("[datastore] directory/%s", fileName);
}
cleanup:

View File

@ -187,18 +187,14 @@ testCompareHelper(const void *data)
char *xml = NULL;
char *cfg = NULL;
if (virAsprintf(&xml, "%s/xlconfigdata/test-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&cfg, "%s/xlconfigdata/test-%s.cfg",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/xlconfigdata/test-%s.xml", abs_srcdir, info->name);
cfg = g_strdup_printf("%s/xlconfigdata/test-%s.cfg", abs_srcdir, info->name);
if (info->mode == 0)
result = testCompareParseXML(cfg, xml, info->replaceVars);
else
result = testCompareFormatXML(cfg, xml, info->replaceVars);
cleanup:
VIR_FREE(xml);
VIR_FREE(cfg);

View File

@ -131,18 +131,14 @@ testCompareHelper(const void *data)
char *cfg = NULL;
char *cfgout = NULL;
if (virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg",
abs_srcdir, info->name) < 0)
goto cleanup;
xml = g_strdup_printf("%s/xmconfigdata/test-%s.xml", abs_srcdir, info->name);
cfg = g_strdup_printf("%s/xmconfigdata/test-%s.cfg", abs_srcdir, info->name);
if (info->mode == 0)
result = testCompareParseXML(cfg, xml);
else
result = testCompareFormatXML(cfg, xml);
cleanup:
VIR_FREE(xml);
VIR_FREE(cfg);
VIR_FREE(cfgout);

View File

@ -115,16 +115,13 @@ testCompareHelper(const void *data)
char *xml = NULL;
char *vmx = NULL;
if (virAsprintf(&xml, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
info->input) < 0 ||
virAsprintf(&vmx, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
info->output) < 0) {
goto cleanup;
}
xml = g_strdup_printf("%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
info->input);
vmx = g_strdup_printf("%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
info->output);
result = testCompareFiles(xml, vmx, info->virtualHW_version);
cleanup:
VIR_FREE(xml);
VIR_FREE(vmx);
@ -169,9 +166,8 @@ testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED)
directoryAndFileName += strspn(directoryAndFileName, " ");
}
if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", datastoreName,
directoryAndFileName) < 0)
goto cleanup;
absolutePath = g_strdup_printf("/vmfs/volumes/%s/%s", datastoreName,
directoryAndFileName);
} else if (STRPREFIX(src, "/")) {
/* Found absolute path */
absolutePath = g_strdup(src);