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