xref: /openbmc/qemu/tests/avocado/multiprocess.py (revision 907b5105)
1# Test for multiprocess qemu
2#
3# This work is licensed under the terms of the GNU GPL, version 2 or
4# later.  See the COPYING file in the top-level directory.
5
6
7import os
8import socket
9
10from avocado_qemu import QemuSystemTest
11from avocado_qemu import wait_for_console_pattern
12from avocado_qemu import exec_command
13from avocado_qemu import exec_command_and_wait_for_pattern
14
15class Multiprocess(QemuSystemTest):
16    """
17    :avocado: tags=multiprocess
18    """
19    KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
20
21    def do_test(self, kernel_url, initrd_url, kernel_command_line,
22                machine_type):
23        """Main test method"""
24        self.require_accelerator('kvm')
25
26        # Create socketpair to connect proxy and remote processes
27        proxy_sock, remote_sock = socket.socketpair(socket.AF_UNIX,
28                                                    socket.SOCK_STREAM)
29        os.set_inheritable(proxy_sock.fileno(), True)
30        os.set_inheritable(remote_sock.fileno(), True)
31
32        kernel_path = self.fetch_asset(kernel_url)
33        initrd_path = self.fetch_asset(initrd_url)
34
35        # Create remote process
36        remote_vm = self.get_vm()
37        remote_vm.add_args('-machine', 'x-remote')
38        remote_vm.add_args('-nodefaults')
39        remote_vm.add_args('-device', 'lsi53c895a,id=lsi1')
40        remote_vm.add_args('-object', 'x-remote-object,id=robj1,'
41                           'devid=lsi1,fd='+str(remote_sock.fileno()))
42        remote_vm.launch()
43
44        # Create proxy process
45        self.vm.set_console()
46        self.vm.add_args('-machine', machine_type)
47        self.vm.add_args('-accel', 'kvm')
48        self.vm.add_args('-cpu', 'host')
49        self.vm.add_args('-object',
50                         'memory-backend-memfd,id=sysmem-file,size=2G')
51        self.vm.add_args('--numa', 'node,memdev=sysmem-file')
52        self.vm.add_args('-m', '2048')
53        self.vm.add_args('-kernel', kernel_path,
54                         '-initrd', initrd_path,
55                         '-append', kernel_command_line)
56        self.vm.add_args('-device',
57                         'x-pci-proxy-dev,'
58                         'id=lsi1,fd='+str(proxy_sock.fileno()))
59        self.vm.launch()
60        wait_for_console_pattern(self, 'as init process',
61                                 'Kernel panic - not syncing')
62        exec_command(self, 'mount -t sysfs sysfs /sys')
63        exec_command_and_wait_for_pattern(self,
64                                          'cat /sys/bus/pci/devices/*/uevent',
65                                          'PCI_ID=1000:0012')
66
67    def test_multiprocess_x86_64(self):
68        """
69        :avocado: tags=arch:x86_64
70        """
71        kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
72                      '/linux/releases/31/Everything/x86_64/os/images'
73                      '/pxeboot/vmlinuz')
74        initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
75                      '/linux/releases/31/Everything/x86_64/os/images'
76                      '/pxeboot/initrd.img')
77        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
78                               'console=ttyS0 rdinit=/bin/bash')
79        machine_type = 'pc'
80        self.do_test(kernel_url, initrd_url, kernel_command_line, machine_type)
81
82    def test_multiprocess_aarch64(self):
83        """
84        :avocado: tags=arch:aarch64
85        """
86        kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
87                      '/linux/releases/31/Everything/aarch64/os/images'
88                      '/pxeboot/vmlinuz')
89        initrd_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
90                      '/linux/releases/31/Everything/aarch64/os/images'
91                      '/pxeboot/initrd.img')
92        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
93                               'rdinit=/bin/bash console=ttyAMA0')
94        machine_type = 'virt,gic-version=3'
95        self.do_test(kernel_url, initrd_url, kernel_command_line, machine_type)
96