tests: remove text monitor testing infrastructure

We removed testing for text monitor some time ago, remove
the remains from the test infrastructure.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Ján Tomko 2019-06-15 12:09:41 +02:00
parent fba29dff83
commit 6d11c756f2

View File

@ -126,40 +126,33 @@ qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test,
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
VIR_AUTOFREE(char *) escapemsg = NULL; VIR_AUTOFREE(char *) escapemsg = NULL;
VIR_AUTOFREE(char *) jsonmsg = NULL; VIR_AUTOFREE(char *) jsonmsg = NULL;
const char *monmsg = NULL;
char *tmp; char *tmp;
if (!usermsg) if (!usermsg)
usermsg = "unexpected command"; usermsg = "unexpected command";
if (test->json || test->agent) { virBufferEscape(&buf, '\\', "\"", "%s", usermsg);
virBufferEscape(&buf, '\\', "\"", "%s", usermsg); if (virBufferCheckError(&buf) < 0)
if (virBufferCheckError(&buf) < 0) return -1;
return -1; escapemsg = virBufferContentAndReset(&buf);
escapemsg = virBufferContentAndReset(&buf);
/* replace newline/carriage return with space */ /* replace newline/carriage return with space */
tmp = escapemsg; tmp = escapemsg;
while (*tmp) { while (*tmp) {
if (*tmp == '\r' || *tmp == '\n') if (*tmp == '\r' || *tmp == '\n')
*tmp = ' '; *tmp = ' ';
tmp++; tmp++;
}
/* format the JSON error message */
if (virAsprintf(&jsonmsg, "{ \"error\": "
" { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }",
escapemsg) < 0)
return -1;
monmsg = jsonmsg;
} else {
monmsg = usermsg;
} }
return qemuMonitorTestAddResponse(test, monmsg); /* format the JSON error message */
if (virAsprintf(&jsonmsg, "{ \"error\": "
" { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }",
escapemsg) < 0)
return -1;
return qemuMonitorTestAddResponse(test, jsonmsg);
} }
@ -203,6 +196,7 @@ int ATTRIBUTE_FMT_PRINTF(2, 3)
qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...) qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
{ {
va_list msgargs; va_list msgargs;
VIR_AUTOFREE(char *) tmp = NULL;
char *msg = NULL; char *msg = NULL;
char *jsonmsg = NULL; char *jsonmsg = NULL;
int ret = -1; int ret = -1;
@ -212,20 +206,14 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
if (virVasprintf(&msg, errmsg, msgargs) < 0) if (virVasprintf(&msg, errmsg, msgargs) < 0)
goto cleanup; goto cleanup;
if (test->agent || test->json) { if (!(tmp = qemuMonitorEscapeArg(msg)))
VIR_AUTOFREE(char *) tmp = NULL; goto cleanup;
if (!(tmp = qemuMonitorEscapeArg(msg)))
goto cleanup;
if (virAsprintf(&jsonmsg, "{ \"error\": " if (virAsprintf(&jsonmsg, "{ \"error\": "
" { \"desc\": \"%s\", " " { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }", " \"class\": \"UnexpectedCommand\" } }",
tmp) < 0) tmp) < 0)
goto cleanup; goto cleanup;
} else {
if (virAsprintf(&jsonmsg, "error: '%s'", msg) < 0)
goto cleanup;
}
ret = qemuMonitorTestAddResponse(test, jsonmsg); ret = qemuMonitorTestAddResponse(test, jsonmsg);
@ -600,37 +588,19 @@ qemuMonitorTestProcessCommandDefault(qemuMonitorTestPtr test,
struct qemuMonitorTestHandlerData *data = item->opaque; struct qemuMonitorTestHandlerData *data = item->opaque;
virJSONValuePtr val = NULL; virJSONValuePtr val = NULL;
virJSONValuePtr cmdargs = NULL; virJSONValuePtr cmdargs = NULL;
char *cmdcopy = NULL;
const char *cmdname; const char *cmdname;
char *tmp;
int ret = -1; int ret = -1;
int rc; int rc;
if (test->agent || test->json) { if (!(val = virJSONValueFromString(cmdstr)))
if (!(val = virJSONValueFromString(cmdstr))) return -1;
return -1;
if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) { if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) {
ret = qemuMonitorReportError(test, "Missing command name in %s", cmdstr); ret = qemuMonitorReportError(test, "Missing command name in %s", cmdstr);
goto cleanup; goto cleanup;
}
cmdargs = virJSONValueObjectGet(val, "arguments");
} else {
if (VIR_STRDUP(cmdcopy, cmdstr) < 0)
return -1;
cmdname = cmdcopy;
if (!(tmp = strchr(cmdcopy, ' '))) {
ret = qemuMonitorReportError(test,
"Cannot find command name in '%s'",
cmdstr);
goto cleanup;
}
*tmp = '\0';
} }
cmdargs = virJSONValueObjectGet(val, "arguments");
if ((rc = qemuMonitorTestProcessCommandDefaultValidate(test, cmdname, cmdargs)) < 0) if ((rc = qemuMonitorTestProcessCommandDefaultValidate(test, cmdname, cmdargs)) < 0)
goto cleanup; goto cleanup;
@ -646,7 +616,6 @@ qemuMonitorTestProcessCommandDefault(qemuMonitorTestPtr test,
ret = qemuMonitorTestAddResponse(test, data->response); ret = qemuMonitorTestAddResponse(test, data->response);
cleanup: cleanup:
VIR_FREE(cmdcopy);
virJSONValueFree(val); virJSONValueFree(val);
return ret; return ret;
} }
@ -689,23 +658,21 @@ qemuMonitorTestProcessCommandVerbatim(qemuMonitorTestPtr test,
int rc; int rc;
/* JSON strings will be reformatted to simplify checking */ /* JSON strings will be reformatted to simplify checking */
if (test->json || test->agent) { if (!(json = virJSONValueFromString(cmdstr)) ||
if (!(json = virJSONValueFromString(cmdstr)) || !(reformatted = virJSONValueToString(json, false)))
!(reformatted = virJSONValueToString(json, false))) return -1;
cmdstr = reformatted;
/* in this case we do a best-effort schema check if we can find the command */
if ((cmdname = virJSONValueObjectGetString(json, "execute"))) {
cmdargs = virJSONValueObjectGet(json, "arguments");
if ((rc = qemuMonitorTestProcessCommandDefaultValidate(test, cmdname, cmdargs)) < 0)
return -1; return -1;
cmdstr = reformatted; if (rc == 1)
return 0;
/* in this case we do a best-effort schema check if we can find the command */
if ((cmdname = virJSONValueObjectGetString(json, "execute"))) {
cmdargs = virJSONValueObjectGet(json, "arguments");
if ((rc = qemuMonitorTestProcessCommandDefaultValidate(test, cmdname, cmdargs)) < 0)
return -1;
if (rc == 1)
return 0;
}
} }
if (STREQ(data->command_name, cmdstr)) { if (STREQ(data->command_name, cmdstr)) {
@ -756,11 +723,7 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test,
VIR_STRDUP(data->cmderr, cmderr) < 0) VIR_STRDUP(data->cmderr, cmderr) < 0)
goto error; goto error;
if (test->json || test->agent) data->command_name = virJSONStringReformat(command, false);
data->command_name = virJSONStringReformat(command, false);
else
ignore_value(VIR_STRDUP(data->command_name, command));
if (!data->command_name) if (!data->command_name)
goto error; goto error;