未验证 提交 37665cea 编写于 作者: Q Qianqian Zhu 提交者: GitHub

Merge pull request #2265 from nanliu-r/cpu_model

new case: Support memory protection key
- x86_cpu_flags:
type = x86_cpu_flags
cpu_model_flags += ",enforce,-mpx"
kill_vm_on_error = yes
start_vm = no
check_host_flags = yes
reboot_method = "shell"
only i386, x86_64
check_flag_cmd = "lscpu | grep Flags | awk -F ':' '{print $2}'"
variants:
- intel:
vendor_id = 'intel'
variants:
- memory_protection_key:
cpu_model_flags += ",+pku,check"
flags = "pku ospke"
import logging
from avocado.utils import cpu
from virttest import error_context, env_process
from qemu.tests.x86_cpu_model import check_flags
@error_context.context_aware
def run(test, params, env):
"""
Test cpu flags.
1) Check if current flags are in the supported lists, 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.
"""
vendor_id = params.get("vendor_id", "")
if vendor_id:
if vendor_id != cpu.get_vendor():
test.cancel("Need host vendor %s to support this test case" % vendor_id)
flags = params["flags"]
check_host_flags = params.get_boolean("check_host_flags")
if check_host_flags:
check_flags(params, flags, test)
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", logging.info)
session = vm.wait_for_login()
if params["os_type"] == "linux":
check_flags(params, flags, test, session)
if params.get("reboot_method"):
error_context.context("Reboot guest '%s'." % vm.name, logging.info)
session = vm.reboot(session=session)
vm.verify_kernel_crash()
session.close()
......@@ -6,6 +6,35 @@ from avocado.utils import cpu, process
from virttest import error_context, utils_misc, env_process
def check_flags(params, flags, test, session=None):
"""
Check cpu flags on host or guest.(only for Linux now)
:param params: Dictionary with the test parameters
:param flags: checked flags
:param test: QEMU test object
:param session: guest session
"""
cmd = params["check_flag_cmd"]
func = process.getoutput
if session:
func = session.cmd_output
out = func(cmd).split()
missing = [f for f in flags.split() if f not in out]
if session:
error_context.context("Check cpu flags inside guest", logging.info)
if missing:
test.fail("Flag %s not in guest" % missing)
no_flags = params.get("no_flags")
if no_flags:
err_flags = [f for f in no_flags.split() if f in out]
if err_flags:
test.fail("Flag %s should not be present in guest" % err_flags)
else:
error_context.context("Check cpu flags on host", logging.info)
if missing:
test.cancel("This host doesn't support flag %s" % missing)
@error_context.context_aware
def run(test, params, env):
"""
......@@ -72,21 +101,11 @@ def run(test, params, env):
test.fail("Guest cpu model is not right")
if params["os_type"] == "linux":
error_context.context("Check cpu flags inside guest", logging.info)
cmd = params["check_flag_cmd"]
out = session.cmd_output(cmd).split()
missing = [f for f in flags.split() if f not in out]
if missing:
test.fail("Flag %s not in guest" % missing)
no_flags = params.get("no_flags")
if no_flags:
err_flags = [f for f in no_flags.split() if f in out]
if err_flags:
test.fail("Flag %s should not be present in guest" % err_flags)
check_flags(params, flags, test, session)
if params.get("reboot_method"):
error_context.context("Reboot guest '%s'." % vm.name, logging.info)
vm.reboot(session=session)
session = vm.reboot(session=session)
vm.verify_kernel_crash()
session.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册