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