提交 e00ecd1b 编写于 作者: P Peter Krempa

tests: qemucapsprobemock: Prepare 'qemucapsprobe' for the new format

Change the output of qemucapsprobe to record the commands used for
querying. This allows to easily identify which reply belongs to which
command and also will allow to test whether we use stable queries.

This change includes changing dropping of the QMP greeting from the file
and reformatting of the query and output to stdout.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 9369348e
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
} \ } \
} while (0) } while (0)
static bool first = true;
static void static void
printLineSkipEmpty(const char *line, printLineSkipEmpty(const char *line,
...@@ -60,9 +61,22 @@ int ...@@ -60,9 +61,22 @@ int
qemuMonitorSend(qemuMonitorPtr mon, qemuMonitorSend(qemuMonitorPtr mon,
qemuMonitorMessagePtr msg) qemuMonitorMessagePtr msg)
{ {
char *reformatted;
REAL_SYM(realQemuMonitorSend); REAL_SYM(realQemuMonitorSend);
fprintf(stderr, "%s", msg->txBuffer); if (!(reformatted = virJSONStringReformat(msg->txBuffer, true))) {
fprintf(stderr, "Failed to reformat command string '%s'\n", msg->txBuffer);
abort();
}
if (first)
first = false;
else
printLineSkipEmpty("\n", stdout);
printLineSkipEmpty(reformatted, stdout);
VIR_FREE(reformatted);
return realQemuMonitorSend(mon, msg); return realQemuMonitorSend(mon, msg);
} }
...@@ -77,7 +91,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon, ...@@ -77,7 +91,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
const char *line, const char *line,
qemuMonitorMessagePtr msg) qemuMonitorMessagePtr msg)
{ {
static bool first = true;
virJSONValuePtr value = NULL; virJSONValuePtr value = NULL;
char *json = NULL; char *json = NULL;
int ret; int ret;
...@@ -93,14 +106,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon, ...@@ -93,14 +106,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
abort(); abort();
} }
if (first) { /* Ignore QMP greeting */
if (virJSONValueObjectHasKey(value, "QMP"))
goto cleanup;
if (first)
first = false; first = false;
} else { else
/* Ignore QMP greeting if it's not the first one */ printLineSkipEmpty("\n", stdout);
if (virJSONValueObjectHasKey(value, "QMP"))
goto cleanup;
putchar('\n');
}
printLineSkipEmpty(json, stdout); printLineSkipEmpty(json, stdout);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册