]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: monitor: json: Fix error message when returning json in json
authorPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jun 2014 15:12:48 +0000 (17:12 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jun 2014 15:19:24 +0000 (17:19 +0200)
The qemu JSON monitor test allows to test also expected command
arguments. As the error from the monitor simulator is returned as a
simulated qemu error (in JSON) all other JSON contained in the error
message needs to be escaped. This will happen if the monitor command
under test receives a JSON array as an argument.

This will improve the error message from:
libvirt:  error : internal error: cannot parse json { "error":  { "desc":
"Invalid value of argument 'keys' of command 'send-key': expected 'ble'
got '[{"type":"number","data":43},{"type":"number","data":26},
{"type":"number","data":46},{"type":"number","data":32}]'",
"class": "UnexpectedCommand" } }: lexical error: invalid string in json text.

To:
libvirt: QEMU Driver error : internal error: unable to execute QEMU
command 'send-key': Invalid value of argument 'keys' of command
'send-key': expected 'ble' got '[{"type":"number","data":43},
{"type":"number","data":26},{"type":"number","data":46},
{"type":"number","data":32}]'

This improvement will not have any effect on tests executing as
expected, but it will help test development.

tests/qemumonitortestutils.c

index 30c2153fe18bf5ff33a047894fa09c4e24f21d32..8155a69ddd8fe2b96d9514f6ced5f355aec7767a 100644 (file)
@@ -145,6 +145,12 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
         goto cleanup;
 
     if (test->agent || test->json) {
+        char *tmp = msg;
+        msg = qemuMonitorEscapeArg(tmp);
+        VIR_FREE(tmp);
+        if (!msg)
+            goto cleanup;
+
         if (virAsprintf(&jsonmsg, "{ \"error\": "
                                   " { \"desc\": \"%s\", "
                                   "   \"class\": \"UnexpectedCommand\" } }",