tests: vir: remove pointless labels

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Ján Tomko 2021-09-04 22:41:36 +02:00
parent cfef887893
commit 2ef57217f8
15 changed files with 108 additions and 216 deletions

View File

@ -153,10 +153,8 @@ test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED)
int ret = 0; int ret = 0;
g_autoptr(virCaps) caps = NULL; g_autoptr(virCaps) caps = NULL;
if (!(caps = testQemuCapsInit())) { if (!(caps = testQemuCapsInit()))
ret = -1; return -1;
goto out;
}
/* Checking each parameter individually */ /* Checking each parameter individually */
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL, CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
@ -195,7 +193,6 @@ test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED)
"/usr/bin/qemu-system-aarch64", "pc"); "/usr/bin/qemu-system-aarch64", "pc");
CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc"); CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc");
out:
return ret; return ret;
} }
#endif /* WITH_QEMU */ #endif /* WITH_QEMU */
@ -207,10 +204,8 @@ test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED)
int ret = 0; int ret = 0;
g_autoptr(virCaps) caps = NULL; g_autoptr(virCaps) caps = NULL;
if (!(caps = testLXCCapsInit())) { if (!(caps = testLXCCapsInit()))
ret = -1; return -1;
goto out;
}
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL, CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64, VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64,
@ -219,7 +214,6 @@ test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED)
VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64, VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64,
VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL); VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL);
out:
return ret; return ret;
} }
#endif /* WITH_LXC */ #endif /* WITH_LXC */

View File

