提交 3ea84b95 编写于 作者: M Michal Privoznik

Adapt to VIR_ALLOC and virAsprintf in tests/*

上级 36844c91
...@@ -77,7 +77,7 @@ int main(int argc, char **argv) { ...@@ -77,7 +77,7 @@ int main(int argc, char **argv) {
origenv++; origenv++;
} }
if (VIR_ALLOC_N(newenv, n) < 0) if (VIR_ALLOC_N_QUIET(newenv, n) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
origenv = environ; origenv = environ;
......
...@@ -820,10 +820,8 @@ static int test20(const void *unused ATTRIBUTE_UNUSED) ...@@ -820,10 +820,8 @@ static int test20(const void *unused ATTRIBUTE_UNUSED)
sigaction(SIGPIPE, &sig_action, NULL); sigaction(SIGPIPE, &sig_action, NULL);
if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0) { if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
virCommandSetInputBuffer(cmd, buf); virCommandSetInputBuffer(cmd, buf);
if (virCommandRun(cmd, NULL) < 0) { if (virCommandRun(cmd, NULL) < 0) {
...@@ -996,10 +994,8 @@ mymain(void) ...@@ -996,10 +994,8 @@ mymain(void)
return EXIT_FAILURE; return EXIT_FAILURE;
virEventRegisterDefaultImpl(); virEventRegisterDefaultImpl();
if (VIR_ALLOC(test) < 0) { if (VIR_ALLOC(test) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virMutexInit(&test->lock) < 0) { if (virMutexInit(&test->lock) < 0) {
printf("Unable to init mutex: %d\n", errno); printf("Unable to init mutex: %d\n", errno);
......
...@@ -78,10 +78,8 @@ munge_param(const char *datain, ...@@ -78,10 +78,8 @@ munge_param(const char *datain,
strlen(replace) + strlen(replace) +
strlen(eol) + 1; strlen(eol) + 1;
if (VIR_ALLOC_N(dataout, dataoutlen) < 0) { if (VIR_ALLOC_N(dataout, dataoutlen) < 0)
virReportOOMError();
return NULL; return NULL;
}
memcpy(dataout, datain, (eq - datain) + 1); memcpy(dataout, datain, (eq - datain) + 1);
memcpy(dataout + (eq - datain) + 1, memcpy(dataout + (eq - datain) + 1,
replace, strlen(replace)); replace, strlen(replace));
......
...@@ -87,10 +87,8 @@ static int qemuMonitorTestAddReponse(qemuMonitorTestPtr test, ...@@ -87,10 +87,8 @@ static int qemuMonitorTestAddReponse(qemuMonitorTestPtr test,
if (have < want) { if (have < want) {
size_t need = want - have; size_t need = want - have;
if (VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need) < 0) { if (VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need) < 0)
virReportOOMError();
return -1; return -1;
}
} }
want -= 2; want -= 2;
...@@ -403,7 +401,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, ...@@ -403,7 +401,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
qemuMonitorTestItemPtr item; qemuMonitorTestItemPtr item;
if (VIR_ALLOC(item) < 0) if (VIR_ALLOC(item) < 0)
goto no_memory; goto error;
if (VIR_STRDUP(item->command_name, command_name) < 0 || if (VIR_STRDUP(item->command_name, command_name) < 0 ||
VIR_STRDUP(item->response, response) < 0) VIR_STRDUP(item->response, response) < 0)
...@@ -412,7 +410,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, ...@@ -412,7 +410,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
virMutexLock(&test->lock); virMutexLock(&test->lock);
if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) { if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) {
virMutexUnlock(&test->lock); virMutexUnlock(&test->lock);
goto no_memory; goto error;
} }
test->items[test->nitems - 1] = item; test->items[test->nitems - 1] = item;
...@@ -420,8 +418,6 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, ...@@ -420,8 +418,6 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
qemuMonitorTestItemFree(item); qemuMonitorTestItemFree(item);
return -1; return -1;
...@@ -457,7 +453,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) ...@@ -457,7 +453,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
char *tmpdir_template = NULL; char *tmpdir_template = NULL;
if (VIR_ALLOC(test) < 0) if (VIR_ALLOC(test) < 0)
goto no_memory; goto error;
if (virMutexInit(&test->lock) < 0) { if (virMutexInit(&test->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
...@@ -478,7 +474,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) ...@@ -478,7 +474,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
tmpdir_template = NULL; tmpdir_template = NULL;
if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0) if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
goto no_memory; goto error;
test->json = json; test->json = json;
if (!(test->vm = virDomainObjNew(xmlopt))) if (!(test->vm = virDomainObjNew(xmlopt)))
...@@ -538,9 +534,6 @@ cleanup: ...@@ -538,9 +534,6 @@ cleanup:
VIR_FREE(path); VIR_FREE(path);
return test; return test;
no_memory:
virReportOOMError();
error: error:
VIR_FREE(tmpdir_template); VIR_FREE(tmpdir_template);
qemuMonitorTestFree(test); qemuMonitorTestFree(test);
......
...@@ -61,10 +61,8 @@ testSELinuxMungePath(char **path) ...@@ -61,10 +61,8 @@ testSELinuxMungePath(char **path)
char *tmp; char *tmp;
if (virAsprintf(&tmp, "%s/securityselinuxlabeldata%s", if (virAsprintf(&tmp, "%s/securityselinuxlabeldata%s",
abs_builddir, *path) < 0) { abs_builddir, *path) < 0)
virReportOOMError();
return -1; return -1;
}
VIR_FREE(*path); VIR_FREE(*path);
*path = tmp; *path = tmp;
...@@ -85,19 +83,15 @@ testSELinuxLoadFileList(const char *testname, ...@@ -85,19 +83,15 @@ testSELinuxLoadFileList(const char *testname,
*nfiles = 0; *nfiles = 0;
if (virAsprintf(&path, "%s/securityselinuxlabeldata/%s.txt", if (virAsprintf(&path, "%s/securityselinuxlabeldata/%s.txt",
abs_srcdir, testname) < 0) { abs_srcdir, testname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (!(fp = fopen(path, "r"))) { if (!(fp = fopen(path, "r"))) {
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(line, 1024) < 0) { if (VIR_ALLOC_N(line, 1024) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
while (!feof(fp)) { while (!feof(fp)) {
char *file, *context, *tmp; char *file, *context, *tmp;
...@@ -118,10 +112,8 @@ testSELinuxLoadFileList(const char *testname, ...@@ -118,10 +112,8 @@ testSELinuxLoadFileList(const char *testname,
tmp++; tmp++;
if (virAsprintf(&file, "%s/securityselinuxlabeldata%s", if (virAsprintf(&file, "%s/securityselinuxlabeldata%s",
abs_builddir, line) < 0) { abs_builddir, line) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (*tmp != '\0' && *tmp != '\n') { if (*tmp != '\0' && *tmp != '\n') {
if (VIR_STRDUP(context, tmp) < 0) { if (VIR_STRDUP(context, tmp) < 0) {
VIR_FREE(file); VIR_FREE(file);
...@@ -135,10 +127,8 @@ testSELinuxLoadFileList(const char *testname, ...@@ -135,10 +127,8 @@ testSELinuxLoadFileList(const char *testname,
context = NULL; context = NULL;
} }
if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) { if (VIR_EXPAND_N(*files, *nfiles, 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
(*files)[(*nfiles)-1].file = file; (*files)[(*nfiles)-1].file = file;
(*files)[(*nfiles)-1].context = context; (*files)[(*nfiles)-1].context = context;
...@@ -163,10 +153,8 @@ testSELinuxLoadDef(const char *testname) ...@@ -163,10 +153,8 @@ testSELinuxLoadDef(const char *testname)
size_t i; size_t i;
if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml", if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml",
abs_srcdir, testname) < 0) { abs_srcdir, testname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virFileReadAll(xmlfile, 1024*1024, &xmlstr) < 0) { if (virFileReadAll(xmlfile, 1024*1024, &xmlstr) < 0) {
goto cleanup; goto cleanup;
......
...@@ -69,13 +69,13 @@ testBuildDomainDef(bool dynamic, ...@@ -69,13 +69,13 @@ testBuildDomainDef(bool dynamic,
virSecurityLabelDefPtr secdef; virSecurityLabelDefPtr secdef;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto no_memory; goto error;
if (VIR_ALLOC_N(def->seclabels, 1) < 0) if (VIR_ALLOC_N(def->seclabels, 1) < 0)
goto no_memory; goto error;
if (VIR_ALLOC(secdef) < 0) if (VIR_ALLOC(secdef) < 0)
goto no_memory; goto error;
def->virtType = VIR_DOMAIN_VIRT_KVM; def->virtType = VIR_DOMAIN_VIRT_KVM;
def->seclabels[0] = secdef; def->seclabels[0] = secdef;
...@@ -91,8 +91,6 @@ testBuildDomainDef(bool dynamic, ...@@ -91,8 +91,6 @@ testBuildDomainDef(bool dynamic,
return def; return def;
no_memory:
virReportOOMError();
error: error:
virDomainDefFree(def); virDomainDefFree(def);
return NULL; return NULL;
......
...@@ -103,7 +103,7 @@ void virtTestResult(const char *name, int ret, const char *msg, ...) ...@@ -103,7 +103,7 @@ void virtTestResult(const char *name, int ret, const char *msg, ...)
fprintf(stderr, "FAILED\n"); fprintf(stderr, "FAILED\n");
if (msg) { if (msg) {
char *str; char *str;
if (virVasprintf(&str, msg, vargs) == 0) { if (virVasprintfQuiet(&str, msg, vargs) == 0) {
fprintf(stderr, "%s", str); fprintf(stderr, "%s", str);
VIR_FREE(str); VIR_FREE(str);
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#define testError(...) \ #define testError(...) \
do { \ do { \
char *str; \ char *str; \
if (virAsprintf(&str, __VA_ARGS__) == 0) { \ if (virAsprintfQuiet(&str, __VA_ARGS__) == 0) { \
fprintf(stderr, "%s", str); \ fprintf(stderr, "%s", str); \
VIR_FREE(str); \ VIR_FREE(str); \
} \ } \
......
...@@ -49,10 +49,8 @@ static int testMessageHeaderEncode(const void *args ATTRIBUTE_UNUSED) ...@@ -49,10 +49,8 @@ static int testMessageHeaderEncode(const void *args ATTRIBUTE_UNUSED)
unsigned long msg_buf_size = VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX; unsigned long msg_buf_size = VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX;
int ret = -1; int ret = -1;
if (!msg) { if (!msg)
virReportOOMError();
return -1; return -1;
}
msg->header.prog = 0x11223344; msg->header.prog = 0x11223344;
msg->header.vers = 0x01; msg->header.vers = 0x01;
...@@ -101,16 +99,12 @@ static int testMessageHeaderDecode(const void *args ATTRIBUTE_UNUSED) ...@@ -101,16 +99,12 @@ static int testMessageHeaderDecode(const void *args ATTRIBUTE_UNUSED)
}; };
int ret = -1; int ret = -1;
if (!msg) { if (!msg)
virReportOOMError();
return -1; return -1;
}
msg->bufferLength = 4; msg->bufferLength = 4;
if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
memcpy(msg->buffer, input_buf, msg->bufferLength); memcpy(msg->buffer, input_buf, msg->bufferLength);
msg->header.prog = 0x11223344; msg->header.prog = 0x11223344;
...@@ -225,10 +219,8 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED) ...@@ -225,10 +219,8 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED)
0x00, 0x00, 0x00, 0x00, /* Error network pointer */ 0x00, 0x00, 0x00, 0x00, /* Error network pointer */
}; };
if (!msg) { if (!msg)
virReportOOMError();
return -1; return -1;
}
memset(&err, 0, sizeof(err)); memset(&err, 0, sizeof(err));
...@@ -336,10 +328,8 @@ static int testMessagePayloadDecode(const void *args ATTRIBUTE_UNUSED) ...@@ -336,10 +328,8 @@ static int testMessagePayloadDecode(const void *args ATTRIBUTE_UNUSED)
int ret = -1; int ret = -1;
msg->bufferLength = 4; msg->bufferLength = 4;
if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
memcpy(msg->buffer, input_buffer, msg->bufferLength); memcpy(msg->buffer, input_buffer, msg->bufferLength);
memset(&err, 0, sizeof(err)); memset(&err, 0, sizeof(err));
......
...@@ -98,10 +98,8 @@ testPrepImages(void) ...@@ -98,10 +98,8 @@ testPrepImages(void)
virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 || virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 ||
virAsprintf(&abswrap, "%s/wrap", datadir) < 0 || virAsprintf(&abswrap, "%s/wrap", datadir) < 0 ||
virAsprintf(&absqed, "%s/qed", datadir) < 0 || virAsprintf(&absqed, "%s/qed", datadir) < 0 ||
virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0) { virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0)
virReportOOMError();
goto cleanup; 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");
...@@ -271,7 +269,6 @@ testStorageChain(const void *args) ...@@ -271,7 +269,6 @@ testStorageChain(const void *args)
NULLSTR(elt->directory), NULLSTR(elt->directory),
elt->backingStoreFormat, elt->backingStoreIsFile, elt->backingStoreFormat, elt->backingStoreIsFile,
elt->capacity, elt->encrypted) < 0) { elt->capacity, elt->encrypted) < 0) {
virReportOOMError();
VIR_FREE(expect); VIR_FREE(expect);
VIR_FREE(actual); VIR_FREE(actual);
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册