tests/acceptance: add kernel record/replay test for x86_64
[qemu/ar7.git] / tests / acceptance / replay_kernel.py
blob64956e85f19236c8d71d84c84b7624d29861e3ec
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_qemu import wait_for_console_pattern
17 from avocado.utils import archive
18 from avocado.utils import process
19 from boot_linux_console import LinuxKernelTest
21 class ReplayKernel(LinuxKernelTest):
22 """
23 Boots a Linux kernel in record mode and checks that the console
24 is operational and the kernel command line is properly passed
25 from QEMU to the kernel.
26 Then replays the same scenario and verifies, that QEMU correctly
27 terminates.
28 """
30 timeout = 90
31 KERNEL_COMMON_COMMAND_LINE = 'printk.time=1 panic=-1 '
33 def run_vm(self, kernel_path, kernel_command_line, console_pattern,
34 record, shift, args, replay_path):
35 logger = logging.getLogger('replay')
36 start_time = time.time()
37 vm = self.get_vm()
38 vm.set_console()
39 if record:
40 logger.info('recording the execution...')
41 mode = 'record'
42 else:
43 logger.info('replaying the execution...')
44 mode = 'replay'
45 vm.add_args('-icount', 'shift=%s,rr=%s,rrfile=%s' %
46 (shift, mode, replay_path),
47 '-kernel', kernel_path,
48 '-append', kernel_command_line,
49 '-net', 'none',
50 '-no-reboot')
51 if args:
52 vm.add_args(*args)
53 vm.launch()
54 self.wait_for_console_pattern(console_pattern, vm)
55 if record:
56 vm.shutdown()
57 logger.info('finished the recording with log size %s bytes'
58 % os.path.getsize(replay_path))
59 else:
60 vm.wait()
61 logger.info('successfully finished the replay')
62 elapsed = time.time() - start_time
63 logger.info('elapsed time %.2f sec' % elapsed)
64 return elapsed
66 def run_rr(self, kernel_path, kernel_command_line, console_pattern,
67 shift=7, args=None):
68 replay_path = os.path.join(self.workdir, 'replay.bin')
69 t1 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
70 True, shift, args, replay_path)
71 t2 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
72 False, shift, args, replay_path)
73 logger = logging.getLogger('replay')
74 logger.info('replay overhead {:.2%}'.format(t2 / t1 - 1))
76 @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI')
77 def test_x86_64_pc(self):
78 """
79 :avocado: tags=arch:x86_64
80 :avocado: tags=machine:pc
81 """
82 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
83 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
84 '/vmlinuz')
85 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
86 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
88 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
89 console_pattern = 'VFS: Cannot open root device'
91 self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)