xref: /openbmc/qemu/tests/qemu-iotests/201 (revision c124c152)
1#!/usr/bin/env bash
2#
3# Test savevm and loadvm after live migration with postcopy flag
4#
5# Copyright (C) 2017, IBM Corporation.
6#
7# This file is derived from tests/qemu-iotests/181 by Kevin Wolf
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22seq=`basename $0`
23echo "QA output created by $seq"
24
25status=1	# failure is the default!
26
27MIG_SOCKET="${TEST_DIR}/migrate"
28
29# get standard environment, filters and checks
30. ./common.rc
31. ./common.filter
32. ./common.qemu
33
34_cleanup()
35{
36    rm -f "${MIG_SOCKET}"
37    _cleanup_test_img
38    _cleanup_qemu
39}
40trap "_cleanup; exit \$status" 0 1 2 3 15
41
42_supported_fmt qcow2
43_supported_proto generic
44_supported_os Linux
45
46# Internal snapshots are (currently) impossible with refcount_bits=1
47# This was taken from test 080
48_unsupported_imgopts 'refcount_bits=1[^0-9]'
49
50size=64M
51_make_test_img $size
52
53echo
54echo === Starting VMs ===
55echo
56
57qemu_comm_method="monitor"
58
59if [ "$IMGOPTSSYNTAX" = "true" ]; then
60    _launch_qemu \
61        -drive "${TEST_IMG}",cache=${CACHEMODE},id=disk
62else
63    _launch_qemu \
64        -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk
65fi
66src=$QEMU_HANDLE
67
68if [ "$IMGOPTSSYNTAX" = "true" ]; then
69    _launch_qemu \
70        -drive "${TEST_IMG}",cache=${CACHEMODE},id=disk \
71        -incoming "unix:${MIG_SOCKET}"
72else
73    _launch_qemu \
74        -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk \
75        -incoming "unix:${MIG_SOCKET}"
76fi
77dest=$QEMU_HANDLE
78
79echo
80echo === Set \'migrate_set_capability postcopy-ram on\' and migrate ===
81echo
82
83silent=yes
84_send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)"
85
86qemu_error_no_exit=yes success_or_failure=yes \
87    _send_qemu_cmd $dest '' "(qemu)" "Postcopy is not supported"
88if [ ${QEMU_STATUS[$dest]} -lt 0 ]; then
89    _send_qemu_cmd $dest '' "(qemu)"
90
91    _send_qemu_cmd $src 'quit' ""
92    _send_qemu_cmd $dest 'quit' ""
93    wait=1 _cleanup_qemu
94
95    _notrun 'Postcopy is not supported'
96fi
97
98_send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)"
99_send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)"
100
101QEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \
102    _send_qemu_cmd $src "info migrate" "completed\|failed"
103silent=yes _send_qemu_cmd $src "" "(qemu)"
104
105echo
106echo === Check if migration was successful ===
107echo
108
109QEMU_COMM_TIMEOUT=1 silent=yes \
110    _send_qemu_cmd $src "info migrate" "completed"
111silent=yes _send_qemu_cmd $src "" "(qemu)"
112
113echo
114echo === On destination, execute savevm and loadvm ===
115echo
116
117silent=
118_send_qemu_cmd $dest 'savevm state1' "(qemu)"
119_send_qemu_cmd $dest 'loadvm state1' "(qemu)"
120
121echo
122echo === Shut down and check image ===
123echo
124
125_send_qemu_cmd $src 'quit' ""
126_send_qemu_cmd $dest 'quit' ""
127wait=1 _cleanup_qemu
128
129_check_test_img
130
131# success, all done
132echo "*** done"
133status=0
134