chardev: Add -qmp-pretty
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.
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 | 16 +- vl.c | 15 +- 5 files changed, 756 insertions(+), 64 deletions(-)
Signature · 1 line
1.9.3
PATCH 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
Quoted 9 lines · Max Reitz
Add a command line option for adding a QMP monitor using pretty JSON formatting.
Signed-off-by Max Reitz <[email protected]>--- qemu-options.hx | 8 ++++++++ vl.c | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)
Minor grammar suggestions:
qemu-options.hx STEXI · line 2792
Quoted 10 lines
qemu-options.hx +2
-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",
maybe s/dev like -qmp/dev: like -qmp,/
qemu-options.hx STEXI · line 2797
Quoted 5 lines
qemu-options.hx +5
-0+ QEMU_ARCH_ALL) +STEXI +@item -qmp-pretty @var{dev} +@findex -qmp-pretty +Like -qmp but uses pretty JSON formatting.
maybe s/-qmp/-qmp,/
Either way,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 24 lines · Eric Blake
Quoted 9 lines · Max Reitz
Add a command line option for adding a QMP monitor using pretty JSON formatting.
Signed-off-by Max Reitz <[email protected]>--- qemu-options.hx | 8 ++++++++ vl.c | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)Minor grammar suggestions:
qemu-options.hx STEXI · line 2792
Quoted 10 lines
qemu-options.hx +2
-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",maybe s/dev like -qmp/dev: like -qmp,/
Quoted 6 lines
qemu-options.hx STEXI · line 2797
Quoted 5 lines
qemu-options.hx +5
-0+ QEMU_ARCH_ALL) +STEXI +@item -qmp-pretty @var{dev} +@findex -qmp-pretty +Like -qmp but uses pretty JSON formatting.maybe s/-qmp/-qmp,/
That's what I wrote at first, but then I saw the entry above: "Like -monitor but opens in 'control' mode" and decided to stay consistent.
Quoted 2 lines
Either way,
Reviewed-by Eric Blake <[email protected]>
Thanks!
Max
PATCH 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
tests/qemu-iotests/common.filter +15 -1
@@ -165,9 +165,23 @@ _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 's#\\#\\\\#g' | \ + while IFS='' read line; do + if [[ $line == ' "QMP": {' ]]; then + discard=1 + echo ' QMP_VERSION' + fi + if [[ $discard == 0 ]]; then + echo "$line" + elif [[ $discard == 1 && $line == ' }' ]]; then + discard=0 + fi + done } # replace driver-specific options in the "Formatting..." line
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 2/3] iotests: _filter_qmp for pretty JSON output
Quoted 15 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)tests/qemu-iotests/common.filter +0
-0@@ -165,9 +165,23 @@ _filter_qemu() # replace problematic QMP output like timestamps _filter_qmp()
tests/qemu-iotests/common.filter _filter_qemu() · line 175
Quoted 10 lines
tests/qemu-iotests/common.filter +6
-1{ + 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 's#\\#\\\\#g' | \ + while IFS='' read line; do + if [[ $line == ' "QMP": {' ]]; then
Good that this is a /bin/bash script and not /bin/sh :)
But - is it really worth doing this in shell? Why not just do it in sed?
sed -e ... \
-e 's#\\#\\\\#g' \
-e '/ "QMP": {/,/ }/ c\' \
-e ' QMP_VERSION'Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/3] iotests: _filter_qmp for pretty JSON output
Quoted 19 lines · Eric Blake
Quoted 18 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)tests/qemu-iotests/common.filter +2
-0@@ -165,9 +165,23 @@ _filter_qemu() # replace problematic QMP output like timestamps _filter_qmp() { + discard=0 +
Quoted 8 lines
tests/qemu-iotests/common.filter _filter_qemu() · line 175
Quoted 7 lines
tests/qemu-iotests/common.filter +4
-1_filter_win32 | \ sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ - -e 's#^{"QMP":.*}$#QMP_VERSION#' + -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e 's#\\#\\\\#g' | \ + while IFS='' read line; do + if [[ $line == ' "QMP": {' ]]; thenGood that this is a
/bin/bashscript and not/bin/sh:)
Ah, right, yes, I just copied the code I had written for filtering out the image-specific information from the qemu-img info output.
Quoted 1 line
But - is it really worth doing this in shell? Why not just do it in sed?
Because I don't know sed well enough. ;-)
Quoted 4 lines
sed -e ... \
-e 's#\\#\\\\#g' \
-e '/ "QMP": {/,/ }/ c\' \
-e ' QMP_VERSION'Will do, thanks.
Max
Re: [Qemu-devel] [PATCH 2/3] iotests: _filter_qmp for pretty JSON output
Quoted 4 lines · Max Reitz
Quoted 4 lines
Quoted 4 lines
tests/qemu-iotests/common.filter +4
-0+ -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e 's#\\#\\\\#g' | \ + while IFS='' read line; do + if [[ $line == ' "QMP": {' ]]; then
Quoted 12 lines
Quoted 1 line
Good that this is a
/bin/bashscript and not/bin/sh:)Ah, right, yes, I just copied the code I had written for filtering out the image-specific information from the qemu-img info output.
Quoted 1 line
But - is it really worth doing this in shell? Why not just do it in sed?
Because I don't know sed well enough. ;-)
Quoted 3 lines
sed -e ... \ -e 's#\\#\\\\#g' \ -e '/ "QMP": {/,/ }/ c\' \
Better make this line anchored in its searching:
-e '/^ "QMP": {$/,/^ }$/ c\' \
Quoted 7 lines
Quoted 1 line
-e '
QMP_VERSION'Will do, thanks.
Max
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 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
Re: [Qemu-devel] [PATCH 3/3] iotests: Use -qmp-pretty in 067
Quoted 10 lines · Max Reitz
067 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.
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 723 insertions(+), 58 deletions(-)
Large, but mechanical. I'm trusting this one is correct (if the testsuite still passes, you did it right) rather than actually reading it :)
tests/qemu-iotests/067 _supported_os Linux · line 42
Quoted 11 lines
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 "$@"
Such a trivial change for inducing over 700 lines of change in the expected output :)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] iotests: Use -qmp-pretty in 067
Quoted 6 lines · Eric Blake
Quoted 5 lines · Max Reitz
067 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.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 723 insertions(+), 58 deletions(-)Large, but mechanical. I'm trusting this one is correct (if the testsuite still passes, you did it right) rather than actually reading it :)
Yes, for me "Passes before and the output afterwards still makes sense when skipping through" was enough.
Max
Quoted 14 lines
Reviewed-by Eric Blake <[email protected]>tests/qemu-iotests/067 _supported_os Linux · line 42
Quoted 10 lines
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 "$@"Such a trivial change for inducing over 700 lines of change in the expected output :)