@ -67,7 +67,6 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED)
"uint = 12345"; "uint = 12345";
g_autoptr(virConf) conf = virConfReadString(srcdata, 0); g_autoptr(virConf) conf = virConfReadString(srcdata, 0);
int ret = -1;
virConfValue *val; virConfValue *val;
unsigned long long llvalue; unsigned long long llvalue;
g_autofree char *str = NULL; g_autofree char *str = NULL;
@ -77,49 +76,47 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED)
return -1; return -1;
if (!(val = virConfGetValue(conf, "ullong"))) if (!(val = virConfGetValue(conf, "ullong")))
goto cleanup; return -1;
if (val->type != VIR_CONF_STRING) if (val->type != VIR_CONF_STRING)
goto cleanup; return -1;
if (virStrToLong_ull(val->str, NULL, 10, &llvalue) < 0) if (virStrToLong_ull(val->str, NULL, 10, &llvalue) < 0)
goto cleanup; return -1;
if (llvalue != 123456789) { if (llvalue != 123456789) {
fprintf(stderr, "Expected '123' got '%llu'\n", llvalue); fprintf(stderr, "Expected '123' got '%llu'\n", llvalue);
goto cleanup; return -1;
} }
if (virConfGetValueType(conf, "string") != if (virConfGetValueType(conf, "string") !=
VIR_CONF_STRING) { VIR_CONF_STRING) {
fprintf(stderr, "expected a string for 'string'\n"); fprintf(stderr, "expected a string for 'string'\n");
goto cleanup; return -1;
} }
if (virConfGetValueString(conf, "string", &str) < 0) if (virConfGetValueString(conf, "string", &str) < 0)
goto cleanup; return -1;
if (STRNEQ_NULLABLE(str, "foo")) { if (STRNEQ_NULLABLE(str, "foo")) {
fprintf(stderr, "Expected 'foo' got '%s'\n", str); fprintf(stderr, "Expected 'foo' got '%s'\n", str);
goto cleanup; return -1;
} }
if (virConfGetValueType(conf, "uint") != VIR_CONF_ULLONG) { if (virConfGetValueType(conf, "uint") != VIR_CONF_ULLONG) {
fprintf(stderr, "expected an unsigned long for 'uint'\n"); fprintf(stderr, "expected an unsigned long for 'uint'\n");
goto cleanup; return -1;
} }
if (virConfGetValueInt(conf, "uint", &uintvalue) < 0) if (virConfGetValueInt(conf, "uint", &uintvalue) < 0)
goto cleanup; return -1;
if (uintvalue != 12345) { if (uintvalue != 12345) {
fprintf(stderr, "Expected 12345 got %ud\n", uintvalue); fprintf(stderr, "Expected 12345 got %ud\n", uintvalue);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -338,7 +335,6 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED)
"int = 6963472309248\n" \ "int = 6963472309248\n" \
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1;
g_autoptr(virConf) conf = virConfReadString(srcdata, 0); g_autoptr(virConf) conf = virConfReadString(srcdata, 0);
g_autofree char *str = NULL; g_autofree char *str = NULL;
@ -348,25 +344,23 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED)
if (virConfGetValueType(conf, "string") != if (virConfGetValueType(conf, "string") !=
VIR_CONF_STRING) { VIR_CONF_STRING) {
fprintf(stderr, "expected a string for 'string'\n"); fprintf(stderr, "expected a string for 'string'\n");
goto cleanup; return -1;
} }
if (virConfGetValueString(conf, "string", &str) < 0) if (virConfGetValueString(conf, "string", &str) < 0)
goto cleanup; return -1;
if (STRNEQ_NULLABLE(str, "foo")) { if (STRNEQ_NULLABLE(str, "foo")) {
fprintf(stderr, "Expected 'foo' got '%s'\n", str); fprintf(stderr, "Expected 'foo' got '%s'\n", str);
goto cleanup; return -1;
} }
if (virConfGetValueString(conf, "int", &str) != -1) { if (virConfGetValueString(conf, "int", &str) != -1) {
fprintf(stderr, "Expected error for 'int'\n"); fprintf(stderr, "Expected error for 'int'\n");
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -38,22 +38,19 @@ testCryptoHash(const void *opaque)
{ {
const struct testCryptoHashData *data = opaque; const struct testCryptoHashData *data = opaque;
g_autofree char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1;
if (virCryptoHashString(data->hash, data->input, &actual) < 0) { if (virCryptoHashString(data->hash, data->input, &actual) < 0) {
fprintf(stderr, "Failed to generate crypto hash\n"); fprintf(stderr, "Failed to generate crypto hash\n");
goto cleanup; return -1;
} }
if (STRNEQ_NULLABLE(data->output, actual)) { if (STRNEQ_NULLABLE(data->output, actual)) {
fprintf(stderr, "Expected hash '%s' but got '%s'\n", fprintf(stderr, "Expected hash '%s' but got '%s'\n",
data->output, NULLSTR(actual)); data->output, NULLSTR(actual));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -75,7 +72,6 @@ testCryptoEncrypt(const void *opaque)
size_t ivlen = 16; size_t ivlen = 16;
g_autofree uint8_t *ciphertext = NULL; g_autofree uint8_t *ciphertext = NULL;
size_t ciphertextlen = 0; size_t ciphertextlen = 0;
int ret = -1;
if (!virCryptoHaveCipher(data->algorithm)) { if (!virCryptoHaveCipher(data->algorithm)) {
fprintf(stderr, "cipher algorithm=%d unavailable\n", data->algorithm); fprintf(stderr, "cipher algorithm=%d unavailable\n", data->algorithm);
@ -88,29 +84,26 @@ testCryptoEncrypt(const void *opaque)
if (virRandomBytes(enckey, enckeylen) < 0 || if (virRandomBytes(enckey, enckeylen) < 0 ||
virRandomBytes(iv, ivlen) < 0) { virRandomBytes(iv, ivlen) < 0) {
fprintf(stderr, "Failed to generate random bytes\n"); fprintf(stderr, "Failed to generate random bytes\n");
goto cleanup; return -1;
} }
if (virCryptoEncryptData(data->algorithm, enckey, enckeylen, iv, ivlen, if (virCryptoEncryptData(data->algorithm, enckey, enckeylen, iv, ivlen,
data->input, data->inputlen, data->input, data->inputlen,
&ciphertext, &ciphertextlen) < 0) &ciphertext, &ciphertextlen) < 0)
goto cleanup; return -1;
if (data->ciphertextlen != ciphertextlen) { if (data->ciphertextlen != ciphertextlen) {
fprintf(stderr, "Expected ciphertextlen(%zu) doesn't match (%zu)\n", fprintf(stderr, "Expected ciphertextlen(%zu) doesn't match (%zu)\n",
data->ciphertextlen, ciphertextlen); data->ciphertextlen, ciphertextlen);
goto cleanup; return -1;
} }
if (memcmp(data->ciphertext, ciphertext, ciphertextlen)) { if (memcmp(data->ciphertext, ciphertext, ciphertextlen)) {
fprintf(stderr, "Expected ciphertext doesn't match\n"); fprintf(stderr, "Expected ciphertext doesn't match\n");
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -103,7 +103,6 @@ static int
testFileSanitizePath(const void *opaque) testFileSanitizePath(const void *opaque)
{ {
const struct testFileSanitizePathData *data = opaque; const struct testFileSanitizePathData *data = opaque;
int ret = -1;
g_autofree char *actual = NULL; g_autofree char *actual = NULL;
if (!(actual = virFileSanitizePath(data->path))) if (!(actual = virFileSanitizePath(data->path)))
@ -111,13 +110,10 @@ testFileSanitizePath(const void *opaque)
if (STRNEQ(actual, data->expect)) { if (STRNEQ(actual, data->expect)) {
fprintf(stderr, "\nexpect: '%s'\nactual: '%s'\n", data->expect, actual); fprintf(stderr, "\nexpect: '%s'\nactual: '%s'\n", data->expect, actual);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -195,41 +191,38 @@ holesSupported(void)
off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1}; off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1};
off_t tmp; off_t tmp;
VIR_AUTOCLOSE fd = -1; VIR_AUTOCLOSE fd = -1;
bool ret = false;
if ((fd = makeSparseFile(offsets, true)) < 0) if ((fd = makeSparseFile(offsets, true)) < 0)
goto cleanup; return false;
/* The way this works is: there are 4K of data followed by 4K hole followed /* The way this works is: there are 4K of data followed by 4K hole followed
* by 4K hole again. Check if the filesystem we are running the test suite * by 4K hole again. Check if the filesystem we are running the test suite
* on supports holes. */ * on supports holes. */
if ((tmp = lseek(fd, 0, SEEK_DATA)) == (off_t) -1) if ((tmp = lseek(fd, 0, SEEK_DATA)) == (off_t) -1)
goto cleanup; return false;
if (tmp != 0) if (tmp != 0)
goto cleanup; return false;
if ((tmp = lseek(fd, tmp, SEEK_HOLE)) == (off_t) -1) if ((tmp = lseek(fd, tmp, SEEK_HOLE)) == (off_t) -1)
goto cleanup; return false;
if (tmp != EXTENT * 1024) if (tmp != EXTENT * 1024)
goto cleanup; return false;
if ((tmp = lseek(fd, tmp, SEEK_DATA)) == (off_t) -1) if ((tmp = lseek(fd, tmp, SEEK_DATA)) == (off_t) -1)
goto cleanup; return false;
if (tmp != 2 * EXTENT * 1024) if (tmp != 2 * EXTENT * 1024)
goto cleanup; return false;
if ((tmp = lseek(fd, tmp, SEEK_HOLE)) == (off_t) -1) if ((tmp = lseek(fd, tmp, SEEK_HOLE)) == (off_t) -1)
goto cleanup; return false;
if (tmp != 3 * EXTENT * 1024) if (tmp != 3 * EXTENT * 1024)
goto cleanup; return false;
ret = true; return true;
cleanup:
return ret;
} }
#else /* !WITH_DECL_SEEK_HOLE || !defined(__linux__)*/ #else /* !WITH_DECL_SEEK_HOLE || !defined(__linux__)*/
@ -261,11 +254,10 @@ testFileInData(const void *opaque)
{ {
const struct testFileInData *data = opaque; const struct testFileInData *data = opaque;
VIR_AUTOCLOSE fd = -1; VIR_AUTOCLOSE fd = -1;
int ret = -1;
size_t i; size_t i;
if ((fd = makeSparseFile(data->offsets, data->startData)) < 0) if ((fd = makeSparseFile(data->offsets, data->startData)) < 0)
goto cleanup; return -1;
for (i = 0; data->offsets[i] != (off_t) -1; i++) { for (i = 0; data->offsets[i] != (off_t) -1; i++) {
bool shouldInData = data->startData; bool shouldInData = data->startData;
@ -277,32 +269,29 @@ testFileInData(const void *opaque)
shouldInData = !shouldInData; shouldInData = !shouldInData;
if (virFileInData(fd, &realInData, &realLen) < 0) if (virFileInData(fd, &realInData, &realLen) < 0)
goto cleanup; return -1;
if (realInData != shouldInData) { if (realInData != shouldInData) {
fprintf(stderr, "Unexpected data/hole. Expected %s got %s\n", fprintf(stderr, "Unexpected data/hole. Expected %s got %s\n",
shouldInData ? "data" : "hole", shouldInData ? "data" : "hole",
realInData ? "data" : "hole"); realInData ? "data" : "hole");
goto cleanup; return -1;
} }
shouldLen = data->offsets[i] * 1024; shouldLen = data->offsets[i] * 1024;
if (realLen != shouldLen) { if (realLen != shouldLen) {
fprintf(stderr, "Unexpected section length. Expected %lld got %lld\n", fprintf(stderr, "Unexpected section length. Expected %lld got %lld\n",
shouldLen, realLen); shouldLen, realLen);
goto cleanup; return -1;
} }
if (lseek(fd, shouldLen, SEEK_CUR) < 0) { if (lseek(fd, shouldLen, SEEK_CUR) < 0) {
fprintf(stderr, "Unable to seek\n"); fprintf(stderr, "Unable to seek\n");
goto cleanup; return -1;
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -30,7 +30,6 @@ linuxTestCompareFiles(const char *cpuinfofile,
virArch arch, virArch arch,
const char *outputfile) const char *outputfile)
{ {
int ret = -1;
g_autofree char *actualData = NULL; g_autofree char *actualData = NULL;
virNodeInfo nodeinfo; virNodeInfo nodeinfo;
g_autoptr(FILE) cpuinfo = NULL; g_autoptr(FILE) cpuinfo = NULL;
@ -39,7 +38,7 @@ linuxTestCompareFiles(const char *cpuinfofile,
if (!cpuinfo) { if (!cpuinfo) {
fprintf(stderr, "unable to open: %s : %s\n", fprintf(stderr, "unable to open: %s : %s\n",
cpuinfofile, g_strerror(errno)); cpuinfofile, g_strerror(errno));
goto fail; return -1;
} }
memset(&nodeinfo, 0, sizeof(nodeinfo)); memset(&nodeinfo, 0, sizeof(nodeinfo));
@ -51,7 +50,7 @@ linuxTestCompareFiles(const char *cpuinfofile,
if (virGetLastErrorCode()) if (virGetLastErrorCode())
VIR_TEST_DEBUG("\n%s", virGetLastErrorMessage()); VIR_TEST_DEBUG("\n%s", virGetLastErrorMessage());
} }
goto fail; return -1;
} }
actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, "
@ -61,12 +60,9 @@ linuxTestCompareFiles(const char *cpuinfofile,
nodeinfo.cores, nodeinfo.threads); nodeinfo.cores, nodeinfo.threads);
if (virTestCompareToFile(actualData, outputfile) < 0) if (virTestCompareToFile(actualData, outputfile) < 0)
goto fail; return -1;
ret = 0; return 0;
fail:
return ret;
} }

View File

@ -211,7 +211,6 @@ testISCSIGetSession(const void *data)
const struct testSessionInfo *info = data; const struct testSessionInfo *info = data;
struct testIscsiadmCbData cbData = { 0 }; struct testIscsiadmCbData cbData = { 0 };
g_autofree char *actual_session = NULL; g_autofree char *actual_session = NULL;
int ret = -1;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
cbData.output_version = info->output_version; cbData.output_version = info->output_version;
@ -225,13 +224,10 @@ testISCSIGetSession(const void *data)
"Expected session: '%s' got: '%s'", "Expected session: '%s' got: '%s'",
NULLSTR(info->expected_session), NULLSTR(info->expected_session),
NULLSTR(actual_session)); NULLSTR(actual_session));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
struct testScanTargetsInfo { struct testScanTargetsInfo {
@ -295,17 +291,14 @@ testISCSIConnectionLogin(const void *data)
{ {
const struct testConnectionInfoLogin *info = data; const struct testConnectionInfoLogin *info = data;
struct testIscsiadmCbData cbData = { 0 }; struct testIscsiadmCbData cbData = { 0 };
int ret = -1;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
virCommandSetDryRun(dryRunToken, NULL, false, false, testIscsiadmCb, &cbData); virCommandSetDryRun(dryRunToken, NULL, false, false, testIscsiadmCb, &cbData);
if (virISCSIConnectionLogin(info->portal, info->initiatoriqn, info->target) < 0) if (virISCSIConnectionLogin(info->portal, info->initiatoriqn, info->target) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -34,30 +34,25 @@
static int static int
checkOutput(virBuffer *buf, const char *exp_cmd) checkOutput(virBuffer *buf, const char *exp_cmd)
{ {
int ret = -1;
g_autofree char *actual_cmd = NULL; g_autofree char *actual_cmd = NULL;
if (!(actual_cmd = virBufferContentAndReset(buf))) { if (!(actual_cmd = virBufferContentAndReset(buf))) {
fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd);
goto cleanup; return -1;
} }
if (STRNEQ(exp_cmd, actual_cmd)) { if (STRNEQ(exp_cmd, actual_cmd)) {
virTestDifference(stderr, exp_cmd, actual_cmd); virTestDifference(stderr, exp_cmd, actual_cmd);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testKModLoad(const void *args G_GNUC_UNUSED) testKModLoad(const void *args G_GNUC_UNUSED)
{ {
int ret = -1;
g_autofree char *errbuf = NULL; g_autofree char *errbuf = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
@ -67,23 +62,19 @@ testKModLoad(const void *args G_GNUC_UNUSED)
errbuf = virKModLoad(MODNAME); errbuf = virKModLoad(MODNAME);
if (errbuf) { if (errbuf) {
fprintf(stderr, "Failed to load, error: %s\n", errbuf); fprintf(stderr, "Failed to load, error: %s\n", errbuf);
goto cleanup; return -1;
} }
if (checkOutput(&buf, MODPROBE " -b " MODNAME "\n") < 0) if (checkOutput(&buf, MODPROBE " -b " MODNAME "\n") < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testKModUnload(const void *args G_GNUC_UNUSED) testKModUnload(const void *args G_GNUC_UNUSED)
{ {
int ret = -1;
g_autofree char *errbuf = NULL; g_autofree char *errbuf = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
@ -93,16 +84,13 @@ testKModUnload(const void *args G_GNUC_UNUSED)
errbuf = virKModUnload(MODNAME); errbuf = virKModUnload(MODNAME);
if (errbuf) { if (errbuf) {
fprintf(stderr, "Failed to unload, error: %s\n", errbuf); fprintf(stderr, "Failed to unload, error: %s\n", errbuf);
goto cleanup; return -1;
} }
if (checkOutput(&buf, RMMOD " " MODNAME "\n") < 0) if (checkOutput(&buf, RMMOD " " MODNAME "\n") < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -40,12 +40,11 @@ testMACLookup(const void *opaque)
GSList *next; GSList *next;
size_t i, j; size_t i, j;
g_autofree char *file = NULL; g_autofree char *file = NULL;
int ret = -1;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
if (!(mgr = virMacMapNew(file))) if (!(mgr = virMacMapNew(file)))
goto cleanup; return -1;
macs = virMacMapLookup(mgr, data->domain); macs = virMacMapLookup(mgr, data->domain);
@ -59,7 +58,7 @@ testMACLookup(const void *opaque)
fprintf(stderr, fprintf(stderr,
"Unexpected %s in the returned list of MACs\n", "Unexpected %s in the returned list of MACs\n",
(const char *) next->data); (const char *) next->data);
goto cleanup; return -1;
} }
} }
@ -72,13 +71,11 @@ testMACLookup(const void *opaque)
if (!next) { if (!next) {
fprintf(stderr, fprintf(stderr,
"Expected %s in the returned list of MACs\n", data->macs[i]); "Expected %s in the returned list of MACs\n", data->macs[i]);
goto cleanup; return -1;
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -90,18 +87,17 @@ testMACRemove(const void *opaque)
GSList *macs; GSList *macs;
size_t i; size_t i;
g_autofree char *file = NULL; g_autofree char *file = NULL;
int ret = -1;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
if (!(mgr = virMacMapNew(file))) if (!(mgr = virMacMapNew(file)))
goto cleanup; return -1;
for (i = 0; data->macs && data->macs[i]; i++) { for (i = 0; data->macs && data->macs[i]; i++) {
if (virMacMapRemove(mgr, data->domain, data->macs[i]) < 0) { if (virMacMapRemove(mgr, data->domain, data->macs[i]) < 0) {
fprintf(stderr, fprintf(stderr,
"Error when removing %s from the list of MACs\n", data->macs[i]); "Error when removing %s from the list of MACs\n", data->macs[i]);
goto cleanup; return -1;
} }
} }
@ -109,12 +105,10 @@ testMACRemove(const void *opaque)
fprintf(stderr, fprintf(stderr,
"Not removed all MACs for domain %s: %s\n", "Not removed all MACs for domain %s: %s\n",
data->domain, (const char *) macs->data); data->domain, (const char *) macs->data);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -124,19 +118,16 @@ testMACFlush(const void *opaque)
const struct testData *data = opaque; const struct testData *data = opaque;
g_autofree char *file = NULL; g_autofree char *file = NULL;
g_autofree char *str = NULL; g_autofree char *str = NULL;
int ret = -1;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
if (virMacMapDumpStr(data->mgr, &str) < 0) if (virMacMapDumpStr(data->mgr, &str) < 0)
goto cleanup; return -1;
if (virTestCompareToFile(str, file) < 0) if (virTestCompareToFile(str, file) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -37,21 +37,18 @@ static int
testCompareXMLToXMLFiles(const char *expected) testCompareXMLToXMLFiles(const char *expected)
{ {
g_autofree char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1;
g_autoptr(virNetworkPortDef) dev = NULL; g_autoptr(virNetworkPortDef) dev = NULL;
if (!(dev = virNetworkPortDefParseFile(expected))) if (!(dev = virNetworkPortDefParseFile(expected)))
goto cleanup; return -1;
if (!(actual = virNetworkPortDefFormat(dev))) if (!(actual = virNetworkPortDefFormat(dev)))
goto cleanup; return -1;
if (virTestCompareToFile(actual, expected) < 0) if (virTestCompareToFile(actual, expected) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }
struct testInfo { struct testInfo {
@ -62,14 +59,12 @@ static int
testCompareXMLToXMLHelper(const void *data) testCompareXMLToXMLHelper(const void *data)
{ {
const struct testInfo *info = data; const struct testInfo *info = data;
int ret = -1;
g_autofree char *xml = NULL; g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir, xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir,
info->name); info->name);
ret = testCompareXMLToXMLFiles(xml); return testCompareXMLToXMLFiles(xml);
return ret;
} }
static int static int

View File

@ -162,7 +162,6 @@ virNumaGetPages(int node,
int int
virNumaGetNodeCPUs(int node, virBitmap **cpus) virNumaGetNodeCPUs(int node, virBitmap **cpus)
{ {
int ret = -1;
g_autofree char *cpulist = NULL; g_autofree char *cpulist = NULL;
if (virFileReadValueString(&cpulist, if (virFileReadValueString(&cpulist,
@ -177,9 +176,7 @@ virNumaGetNodeCPUs(int node, virBitmap **cpus)
*cpus = virBitmapParseUnlimited(cpulist); *cpus = virBitmapParseUnlimited(cpulist);
} }
if (!*cpus) if (!*cpus)
goto cleanup; return -1;
ret = virBitmapCountBits(*cpus); return virBitmapCountBits(*cpus);
cleanup:
return ret;
} }

View File

@ -34,22 +34,19 @@ testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected)
{ {
g_autofree char *path = NULL; g_autofree char *path = NULL;
g_autofree char *driver = NULL; g_autofree char *driver = NULL;
int ret = -1;
if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0) if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0)
goto cleanup; return -1;
if (STRNEQ_NULLABLE(driver, expected)) { if (STRNEQ_NULLABLE(driver, expected)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"PCI device %s driver mismatch: %s, expecting %s", "PCI device %s driver mismatch: %s, expecting %s",
virPCIDeviceGetName(dev), NULLSTR(driver), virPCIDeviceGetName(dev), NULLSTR(driver),
NULLSTR(expected)); NULLSTR(expected));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int

View File

@ -20,7 +20,6 @@ test_virResctrlGetUnused(const void *opaque)
struct virResctrlData *data = (struct virResctrlData *) opaque; struct virResctrlData *data = (struct virResctrlData *) opaque;
g_autofree char *system_dir = NULL; g_autofree char *system_dir = NULL;
g_autofree char *resctrl_dir = NULL; g_autofree char *resctrl_dir = NULL;
int ret = -1;
g_autoptr(virResctrlAlloc) alloc = NULL; g_autoptr(virResctrlAlloc) alloc = NULL;
g_autofree char *schemata_str = NULL; g_autofree char *schemata_str = NULL;
g_autofree char *schemata_file = NULL; g_autofree char *schemata_file = NULL;
@ -41,7 +40,7 @@ test_virResctrlGetUnused(const void *opaque)
caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false); caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false);
if (!caps || virCapabilitiesInitCaches(caps) < 0) { if (!caps || virCapabilitiesInitCaches(caps) < 0) {
fprintf(stderr, "Could not initialize capabilities"); fprintf(stderr, "Could not initialize capabilities");
goto cleanup; return -1;
} }
alloc = virResctrlAllocGetUnused(caps->host.resctrl); alloc = virResctrlAllocGetUnused(caps->host.resctrl);
@ -50,22 +49,19 @@ test_virResctrlGetUnused(const void *opaque)
if (!alloc) { if (!alloc) {
if (data->fail) if (data->fail)
ret = 0; return 0;
goto cleanup; return -1;
} else if (data->fail) { } else if (data->fail) {
VIR_TEST_DEBUG("Error expected but there wasn't any."); VIR_TEST_DEBUG("Error expected but there wasn't any.");
ret = -1; return -1;
goto cleanup;
} }
schemata_str = virResctrlAllocFormat(alloc); schemata_str = virResctrlAllocFormat(alloc);
if (virTestCompareToFile(schemata_str, schemata_file) < 0) if (virTestCompareToFile(schemata_str, schemata_file) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -37,18 +37,15 @@ static int
test1(const void *data G_GNUC_UNUSED) test1(const void *data G_GNUC_UNUSED)
{ {
g_autofree char *name = NULL; g_autofree char *name = NULL;
int ret = -1;
if (!(name = virSCSIDeviceGetDevName(virscsi_prefix, if (!(name = virSCSIDeviceGetDevName(virscsi_prefix,
"scsi_host1", 0, 0, 0))) "scsi_host1", 0, 0, 0)))
return -1; return -1;
if (STRNEQ(name, "sdh")) if (STRNEQ(name, "sdh"))
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }
/* /*
@ -161,7 +158,6 @@ test2(const void *data G_GNUC_UNUSED)
static int static int
create_symlink(const char *tmpdir, const char *src_name, const char *dst_name) create_symlink(const char *tmpdir, const char *src_name, const char *dst_name)
{ {
int ret = -1;
g_autofree char *src_path = NULL; g_autofree char *src_path = NULL;
g_autofree char *dst_path = NULL; g_autofree char *dst_path = NULL;
@ -171,13 +167,10 @@ create_symlink(const char *tmpdir, const char *src_name, const char *dst_name)
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);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int

View File

@ -223,7 +223,6 @@ testStringReplace(const void *opaque G_GNUC_UNUSED)
{ {
const struct stringReplaceData *data = opaque; const struct stringReplaceData *data = opaque;
g_autofree char *result = NULL; g_autofree char *result = NULL;
int ret = -1;
result = virStringReplace(data->haystack, result = virStringReplace(data->haystack,
data->oldneedle, data->oldneedle,
@ -232,13 +231,10 @@ testStringReplace(const void *opaque G_GNUC_UNUSED)
if (STRNEQ_NULLABLE(data->result, result)) { if (STRNEQ_NULLABLE(data->result, result)) {
fprintf(stderr, "Expected '%s' but got '%s'\n", fprintf(stderr, "Expected '%s' but got '%s'\n",
data->result, NULLSTR(result)); data->result, NULLSTR(result));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -400,7 +396,6 @@ struct testStripData {
static int testStripIPv6Brackets(const void *args) static int testStripIPv6Brackets(const void *args)
{ {
const struct testStripData *data = args; const struct testStripData *data = args;
int ret = -1;
g_autofree char *res = NULL; g_autofree char *res = NULL;
res = g_strdup(data->string); res = g_strdup(data->string);
@ -410,19 +405,15 @@ static int testStripIPv6Brackets(const void *args)
if (STRNEQ_NULLABLE(res, data->result)) { if (STRNEQ_NULLABLE(res, data->result)) {
fprintf(stderr, "Returned '%s', expected '%s'\n", fprintf(stderr, "Returned '%s', expected '%s'\n",
NULLSTR(res), NULLSTR(data->result)); NULLSTR(res), NULLSTR(data->result));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int testStripControlChars(const void *args) static int testStripControlChars(const void *args)
{ {
const struct testStripData *data = args; const struct testStripData *data = args;
int ret = -1;
g_autofree char *res = NULL; g_autofree char *res = NULL;
res = g_strdup(data->string); res = g_strdup(data->string);
@ -432,13 +423,10 @@ static int testStripControlChars(const void *args)
if (STRNEQ_NULLABLE(res, data->result)) { if (STRNEQ_NULLABLE(res, data->result)) {
fprintf(stderr, "Returned '%s', expected '%s'\n", fprintf(stderr, "Returned '%s', expected '%s'\n",
NULLSTR(res), NULLSTR(data->result)); NULLSTR(res), NULLSTR(data->result));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
struct testFilterData { struct testFilterData {
@ -450,7 +438,6 @@ struct testFilterData {
static int testFilterChars(const void *args) static int testFilterChars(const void *args)
{ {
const struct testFilterData *data = args; const struct testFilterData *data = args;
int ret = -1;
g_autofree char *res = NULL; g_autofree char *res = NULL;
res = g_strdup(data->string); res = g_strdup(data->string);
@ -460,13 +447,10 @@ static int testFilterChars(const void *args)
if (STRNEQ_NULLABLE(res, data->result)) { if (STRNEQ_NULLABLE(res, data->result)) {
fprintf(stderr, "Returned '%s', expected '%s'\n", fprintf(stderr, "Returned '%s', expected '%s'\n",
NULLSTR(res), NULLSTR(data->result)); NULLSTR(res), NULLSTR(data->result));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int

View File

@ -369,45 +369,37 @@ static int
testScopeName(const void *opaque) testScopeName(const void *opaque)
{ {
const struct testNameData *data = opaque; const struct testNameData *data = opaque;
int ret = -1;
g_autofree char *actual = NULL; g_autofree char *actual = NULL;
if (!(actual = virSystemdMakeScopeName(data->name, "lxc", data->legacy))) if (!(actual = virSystemdMakeScopeName(data->name, "lxc", data->legacy)))
goto cleanup; return -1;
if (STRNEQ(actual, data->expected)) { if (STRNEQ(actual, data->expected)) {
fprintf(stderr, "Expected '%s' but got '%s'\n", fprintf(stderr, "Expected '%s' but got '%s'\n",
data->expected, actual); data->expected, actual);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int
testMachineName(const void *opaque) testMachineName(const void *opaque)
{ {
const struct testNameData *data = opaque; const struct testNameData *data = opaque;
int ret = -1;
g_autofree char *actual = NULL; g_autofree char *actual = NULL;
if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root, if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root,
data->id, data->name, true))) data->id, data->name, true)))
goto cleanup; return -1;
if (STRNEQ(actual, data->expected)) { if (STRNEQ(actual, data->expected)) {
fprintf(stderr, "Expected '%s' but got '%s'\n", fprintf(stderr, "Expected '%s' but got '%s'\n",
data->expected, actual); data->expected, actual);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
typedef int (*virSystemdCanHelper)(bool * result); typedef int (*virSystemdCanHelper)(bool * result);