| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Functional test that hotplugs a CPU and checks it on a Linux guest |
| 4 | # |
| 5 | # Copyright (c) 2021 Red Hat, Inc. |
| 6 | # |
| 7 | # Author: |
| 8 | # Cleber Rosa <crosa@redhat.com> |
| 9 | # |
| 10 | # This work is licensed under the terms of the GNU GPL, version 2 or |
| 11 | # later. See the COPYING file in the top-level directory. |
| 12 | |
| 13 | from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern |
| 14 | |
| 15 | |
| 16 | class HotPlugCPU(LinuxKernelTest): |
| 17 | |
| 18 | ASSET_KERNEL = Asset( |
| 19 | ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases' |
| 20 | '/31/Server/x86_64/os/images/pxeboot/vmlinuz'), |
| 21 | 'd4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129') |
| 22 | |
| 23 | ASSET_INITRD = Asset( |
| 24 | ('https://archives.fedoraproject.org/pub/archive/fedora/linux/releases' |
| 25 | '/31/Server/x86_64/os/images/pxeboot/initrd.img'), |
| 26 | '277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b') |
| 27 | |
| 28 | def test_hotplug(self): |
| 29 | |
| 30 | self.require_accelerator('kvm') |
| 31 | self.vm.add_args('-accel', 'kvm') |
| 32 | self.vm.add_args('-cpu', 'Haswell') |
| 33 | self.vm.add_args('-smp', '1,sockets=1,cores=2,threads=1,maxcpus=2') |
| 34 | self.vm.add_args('-m', '1G') |
| 35 | self.vm.add_args('-append', 'console=ttyS0 rd.rescue') |
| 36 | |
| 37 | self.launch_kernel(self.ASSET_KERNEL.fetch(), |
| 38 | self.ASSET_INITRD.fetch(), |
| 39 | wait_for='Entering emergency mode.') |
| 40 | prompt = '# ' |
| 41 | self.wait_for_console_pattern(prompt) |
| 42 | |
| 43 | exec_command_and_wait_for_pattern(self, |
| 44 | 'cd /sys/devices/system/cpu/cpu0', |
| 45 | 'cpu0#') |
| 46 | exec_command_and_wait_for_pattern(self, |
| 47 | 'cd /sys/devices/system/cpu/cpu1', |
| 48 | 'No such file or directory') |
| 49 | |
| 50 | self.vm.cmd('device_add', |
| 51 | driver='Haswell-x86_64-cpu', |
| 52 | id='c1', |
| 53 | socket_id=0, |
| 54 | core_id=1, |
| 55 | thread_id=0) |
| 56 | self.wait_for_console_pattern('CPU1 has been hot-added') |
| 57 | |
| 58 | exec_command_and_wait_for_pattern(self, |
| 59 | 'cd /sys/devices/system/cpu/cpu1', |
| 60 | 'cpu1#') |
| 61 | |
| 62 | exec_command_and_wait_for_pattern(self, 'cd ..', prompt) |
| 63 | self.vm.cmd('device_del', id='c1') |
| 64 | |
| 65 | exec_command_and_wait_for_pattern(self, |
| 66 | 'while cd /sys/devices/system/cpu/cpu1 ;' |
| 67 | ' do sleep 0.2 ; done', |
| 68 | 'No such file or directory') |
| 69 | |
| 70 | if __name__ == '__main__': |
| 71 | LinuxKernelTest.main() |