Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
tests/cputest.c | 42 ++++++++++++--------------------
tests/domaincapstest.c | 39 ++++++++++++-----------------
tests/domainconftest.c | 12 +++------
tests/fchosttest.c | 40 +++++++++++-------------------
tests/lxcconf2xmltest.c | 16 +++++-------
tests/metadatatest.c | 28 +++++++--------------
tests/openvzutilstest.c | 11 +++------
tests/scsihosttest.c | 22 +++++++----------
tests/securityselinuxlabeltest.c | 12 +++------
tests/vmwarevertest.c | 14 ++++-------
10 files changed, 84 insertions(+), 152 deletions(-)
diff --git a/tests/cputest.c b/tests/cputest.c
index 11305d56c5..0f0621292a 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -520,7 +520,6 @@ static int
cpuTestCPUID(bool guest, const void *arg)
{
const struct data *data = arg;
- int ret = -1;
g_autoptr(virCPUData) hostData = NULL;
g_autofree char *hostFile = NULL;
g_autofree char *host = NULL;
@@ -533,7 +532,7 @@ cpuTestCPUID(bool guest, const void *arg)
if (virTestLoadFile(hostFile, &host) < 0 ||
!(hostData = virCPUDataParse(host)))
- goto cleanup;
+ return -1;
cpu = virCPUDefNew();
cpu->arch = hostData->arch;
@@ -549,21 +548,16 @@ cpuTestCPUID(bool guest, const void *arg)
int rc;
rc = cpuTestGetCPUModels(data, &models);
- if (rc != 0) {
- ret = rc;
- goto cleanup;
- }
+ if (rc != 0)
+ return rc;
}
if (cpuDecode(cpu, hostData, models) < 0)
- goto cleanup;
+ return -1;
result = g_strdup_printf("cpuid-%s-%s", data->host, guest ?
"guest" : "host");
- ret = cpuTestCompareXML(data->arch, cpu, result);
-
- cleanup:
- return ret;
+ return cpuTestCompareXML(data->arch, cpu, result);
}
@@ -729,27 +723,26 @@ cpuTestUpdateLive(const void *arg)
g_autoptr(virCPUDef) expected = NULL;
g_autoptr(virDomainCapsCPUModels) hvModels = NULL;
g_autoptr(virDomainCapsCPUModels) models = NULL;
- int ret = -1;
cpuFile = g_strdup_printf("cpuid-%s-guest", data->host);
if (!(cpu = cpuTestLoadXML(data->arch, cpuFile)))
- goto cleanup;
+ return -1;
enabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-enabled.xml",
abs_srcdir, virArchToString(data->arch),
data->host);
if (virTestLoadFile(enabledFile, &enabled) < 0 ||
!(enabledData = virCPUDataParse(enabled)))
- goto cleanup;
+ return -1;
disabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-disabled.xml",
abs_srcdir, virArchToString(data->arch),
data->host);
if (virTestLoadFile(disabledFile, &disabled) < 0 ||
!(disabledData = virCPUDataParse(disabled)))
- goto cleanup;
+ return -1;
expectedFile = g_strdup_printf("cpuid-%s-json", data->host);
if (!(expected = cpuTestLoadXML(data->arch, expectedFile)))
- goto cleanup;
+ return -1;
/* In case the host CPU signature does not exactly match any CPU model in
* src/cpu_map, the CPU model we detect from CPUID may differ from the one
@@ -764,13 +757,11 @@ cpuTestUpdateLive(const void *arg)
int rc;
if (!(models = virDomainCapsCPUModelsNew(0)))
- goto cleanup;
+ return -1;
rc = cpuTestGetCPUModels(data, &hvModels);
- if (rc != 0) {
- ret = rc;
- goto cleanup;
- }
+ if (rc != 0)
+ return rc;
hvModel = virDomainCapsCPUModelsGet(hvModels, expected->model);
@@ -781,7 +772,7 @@ cpuTestUpdateLive(const void *arg)
if (virDomainCapsCPUModelsAdd(models, expected->model,
usable, blockers, false) < 0)
- goto cleanup;
+ return -1;
cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
ignore_value(virCPUTranslate(data->arch, cpu, models));
@@ -789,12 +780,9 @@ cpuTestUpdateLive(const void *arg)
}
if (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0)
- goto cleanup;
+ return -1;
- ret = cpuTestUpdateLiveCompare(data->arch, cpu, expected);
-
- cleanup:
- return ret;
+ return cpuTestUpdateLiveCompare(data->arch, cpu, expected);
}
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 463ff83890..9ea5bed5c2 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -73,18 +73,17 @@ fillQemuCaps(virDomainCaps *domCaps,
const char *machine,
virQEMUDriverConfig *cfg)
{
- int ret = -1;
g_autofree char *path = NULL;
g_autoptr(virQEMUCaps) qemuCaps = NULL;
virDomainCapsLoader *loader = &domCaps->os.loader;
virDomainVirtType virtType;
if (fakeHostCPU(domCaps->arch) < 0)
- goto cleanup;
+ return -1;
path = g_strdup_printf("%s/%s.%s.xml", TEST_QEMU_CAPS_PATH, name, arch);
if (!(qemuCaps = qemuTestParseCapabilitiesArch(domCaps->arch, path)))
- goto cleanup;
+ return -1;
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
virtType = VIR_DOMAIN_VIRT_KVM;
@@ -103,7 +102,7 @@ fillQemuCaps(virDomainCaps *domCaps,
false,
cfg->firmwares,
cfg->nfirmwares) < 0)
- goto cleanup;
+ return -1;
/* The function above tries to query host's VFIO capabilities by calling
* qemuHostdevHostSupportsPassthroughVFIO() which, however, can't be
@@ -123,11 +122,9 @@ fillQemuCaps(virDomainCaps *domCaps,
"/usr/share/AAVMF/AAVMF32_CODE.fd",
"/usr/share/OVMF/OVMF_CODE.fd",
NULL) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
#endif /* WITH_QEMU */
@@ -167,19 +164,16 @@ static int
fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps)
{
g_autofree virDomainCapsStringValues *firmwares = NULL;
- int ret = -1;
firmwares = g_new0(virDomainCapsStringValues, 1);
if (fillStringValues(firmwares, "/foo/bar", "/foo/baz", NULL)
< 0)
- goto cleanup;
+ return -1;
if (virBhyveDomainCapsFill(domCaps, *bhyve_caps, firmwares) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
#endif /* WITH_BHYVE */
@@ -208,14 +202,13 @@ test_virDomainCapsFormat(const void *opaque)
g_autoptr(virDomainCaps) domCaps = NULL;
g_autofree char *path = NULL;
g_autofree char *domCapsXML = NULL;
- int ret = -1;
path = g_strdup_printf("%s/domaincapsdata/%s.xml", abs_srcdir,
data->name);
if (!(domCaps = virDomainCapsNew(data->emulator, data->machine,
virArchFromString(data->arch),
data->type)))
- goto cleanup;
+ return -1;
switch (data->capsType) {
case CAPS_NONE:
@@ -225,33 +218,31 @@ test_virDomainCapsFormat(const void *opaque)
#if WITH_QEMU
if (fillQemuCaps(domCaps, data->capsName, data->arch, data->machine,
data->capsOpaque) < 0)
- goto cleanup;
+ return -1;
#endif
break;
case CAPS_LIBXL:
#if WITH_LIBXL
if (fillXenCaps(domCaps) < 0)
- goto cleanup;
+ return -1;
#endif
break;
case CAPS_BHYVE:
#if WITH_BHYVE
if (fillBhyveCaps(domCaps, data->capsOpaque) < 0)
- goto cleanup;
+ return -1;
#endif
break;
}
if (!(domCapsXML = virDomainCapsFormat(domCaps)))
- goto cleanup;
+ return -1;
if (virTestCompareToFile(domCapsXML, path) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
diff --git a/tests/domainconftest.c b/tests/domainconftest.c
index aaf58bcf93..71fd1f7b73 100644
--- a/tests/domainconftest.c
+++ b/tests/domainconftest.c
@@ -40,7 +40,6 @@ struct testGetFilesystemData {
static int testGetFilesystem(const void *opaque)
{
- int ret = -1;
g_autoptr(virDomainDef) def = NULL;
g_autofree char *filename = NULL;
const struct testGetFilesystemData *data = opaque;
@@ -50,7 +49,7 @@ static int testGetFilesystem(const void *opaque)
data->filename);
if (!(def = virDomainDefParseFile(filename, xmlopt, NULL, 0)))
- goto cleanup;
+ return -1;
fsdef = virDomainGetFilesystemForTarget(def,
data->path);
@@ -58,20 +57,17 @@ static int testGetFilesystem(const void *opaque)
if (data->expectEntry) {
fprintf(stderr, "Expected FS for path '%s' in
'%s'\n",
data->path, filename);
- goto cleanup;
+ return -1;
}
} else {
if (!data->expectEntry) {
fprintf(stderr, "Unexpected FS for path '%s' in
'%s'\n",
data->path, filename);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int
diff --git a/tests/fchosttest.c b/tests/fchosttest.c
index 707dd7e410..dc1503e9a7 100644
--- a/tests/fchosttest.c
+++ b/tests/fchosttest.c
@@ -123,7 +123,6 @@ test3(const void *data G_GNUC_UNUSED)
g_autofree char *fabric_wwn = NULL;
g_autofree char *max_vports = NULL;
g_autofree char *vports = NULL;
- int ret = -1;
if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
"node_name")))
@@ -131,31 +130,29 @@ test3(const void *data G_GNUC_UNUSED)
if (!(wwpn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
"port_name")))
- goto cleanup;
+ return -1;
if (!(fabric_wwn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
"fabric_name")))
- goto cleanup;
+ return -1;
if (!(max_vports = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
"max_npiv_vports")))
- goto cleanup;
+ return -1;
if (!(vports = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
"npiv_vports_inuse")))
- goto cleanup;
+ return -1;
if (STRNEQ(expect_wwnn, wwnn) ||
STRNEQ(expect_wwpn, wwpn) ||
STRNEQ(expect_fabric_wwn, fabric_wwn) ||
STRNEQ(expect_max_vports, max_vports) ||
STRNEQ(expect_vports, vports))
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
/* Test virVHBAGetHostByWWN */
@@ -164,7 +161,6 @@ test4(const void *data G_GNUC_UNUSED)
{
const char *expect_hostname = "host5";
g_autofree char *hostname = NULL;
- int ret = -1;
if (!(hostname = virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX,
"2001001b32a9da4e",
@@ -172,11 +168,9 @@ test4(const void *data G_GNUC_UNUSED)
return -1;
if (STRNEQ(hostname, expect_hostname))
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
/* Test virVHBAFindVportHost
@@ -188,17 +182,14 @@ test5(const void *data G_GNUC_UNUSED)
{
const char *expect_hostname = "host5";
g_autofree char *hostname = NULL;
- int ret = -1;
if (!(hostname = virVHBAFindVportHost(TEST_FC_HOST_PREFIX)))
return -1;
if (STRNEQ(hostname, expect_hostname))
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
/* Test virVHBAGetConfig fabric name optional */
@@ -210,7 +201,6 @@ test6(const void *data G_GNUC_UNUSED)
g_autofree char *wwnn = NULL;
g_autofree char *wwpn = NULL;
g_autofree char *fabric_wwn = NULL;
- int ret = -1;
if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
"node_name")))
@@ -218,20 +208,18 @@ test6(const void *data G_GNUC_UNUSED)
if (!(wwpn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
"port_name")))
- goto cleanup;
+ return -1;
if ((fabric_wwn = virVHBAGetConfig(TEST_FC_HOST_PREFIX,
TEST_FC_HOST_NUM_NO_FAB,
"fabric_name")))
- goto cleanup;
+ return -1;
if (STRNEQ(expect_wwnn, wwnn) ||
STRNEQ(expect_wwpn, wwpn))
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c
index be70671d68..09f6465567 100644
--- a/tests/lxcconf2xmltest.c
+++ b/tests/lxcconf2xmltest.c
@@ -25,33 +25,29 @@ testCompareXMLToConfigFiles(const char *xmlfile,
const char *configfile,
bool expectError)
{
- int ret = -1;
g_autofree char *config = NULL;
g_autofree char *actualxml = NULL;
g_autoptr(virDomainDef) vmdef = NULL;
if (virTestLoadFile(configfile, &config) < 0)
- goto fail;
+ return -1;
vmdef = lxcParseConfigString(config, driver->caps, driver->xmlopt);
if ((vmdef && expectError) || (!vmdef && !expectError))
- goto fail;
+ return -1;
if (vmdef) {
if (testSanitizeDef(vmdef) < 0)
- goto fail;
+ return -1;
if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, 0)))
- goto fail;
+ return -1;
if (virTestCompareToFile(actualxml, xmlfile) < 0)
- goto fail;
+ return -1;
}
- ret = 0;
-
- fail:
- return ret;
+ return 0;
}
struct testInfo {
diff --git a/tests/metadatatest.c b/tests/metadatatest.c
index 5112912161..b56428fde5 100644
--- a/tests/metadatatest.c
+++ b/tests/metadatatest.c
@@ -91,7 +91,6 @@ verifyMetadata(virDomainPtr dom,
const char *expectAPI,
const char *uri)
{
- bool ret = false;
g_autofree char *metadataXML = NULL;
g_autofree char *metadataAPI = NULL;
@@ -102,13 +101,13 @@ verifyMetadata(virDomainPtr dom,
virReportError(VIR_ERR_INTERNAL_ERROR,
"expected no metadata in API, but got:\n[%s]",
metadataAPI);
- goto cleanup;
+ return false;
}
} else {
if (!(metadataAPI = virDomainGetMetadata(dom,
VIR_DOMAIN_METADATA_ELEMENT,
uri, 0)))
- goto cleanup;
+ return false;
metadataXMLConvertApostrophe(metadataAPI);
@@ -117,7 +116,7 @@ verifyMetadata(virDomainPtr dom,
"XML metadata in API doesn't match expected metadata:
"
"expected:\n[%s]\ngot:\n[%s]",
expectAPI, metadataAPI);
- goto cleanup;
+ return false;
}
}
@@ -127,11 +126,11 @@ verifyMetadata(virDomainPtr dom,
virReportError(VIR_ERR_INTERNAL_ERROR,
"expected no metadata in XML, but got:\n[%s]",
metadataXML);
- goto cleanup;
+ return false;
}
} else {
if (!(metadataXML = getMetadataFromXML(dom)))
- goto cleanup;
+ return false;
metadataXMLConvertApostrophe(metadataXML);
@@ -140,15 +139,11 @@ verifyMetadata(virDomainPtr dom,
"XML in dump doesn't match expected metadata: "
"expected:\n[%s]\ngot:\n[%s]",
expectXML, metadataXML);
- goto cleanup;
+ return false;
}
}
- ret = true;
-
- cleanup:
-
- return ret;
+ return true;
}
@@ -213,7 +208,6 @@ testTextMetadata(const void *data)
{
const struct metadataTest *test = data;
g_autofree char *actual = NULL;
- int ret = -1;
if (virDomainSetMetadata(test->dom, test->type, test->data, NULL, NULL, 0)
< 0) {
if (test->fail)
@@ -228,14 +222,10 @@ testTextMetadata(const void *data)
"expected metadata doesn't match actual: "
"expected:'%s'\ngot: '%s'",
NULLSTR(test->data), NULLSTR(actual));
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
-
- return ret;
+ return 0;
}
#define TEST_TEXT_METADATA(INDEX, TYPE, DATA, EXPECT, FAIL) \
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index 3ebf38f104..7e6c0b60bb 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -36,7 +36,6 @@ static struct testConfigParam configParams[] = {
static int
testReadConfigParam(const void *data G_GNUC_UNUSED)
{
- int result = -1;
size_t i;
g_autofree char *conf = NULL;
g_autofree char *value = NULL;
@@ -46,7 +45,7 @@ testReadConfigParam(const void *data G_GNUC_UNUSED)
for (i = 0; i < G_N_ELEMENTS(configParams); ++i) {
if (openvzReadConfigParam(conf, configParams[i].param,
&value) != configParams[i].ret) {
- goto cleanup;
+ return -1;
}
if (configParams[i].ret != 1)
@@ -54,15 +53,11 @@ testReadConfigParam(const void *data G_GNUC_UNUSED)
if (STRNEQ(configParams[i].value, value)) {
virTestDifference(stderr, configParams[i].value, value);
- goto cleanup;
+ return -1;
}
}
- result = 0;
-
- cleanup:
-
- return result;
+ return 0;
}
static int
diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c
index aeb91da691..cb66a479e3 100644
--- a/tests/scsihosttest.c
+++ b/tests/scsihosttest.c
@@ -70,7 +70,6 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
g_autofree char *unique_id_path = NULL;
g_autofree char *link_path = NULL;
char *spot;
- int ret = -1;
VIR_AUTOCLOSE fd = -1;
unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id",
@@ -83,13 +82,13 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
*/
if (!(spot = strstr(unique_id_path, "unique_id"))) {
fprintf(stderr, "Did not find unique_id in path\n");
- goto cleanup;
+ return -1;
}
spot--;
*spot = '\0';
if (g_mkdir_with_parents(unique_id_path, 0755) < 0) {
fprintf(stderr, "Unable to make path to '%s'\n",
unique_id_path);
- goto cleanup;
+ return -1;
}
*spot = '/';
@@ -98,45 +97,42 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
*/
if (!(spot = strstr(link_path, hostname))) {
fprintf(stderr, "Did not find hostname in path\n");
- goto cleanup;
+ return -1;
}
spot--;
*spot = '\0';
if (g_mkdir_with_parents(link_path, 0755) < 0) {
fprintf(stderr, "Unable to make path to '%s'\n", link_path);
- goto cleanup;
+ return -1;
}
*spot = '/';
if ((fd = open(unique_id_path, O_CREAT|O_WRONLY, 0444)) < 0) {
fprintf(stderr, "Unable to create '%s'\n", unique_id_path);
- goto cleanup;
+ return -1;
}
if (safewrite(fd, unique_id, 1) != 1) {
fprintf(stderr, "Unable to write '%s'\n", unique_id);
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Created unique_id '%s'", unique_id_path);
/* The link is to the path not the file - so remove the file */
if (!(spot = strstr(unique_id_path, "unique_id"))) {
fprintf(stderr, "Did not find unique_id in path\n");
- goto cleanup;
+ return -1;
}
spot--;
*spot = '\0';
if (symlink(unique_id_path, link_path) < 0) {
fprintf(stderr, "Unable to create symlink '%s' to
'%s'\n",
link_path, unique_id_path);
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Created symlink '%s'", link_path);
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int
diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index 2e5941d7ef..87b2fc738a 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -99,7 +99,6 @@ testSELinuxLoadFileList(const char *testname,
testSELinuxFile **files,
size_t *nfiles)
{
- int ret = -1;
g_autofree char *path = NULL;
g_autoptr(FILE) fp = NULL;
g_autofree char *line = NULL;
@@ -111,7 +110,7 @@ testSELinuxLoadFileList(const char *testname,
testname);
if (!(fp = fopen(path, "r")))
- goto cleanup;
+ return -1;
line = g_new0(char, 1024);
@@ -119,7 +118,7 @@ testSELinuxLoadFileList(const char *testname,
char *file = NULL, *context = NULL, *tmp;
if (!fgets(line, 1024, fp)) {
if (!feof(fp))
- goto cleanup;
+ return -1;
break;
}
@@ -128,7 +127,7 @@ testSELinuxLoadFileList(const char *testname,
virReportError(VIR_ERR_INTERNAL_ERROR,
"unexpected format for line '%s'",
line);
- goto cleanup;
+ return -1;
}
*tmp = '\0';
tmp++;
@@ -148,10 +147,7 @@ testSELinuxLoadFileList(const char *testname,
(*files)[(*nfiles)-1].context = context;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
diff --git a/tests/vmwarevertest.c b/tests/vmwarevertest.c
index 7cb358795f..cdbd58fb4f 100644
--- a/tests/vmwarevertest.c
+++ b/tests/vmwarevertest.c
@@ -37,7 +37,6 @@ static int
testVerStrParse(const void *data)
{
const struct testInfo *info = data;
- int ret = -1;
g_autofree char *path = NULL;
g_autofree char *databuf = NULL;
unsigned long version;
@@ -46,24 +45,21 @@ testVerStrParse(const void *data)
path = g_strdup_printf("%s/vmwareverdata/%s.txt", abs_srcdir,
info->name);
if (virTestLoadFile(path, &databuf) < 0)
- goto cleanup;
+ return -1;
if ((vmware_type = vmwareDriverTypeFromString(info->vmware_type)) < 0)
- goto cleanup;
+ return -1;
if (vmwareParseVersionStr(vmware_type, databuf, &version) < 0)
- goto cleanup;
+ return -1;
if (version != info->version) {
fprintf(stderr, "%s: parsed versions do not match: got %lu, "
"expected %lu\n", info->name, version, info->version);
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int
--
2.31.1