From cfc6837cab43aa98719a8e8ffbcca99a3e70f248 Mon Sep 17 00:00:00 2001 From: Xudong Hao Date: Wed, 11 Dec 2024 16:12:28 +0800 Subject: [PATCH 1/2] KVM: Add CPU offline/online cases with TD/VM booting Signed-off-by: Xudong Hao --- KVM/qemu/host_cpu_offline_online.cfg | 18 +++++++++ KVM/qemu/tests/host_cpu_offline_online.py | 45 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 KVM/qemu/host_cpu_offline_online.cfg create mode 100644 KVM/qemu/tests/host_cpu_offline_online.py diff --git a/KVM/qemu/host_cpu_offline_online.cfg b/KVM/qemu/host_cpu_offline_online.cfg new file mode 100644 index 0000000..99df741 --- /dev/null +++ b/KVM/qemu/host_cpu_offline_online.cfg @@ -0,0 +1,18 @@ +- host_cpu_offline_online: + type = host_cpu_offline_online + virt_test_type = qemu + vm_accelerator = kvm + # Don't create/remove guest images + force_create_image = no + remove_image = no + # Automatically start VM + start_vm = yes + # Stop VM after testing + kill_vm = yes + variants: + - vm: + - tdvm: + machine_type_extra_params = "kernel-irqchip=split" + vm_secure_guest_type = tdx + auto_cpu_model = "no" + cpu_model = host diff --git a/KVM/qemu/tests/host_cpu_offline_online.py b/KVM/qemu/tests/host_cpu_offline_online.py new file mode 100644 index 0000000..b01bb17 --- /dev/null +++ b/KVM/qemu/tests/host_cpu_offline_online.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) 2024 Intel Corporation + +# Author: Xudong Hao +# +# History: Dec. 2024 - Xudong Hao - creation + +import random +from avocado.utils import cpu + +from virttest.cpu import check_if_vm_vcpu_match + + +def run(test, params, env): + """ + pCPU offline/online test: + 1) Launch a guest with many CPU. + 2) Offline 3 random online pCPU. + 3) Check guest's status + 4) Online the offlined pCPU again. + + :param test: QEMU test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + vm = env.get_vm(params["main_vm"]) + vcpus = params["smp"] + vm.verify_alive() + timeout = params.get_numeric("login_timeout", 240) + session = vm.wait_for_login(timeout=timeout) + + host_cpu_list = cpu.online_list() + processor_list = random.sample(host_cpu_list, 3) + for processor in processor_list: + cpu.offline(processor) + test.log.info("CPUs {} have been offline.".format(processor_list)) + if not check_if_vm_vcpu_match(vcpus, vm): + test.fail("vCPU quantity on guest mismatch after offline") + + for processor in processor_list: + cpu.online(processor) + test.log.info("CPUs {} have been online.".format(processor_list)) + session.close() From 1546b5833491f9f8184153ca0e32eac72e4656a1 Mon Sep 17 00:00:00 2001 From: Xudong Hao Date: Thu, 12 Dec 2024 08:44:09 +0800 Subject: [PATCH 2/2] Fix a tiny cfg format issue Signed-off-by: Xudong Hao --- KVM/qemu/host_cpu_offline_online.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KVM/qemu/host_cpu_offline_online.cfg b/KVM/qemu/host_cpu_offline_online.cfg index 99df741..6550c6a 100644 --- a/KVM/qemu/host_cpu_offline_online.cfg +++ b/KVM/qemu/host_cpu_offline_online.cfg @@ -1,5 +1,5 @@ - host_cpu_offline_online: - type = host_cpu_offline_online + type = host_cpu_offline_online virt_test_type = qemu vm_accelerator = kvm # Don't create/remove guest images