From 56c2f2b45bc91e85dc589672598d7f37c1180b5e Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 7 Jun 2019 10:38:06 +0200 Subject: [PATCH] tests: qemu: Add QMP schema checking in qemuMonitorTestProcessCommandVerbatim In case when we are testing a QMP command we can try to schema check it so that we catch inconsistencies. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- tests/qemumonitortestutils.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 1cd35830af..0de9048243 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -690,14 +690,30 @@ qemuMonitorTestProcessCommandVerbatim(qemuMonitorTestPtr test, struct qemuMonitorTestHandlerData *data = item->opaque; VIR_AUTOFREE(char *) reformatted = NULL; VIR_AUTOFREE(char *) errmsg = NULL; + VIR_AUTOPTR(virJSONValue) json = NULL; + virJSONValuePtr cmdargs; + const char *cmdname; int ret = -1; + int rc; /* JSON strings will be reformatted to simplify checking */ if (test->json || test->agent) { - if (!(reformatted = virJSONStringReformat(cmdstr, false))) + if (!(json = virJSONValueFromString(cmdstr)) || + !(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; + + if (rc == 1) + return 0; + } } if (STREQ(data->command_name, cmdstr)) {