target-i386: do not pass MSR_TSC_AUX to KVM ioctls if CPUID bit is not set
[qemu/ar7.git] / tests / qemu-iotests / 148
blobd066ec3e41f7cbe3c8764d6420890201b562b590
1 #!/usr/bin/env python
3 # Test the rate limit of QMP events
5 # Copyright (C) 2016 Igalia, S.L.
6 # Author: Alberto Garcia <berto@igalia.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 import os
23 import iotests
25 imgs = (os.path.join(iotests.test_dir, 'quorum0.img'),
26 os.path.join(iotests.test_dir, 'quorum1.img'),
27 os.path.join(iotests.test_dir, 'quorum2.img'))
29 img_conf = (os.path.join(iotests.test_dir, 'quorum0.conf'),
30 os.path.join(iotests.test_dir, 'quorum1.conf'),
31 os.path.join(iotests.test_dir, 'quorum2.conf'))
33 event_rate = 1000000000
34 sector_size = 512
35 offset = 10
37 class TestQuorumEvents(iotests.QMPTestCase):
38 read_pattern = 'quorum'
40 def create_blkdebug_file(self, blkdebug_file, bad_sector):
41 file = open(blkdebug_file, 'w')
42 file.write('''
43 [inject-error]
44 event = "read_aio"
45 errno = "5"
46 sector = "%d"
47 ''' % bad_sector)
48 file.close()
50 def setUp(self):
51 driveopts = ['driver=quorum', 'vote-threshold=2']
52 driveopts.append('read-pattern=%s' % self.read_pattern)
53 for i in range(len(imgs)):
54 iotests.qemu_img('create', '-f', iotests.imgfmt, imgs[i], '1M')
55 self.create_blkdebug_file(img_conf[i], i + offset)
56 driveopts.append('children.%d.driver=%s' % (i, iotests.imgfmt))
57 driveopts.append('children.%d.file.driver=blkdebug' % i)
58 driveopts.append('children.%d.file.config=%s' % (i, img_conf[i]))
59 driveopts.append('children.%d.file.image.filename=%s' % (i, imgs[i]))
60 driveopts.append('children.%d.node-name=img%d' % (i, i))
61 self.vm = iotests.VM()
62 self.vm.add_drive(None, opts = ','.join(driveopts))
63 self.vm.launch()
65 def tearDown(self):
66 self.vm.shutdown()
67 for i in range(len(imgs)):
68 os.remove(imgs[i])
69 os.remove(img_conf[i])
71 def do_check_event(self, node, sector = 0):
72 if node == None:
73 self.assertEqual(self.vm.get_qmp_event(), None)
74 return
76 for event in self.vm.get_qmp_events(wait=True):
77 if event['event'] == 'QUORUM_REPORT_BAD':
78 self.assert_qmp(event, 'data/node-name', node)
79 self.assert_qmp(event, 'data/sector-num', sector)
81 def testQuorum(self):
82 if not 'quorum' in iotests.qemu_img_pipe('--help'):
83 return
85 # Generate an error and get an event
86 self.vm.hmp_qemu_io("drive0", "aio_read %d %d" %
87 (offset * sector_size, sector_size))
88 self.vm.qtest("clock_step 10")
89 self.do_check_event('img0', offset)
91 # I/O errors in the same child: only one event is emitted
92 delay = 10
93 for i in range(3):
94 self.vm.hmp_qemu_io("drive0", "aio_read %d %d" %
95 (offset * sector_size, sector_size))
96 self.vm.qtest("clock_step %d" % delay)
97 self.do_check_event(None)
99 # Wait enough so the event is finally emitted
100 self.vm.qtest("clock_step %d" % (2 * event_rate))
101 self.do_check_event('img0', offset)
103 # I/O errors in the same child: all events are emitted
104 delay = 2 * event_rate
105 for i in range(3):
106 self.vm.hmp_qemu_io("drive0", "aio_read %d %d" %
107 (offset * sector_size, sector_size))
108 self.vm.qtest("clock_step %d" % delay)
109 self.do_check_event('img0', offset)
111 # I/O errors in different children: all events are emitted
112 delay = 10
113 for i in range(len(imgs)):
114 self.vm.hmp_qemu_io("drive0", "aio_read %d %d" %
115 ((offset + i) * sector_size, sector_size))
116 self.vm.qtest("clock_step %d" % delay)
117 # In fifo mode only errors in the first child are detected
118 if i > 0 and self.read_pattern == 'fifo':
119 self.do_check_event(None)
120 else:
121 self.do_check_event('img%d' % i, offset + i)
123 # I/O errors in different children: all events are emitted
124 delay = 2 * event_rate
125 for i in range(len(imgs)):
126 self.vm.hmp_qemu_io("drive0", "aio_read %d %d" %
127 ((offset + i) * sector_size, sector_size))
128 self.vm.qtest("clock_step %d" % delay)
129 # In fifo mode only errors in the first child are detected
130 if i > 0 and self.read_pattern == 'fifo':
131 self.do_check_event(None)
132 else:
133 self.do_check_event('img%d' % i, offset + i)
135 # No more pending events
136 self.do_check_event(None)
138 class TestFifoQuorumEvents(TestQuorumEvents):
139 read_pattern = 'fifo'
141 if __name__ == '__main__':
142 iotests.main(supported_fmts=["raw"])