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