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

Adapt to VIR_ALLOC and virAsprintf in tests/*

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