mirror of https://gitee.com/openkylin/libvirt.git
tests: More usage of virGetLastErrorMessage()
Use virGetLastErrorMessage() instead of virGetLastError() in tests
This commit is contained in:
parent
ee7e99feb3
commit
c66150eca1
|
@ -178,8 +178,7 @@ static int test2(const void *unused ATTRIBUTE_UNUSED)
|
|||
int ret;
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -190,8 +189,7 @@ static int test2(const void *unused ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -218,8 +216,7 @@ static int test3(const void *unused ATTRIBUTE_UNUSED)
|
|||
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -260,8 +257,7 @@ static int test4(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandDaemonize(cmd);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -294,8 +290,7 @@ static int test5(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandAddEnvPassCommon(cmd);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -318,8 +313,7 @@ static int test6(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandAddEnvPassBlockSUID(cmd, "DOESNOTEXIST", NULL);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -343,8 +337,7 @@ static int test7(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandAddEnvPassBlockSUID(cmd, "DOESNOTEXIST", NULL);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -368,8 +361,7 @@ static int test8(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandAddEnvPair(cmd, "USER", "test");
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -406,8 +398,7 @@ static int test9(const void *unused ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -432,8 +423,7 @@ static int test10(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandAddArgSet(cmd, args);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -456,8 +446,7 @@ static int test11(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandPtr cmd = virCommandNewArgs(args);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -478,8 +467,7 @@ static int test12(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandSetInputBuffer(cmd, "Hello World\n");
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
virCommandFree(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -506,8 +494,7 @@ static int test13(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandSetOutputBuffer(cmd, &outactual);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if (!outactual)
|
||||
|
@ -559,8 +546,7 @@ static int test14(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandSetErrorBuffer(cmd, &erractual);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if (!outactual || !erractual)
|
||||
|
@ -573,8 +559,7 @@ static int test14(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandSetOutputBuffer(cmd, &jointactual);
|
||||
virCommandSetErrorBuffer(cmd, &jointactual);
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if (!jointactual)
|
||||
|
@ -620,8 +605,7 @@ static int test15(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandSetUmask(cmd, 002);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -651,8 +635,7 @@ static int test16(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandAddArg(cmd, "G H");
|
||||
|
||||
if ((outactual = virCommandToString(cmd)) == NULL) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot convert to string: %s\n", err->message);
|
||||
printf("Cannot convert to string: %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if ((fd = open(abs_builddir "/commandhelper.log",
|
||||
|
@ -697,8 +680,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -720,8 +702,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -756,8 +737,7 @@ static int test18(const void *unused ATTRIBUTE_UNUSED)
|
|||
|
||||
alarm(5);
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
alarm(0);
|
||||
|
@ -798,8 +778,7 @@ static int test19(const void *unused ATTRIBUTE_UNUSED)
|
|||
|
||||
alarm(5);
|
||||
if (virCommandRunAsync(cmd, &pid) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -848,8 +827,7 @@ static int test20(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandSetInputBuffer(cmd, buf);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -891,8 +869,7 @@ static int test21(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandDoAsyncIO(cmd);
|
||||
|
||||
if (virCommandRunAsync(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -930,8 +907,7 @@ test22(const void *unused ATTRIBUTE_UNUSED)
|
|||
cmd = virCommandNewArgList("/bin/sh", "-c", "exit 3", NULL);
|
||||
|
||||
if (virCommandRun(cmd, &status) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if (status != 3) {
|
||||
|
@ -941,8 +917,7 @@ test22(const void *unused ATTRIBUTE_UNUSED)
|
|||
|
||||
virCommandRawStatus(cmd);
|
||||
if (virCommandRun(cmd, &status) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 3) {
|
||||
|
@ -960,8 +935,7 @@ test22(const void *unused ATTRIBUTE_UNUSED)
|
|||
|
||||
virCommandRawStatus(cmd);
|
||||
if (virCommandRun(cmd, &status) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL) {
|
||||
|
@ -1057,8 +1031,7 @@ static int test24(const void *unused ATTRIBUTE_UNUSED)
|
|||
virCommandPassListenFDs(cmd);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
printf("Cannot run child %s\n", err->message);
|
||||
printf("Cannot run child %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ testCorrupt(const void *opaque)
|
|||
data->params,
|
||||
data->paramnum,
|
||||
&type);
|
||||
virErrorPtr err = NULL;
|
||||
const char *err = NULL;
|
||||
|
||||
if (!newdata)
|
||||
return -1;
|
||||
|
@ -115,15 +115,15 @@ testCorrupt(const void *opaque)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
err = virGetLastError();
|
||||
if (!err || !err->message) {
|
||||
err = virGetLastErrorMessage();
|
||||
if (!err) {
|
||||
VIR_DEBUG("No error or message %p", err);
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
#if !WITH_SASL
|
||||
if (strstr(err->message, "unsupported auth sasl")) {
|
||||
if (strstr(err, "unsupported auth sasl")) {
|
||||
VIR_DEBUG("sasl unsupported, skipping this config");
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -131,24 +131,24 @@ testCorrupt(const void *opaque)
|
|||
|
||||
switch (type) {
|
||||
case VIR_CONF_ULONG:
|
||||
if (!strstr(err->message, "invalid type: got string; expected unsigned long") &&
|
||||
!strstr(err->message, "invalid type: got string; expected long")) {
|
||||
if (!strstr(err, "invalid type: got string; expected unsigned long") &&
|
||||
!strstr(err, "invalid type: got string; expected long")) {
|
||||
VIR_DEBUG("Wrong error for long: '%s'",
|
||||
err->message);
|
||||
err);
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
case VIR_CONF_STRING:
|
||||
if (!strstr(err->message, "invalid type: got unsigned long; expected string")) {
|
||||
if (!strstr(err, "invalid type: got unsigned long; expected string")) {
|
||||
VIR_DEBUG("Wrong error for string: '%s'",
|
||||
err->message);
|
||||
err);
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
case VIR_CONF_LIST:
|
||||
if (!strstr(err->message, "must be a string or list of strings")) {
|
||||
if (!strstr(err, "must be a string or list of strings")) {
|
||||
VIR_DEBUG("Wrong error for list: '%s'",
|
||||
err->message);
|
||||
err);
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
|
@ -212,8 +212,8 @@ mymain(void)
|
|||
}
|
||||
|
||||
if (virFileReadAll(filename, 1024*1024, &filedata) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
fprintf(stderr, "Cannot load %s for testing: %s", filename, err->message);
|
||||
const char *err = virGetLastErrorMessage();
|
||||
fprintf(stderr, "Cannot load %s for testing: %s", filename, err);
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,6 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
|
|||
int result = -1;
|
||||
virDomainDefPtr def = NULL;
|
||||
char *actual = NULL;
|
||||
virErrorPtr err = NULL;
|
||||
const char *expected =
|
||||
"<domain type='openvz'>\n"
|
||||
" <uuid>00000000-0000-0000-0000-000000000000</uuid>\n"
|
||||
|
@ -110,16 +109,14 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
|
|||
def->os.type = VIR_DOMAIN_OSTYPE_EXE;
|
||||
|
||||
if (openvzReadNetworkConf(def, 1) < 0) {
|
||||
err = virGetLastError();
|
||||
fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
|
||||
fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
actual = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
|
||||
|
||||
if (actual == NULL) {
|
||||
err = virGetLastError();
|
||||
fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
|
||||
fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,8 @@ eventLoop(void *opaque ATTRIBUTE_UNUSED)
|
|||
{
|
||||
while (1) {
|
||||
if (virEventRunDefaultImpl() < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
fprintf(stderr, "Failed to run event loop: %s\n",
|
||||
err && err->message ? err->message : "Unknown error");
|
||||
virGetLastErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,9 +62,8 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (virEventRegisterDefaultImpl() < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
fprintf(stderr, "Failed to register event implementation: %s\n",
|
||||
err && err->message ? err->message: "Unknown error");
|
||||
virGetLastErrorMessage());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -230,8 +230,7 @@ testSELinuxGenLabel(const void *opaque)
|
|||
goto cleanup;
|
||||
|
||||
if (virSecurityManagerGenLabel(data->mgr, def) < 0) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
fprintf(stderr, "Cannot generate label: %s\n", err->message);
|
||||
fprintf(stderr, "Cannot generate label: %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -275,9 +274,8 @@ mymain(void)
|
|||
if (!(mgr = virSecurityManagerNew("selinux", "QEMU",
|
||||
VIR_SECURITY_MANAGER_DEFAULT_CONFINED |
|
||||
VIR_SECURITY_MANAGER_PRIVILEGED))) {
|
||||
virErrorPtr err = virGetLastError();
|
||||
fprintf(stderr, "Unable to initialize security driver: %s\n",
|
||||
err->message);
|
||||
virGetLastErrorMessage());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue