| 1 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | # |
| 3 | # Test for multiprocess qemu |
| 4 | # |
| 5 | # This work is licensed under the terms of the GNU GPL, version 2 or |
| 6 | # later. See the COPYING file in the top-level directory. |
| 7 | |
| 8 | |
| 9 | import os |
| 10 | import socket |
| 11 | |
| 12 | from qemu_test import QemuSystemTest, wait_for_console_pattern |
| 13 | from qemu_test import exec_command, exec_command_and_wait_for_pattern |
| 14 | |
| 15 | class Multiprocess(QemuSystemTest): |
| 16 | |
| 17 | KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' |
| 18 | |
| 19 | def do_test(self, kernel_asset, initrd_asset, |
| 20 | kernel_command_line, machine_type): |
| 21 | """Main test method""" |
| 22 | self.require_accelerator('kvm') |
| 23 | self.require_device('x-pci-proxy-dev') |
| 24 | |
| 25 | # Create socketpair to connect proxy and remote processes |
| 26 | proxy_sock, remote_sock = socket.socketpair(socket.AF_UNIX, |
| 27 | socket.SOCK_STREAM) |
| 28 | os.set_inheritable(proxy_sock.fileno(), True) |
| 29 | os.set_inheritable(remote_sock.fileno(), True) |
| 30 | |
| 31 | kernel_path = kernel_asset.fetch() |
| 32 | initrd_path = initrd_asset.fetch() |
| 33 | |
| 34 | # Create remote process |
| 35 | remote_vm = self.get_vm() |
| 36 | remote_vm.add_args('-machine', 'x-remote') |
| 37 | remote_vm.add_args('-nodefaults') |
| 38 | remote_vm.add_args('-device', 'lsi53c895a,id=lsi1') |
| 39 | remote_vm.add_args('-object', 'x-remote-object,id=robj1,' |
| 40 | 'devid=lsi1,fd='+str(remote_sock.fileno())) |
| 41 | remote_vm.launch() |
| 42 | |
| 43 | # Create proxy process |
| 44 | self.vm.set_console() |
| 45 | self.vm.add_args('-machine', machine_type) |
| 46 | self.vm.add_args('-accel', 'kvm') |
| 47 | self.vm.add_args('-cpu', 'host') |
| 48 | self.vm.add_args('-object', |
| 49 | 'memory-backend-memfd,id=sysmem-file,size=2G') |
| 50 | self.vm.add_args('--numa', 'node,memdev=sysmem-file') |
| 51 | self.vm.add_args('-m', '2048') |
| 52 | self.vm.add_args('-kernel', kernel_path, |
| 53 | '-initrd', initrd_path, |
| 54 | '-append', kernel_command_line) |
| 55 | self.vm.add_args('-device', |
| 56 | 'x-pci-proxy-dev,' |
| 57 | 'id=lsi1,fd='+str(proxy_sock.fileno())) |
| 58 | self.vm.launch() |
| 59 | wait_for_console_pattern(self, 'as init process', |
| 60 | 'Kernel panic - not syncing') |
| 61 | exec_command(self, 'mount -t sysfs sysfs /sys') |
| 62 | exec_command_and_wait_for_pattern(self, |
| 63 | 'cat /sys/bus/pci/devices/*/uevent', |
| 64 | 'PCI_ID=1000:0012') |
| 65 | |
| 66 | proxy_sock.close() |
| 67 | remote_sock.close() |