chardev: Add -qmp-pretty
v2 cover chardev: Add -qmp-pretty
This series does not add new functionality. Adding a QMP monitor with prettily formatted JSON output can be done as follows:
$ qemu -chardev stdio,id=mon0 -mon chardev=mon0,mode=control,pretty=on
However, this is rather cumbersome, so this series (its first patch) adds a shortcut in the form of the new command line option -qmp-pretty.
Since the argument given to a monitor command line option (such as -qmp) is parsed depending on its prefix and probably also depending on the current phase of the moon, this is cleaner than trying to add a "switch" to -qmp itself (in the form of "-qmp stdio,pretty=on").
Patch 3 makes uses of the new option in qemu-iotest 067 to greatly increase maintainability of its reference output. Patch 2 extends the QMP filter for qemu-iotests so it is able to filter out the QMP version object in pretty mode.
v2:
- Patch 2: Replaced the multi-line QMP_VERSION replacement written in bash by a nice sed script [Eric]
Max Reitz (3):
chardev: Add -qmp-pretty
iotests: _filter_qmp for pretty JSON output
iotests: Use -qmp-pretty in 067
qemu-options.hx | 8 + tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 ++++++++++++++++++++++++++++++++++++--- tests/qemu-iotests/common.filter | 5 +- vl.c | 15 +- 5 files changed, 745 insertions(+), 64 deletions(-)
Signature · 1 line
1.9.3
PATCH v2 1/3 chardev: Add -qmp-pretty
Add a command line option for adding a QMP monitor using pretty JSON formatting.
--- qemu-options.hx | 8 ++++++++ vl.c | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)
qemu-options.hx +8 -0
@@ -2788,6 +2788,14 @@ STEXI @findex -qmp Like -monitor but opens in 'control' mode. ETEXI +DEF("qmp-pretty", HAS_ARG, QEMU_OPTION_qmp_pretty, \ + "-qmp-pretty dev like -qmp but uses pretty JSON formatting\n", + QEMU_ARCH_ALL) +STEXI +@item -qmp-pretty @var{dev} +@findex -qmp-pretty +Like -qmp but uses pretty JSON formatting. +ETEXI DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ "-mon [chardev=]name[,mode=readline|control][,default]\n", QEMU_ARCH_ALL)
vl.c +10 -5
@@ -2284,7 +2284,7 @@ static int mon_init_func(QemuOpts *opts, void *opaque)return 0 ; } -static void monitor_parse (const char *optarg,const char *mode) +static void monitor_parse (const char *optarg,const char *mode,bool pretty) {static int monitor_device_index =0 ;QemuOpts *opts;
@@ -2314,6 +2314,7 @@ static void monitor_parse(const char *optarg, const char *mode) }qemu_opt_set (opts,"mode" , mode);qemu_opt_set (opts,"chardev" , label); +qemu_opt_set_bool (opts,"pretty" , pretty);if (def)qemu_opt_set (opts,"default" ,"on" ); monitor_device_index++;
@@ -3292,11 +3293,15 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_monitor: default_monitor =0 ;if (strncmp (optarg,"none" ,4 )) { -monitor_parse (optarg,"readline" ); +monitor_parse (optarg,"readline" , false); }break ;case QEMU_OPTION_qmp: -monitor_parse (optarg,"control" ); +monitor_parse (optarg,"control" , false); + default_monitor =0 ; +break ; +case QEMU_OPTION_qmp_pretty: +monitor_parse (optarg,"control" , true); default_monitor =0 ;break ;case QEMU_OPTION_mon:
@@ -3994,7 +3999,7 @@ int main(int argc, char **argv, char **envp)add_device_config (DEV_SCLP ,"stdio" ); }if (default_monitor) -monitor_parse ("stdio" ,"readline" ); +monitor_parse ("stdio" ,"readline" , false); } }else {if (default_serial)
@@ -4002,7 +4007,7 @@ int main(int argc, char **argv, char **envp)if (default_parallel)add_device_config (DEV_PARALLEL ,"vc:80Cx24C" );if (default_monitor) -monitor_parse ("vc:80Cx24C" ,"readline" ); +monitor_parse ("vc:80Cx24C" ,"readline" , false);if (default_virtcon)add_device_config (DEV_VIRTCON ,"vc:80Cx24C" );if (default_sclp) {
Signature · 1 line
1.9.3
PATCH v2 2/3 iotests: _filter_qmp for pretty JSON output
In reply to Max Reitz_filter_qmp should be able to correctly filter out the QMP version object for pretty JSON output.
--- tests/qemu-iotests/common.filter | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tests/qemu-iotests/common.filter +4 -1
@@ -165,9 +165,12 @@ _filter_qemu() # replace problematic QMP output like timestamps _filter_qmp() { + discard=0 + _filter_win32 | \ sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ - -e 's#^{"QMP":.*}$#QMP_VERSION#' + -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e '/^ "QMP": {\s*$/, /^ }\s*$/ c\ QMP_VERSION' } # replace driver-specific options in the "Formatting..." line
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v2 2/3] iotests: _filter_qmp for pretty JSON output
Quoted 13 lines · Max Reitz
_filter_qmpshould be able to correctly filter out the QMP version object for pretty JSON output.Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/common.filter | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tests/qemu-iotests/common.filter +0
-0
tests/qemu-iotests/common.filter _filter_qemu() · line 169
Quoted 5 lines
tests/qemu-iotests/common.filter +2
-0@@ -165,9 +165,12 @@ _filter_qemu() # replace problematic QMP output like timestamps _filter_qmp() { + discard=0 +
Urgh, self-NACK. We don't need that anymore.
Max
Quoted 8 lines
tests/qemu-iotests/common.filter +2
-1_filter_win32 | \ sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ - -e 's#^{"QMP":.*}$#QMP_VERSION#' + -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e '/^ "QMP": {\s*$/, /^ }\s*$/ c\ QMP_VERSION' } # replace driver-specific options in the "Formatting..." line
Re: [Qemu-devel] [PATCH v2 2/3] iotests: _filter_qmp for pretty JSON output
In reply to Max ReitzQuoted 13 lines · Max Reitz
_filter_qmpshould be able to correctly filter out the QMP version object for pretty JSON output.Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/common.filter | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tests/qemu-iotests/common.filter +0
-0
tests/qemu-iotests/common.filter _filter_qemu() · line 173
Quoted 10 lines
tests/qemu-iotests/common.filter +4
-1@@ -165,9 +165,12 @@ _filter_qemu() # replace problematic QMP output like timestamps _filter_qmp() { + discard=0 + _filter_win32 | \ sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ - -e 's#^{"QMP":.*}$#QMP_VERSION#' + -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e '/^ "QMP": {\s*$/, /^ }\s*$/ c\ QMP_VERSION'
Technically, portable sed requires a newline between the initial 'c\' and the first line of replacement. Use of multiple -e is the easiest way to provide newlines (sed concatenates separate -e strings with an implicit newline). Even though GNU sed doesn't barf on your variant, I'd still prefer:
-e '/^ "QMP": {/, /^ }/ c\' \
-e ' QMP_VERSION'
written as two lines, to ensure we don't upset BSD sed.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 3/3 iotests: Use -qmp-pretty in 067
In reply to Max Reitz067 invokes query-block, resulting in a reference output with really long lines (which may pose a problem in email patches and always poses a problem when the output changes, because it is hard to see what has actually changed). Use -qmp-pretty to mitigate this issue.
--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 723 insertions(+), 58 deletions(-)
tests/qemu-iotests/067 +1 -1
@@ -39,7 +39,7 @@ _supported_os Linux function do_run_qemu() { echo Testing: "$@" - $QEMU -nographic -qmp stdio -serial none "$@" + $QEMU -nographic -qmp-pretty stdio -serial none "$@" echo }
tests/qemu-iotests/067.out +722 -57
799 lines not on this page · raw message
Signature · 1 line
1.9.3