xref: /qemu/tests/functional/test_x86_64_replay.py (revision 55f5bf716a65f67663d0769bcb8c017764b3e53a)
10f31f0f5SThomas Huth#!/usr/bin/env python3
20f31f0f5SThomas Huth#
30f31f0f5SThomas Huth# Replay test that boots a Linux kernel on x86_64 machines
40f31f0f5SThomas Huth# and checks the console
50f31f0f5SThomas Huth#
60f31f0f5SThomas Huth# SPDX-License-Identifier: GPL-2.0-or-later
70f31f0f5SThomas Huth
8*7fecdb0aSThomas Huthfrom subprocess import check_call, DEVNULL
9*7fecdb0aSThomas Huth
10*7fecdb0aSThomas Huthfrom qemu_test import Asset, skipFlakyTest, get_qemu_img
110f31f0f5SThomas Huthfrom replay_kernel import ReplayKernelBase
120f31f0f5SThomas Huth
130f31f0f5SThomas Huth
140f31f0f5SThomas Huthclass X86Replay(ReplayKernelBase):
150f31f0f5SThomas Huth
160f31f0f5SThomas Huth    ASSET_KERNEL = Asset(
17*7fecdb0aSThomas Huth        'https://storage.tuxboot.com/buildroot/20241119/x86_64/bzImage',
18*7fecdb0aSThomas Huth        'f57bfc6553bcd6e0a54aab86095bf642b33b5571d14e3af1731b18c87ed5aef8')
190f31f0f5SThomas Huth
20*7fecdb0aSThomas Huth    ASSET_ROOTFS = Asset(
21*7fecdb0aSThomas Huth        'https://storage.tuxboot.com/buildroot/20241119/x86_64/rootfs.ext4.zst',
22*7fecdb0aSThomas Huth        '4b8b2a99117519c5290e1202cb36eb6c7aaba92b357b5160f5970cf5fb78a751')
23*7fecdb0aSThomas Huth
24*7fecdb0aSThomas Huth    def do_test_x86(self, machine, blkdevice, devroot):
25*7fecdb0aSThomas Huth        self.require_netdev('user')
260f31f0f5SThomas Huth        self.set_machine(machine)
27*7fecdb0aSThomas Huth        self.cpu="Nehalem"
280f31f0f5SThomas Huth        kernel_path = self.ASSET_KERNEL.fetch()
29*7fecdb0aSThomas Huth
30*7fecdb0aSThomas Huth        raw_disk = self.uncompress(self.ASSET_ROOTFS)
31*7fecdb0aSThomas Huth        disk = self.scratch_file('scratch.qcow2')
32*7fecdb0aSThomas Huth        qemu_img = get_qemu_img(self)
33*7fecdb0aSThomas Huth        check_call([qemu_img, 'create', '-f', 'qcow2', '-b', raw_disk,
34*7fecdb0aSThomas Huth                    '-F', 'raw', disk], stdout=DEVNULL, stderr=DEVNULL)
35*7fecdb0aSThomas Huth
36*7fecdb0aSThomas Huth        args = ('-drive', 'file=%s,snapshot=on,id=hd0,if=none' % disk,
37*7fecdb0aSThomas Huth                '-drive', 'driver=blkreplay,id=hd0-rr,if=none,image=hd0',
38*7fecdb0aSThomas Huth                '-device', '%s,drive=hd0-rr' % blkdevice,
39*7fecdb0aSThomas Huth                '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
40*7fecdb0aSThomas Huth                '-device', 'virtio-net,netdev=vnet',
41*7fecdb0aSThomas Huth                '-object', 'filter-replay,id=replay,netdev=vnet')
42*7fecdb0aSThomas Huth
43*7fecdb0aSThomas Huth        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
44*7fecdb0aSThomas Huth                               f"console=ttyS0 root=/dev/{devroot}")
45*7fecdb0aSThomas Huth        console_pattern = 'Welcome to TuxTest'
46*7fecdb0aSThomas Huth        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5,
47*7fecdb0aSThomas Huth                    args=args)
480f31f0f5SThomas Huth
490f31f0f5SThomas Huth    @skipFlakyTest('https://gitlab.com/qemu-project/qemu/-/issues/2094')
500f31f0f5SThomas Huth    def test_pc(self):
51*7fecdb0aSThomas Huth        self.do_test_x86('pc', 'virtio-blk', 'vda')
520f31f0f5SThomas Huth
530f31f0f5SThomas Huth    def test_q35(self):
54*7fecdb0aSThomas Huth        self.do_test_x86('q35', 'ide-hd', 'sda')
550f31f0f5SThomas Huth
560f31f0f5SThomas Huth
570f31f0f5SThomas Huthif __name__ == '__main__':
580f31f0f5SThomas Huth    ReplayKernelBase.main()
59