Skip to content

Commit

Permalink
Add 4 test cases to test TSC deadline cpu flag
Browse files Browse the repository at this point in the history
x86_cpu_flags.tsc_deadline.default.tdvm
x86_cpu_flags.tsc_deadline.disable.tdvm
x86_cpu_flags.tsc_deadline.default.vm
x86_cpu_flags.tsc_deadline.disable.vm

Signed-off-by: Xudong Hao <[email protected]>
  • Loading branch information
xhao22 committed Jul 4, 2024
1 parent c4f27dd commit e9ae287
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
72 changes: 72 additions & 0 deletions KVM/qemu/tests/x86_cpu_flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; specifically version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat (c) 2024 and Avocado contributors
# Copy from tp-qemu

from virttest import error_context, env_process, cpu
from provider.cpu_utils import check_cpu_flags


@error_context.context_aware
def run(test, params, env):
"""
Test cpu flags.
1) Check if current flags are in the supported lists on host, if no, cancel test
2) Otherwise, boot guest with the cpu flags
3) Check cpu flags inside guest(only for linux guest)
4) Reboot guest
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
flags = params["flags"]
check_host_flags = params.get_boolean("check_host_flags")
if check_host_flags:
check_cpu_flags(params, flags, test)

unsupported_models = params.get("unsupported_models", "")
cpu_model = params.get("cpu_model")
if not cpu_model:
cpu_model = cpu.get_qemu_best_cpu_model(params)
if cpu_model in unsupported_models.split():
test.cancel("'%s' doesn't support this test case" % cpu_model)
fallback_models_map = eval(params.get('fallback_models_map', '{}'))
if cpu_model in fallback_models_map.keys():
params["cpu_model"] = fallback_models_map[cpu_model]

params["start_vm"] = "yes"
vm_name = params['main_vm']
env_process.preprocess_vm(test, params, env, vm_name)

vm = env.get_vm(vm_name)
error_context.context("Try to log into guest", test.log.info)
session = vm.wait_for_login()
if params["os_type"] == "linux":
if params.get("guest_flags"):
flags = params.get("guest_flags")
if params.get("no_flags", "") == flags:
flags = ""
check_guest_cmd = params.get("check_guest_cmd")
check_cpu_flags(params, flags, test, session)
if check_guest_cmd:
expect_items = params.get("expect_items")
if expect_items:
result = session.cmd_status(check_guest_cmd % expect_items)
if result:
test.fail("'%s' can't be found inside guest" % expect_items)

if params.get("reboot_method"):
error_context.context("Reboot guest '%s'." % vm.name, test.log.info)
session = vm.reboot(session=session)

vm.verify_kernel_crash()
session.close()
25 changes: 25 additions & 0 deletions KVM/qemu/x86_cpu_flags.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- x86_cpu_flags:
type = x86_cpu_flags
kill_vm_on_error = yes
start_vm = no
check_host_flags = yes
only i386, x86_64
variants:
- vm:
# Only No-TDVM supports soft reboot
reboot_method = "shell"
- tdvm:
# TDVM doesn't support soft reboot
machine_type_extra_params = "kernel-irqchip=split"
vm_secure_guest_type = tdx
vga = std
variants:
- tsc_deadline:
auto_cpu_model = "no"
cpu_model = host
flags = "tsc_deadline_timer"
variants:
- default:
- disable:
cpu_model_flags = ",-tsc-deadline"
no_flags = "tsc_deadline_timer"

0 comments on commit e9ae287

Please sign in to comment.