def run(test, params, env): """ Boot guest with iommu_platform, then do ping test 1) Boot a VM with iommu_platform=on 2) add intel_iommu=on in guest kernel line 3) reboot guest 4) do ping test :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ if utils_misc.get_cpu_vendor(verbose=False) != 'GenuineIntel': test.cancel("This case only support Intel platform") login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) ping_count = int(params.get("ping_count", 10)) guest_ip = vm.get_address() try: status, output = utils_test.ping(guest_ip, ping_count, timeout=float(ping_count) * 1.5) if status != 0: test.fail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) if package_lost != 0: test.fail("%s packeage lost when ping guest ip %s " % (package_lost, guest_ip)) finally: session.close()
def get_kvm_module_list(): if ARCH == 'x86_64': arch_convert = {'GenuineIntel': 'intel', 'AuthenticAMD': 'amd'} host_cpu_type = utils_misc.get_cpu_vendor(verbose=False) return ["kvm", "kvm-%s" % arch_convert[host_cpu_type]] elif ARCH == 'ppc64': return ["kvm"]
def test_cpu_vendor_amd(self): cpu_info = """processor : 3 vendor_id : AuthenticAMD cpu family : 21 model : 16 model name : AMD A10-5800K APU with Radeon(tm) HD Graphics """ vendor = utils_misc.get_cpu_vendor(cpu_info, False) self.assertEqual(vendor, 'AuthenticAMD')
def test_cpu_vendor_intel(self): cpu_info = """processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz """ vendor = utils_misc.get_cpu_vendor(cpu_info, False) self.assertEqual(vendor, 'GenuineIntel')
def run(test, params, env): """ boot cpu model test: steps: 1). boot guest with cpu model 2). check flags if enable_check == "yes", otherwise shutdown guest :param test: QEMU test object :param params: Dictionary with the test parameters """ cpu_vendor = utils_misc.get_cpu_vendor() host_model = utils_misc.get_host_cpu_models() model_list = params.get("cpu_model") if not model_list: if cpu_vendor == "unknow": raise error.TestError("unknow cpu vendor") else: model_list = params.get("cpu_model_%s" % cpu_vendor, host_model[-1]) extra_flags = params.get("cpu_model_flags_%s" % cpu_vendor, "") if extra_flags: cpu_flags = params.get("cpu_model_flags", "") + extra_flags params["cpu_model_flags"] = cpu_flags if model_list: model_list = model_list.split(" ") for model in model_list: if model in host_model or model == "host": params["cpu_model"] = model params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params["main_vm"]) # check guest flags if params.get("enable_check", "no") == "yes": utils_test.run_virt_sub_test(test, params, env, sub_type="flag_check") else: # log in and shutdown guest utils_test.run_virt_sub_test(test, params, env, sub_type="shutdown") logging.info("shutdown guest successfully") else: if params.get("enable_check", "no") == "yes": raise error.TestWarn("Can not test %s model on %s host, " "pls use %s host" % (model, host_model[0], model))
def run_boot_cpu_model(test, params, env): """ boot cpu model test: steps: 1). boot guest with cpu model 2). check flags if enable_check == "yes", otherwise shutdown guest :param test: QEMU test object :param params: Dictionary with the test parameters """ cpu_vendor = utils_misc.get_cpu_vendor() host_model = utils_misc.get_host_cpu_models() model_list = params.get("cpu_model") if not model_list: if cpu_vendor == "unknow": raise error.TestError("unknow cpu vendor") else: model_list = params.get("cpu_model_%s" % cpu_vendor, host_model[-1]) extra_flags = params.get("cpu_model_flags_%s" % cpu_vendor, "") if extra_flags: cpu_flags = params.get("cpu_model_flags", "") + extra_flags params["cpu_model_flags"] = cpu_flags if model_list: model_list = model_list.split(" ") for model in model_list: if model in host_model or model == "host": params["cpu_model"] = model params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params["main_vm"]) # check guest flags if params.get("enable_check", "no") == "yes": utils_test.run_virt_sub_test(test, params, env, sub_type="flag_check") else: # log in and shutdown guest utils_test.run_virt_sub_test(test, params, env, sub_type="shutdown") logging.info("shutdown guest successfully") else: if params.get("enable_check", "no") == "yes": raise error.TestWarn("Can not test %s model on %s host, " "pls use %s host" % (model, host_model[0], model))
#!/usr/bin/python """ Program to help setup kvm test environment @copyright: Red Hat 2010 """ import os, sys try: import autotest.common as common except ImportError: import common from virttest import utils_misc test_name = "kvm" test_dir = os.path.dirname(sys.modules[__name__].__file__) test_dir = os.path.abspath(test_dir) base_dir = "/tmp/kvm_autotest_root" default_userspace_paths = ["/usr/bin/qemu-kvm", "/usr/bin/qemu-img"] check_modules = ["kvm", "kvm-%s" % utils_misc.get_cpu_vendor(verbose=False)] online_docs_url = "https://github.com/autotest/autotest/wiki/KVMAutotest-GetStartedClient" if __name__ == "__main__": utils_misc.virt_test_assistant(test_name, test_dir, base_dir, default_userspace_paths, check_modules, online_docs_url)
def get_kvm_module_list(): if ARCH == 'x86_64': return ["kvm", "kvm-%s" % utils_misc.get_cpu_vendor(verbose=False)] elif ARCH == 'ppc64': return ["kvm"]
def run(test, params, env): """ Qemu reboot test: 1) Start qemu to get cpu model supported by host 3) Boot guest with the cpu model 4) Check cpu model name in guest 5) Check cpu flags in guest(only for linux guest) 6) Reboot guest :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ error_context.context("Start qemu to get support cpu model", logging.info) vm = env.get_vm(params["main_vm"]) out = vm.monitor.info("cpu-definitions") vm.destroy() model = params["model"] model_pattern = params["model_pattern"] flags = params["flags"] if utils_misc.get_cpu_vendor(verbose=False) == 'GenuineIntel': model_ib = "%s-IBRS" % model flag_ib = " ibpb ibrs" name_ib = ", IBRS( update)?" else: model_ib = "%s-IBPB" % model flag_ib = " ibpb" name_ib = " \\(with IBPB\\)" models = [x["name"] for x in out if not x["unavailable-features"]] if model_ib in models: cpu_model = model_ib guest_model = model_pattern % name_ib flags += flag_ib elif model in models: cpu_model = model guest_model = model_pattern % "" else: test.cancel("This host doesn't support cpu model %s" % model) params["paused_after_start_vm"] = "no" params["cpu_model"] = cpu_model vm.create(params=params) vm.verify_alive() error_context.context("Try to log into guest", logging.info) session = vm.wait_for_login() error_context.context("Check cpu model inside guest", logging.info) cmd = params["get_model_cmd"] out = session.cmd_output(cmd) if not re.search(guest_model, out): 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) if params.get("reboot_method"): error_context.context("Reboot guest '%s'." % vm.name, logging.info) vm.reboot(session=session) vm.verify_kernel_crash() session.close()
def test_vendor_unknown(self): cpu_info = "this is an unknown cpu" vendor = utils_misc.get_cpu_vendor(cpu_info, False) self.assertEqual(vendor, 'unknown')