gdbstub: add reverse continue support in replay mode
[qemu/ar7.git] / tests / acceptance / replay_kernel.py
blob952f429cace6e78b27e34426666a319601e3e0b4
1 # Record/replay test that boots a Linux kernel
3 # Copyright (c) 2020 ISP RAS
5 # Author:
6 # Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
8 # This work is licensed under the terms of the GNU GPL, version 2 or
9 # later. See the COPYING file in the top-level directory.
11 import os
12 import logging
13 import time
15 from avocado import skipIf
16 from avocado import skipUnless
17 from avocado_qemu import wait_for_console_pattern
18 from avocado.utils import archive
19 from avocado.utils import process
20 from boot_linux_console import LinuxKernelTest
22 class ReplayKernel(LinuxKernelTest):
23 """
24 Boots a Linux kernel in record mode and checks that the console
25 is operational and the kernel command line is properly passed
26 from QEMU to the kernel.
27 Then replays the same scenario and verifies, that QEMU correctly
28 terminates.
29 """
31 timeout = 90
32 KERNEL_COMMON_COMMAND_LINE = 'printk.time=1 panic=-1 '
34 def run_vm(self, kernel_path, kernel_command_line, console_pattern,
35 record, shift, args, replay_path):
36 logger = logging.getLogger('replay')
37 start_time = time.time()
38 vm = self.get_vm()
39 vm.set_console()
40 if record:
41 logger.info('recording the execution...')
42 mode = 'record'
43 else:
44 logger.info('replaying the execution...')
45 mode = 'replay'
46 vm.add_args('-icount', 'shift=%s,rr=%s,rrfile=%s' %
47 (shift, mode, replay_path),
48 '-kernel', kernel_path,
49 '-append', kernel_command_line,
50 '-net', 'none',
51 '-no-reboot')
52 if args:
53 vm.add_args(*args)
54 vm.launch()
55 self.wait_for_console_pattern(console_pattern, vm)
56 if record:
57 vm.shutdown()
58 logger.info('finished the recording with log size %s bytes'
59 % os.path.getsize(replay_path))
60 else:
61 vm.wait()
62 logger.info('successfully finished the replay')
63 elapsed = time.time() - start_time
64 logger.info('elapsed time %.2f sec' % elapsed)
65 return elapsed
67 def run_rr(self, kernel_path, kernel_command_line, console_pattern,
68 shift=7, args=None):
69 replay_path = os.path.join(self.workdir, 'replay.bin')
70 t1 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
71 True, shift, args, replay_path)
72 t2 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
73 False, shift, args, replay_path)
74 logger = logging.getLogger('replay')
75 logger.info('replay overhead {:.2%}'.format(t2 / t1 - 1))
77 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
78 def test_x86_64_pc(self):
79 """
80 :avocado: tags=arch:x86_64
81 :avocado: tags=machine:pc
82 """
83 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
84 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
85 '/vmlinuz')
86 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
87 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
89 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
90 console_pattern = 'VFS: Cannot open root device'
92 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
94 def test_aarch64_virt(self):
95 """
96 :avocado: tags=arch:aarch64
97 :avocado: tags=machine:virt
98 :avocado: tags=cpu:cortex-a53
99 """
100 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
101 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
102 '/vmlinuz')
103 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
104 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
106 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
107 'console=ttyAMA0')
108 console_pattern = 'VFS: Cannot open root device'
110 self.run_rr(kernel_path, kernel_command_line, console_pattern,
111 args=('-cpu', 'cortex-a53'))
113 def test_arm_virt(self):
115 :avocado: tags=arch:arm
116 :avocado: tags=machine:virt
118 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
119 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
120 '/vmlinuz')
121 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
122 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
124 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
125 'console=ttyAMA0')
126 console_pattern = 'VFS: Cannot open root device'
128 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=1)
130 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
131 @skipUnless(os.getenv('ARMBIAN_ARTIFACTS_CACHED'),
132 'Test artifacts fetched from unreliable apt.armbian.com')
133 def test_arm_cubieboard_initrd(self):
135 :avocado: tags=arch:arm
136 :avocado: tags=machine:cubieboard
138 deb_url = ('https://apt.armbian.com/pool/main/l/'
139 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
140 deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
141 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
142 kernel_path = self.extract_from_deb(deb_path,
143 '/boot/vmlinuz-4.20.7-sunxi')
144 dtb_path = '/usr/lib/linux-image-dev-sunxi/sun4i-a10-cubieboard.dtb'
145 dtb_path = self.extract_from_deb(deb_path, dtb_path)
146 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
147 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
148 'arm/rootfs-armv5.cpio.gz')
149 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
150 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
151 initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
152 archive.gzip_uncompress(initrd_path_gz, initrd_path)
154 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
155 'console=ttyS0,115200 '
156 'usbcore.nousb '
157 'panic=-1 noreboot')
158 console_pattern = 'Boot successful.'
159 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=1,
160 args=('-dtb', dtb_path,
161 '-initrd', initrd_path,
162 '-no-reboot'))
164 def test_ppc64_pseries(self):
166 :avocado: tags=arch:ppc64
167 :avocado: tags=machine:pseries
169 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
170 '/fedora-secondary/releases/29/Everything/ppc64le/os'
171 '/ppc/ppc64/vmlinuz')
172 kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
173 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
175 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
176 # icount is not good enough for PPC64 for complete boot yet
177 console_pattern = 'Kernel command line: %s' % kernel_command_line
178 self.run_rr(kernel_path, kernel_command_line, console_pattern)
180 def test_m68k_q800(self):
182 :avocado: tags=arch:m68k
183 :avocado: tags=machine:q800
185 deb_url = ('https://snapshot.debian.org/archive/debian-ports'
186 '/20191021T083923Z/pool-m68k/main'
187 '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
188 deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
189 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
190 kernel_path = self.extract_from_deb(deb_path,
191 '/boot/vmlinux-5.3.0-1-m68k')
193 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
194 'console=ttyS0 vga=off')
195 console_pattern = 'No filesystem could mount root'
196 self.run_rr(kernel_path, kernel_command_line, console_pattern)
198 def do_test_advcal_2018(self, file_path, kernel_name, args=None):
199 archive.extract(file_path, self.workdir)
201 for entry in os.scandir(self.workdir):
202 if entry.name.startswith('day') and entry.is_dir():
203 kernel_path = os.path.join(entry.path, kernel_name)
204 break
206 kernel_command_line = ''
207 console_pattern = 'QEMU advent calendar'
208 self.run_rr(kernel_path, kernel_command_line, console_pattern,
209 args=args)
211 def test_arm_vexpressa9(self):
213 :avocado: tags=arch:arm
214 :avocado: tags=machine:vexpress-a9
216 tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b'
217 tar_url = ('https://www.qemu-advent-calendar.org'
218 '/2018/download/day16.tar.xz')
219 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
220 dtb_path = self.workdir + '/day16/vexpress-v2p-ca9.dtb'
221 self.do_test_advcal_2018(file_path, 'winter.zImage',
222 args=('-dtb', dtb_path))
224 def test_m68k_mcf5208evb(self):
226 :avocado: tags=arch:m68k
227 :avocado: tags=machine:mcf5208evb
229 tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c'
230 tar_url = ('https://www.qemu-advent-calendar.org'
231 '/2018/download/day07.tar.xz')
232 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
233 self.do_test_advcal_2018(file_path, 'sanity-clause.elf')
235 def test_microblaze_s3adsp1800(self):
237 :avocado: tags=arch:microblaze
238 :avocado: tags=machine:petalogix-s3adsp1800
240 tar_hash = '08bf3e3bfb6b6c7ce1e54ab65d54e189f2caf13f'
241 tar_url = ('https://www.qemu-advent-calendar.org'
242 '/2018/download/day17.tar.xz')
243 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
244 self.do_test_advcal_2018(file_path, 'ballerina.bin')
246 def test_ppc64_e500(self):
248 :avocado: tags=arch:ppc64
249 :avocado: tags=machine:ppce500
250 :avocado: tags=cpu:e5500
252 tar_hash = '6951d86d644b302898da2fd701739c9406527fe1'
253 tar_url = ('https://www.qemu-advent-calendar.org'
254 '/2018/download/day19.tar.xz')
255 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
256 self.do_test_advcal_2018(file_path, 'uImage', ('-cpu', 'e5500'))
258 def test_ppc_g3beige(self):
260 :avocado: tags=arch:ppc
261 :avocado: tags=machine:g3beige
263 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
264 tar_url = ('https://www.qemu-advent-calendar.org'
265 '/2018/download/day15.tar.xz')
266 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
267 self.do_test_advcal_2018(file_path, 'invaders.elf',
268 args=('-M', 'graphics=off'))
270 def test_ppc_mac99(self):
272 :avocado: tags=arch:ppc
273 :avocado: tags=machine:mac99
275 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
276 tar_url = ('https://www.qemu-advent-calendar.org'
277 '/2018/download/day15.tar.xz')
278 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
279 self.do_test_advcal_2018(file_path, 'invaders.elf',
280 args=('-M', 'graphics=off'))
282 def test_sparc_ss20(self):
284 :avocado: tags=arch:sparc
285 :avocado: tags=machine:SS-20
287 tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f'
288 tar_url = ('https://www.qemu-advent-calendar.org'
289 '/2018/download/day11.tar.xz')
290 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
291 self.do_test_advcal_2018(file_path, 'zImage.elf')
293 def test_xtensa_lx60(self):
295 :avocado: tags=arch:xtensa
296 :avocado: tags=machine:lx60
297 :avocado: tags=cpu:dc233c
299 tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34'
300 tar_url = ('https://www.qemu-advent-calendar.org'
301 '/2018/download/day02.tar.xz')
302 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
303 self.do_test_advcal_2018(file_path, 'santas-sleigh-ride.elf',
304 args=('-cpu', 'dc233c'))