提交 5f02df44 编写于 作者: J John Ferlan

tests: Use VIR_AUTOFREE for various storage tests

Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 ceb3255c
......@@ -57,32 +57,27 @@ test_node_info_parser(const void *opaque)
{
const struct testNodeInfoParserData *data = opaque;
collie_test test = data->data;
int ret = -1;
char *output = NULL;
VIR_AUTOFREE(char *) output = NULL;
VIR_AUTOPTR(virStoragePoolDef) pool = NULL;
if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
goto cleanup;
return -1;
if (VIR_STRDUP(output, test.output) < 0)
goto cleanup;
return -1;
if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
test.expected_return)
goto cleanup;
return -1;
if (test.expected_return) {
ret = 0;
goto cleanup;
}
if (test.expected_return)
return 0;
if (pool->capacity == test.expected_capacity &&
pool->allocation == test.expected_allocation)
ret = 0;
return 0;
cleanup:
VIR_FREE(output);
return ret;
return -1;
}
static int
......@@ -90,36 +85,31 @@ test_vdi_list_parser(const void *opaque)
{
const struct testVDIListParserData *data = opaque;
collie_test test = data->data;
int ret = -1;
char *output = NULL;
VIR_AUTOFREE(char *) output = NULL;
VIR_AUTOPTR(virStoragePoolDef) pool = NULL;
VIR_AUTOPTR(virStorageVolDef) vol = NULL;
if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
goto cleanup;
return -1;
if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0)))
goto cleanup;
return -1;
if (VIR_STRDUP(output, test.output) < 0)
goto cleanup;
return -1;
if (virStorageBackendSheepdogParseVdiList(vol, output) !=
test.expected_return)
goto cleanup;
return -1;
if (test.expected_return) {
ret = 0;
goto cleanup;
}
if (test.expected_return)
return 0;
if (vol->target.capacity == test.expected_capacity &&
vol->target.allocation == test.expected_allocation)
ret = 0;
return 0;
cleanup:
VIR_FREE(output);
return ret;
return -1;
}
......@@ -127,8 +117,8 @@ static int
mymain(void)
{
int ret = 0;
char *poolxml = NULL;
char *volxml = NULL;
VIR_AUTOFREE(char *) poolxml = NULL;
VIR_AUTOFREE(char *) volxml = NULL;
collie_test node_info_tests[] = {
{"", -1, 0, 0},
......@@ -215,8 +205,6 @@ mymain(void)
}
cleanup:
VIR_FREE(poolxml);
VIR_FREE(volxml);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
......@@ -83,7 +83,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
ret = 0;
cleanup:
VIR_FREE(actualCmdline);
virStoragePoolObjEndAPI(&pool);
if (shouldFail) {
virResetLastError();
......@@ -101,27 +100,20 @@ struct testInfo {
static int
testCompareXMLToArgvHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data;
char *poolxml = NULL;
char *cmdline = NULL;
VIR_AUTOFREE(char *) poolxml = NULL;
VIR_AUTOFREE(char *) cmdline = NULL;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool) < 0)
goto cleanup;
return -1;
if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s%s.argv",
abs_srcdir, info->pool, info->platformSuffix) < 0 &&
!info->shouldFail)
goto cleanup;
result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline);
cleanup:
VIR_FREE(poolxml);
VIR_FREE(cmdline);
return -1;
return result;
return testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline);
}
......
......@@ -18,47 +18,34 @@
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
char *actual = NULL;
int ret = -1;
VIR_AUTOFREE(char *) actual = NULL;
VIR_AUTOPTR(virStoragePoolDef) dev = NULL;
if (!(dev = virStoragePoolDefParseFile(inxml)))
goto fail;
return -1;
if (!(actual = virStoragePoolDefFormat(dev)))
goto fail;
return -1;
if (virTestCompareToFile(actual, outxml) < 0)
goto fail;
return -1;
ret = 0;
fail:
VIR_FREE(actual);
return ret;
return 0;
}
static int
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
char *inxml = NULL;
char *outxml = NULL;
VIR_AUTOFREE(char *) inxml = NULL;
VIR_AUTOFREE(char *) outxml = NULL;
if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, (const char*)data) < 0 ||
virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml",
abs_srcdir, (const char*)data) < 0) {
goto cleanup;
}
result = testCompareXMLToXMLFiles(inxml, outxml);
cleanup:
VIR_FREE(inxml);
VIR_FREE(outxml);
abs_srcdir, (const char*)data) < 0)
return -1;
return result;
return testCompareXMLToXMLFiles(inxml, outxml);
}
static int
......
......@@ -42,11 +42,11 @@ testCompareXMLToArgvFiles(bool shouldFail,
unsigned int flags,
unsigned long parse_flags)
{
char *actualCmdline = NULL;
virStorageVolEncryptConvertStep convertStep = VIR_STORAGE_VOL_ENCRYPT_NONE;
int ret = -1;
virStoragePoolDefPtr def = NULL;
virStoragePoolObjPtr obj = NULL;
VIR_AUTOFREE(char *) actualCmdline = NULL;
VIR_AUTOPTR(virStorageVolDef) vol = NULL;
VIR_AUTOPTR(virStorageVolDef) inputvol = NULL;
VIR_AUTOPTR(virStoragePoolDef) inputpool = NULL;
......@@ -108,7 +108,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
goto cleanup;
} else {
char *createCmdline = actualCmdline;
char *cvtCmdline;
VIR_AUTOFREE(char *) cvtCmdline = NULL;
int rc;
if (!(cvtCmdline = virCommandToString(cmd, false)))
......@@ -118,7 +118,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
createCmdline, cvtCmdline);
VIR_FREE(createCmdline);
VIR_FREE(cvtCmdline);
if (rc < 0)
goto cleanup;
}
......@@ -138,7 +137,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
ret = 0;
cleanup:
VIR_FREE(actualCmdline);
virStoragePoolObjEndAPI(&obj);
return ret;
}
......@@ -157,45 +155,35 @@ struct testInfo {
static int
testCompareXMLToArgvHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data;
char *poolxml = NULL;
char *inputpoolxml = NULL;
char *volxml = NULL;
char *inputvolxml = NULL;
char *cmdline = NULL;
VIR_AUTOFREE(char *) poolxml = NULL;
VIR_AUTOFREE(char *) inputpoolxml = NULL;
VIR_AUTOFREE(char *) volxml = NULL;
VIR_AUTOFREE(char *) inputvolxml = NULL;
VIR_AUTOFREE(char *) cmdline = NULL;
if (info->inputvol &&
virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->inputvol) < 0)
goto cleanup;
return -1;
if (info->inputpool &&
virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->inputpool) < 0)
goto cleanup;
return -1;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool) < 0 ||
virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->vol) < 0) {
goto cleanup;
return -1;
}
if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv",
abs_srcdir, info->cmdline) < 0 && !info->shouldFail)
goto cleanup;
result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
inputpoolxml, inputvolxml,
cmdline, info->flags,
info->parseflags);
cleanup:
VIR_FREE(poolxml);
VIR_FREE(volxml);
VIR_FREE(inputvolxml);
VIR_FREE(inputpoolxml);
VIR_FREE(cmdline);
return -1;
return result;
return testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
inputpoolxml, inputvolxml,
cmdline, info->flags,
info->parseflags);
}
......
......@@ -17,28 +17,23 @@ static int
testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
const char *outxml, unsigned int flags)
{
char *actual = NULL;
int ret = -1;
VIR_AUTOFREE(char *) actual = NULL;
VIR_AUTOPTR(virStoragePoolDef) pool = NULL;
VIR_AUTOPTR(virStorageVolDef) dev = NULL;
if (!(pool = virStoragePoolDefParseFile(poolxml)))
goto fail;
return -1;
if (!(dev = virStorageVolDefParseFile(pool, inxml, flags)))
goto fail;
return -1;
if (!(actual = virStorageVolDefFormat(pool, dev)))
goto fail;
return -1;
if (virTestCompareToFile(actual, outxml) < 0)
goto fail;
return -1;
ret = 0;
fail:
VIR_FREE(actual);
return ret;
return 0;
}
struct testInfo {
......@@ -50,29 +45,20 @@ struct testInfo {
static int
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data;
char *poolxml = NULL;
char *inxml = NULL;
char *outxml = NULL;
VIR_AUTOFREE(char *) poolxml = NULL;
VIR_AUTOFREE(char *) inxml = NULL;
VIR_AUTOFREE(char *) outxml = NULL;
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, info->pool) < 0 ||
virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, info->name) < 0 ||
virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml",
abs_srcdir, info->name) < 0) {
goto cleanup;
}
result = testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags);
cleanup:
VIR_FREE(poolxml);
VIR_FREE(inxml);
VIR_FREE(outxml);
abs_srcdir, info->name) < 0)
return -1;
return result;
return testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags);
}
......
......@@ -128,9 +128,9 @@ static int
testPrepImages(void)
{
int ret = EXIT_FAILURE;
char *buf = NULL;
bool compat = false;
VIR_AUTOPTR(virCommand) cmd = NULL;
VIR_AUTOFREE(char *) buf = NULL;
qemuimg = virFindFileInPath("qemu-img");
if (!qemuimg)
......@@ -245,7 +245,6 @@ testPrepImages(void)
ret = 0;
cleanup:
VIR_FREE(buf);
if (ret)
testCleanupImages();
return ret;
......@@ -313,7 +312,7 @@ testStorageChain(const void *args)
virStorageSourcePtr meta;
virStorageSourcePtr elt;
size_t i = 0;
char *broken = NULL;
VIR_AUTOFREE(char *) broken = NULL;
meta = testStorageFileGetMetadata(data->start, data->format, -1, -1);
if (!meta) {
......@@ -349,8 +348,8 @@ testStorageChain(const void *args)
elt = meta;
while (virStorageSourceIsBacking(elt)) {
char *expect = NULL;
char *actual = NULL;
VIR_AUTOFREE(char *) expect = NULL;
VIR_AUTOFREE(char *) actual = NULL;
if (i == data->nfiles) {
fprintf(stderr, "probed chain was too long\n");
......@@ -379,18 +378,12 @@ testStorageChain(const void *args)
elt->format,
virStorageNetProtocolTypeToString(elt->protocol),
NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)) < 0) {
VIR_FREE(expect);
VIR_FREE(actual);
goto cleanup;
}
if (STRNEQ(expect, actual)) {
virTestDifference(stderr, expect, actual);
VIR_FREE(expect);
VIR_FREE(actual);
goto cleanup;
}
VIR_FREE(expect);
VIR_FREE(actual);
elt = elt->backingStore;
i++;
}
......@@ -401,7 +394,6 @@ testStorageChain(const void *args)
ret = 0;
cleanup:
VIR_FREE(broken);
virStorageSourceFree(meta);
return ret;
}
......@@ -539,8 +531,7 @@ static int
testPathCanonicalize(const void *args)
{
const struct testPathCanonicalizeData *data = args;
char *canon = NULL;
int ret = -1;
VIR_AUTOFREE(char *) canon = NULL;
canon = virStorageFileCanonicalizePath(data->path,
testPathCanonicalizeReadlink,
......@@ -551,15 +542,10 @@ testPathCanonicalize(const void *args)
"path canonicalization of '%s' failed: expected '%s' got '%s'\n",
data->path, NULLSTR(data->expect), NULLSTR(canon));
goto cleanup;
return -1;
}
ret = 0;
cleanup:
VIR_FREE(canon);
return ret;
return 0;
}
static virStorageSource backingchain[12];
......@@ -629,14 +615,13 @@ static int
testPathRelative(const void *args)
{
const struct testPathRelativeBacking *data = args;
char *actual = NULL;
int ret = -1;
VIR_AUTOFREE(char *) actual = NULL;
if (virStorageFileGetRelativeBackingPath(data->top,
data->base,
&actual) < 0) {
fprintf(stderr, "relative backing path resolution failed\n");
goto cleanup;
return -1;
}
if (STRNEQ_NULLABLE(data->expect, actual)) {
......@@ -644,15 +629,10 @@ testPathRelative(const void *args)
"expected '%s', got '%s'\n",
data->top->path, data->base->path,
NULLSTR(data->expect), NULLSTR(actual));
goto cleanup;
return -1;
}
ret = 0;
cleanup:
VIR_FREE(actual);
return ret;
return 0;
}
......@@ -667,8 +647,8 @@ testBackingParse(const void *args)
const struct testBackingParseData *data = args;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virStorageSourcePtr src = NULL;
char *xml = NULL;
int ret = -1;
VIR_AUTOFREE(char *) xml = NULL;
if (!(src = virStorageSourceNewFromBackingAbsolute(data->backing))) {
if (!data->expect)
......@@ -702,7 +682,6 @@ testBackingParse(const void *args)
cleanup:
virStorageSourceFree(src);
virBufferFreeAndReset(&buf);
VIR_FREE(xml);
return ret;
}
......
......@@ -45,9 +45,9 @@ testGlusterExtractPoolSources(const void *opaque)
.sources = NULL
};
size_t i;
char *srcxmldata = NULL;
char *actual = NULL;
int ret = -1;
VIR_AUTOFREE(char *) srcxmldata = NULL;
VIR_AUTOFREE(char *) actual = NULL;
if (virTestLoadFile(data->srcxml, &srcxmldata) < 0)
goto cleanup;
......@@ -62,9 +62,6 @@ testGlusterExtractPoolSources(const void *opaque)
ret = virTestCompareToFile(actual, data->dstxml);
cleanup:
VIR_FREE(srcxmldata);
VIR_FREE(actual);
for (i = 0; i < list.nsources; i++)
virStoragePoolSourceClear(&list.sources[i]);
VIR_FREE(list.sources);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册