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 *xml = NULL;
char *args = NULL; char *args = NULL;
if (virAsprintf(&xml, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.xml", xml = g_strdup_printf("%s/bhyveargv2xmldata/bhyveargv2xml-%s.xml",
abs_srcdir, info->name) < 0 || abs_srcdir, info->name);
virAsprintf(&args, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.args", args = g_strdup_printf("%s/bhyveargv2xmldata/bhyveargv2xml-%s.args",
abs_srcdir, info->name) < 0) abs_srcdir, info->name);
goto cleanup;
result = testCompareXMLToArgvFiles(xml, args, info->flags); result = testCompareXMLToArgvFiles(xml, args, info->flags);
cleanup:
VIR_FREE(xml); VIR_FREE(xml);
VIR_FREE(args); VIR_FREE(args);
return result; return result;

View File

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

View File

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

View File

@ -67,11 +67,8 @@ static int checkoutput(const char *testname,
char *actualname = NULL; char *actualname = NULL;
char *actuallog = NULL; char *actuallog = NULL;
if (virAsprintf(&expectname, "%s/commanddata/%s.log", abs_srcdir, expectname = g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, testname);
testname) < 0) actualname = g_strdup_printf("%s/commandhelper.log", abs_builddir);
goto cleanup;
if (virAsprintf(&actualname, "%s/commandhelper.log", abs_builddir) < 0)
goto cleanup;
if (virFileReadAll(expectname, 1024*64, &expectlog) < 0) { if (virFileReadAll(expectname, 1024*64, &expectlog) < 0) {
fprintf(stderr, "cannot read %s\n", expectname); fprintf(stderr, "cannot read %s\n", expectname);
@ -86,8 +83,7 @@ static int checkoutput(const char *testname,
if (prefix) { if (prefix) {
char *tmp = NULL; char *tmp = NULL;
if (virAsprintf(&tmp, "%s%s", prefix, expectlog) < 0) tmp = g_strdup_printf("%s%s", prefix, expectlog);
goto cleanup;
VIR_FREE(expectlog); VIR_FREE(expectlog);
expectlog = tmp; expectlog = tmp;
@ -595,8 +591,7 @@ static int test15(const void *unused G_GNUC_UNUSED)
char *cwd = NULL; char *cwd = NULL;
int ret = -1; int ret = -1;
if (virAsprintf(&cwd, "%s/commanddata", abs_srcdir) < 0) cwd = g_strdup_printf("%s/commanddata", abs_srcdir);
goto cleanup;
virCommandSetWorkingDirectory(cmd, cwd); virCommandSetWorkingDirectory(cmd, cwd);
virCommandSetUmask(cmd, 002); virCommandSetUmask(cmd, 002);
@ -815,8 +810,7 @@ static int test20(const void *unused G_GNUC_UNUSED)
sigaction(SIGPIPE, &sig_action, NULL); sigaction(SIGPIPE, &sig_action, NULL);
if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0) buf = g_strdup_printf("1\n%100000d\n", 2);
goto cleanup;
virCommandSetInputBuffer(cmd, buf); virCommandSetInputBuffer(cmd, buf);
if (virCommandRun(cmd, NULL) < 0) { if (virCommandRun(cmd, NULL) < 0) {
@ -1174,13 +1168,10 @@ static int test27(const void *unused G_GNUC_UNUSED)
buffer2[buflen - 2] = '\n'; buffer2[buflen - 2] = '\n';
buffer2[buflen - 1] = 0; buffer2[buflen - 1] = 0;
if (virAsprintf(&outexpect, TEST27_OUTEXPECT_TEMP, outexpect = g_strdup_printf(TEST27_OUTEXPECT_TEMP,
buffer0, buffer1, buffer2) < 0 || buffer0, buffer1, buffer2);
virAsprintf(&errexpect, TEST27_ERREXPECT_TEMP, errexpect = g_strdup_printf(TEST27_ERREXPECT_TEMP,
buffer0, buffer1, buffer2) < 0) { buffer0, buffer1, buffer2);
printf("Could not virAsprintf expected output\n");
goto cleanup;
}
if (pipe(pipe1) < 0 || pipe(pipe2) < 0) { if (pipe(pipe1) < 0 || pipe(pipe2) < 0) {
printf("Could not create pipe: %s\n", g_strerror(errno)); 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; xmlXPathContextPtr ctxt = NULL;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
abs_srcdir, virArchToString(arch), name) < 0) virArchToString(arch), name);
goto cleanup;
if (!(doc = virXMLParseFileCtxt(xml, &ctxt))) if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
goto cleanup; goto cleanup;
@ -105,9 +104,8 @@ cpuTestLoadMultiXML(virArch arch,
int n; int n;
size_t i; size_t i;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
abs_srcdir, virArchToString(arch), name) < 0) virArchToString(arch), name);
goto cleanup;
if (!(doc = virXMLParseFileCtxt(xml, &ctxt))) if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
goto cleanup; goto cleanup;
@ -150,9 +148,8 @@ cpuTestCompareXML(virArch arch,
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
abs_srcdir, virArchToString(arch), name) < 0) virArchToString(arch), name);
goto cleanup;
if (!(actual = virCPUDefFormat(cpu, NULL))) if (!(actual = virCPUDefFormat(cpu, NULL)))
goto cleanup; goto cleanup;
@ -341,8 +338,7 @@ cpuTestBaseline(const void *arg)
suffix = "migratable"; suffix = "migratable";
else else
suffix = "result"; suffix = "result";
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0) result = g_strdup_printf("%s-%s", data->name, suffix);
goto cleanup;
if (cpuTestCompareXML(data->arch, baseline, result) < 0) if (cpuTestCompareXML(data->arch, baseline, result) < 0)
goto cleanup; goto cleanup;
@ -395,8 +391,7 @@ cpuTestUpdate(const void *arg)
if (virCPUUpdate(host->arch, cpu, migHost) < 0) if (virCPUUpdate(host->arch, cpu, migHost) < 0)
goto cleanup; goto cleanup;
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0) result = g_strdup_printf("%s+%s", data->host, data->name);
goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result); ret = cpuTestCompareXML(data->arch, cpu, result);
@ -481,9 +476,8 @@ cpuTestMakeQEMUCaps(const struct data *data)
bool fail_no_props = true; bool fail_no_props = true;
char *json = NULL; char *json = NULL;
if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json", json = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.json", abs_srcdir,
abs_srcdir, virArchToString(data->arch), data->host) < 0) virArchToString(data->arch), data->host);
goto error;
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true))) if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
goto error; goto error;
@ -585,9 +579,8 @@ cpuTestCPUID(bool guest, const void *arg)
char *result = NULL; char *result = NULL;
virDomainCapsCPUModelsPtr models = NULL; virDomainCapsCPUModelsPtr models = NULL;
if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
abs_srcdir, virArchToString(data->arch), data->host) < 0) virArchToString(data->arch), data->host);
goto cleanup;
if (virTestLoadFile(hostFile, &host) < 0 || if (virTestLoadFile(hostFile, &host) < 0 ||
!(hostData = virCPUDataParse(host))) !(hostData = virCPUDataParse(host)))
@ -618,10 +611,7 @@ cpuTestCPUID(bool guest, const void *arg)
if (cpuDecode(cpu, hostData, models) < 0) if (cpuDecode(cpu, hostData, models) < 0)
goto cleanup; goto cleanup;
if (virAsprintf(&result, "cpuid-%s-%s", result = g_strdup_printf("cpuid-%s-%s", data->host, guest ? "guest" : "host");
data->host,
guest ? "guest" : "host") < 0)
goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result); ret = cpuTestCompareXML(data->arch, cpu, result);
@ -663,17 +653,12 @@ cpuTestCompareSignature(const struct data *data,
signature = virCPUx86DataGetSignature(hostData, &family, &model, &stepping); signature = virCPUx86DataGetSignature(hostData, &family, &model, &stepping);
if (virAsprintf(&result, "%s/cputestdata/%s-cpuid-%s.sig", result = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.sig", abs_srcdir,
abs_srcdir, virArchToString(data->arch), data->host) < 0) virArchToString(data->arch), data->host);
return -1;
if (virAsprintf(&sigStr, sigStr = g_strdup_printf("%1$06lx\n" "family: %2$3u (0x%2$02x)\n"
"%1$06lx\n" "model: %3$3u (0x%3$02x)\n" "stepping: %4$3u (0x%4$02x)\n",
"family: %2$3u (0x%2$02x)\n" signature, family, model, stepping);
"model: %3$3u (0x%3$02x)\n"
"stepping: %4$3u (0x%4$02x)\n",
signature, family, model, stepping) < 0)
return -1;
return virTestCompareToFile(sigStr, result); return virTestCompareToFile(sigStr, result);
} }
@ -688,9 +673,8 @@ cpuTestCPUIDSignature(const void *arg)
char *host = NULL; char *host = NULL;
int ret = -1; int ret = -1;
if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
abs_srcdir, virArchToString(data->arch), data->host) < 0) virArchToString(data->arch), data->host);
goto cleanup;
if (virTestLoadFile(hostFile, &host) < 0 || if (virTestLoadFile(hostFile, &host) < 0 ||
!(hostData = virCPUDataParse(host))) !(hostData = virCPUDataParse(host)))
@ -813,24 +797,24 @@ cpuTestUpdateLive(const void *arg)
virDomainCapsCPUModelsPtr models = NULL; virDomainCapsCPUModelsPtr models = NULL;
int ret = -1; int ret = -1;
if (virAsprintf(&cpuFile, "cpuid-%s-guest", data->host) < 0 || cpuFile = g_strdup_printf("cpuid-%s-guest", data->host);
!(cpu = cpuTestLoadXML(data->arch, cpuFile))) if (!(cpu = cpuTestLoadXML(data->arch, cpuFile)))
goto cleanup; goto cleanup;
if (virAsprintf(&enabledFile, "%s/cputestdata/%s-cpuid-%s-enabled.xml", enabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-enabled.xml",
abs_srcdir, virArchToString(data->arch), data->host) < 0 || abs_srcdir, virArchToString(data->arch), data->host);
virTestLoadFile(enabledFile, &enabled) < 0 || if (virTestLoadFile(enabledFile, &enabled) < 0 ||
!(enabledData = virCPUDataParse(enabled))) !(enabledData = virCPUDataParse(enabled)))
goto cleanup; goto cleanup;
if (virAsprintf(&disabledFile, "%s/cputestdata/%s-cpuid-%s-disabled.xml", disabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-disabled.xml",
abs_srcdir, virArchToString(data->arch), data->host) < 0 || abs_srcdir, virArchToString(data->arch), data->host);
virTestLoadFile(disabledFile, &disabled) < 0 || if (virTestLoadFile(disabledFile, &disabled) < 0 ||
!(disabledData = virCPUDataParse(disabled))) !(disabledData = virCPUDataParse(disabled)))
goto cleanup; goto cleanup;
if (virAsprintf(&expectedFile, "cpuid-%s-json", data->host) < 0 || expectedFile = g_strdup_printf("cpuid-%s-json", data->host);
!(expected = cpuTestLoadXML(data->arch, expectedFile))) if (!(expected = cpuTestLoadXML(data->arch, expectedFile)))
goto cleanup; goto cleanup;
/* In case the host CPU signature does not exactly match any CPU model from /* 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; char *result = NULL;
int ret = -1; int ret = -1;
if (virAsprintf(&result, "cpuid-%s-json", data->host) < 0) result = g_strdup_printf("cpuid-%s-json", data->host);
goto cleanup;
if (!(qemuCaps = cpuTestMakeQEMUCaps(data))) if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
goto cleanup; goto cleanup;
@ -1024,11 +1007,8 @@ mymain(void)
tmp = virTestLogContentAndReset(); \ tmp = virTestLogContentAndReset(); \
VIR_FREE(tmp); \ VIR_FREE(tmp); \
\ \
if (virAsprintf(&testLabel, "%s(%s): %s", \ testLabel = g_strdup_printf("%s(%s): %s", #api, \
#api, virArchToString(arch), name) < 0) { \ virArchToString(arch), name); \
ret = -1; \
break; \
} \
\ \
if (virTestRun(testLabel, api, &data) < 0) { \ if (virTestRun(testLabel, api, &data) < 0) { \
if (virTestGetDebug()) { \ if (virTestGetDebug()) { \
@ -1068,12 +1048,9 @@ mymain(void)
suffix = " (expanded)"; \ suffix = " (expanded)"; \
if ((flags) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) \ if ((flags) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) \
suffix = " (migratable)"; \ suffix = " (migratable)"; \
if (virAsprintf(&label, "%s%s", name, suffix) < 0) { \ label = g_strdup_printf("%s%s", name, suffix); \
ret = -1; \ DO_TEST(arch, cpuTestBaseline, label, NULL, \
} else { \ "baseline-" name, NULL, flags, result); \
DO_TEST(arch, cpuTestBaseline, label, NULL, \
"baseline-" name, NULL, flags, result); \
} \
VIR_FREE(label); \ VIR_FREE(label); \
} while (0) } while (0)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -87,12 +87,9 @@ testSchemaDir(const char *schema,
if (ent->d_name[0] == '.') if (ent->d_name[0] == '.')
continue; continue;
if (virAsprintf(&xml_path, "%s/%s", dir_path, ent->d_name) < 0) xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name);
goto cleanup;
if (virAsprintf(&test_name, "Checking %s against %s", test_name = g_strdup_printf("Checking %s against %s", ent->d_name, schema);
ent->d_name, schema) < 0)
goto cleanup;
data.xml_path = xml_path; data.xml_path = xml_path;
if (virTestRun(test_name, testSchemaFile, &data) < 0) if (virTestRun(test_name, testSchemaFile, &data) < 0)
@ -105,7 +102,6 @@ testSchemaDir(const char *schema,
if (rc < 0) if (rc < 0)
ret = -1; ret = -1;
cleanup:
VIR_FREE(test_name); VIR_FREE(test_name);
VIR_FREE(xml_path); VIR_FREE(xml_path);
VIR_DIR_CLOSE(dir); VIR_DIR_CLOSE(dir);
@ -124,16 +120,12 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr validator, ...)
va_start(args, validator); va_start(args, validator);
while ((dir = va_arg(args, char *))) { while ((dir = va_arg(args, char *))) {
if (virAsprintf(&dir_path, "%s/%s", abs_srcdir, dir) < 0) { dir_path = g_strdup_printf("%s/%s", abs_srcdir, dir);
ret = -1;
goto cleanup;
}
if (testSchemaDir(schema, validator, dir_path) < 0) if (testSchemaDir(schema, validator, dir_path) < 0)
ret = -1; ret = -1;
VIR_FREE(dir_path); VIR_FREE(dir_path);
} }
cleanup:
VIR_FREE(dir_path); VIR_FREE(dir_path);
va_end(args); va_end(args);
return ret; return ret;
@ -147,9 +139,8 @@ testSchemaGrammar(const void *opaque)
char *schema_path; char *schema_path;
int ret = -1; int ret = -1;
if (virAsprintf(&schema_path, "%s/docs/schemas/%s", schema_path = g_strdup_printf("%s/docs/schemas/%s", abs_top_srcdir,
abs_top_srcdir, data->schema) < 0) data->schema);
return -1;
if (!(data->validator = virXMLValidatorInit(schema_path))) if (!(data->validator = virXMLValidatorInit(schema_path)))
goto cleanup; 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 *src_path = NULL;
char *dst_path = NULL; char *dst_path = NULL;
if (virAsprintf(&src_path, "%s/%s", virscsi_prefix, src_name) < 0) src_path = g_strdup_printf("%s/%s", virscsi_prefix, src_name);
goto cleanup;
if (virAsprintf(&dst_path, "%s/%s", tmpdir, dst_name) < 0) dst_path = g_strdup_printf("%s/%s", tmpdir, dst_name);
goto cleanup;
if (symlink(src_path, dst_path) < 0) { if (symlink(src_path, dst_path) < 0) {
VIR_WARN("Failed to create symlink '%s' to '%s'", src_path, dst_path); VIR_WARN("Failed to create symlink '%s' to '%s'", src_path, dst_path);
@ -194,10 +192,7 @@ mymain(void)
char *tmpdir = NULL; char *tmpdir = NULL;
char template[] = "/tmp/libvirt_XXXXXX"; char template[] = "/tmp/libvirt_XXXXXX";
if (virAsprintf(&virscsi_prefix, "%s" VIR_SCSI_DATA, abs_srcdir) < 0) { virscsi_prefix = g_strdup_printf("%s" VIR_SCSI_DATA, abs_srcdir);
ret = -1;
goto cleanup;
}
tmpdir = mkdtemp(template); tmpdir = mkdtemp(template);

View File

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

View File

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

View File

@ -109,9 +109,8 @@ checkPath(const char *path,
char *relPath = NULL; char *relPath = NULL;
char *crippledPath = NULL; char *crippledPath = NULL;
if (path[0] != '/' && if (path[0] != '/')
virAsprintfQuiet(&relPath, "./%s", path) < 0) relPath = g_strdup_printf("./%s", path);
goto error;
/* Le sigh. virFileCanonicalizePath() expects @path to exist, otherwise /* Le sigh. virFileCanonicalizePath() expects @path to exist, otherwise
* it will return an error. So if we are called over an non-existent * 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); VIR_FREE(fullPath);
return; 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; const char *p = NULL;
char *path = NULL; char *path = NULL;
if ((p = STRSKIP(real_path, USB_SYSFS)) && if ((p = STRSKIP(real_path, USB_SYSFS)))
virAsprintfQuiet(&path, "%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p) < 0) path = g_strdup_printf("%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p);
goto error;
else if (!p) else if (!p)
path = g_strdup(real_path); path = g_strdup(real_path);
return path; return path;
error:
errno = ENOMEM;
return NULL;
} }
DIR *opendir(const char *name) DIR *opendir(const char *name)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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