xref: /openbmc/qemu/tests/qemu-iotests/068 (revision 9dd003a99842d1d82c336e45c5cce656149de382)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3ab6f2bbbSMax Reitz#
4ab6f2bbbSMax Reitz# Test case for loading a saved VM state from a qcow2 image
5ab6f2bbbSMax Reitz#
6ab6f2bbbSMax Reitz# Copyright (C) 2013 Red Hat, Inc.
7ab6f2bbbSMax Reitz#
8ab6f2bbbSMax Reitz# This program is free software; you can redistribute it and/or modify
9ab6f2bbbSMax Reitz# it under the terms of the GNU General Public License as published by
10ab6f2bbbSMax Reitz# the Free Software Foundation; either version 2 of the License, or
11ab6f2bbbSMax Reitz# (at your option) any later version.
12ab6f2bbbSMax Reitz#
13ab6f2bbbSMax Reitz# This program is distributed in the hope that it will be useful,
14ab6f2bbbSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15ab6f2bbbSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16ab6f2bbbSMax Reitz# GNU General Public License for more details.
17ab6f2bbbSMax Reitz#
18ab6f2bbbSMax Reitz# You should have received a copy of the GNU General Public License
19ab6f2bbbSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20ab6f2bbbSMax Reitz#
21ab6f2bbbSMax Reitz
22ab6f2bbbSMax Reitz# creator
23ab6f2bbbSMax Reitzowner=mreitz@redhat.com
24ab6f2bbbSMax Reitz
25ab6f2bbbSMax Reitzseq="$(basename $0)"
26ab6f2bbbSMax Reitzecho "QA output created by $seq"
27ab6f2bbbSMax Reitz
28ab6f2bbbSMax Reitzstatus=1	# failure is the default!
29ab6f2bbbSMax Reitz
30ab6f2bbbSMax Reitz_cleanup()
31ab6f2bbbSMax Reitz{
32ab6f2bbbSMax Reitz	_cleanup_test_img
33ab6f2bbbSMax Reitz}
34ab6f2bbbSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35ab6f2bbbSMax Reitz
36ab6f2bbbSMax Reitz# get standard environment, filters and checks
37ab6f2bbbSMax Reitz. ./common.rc
38ab6f2bbbSMax Reitz. ./common.filter
39ab6f2bbbSMax Reitz
40e696f335SMax Reitz# This tests qcow2-specific low-level functionality
41ab6f2bbbSMax Reitz_supported_fmt qcow2
42ab6f2bbbSMax Reitz_supported_proto generic
433be2024aSMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1,
443be2024aSMax Reitz# and generally impossible with external data files
453be2024aSMax Reitz_unsupported_imgopts 'compat=0.10' 'refcount_bits=1[^0-9]' data_file
46ab6f2bbbSMax Reitz
47ab6f2bbbSMax ReitzIMG_SIZE=128K
48ab6f2bbbSMax Reitz
49a41aa71cSBo Tucase "$QEMU_DEFAULT_MACHINE" in
50a41aa71cSBo Tu  s390-ccw-virtio)
519bf8027dSSascha Silbe      platform_parm="-no-shutdown"
525aaf590dSStefan Hajnoczi      hba=virtio-scsi-ccw
53a41aa71cSBo Tu      ;;
54a41aa71cSBo Tu  *)
55a41aa71cSBo Tu      platform_parm=""
565aaf590dSStefan Hajnoczi      hba=virtio-scsi-pci
57a41aa71cSBo Tu      ;;
58a41aa71cSBo Tuesac
59a41aa71cSBo Tu
6079645e05SStefan Hajnoczi_qemu()
6179645e05SStefan Hajnoczi{
625aaf590dSStefan Hajnoczi    $QEMU $platform_parm -nographic -monitor stdio -serial none \
635aaf590dSStefan Hajnoczi          -drive if=none,id=drive0,file="$TEST_IMG",format="$IMGFMT" \
645aaf590dSStefan Hajnoczi          -device $hba,id=hba0 \
655aaf590dSStefan Hajnoczi          -device scsi-hd,drive=drive0 \
6679645e05SStefan Hajnoczi          "$@" |\
6779645e05SStefan Hajnoczi    _filter_qemu | _filter_hmp
6879645e05SStefan Hajnoczi}
6979645e05SStefan Hajnoczi
70ea4f3cebSStefan Hajnoczifor extra_args in \
71ea4f3cebSStefan Hajnoczi    "" \
72ea4f3cebSStefan Hajnoczi    "-object iothread,id=iothread0 -set device.hba0.iothread=iothread0"; do
73ea4f3cebSStefan Hajnoczi    echo
74ea4f3cebSStefan Hajnoczi    echo "=== Saving and reloading a VM state to/from a qcow2 image ($extra_args) ==="
75ea4f3cebSStefan Hajnoczi    echo
76ea4f3cebSStefan Hajnoczi
77ea4f3cebSStefan Hajnoczi    _make_test_img $IMG_SIZE
78ea4f3cebSStefan Hajnoczi
79ab6f2bbbSMax Reitz    # Give qemu some time to boot before saving the VM state
80b43671f8SEric Blake    { sleep 1; printf "savevm 0\nquit\n"; } | _qemu $extra_args
81ab6f2bbbSMax Reitz    # Now try to continue from that VM state (this should just work)
8204583a9eSDr. David Alan Gilbert    { sleep 1; printf "loadvm 0\nloadvm 0\nquit\n"; } | _qemu $extra_args -S
83ea4f3cebSStefan Hajnoczidone
84ab6f2bbbSMax Reitz
85ab6f2bbbSMax Reitz# success, all done
86ab6f2bbbSMax Reitzecho "*** done"
87ab6f2bbbSMax Reitzrm -f $seq.full
88ab6f2bbbSMax Reitzstatus=0
89