Replace HMP savevm/loadvm with QMP snapshot-save/snapshot-load
job-based API. Use _run_qmp_job() helper to factor the common
send/wait/dismiss pattern.

The sleep before sending commands is no longer needed: the QMP
qmp_capabilities handshake is synchronous, so QEMU is guaranteed
to be ready.

Signed-off-by: Marc-André Lureau <[email protected]>
---
 tests/qemu-iotests/068     | 56 ++++++++++++++++++++++++++++++++++------------
 tests/qemu-iotests/068.out | 26 ++++++++++-----------
 2 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/tests/qemu-iotests/068 b/tests/qemu-iotests/068
index 11b660a8b7c4..0b756862c1c3 100755
--- a/tests/qemu-iotests/068
+++ b/tests/qemu-iotests/068
@@ -29,6 +29,7 @@ status=1      # failure is the default!
 
 _cleanup()
 {
+       _cleanup_qemu
        _cleanup_test_img
 }
 trap "_cleanup; exit \$status" 0 1 2 3 15
@@ -36,6 +37,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 # get standard environment, filters and checks
 . ./common.rc
 . ./common.filter
+. ./common.qemu
 
 # This tests qcow2-specific low-level functionality
 _supported_fmt qcow2
@@ -43,7 +45,6 @@ _supported_proto generic
 # Internal snapshots are (currently) impossible with refcount_bits=1,
 # and generally impossible with external data files
 _unsupported_imgopts 'compat=0.10' 'refcount_bits=1[^0-9]' data_file
-_require_hmp
 
 IMG_SIZE=128K
 
@@ -56,16 +57,6 @@ case "$QEMU_DEFAULT_MACHINE" in
       ;;
 esac
 
-_qemu()
-{
-    $QEMU $platform_parm -nographic -monitor stdio -serial none \
-          -drive if=none,id=drive0,file="$TEST_IMG",format="$IMGFMT" \
-          -device virtio-scsi,id=hba0 \
-          -device scsi-hd,drive=drive0 \
-          "$@" |\
-    _filter_qemu | _filter_hmp
-}
-
 for extra_args in \
     "" \
     "-object iothread,id=iothread0 -set device.hba0.iothread=iothread0"; do
@@ -75,10 +66,47 @@ for extra_args in \
 
     _make_test_img $IMG_SIZE
 
-    # Give qemu some time to boot before saving the VM state
-    { sleep 1; printf "savevm 0\nquit\n"; } | _qemu $extra_args
+    # Save VM state
+    _launch_qemu $platform_parm \
+          -drive 
if=none,id=drive0,node-name=disk0,file="$TEST_IMG",format="$IMGFMT" \
+          -device virtio-scsi,id=hba0 \
+          -device scsi-hd,drive=drive0 \
+          $extra_args
+    silent=yes _send_qemu_cmd $QEMU_HANDLE \
+        "{ 'execute': 'qmp_capabilities' }" \
+        'return'
+    silent=yes _run_qmp_job $QEMU_HANDLE 'save0' \
+        "{ 'execute': 'snapshot-save',
+           'arguments': { 'job-id': 'save0',
+                          'tag': '0',
+                          'vmstate': 'disk0',
+                          'devices': ['disk0'] } }"
+    _send_qemu_cmd $QEMU_HANDLE \
+        "{ 'execute': 'quit' }" \
+        'return'
+    wait=1 _cleanup_qemu
+
     # Now try to continue from that VM state (this should just work)
-    { sleep 1; printf "loadvm 0\nloadvm 0\nquit\n"; } | _qemu $extra_args -S
+    _launch_qemu $platform_parm \
+          -drive 
if=none,id=drive0,node-name=disk0,file="$TEST_IMG",format="$IMGFMT" \
+          -device virtio-scsi,id=hba0 \
+          -device scsi-hd,drive=drive0 \
+          -S $extra_args
+    silent=yes _send_qemu_cmd $QEMU_HANDLE \
+        "{ 'execute': 'qmp_capabilities' }" \
+        'return'
+    for i in 1 2; do
+        silent=yes _run_qmp_job $QEMU_HANDLE "load$i" \
+            "{ 'execute': 'snapshot-load',
+               'arguments': { 'job-id': 'load$i',
+                              'tag': '0',
+                              'vmstate': 'disk0',
+                              'devices': ['disk0'] } }"
+    done
+    _send_qemu_cmd $QEMU_HANDLE \
+        "{ 'execute': 'quit' }" \
+        'return'
+    wait=1 _cleanup_qemu
 done
 
 # success, all done
diff --git a/tests/qemu-iotests/068.out b/tests/qemu-iotests/068.out
index f07a938a3838..3bc0b5a771db 100644
--- a/tests/qemu-iotests/068.out
+++ b/tests/qemu-iotests/068.out
@@ -3,22 +3,20 @@ QA output created by 068
 === Saving and reloading a VM state to/from a qcow2 image () ===
 
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072
-QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) savevm 0
-(qemu) quit
-QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) loadvm 0
-(qemu) loadvm 0
-(qemu) quit
+{ 'execute': 'quit' }
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
"SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}}
+{"return": {}}
+{ 'execute': 'quit' }
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
"SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}}
+{"return": {}}
 
 === Saving and reloading a VM state to/from a qcow2 image (-object 
iothread,id=iothread0 -set device.hba0.iothread=iothread0) ===
 
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072
-QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) savevm 0
-(qemu) quit
-QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) loadvm 0
-(qemu) loadvm 0
-(qemu) quit
+{ 'execute': 'quit' }
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
"SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}}
+{"return": {}}
+{ 'execute': 'quit' }
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
"SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}}
+{"return": {}}
 *** done

-- 
2.56.0.rc0.29.g47ce80527c56


Reply via email to