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