tests/acceptance/boot_linux: Accept SSH pubkey
[qemu.git] / tests / acceptance / replay_kernel.py
blob00c228382bdc5e898eff7a615f6108f337d0530e
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 lzma
13 import shutil
14 import logging
15 import time
17 from avocado import skipIf
18 from avocado import skipUnless
19 from avocado_qemu import wait_for_console_pattern
20 from avocado.utils import archive
21 from avocado.utils import process
22 from boot_linux_console import LinuxKernelTest
24 class ReplayKernelBase(LinuxKernelTest):
25 """
26 Boots a Linux kernel in record mode and checks that the console
27 is operational and the kernel command line is properly passed
28 from QEMU to the kernel.
29 Then replays the same scenario and verifies, that QEMU correctly
30 terminates.
31 """
33 timeout = 90
34 KERNEL_COMMON_COMMAND_LINE = 'printk.time=1 panic=-1 '
36 def run_vm(self, kernel_path, kernel_command_line, console_pattern,
37 record, shift, args, replay_path):
38 logger = logging.getLogger('replay')
39 start_time = time.time()
40 vm = self.get_vm()
41 vm.set_console()
42 if record:
43 logger.info('recording the execution...')
44 mode = 'record'
45 else:
46 logger.info('replaying the execution...')
47 mode = 'replay'
48 vm.add_args('-icount', 'shift=%s,rr=%s,rrfile=%s' %
49 (shift, mode, replay_path),
50 '-kernel', kernel_path,
51 '-append', kernel_command_line,
52 '-net', 'none',
53 '-no-reboot')
54 if args:
55 vm.add_args(*args)
56 vm.launch()
57 self.wait_for_console_pattern(console_pattern, vm)
58 if record:
59 vm.shutdown()
60 logger.info('finished the recording with log size %s bytes'
61 % os.path.getsize(replay_path))
62 else:
63 vm.wait()
64 logger.info('successfully finished the replay')
65 elapsed = time.time() - start_time
66 logger.info('elapsed time %.2f sec' % elapsed)
67 return elapsed
69 def run_rr(self, kernel_path, kernel_command_line, console_pattern,
70 shift=7, args=None):
71 replay_path = os.path.join(self.workdir, 'replay.bin')
72 t1 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
73 True, shift, args, replay_path)
74 t2 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
75 False, shift, args, replay_path)
76 logger = logging.getLogger('replay')
77 logger.info('replay overhead {:.2%}'.format(t2 / t1 - 1))
79 class ReplayKernelNormal(ReplayKernelBase):
80 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
81 def test_x86_64_pc(self):
82 """
83 :avocado: tags=arch:x86_64
84 :avocado: tags=machine:pc
85 """
86 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
87 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
88 '/vmlinuz')
89 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
90 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
92 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
93 console_pattern = 'VFS: Cannot open root device'
95 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
97 def test_mips_malta(self):
98 """
99 :avocado: tags=arch:mips
100 :avocado: tags=machine:malta
101 :avocado: tags=endian:big
103 deb_url = ('http://snapshot.debian.org/archive/debian/'
104 '20130217T032700Z/pool/main/l/linux-2.6/'
105 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
106 deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
107 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
108 kernel_path = self.extract_from_deb(deb_path,
109 '/boot/vmlinux-2.6.32-5-4kc-malta')
110 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
111 console_pattern = 'Kernel command line: %s' % kernel_command_line
113 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
115 def test_mips64el_malta(self):
117 This test requires the ar tool to extract "data.tar.gz" from
118 the Debian package.
120 The kernel can be rebuilt using this Debian kernel source [1] and
121 following the instructions on [2].
123 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
124 #linux-source-2.6.32_2.6.32-48
125 [2] https://kernel-team.pages.debian.net/kernel-handbook/
126 ch-common-tasks.html#s-common-official
128 :avocado: tags=arch:mips64el
129 :avocado: tags=machine:malta
131 deb_url = ('http://snapshot.debian.org/archive/debian/'
132 '20130217T032700Z/pool/main/l/linux-2.6/'
133 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
134 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
135 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
136 kernel_path = self.extract_from_deb(deb_path,
137 '/boot/vmlinux-2.6.32-5-5kc-malta')
138 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
139 console_pattern = 'Kernel command line: %s' % kernel_command_line
140 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
142 def test_aarch64_virt(self):
144 :avocado: tags=arch:aarch64
145 :avocado: tags=machine:virt
146 :avocado: tags=cpu:cortex-a53
148 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
149 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
150 '/vmlinuz')
151 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
152 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
154 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
155 'console=ttyAMA0')
156 console_pattern = 'VFS: Cannot open root device'
158 self.run_rr(kernel_path, kernel_command_line, console_pattern,
159 args=('-cpu', 'cortex-a53'))
161 def test_arm_virt(self):
163 :avocado: tags=arch:arm
164 :avocado: tags=machine:virt
166 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
167 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
168 '/vmlinuz')
169 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
170 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
172 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
173 'console=ttyAMA0')
174 console_pattern = 'VFS: Cannot open root device'
176 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=1)
178 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
179 @skipUnless(os.getenv('ARMBIAN_ARTIFACTS_CACHED'),
180 'Test artifacts fetched from unreliable apt.armbian.com')
181 def test_arm_cubieboard_initrd(self):
183 :avocado: tags=arch:arm
184 :avocado: tags=machine:cubieboard
186 deb_url = ('https://apt.armbian.com/pool/main/l/'
187 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
188 deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
189 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
190 kernel_path = self.extract_from_deb(deb_path,
191 '/boot/vmlinuz-4.20.7-sunxi')
192 dtb_path = '/usr/lib/linux-image-dev-sunxi/sun4i-a10-cubieboard.dtb'
193 dtb_path = self.extract_from_deb(deb_path, dtb_path)
194 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
195 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
196 'arm/rootfs-armv5.cpio.gz')
197 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
198 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
199 initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
200 archive.gzip_uncompress(initrd_path_gz, initrd_path)
202 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
203 'console=ttyS0,115200 '
204 'usbcore.nousb '
205 'panic=-1 noreboot')
206 console_pattern = 'Boot successful.'
207 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=1,
208 args=('-dtb', dtb_path,
209 '-initrd', initrd_path,
210 '-no-reboot'))
212 def test_ppc64_pseries(self):
214 :avocado: tags=arch:ppc64
215 :avocado: tags=machine:pseries
217 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
218 '/fedora-secondary/releases/29/Everything/ppc64le/os'
219 '/ppc/ppc64/vmlinuz')
220 kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
221 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
223 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
224 # icount is not good enough for PPC64 for complete boot yet
225 console_pattern = 'Kernel command line: %s' % kernel_command_line
226 self.run_rr(kernel_path, kernel_command_line, console_pattern)
228 def test_m68k_q800(self):
230 :avocado: tags=arch:m68k
231 :avocado: tags=machine:q800
233 deb_url = ('https://snapshot.debian.org/archive/debian-ports'
234 '/20191021T083923Z/pool-m68k/main'
235 '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
236 deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
237 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
238 kernel_path = self.extract_from_deb(deb_path,
239 '/boot/vmlinux-5.3.0-1-m68k')
241 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
242 'console=ttyS0 vga=off')
243 console_pattern = 'No filesystem could mount root'
244 self.run_rr(kernel_path, kernel_command_line, console_pattern)
246 def do_test_advcal_2018(self, file_path, kernel_name, args=None):
247 archive.extract(file_path, self.workdir)
249 for entry in os.scandir(self.workdir):
250 if entry.name.startswith('day') and entry.is_dir():
251 kernel_path = os.path.join(entry.path, kernel_name)
252 break
254 kernel_command_line = ''
255 console_pattern = 'QEMU advent calendar'
256 self.run_rr(kernel_path, kernel_command_line, console_pattern,
257 args=args)
259 def test_arm_vexpressa9(self):
261 :avocado: tags=arch:arm
262 :avocado: tags=machine:vexpress-a9
264 tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b'
265 tar_url = ('https://www.qemu-advent-calendar.org'
266 '/2018/download/day16.tar.xz')
267 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
268 dtb_path = self.workdir + '/day16/vexpress-v2p-ca9.dtb'
269 self.do_test_advcal_2018(file_path, 'winter.zImage',
270 args=('-dtb', dtb_path))
272 def test_m68k_mcf5208evb(self):
274 :avocado: tags=arch:m68k
275 :avocado: tags=machine:mcf5208evb
277 tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c'
278 tar_url = ('https://www.qemu-advent-calendar.org'
279 '/2018/download/day07.tar.xz')
280 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
281 self.do_test_advcal_2018(file_path, 'sanity-clause.elf')
283 def test_microblaze_s3adsp1800(self):
285 :avocado: tags=arch:microblaze
286 :avocado: tags=machine:petalogix-s3adsp1800
288 tar_hash = '08bf3e3bfb6b6c7ce1e54ab65d54e189f2caf13f'
289 tar_url = ('https://www.qemu-advent-calendar.org'
290 '/2018/download/day17.tar.xz')
291 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
292 self.do_test_advcal_2018(file_path, 'ballerina.bin')
294 def test_ppc64_e500(self):
296 :avocado: tags=arch:ppc64
297 :avocado: tags=machine:ppce500
298 :avocado: tags=cpu:e5500
300 tar_hash = '6951d86d644b302898da2fd701739c9406527fe1'
301 tar_url = ('https://www.qemu-advent-calendar.org'
302 '/2018/download/day19.tar.xz')
303 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
304 self.do_test_advcal_2018(file_path, 'uImage', ('-cpu', 'e5500'))
306 def test_ppc_g3beige(self):
308 :avocado: tags=arch:ppc
309 :avocado: tags=machine:g3beige
311 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
312 tar_url = ('https://www.qemu-advent-calendar.org'
313 '/2018/download/day15.tar.xz')
314 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
315 self.do_test_advcal_2018(file_path, 'invaders.elf',
316 args=('-M', 'graphics=off'))
318 def test_ppc_mac99(self):
320 :avocado: tags=arch:ppc
321 :avocado: tags=machine:mac99
323 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
324 tar_url = ('https://www.qemu-advent-calendar.org'
325 '/2018/download/day15.tar.xz')
326 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
327 self.do_test_advcal_2018(file_path, 'invaders.elf',
328 args=('-M', 'graphics=off'))
330 def test_sparc_ss20(self):
332 :avocado: tags=arch:sparc
333 :avocado: tags=machine:SS-20
335 tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f'
336 tar_url = ('https://www.qemu-advent-calendar.org'
337 '/2018/download/day11.tar.xz')
338 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
339 self.do_test_advcal_2018(file_path, 'zImage.elf')
341 def test_xtensa_lx60(self):
343 :avocado: tags=arch:xtensa
344 :avocado: tags=machine:lx60
345 :avocado: tags=cpu:dc233c
347 tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34'
348 tar_url = ('https://www.qemu-advent-calendar.org'
349 '/2018/download/day02.tar.xz')
350 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
351 self.do_test_advcal_2018(file_path, 'santas-sleigh-ride.elf',
352 args=('-cpu', 'dc233c'))
354 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
355 class ReplayKernelSlow(ReplayKernelBase):
356 # Override the timeout, because this kernel includes an inner
357 # loop which is executed with TB recompilings during replay,
358 # making it very slow.
359 timeout = 180
361 def test_mips_malta_cpio(self):
363 :avocado: tags=arch:mips
364 :avocado: tags=machine:malta
365 :avocado: tags=endian:big
366 :avocado: tags=slowness:high
368 deb_url = ('http://snapshot.debian.org/archive/debian/'
369 '20160601T041800Z/pool/main/l/linux/'
370 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
371 deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
372 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
373 kernel_path = self.extract_from_deb(deb_path,
374 '/boot/vmlinux-4.5.0-2-4kc-malta')
375 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
376 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
377 'mips/rootfs.cpio.gz')
378 initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
379 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
380 initrd_path = self.workdir + "rootfs.cpio"
381 archive.gzip_uncompress(initrd_path_gz, initrd_path)
383 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
384 'console=ttyS0 console=tty '
385 'rdinit=/sbin/init noreboot')
386 console_pattern = 'Boot successful.'
387 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5,
388 args=('-initrd', initrd_path))
390 @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
391 def test_mips64el_malta_5KEc_cpio(self):
393 :avocado: tags=arch:mips64el
394 :avocado: tags=machine:malta
395 :avocado: tags=endian:little
396 :avocado: tags=slowness:high
398 kernel_url = ('https://github.com/philmd/qemu-testing-blob/'
399 'raw/9ad2df38/mips/malta/mips64el/'
400 'vmlinux-3.19.3.mtoman.20150408')
401 kernel_hash = '00d1d268fb9f7d8beda1de6bebcc46e884d71754'
402 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
403 initrd_url = ('https://github.com/groeck/linux-build-test/'
404 'raw/8584a59e/rootfs/'
405 'mipsel64/rootfs.mipsel64r1.cpio.gz')
406 initrd_hash = '1dbb8a396e916847325284dbe2151167'
407 initrd_path_gz = self.fetch_asset(initrd_url, algorithm='md5',
408 asset_hash=initrd_hash)
409 initrd_path = self.workdir + "rootfs.cpio"
410 archive.gzip_uncompress(initrd_path_gz, initrd_path)
412 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
413 'console=ttyS0 console=tty '
414 'rdinit=/sbin/init noreboot')
415 console_pattern = 'Boot successful.'
416 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5,
417 args=('-initrd', initrd_path, '-cpu', '5KEc'))
419 def do_test_mips_malta32el_nanomips(self, kernel_path_xz):
420 kernel_path = self.workdir + "kernel"
421 with lzma.open(kernel_path_xz, 'rb') as f_in:
422 with open(kernel_path, 'wb') as f_out:
423 shutil.copyfileobj(f_in, f_out)
425 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
426 'mem=256m@@0x0 '
427 'console=ttyS0')
428 console_pattern = 'Kernel command line: %s' % kernel_command_line
429 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5,
430 args=('-cpu', 'I7200'))
432 def test_mips_malta32el_nanomips_4k(self):
434 :avocado: tags=arch:mipsel
435 :avocado: tags=machine:malta
436 :avocado: tags=endian:little
438 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
439 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
440 'generic_nano32r6el_page4k.xz')
441 kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
442 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
443 self.do_test_mips_malta32el_nanomips(kernel_path_xz)
445 def test_mips_malta32el_nanomips_16k_up(self):
447 :avocado: tags=arch:mipsel
448 :avocado: tags=machine:malta
449 :avocado: tags=endian:little
451 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
452 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
453 'generic_nano32r6el_page16k_up.xz')
454 kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
455 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
456 self.do_test_mips_malta32el_nanomips(kernel_path_xz)
458 def test_mips_malta32el_nanomips_64k_dbg(self):
460 :avocado: tags=arch:mipsel
461 :avocado: tags=machine:malta
462 :avocado: tags=endian:little
464 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
465 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
466 'generic_nano32r6el_page64k_dbg.xz')
467 kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
468 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
469 self.do_test_mips_malta32el_nanomips(kernel_path_xz)