Ejemplo n.º 1
0
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 disabled
    3) Check cpu flags inside guest(only for linux guest)
    4) Check kvmclock inside guest(only for linux guest)

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """

    flag = params["flags"]
    check_host_flags = params.get_boolean("check_host_flags")
    if check_host_flags:
        check_cpu_flags(params, flag, 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", test.log.info)
    session = vm.wait_for_login()
    check_cpu_flags(params, '', test, session)

    check_clock = params.get("check_clock")
    vm_clock_out = session.cmd_output(check_clock).split()
    if 'kvmclock' in vm_clock_out:
        test.fail("kvmclock shouldn't be found inside geust")

    vm.verify_kernel_crash()
    session.close()
Ejemplo n.º 2
0
def run(test, params, env):
    """
    support Virtual SPEC_CTRL inside guest

    1. check the 'v_spec_ctrl' on supported host
    2. add guest kernel command line 'spec_store_bypass_disable=on'
    3. verify the guest sets the spec ctrl properly on all the cpus.

    :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)

    supported_models = params.get("supported_models", "")
    cpu_model = params.get("cpu_model")
    if not cpu_model:
        cpu_model = cpu.get_qemu_best_cpu_model(params)
    if cpu_model not in supported_models.split():
        test.cancel("'%s' doesn't support this test case" % cpu_model)

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

    proc_cmdline = params["proc_cmdline"]
    vm = env.get_vm(vm_name)
    session = vm.wait_for_login()
    boot_option = params["boot_option"]
    check_output = str(session.cmd(proc_cmdline, timeout=60)).split()
    if boot_option and boot_option not in check_output:
        error_context.context("Add '%s' to guest" % boot_option, test.log.info)
        update_boot_option(vm, args_added=boot_option)
        session = vm.wait_for_login()

    test_dir = params["test_dir"]
    source_file = params["source_file"]
    src_msr = os.path.join(data_dir.get_deps_dir(), source_file)
    vm.copy_files_to(src_msr, test_dir)
    guest_dir = params["guest_dir"]
    compile_cmd = params["compile_cmd"]
    try:
        session.cmd(compile_cmd % guest_dir)
        check_msr = 'cd %s && ' % guest_dir + params["check_msr"]
        result = session.cmd_output(check_msr)
        nums_vcpus = session.cmd_output("grep processor /proc/cpuinfo -c")
        if result != nums_vcpus:
            test.fail("verify the guest sets the spec ctrl failed.")
    finally:
        session.cmd("rm -rf %s/msr* %s/master*" % (test_dir, test_dir))
        session.close()
        vm.verify_kernel_crash()
        if boot_option and boot_option not in check_output:
            update_boot_option(vm, args_removed=boot_option)
Ejemplo n.º 3
0
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", logging.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, logging.info)
        session = vm.reboot(session=session)

    vm.verify_kernel_crash()
    session.close()
Ejemplo n.º 4
0
def run(test, params, env):
    def get_sve_supported_lengths():
        """
        Get supported SVE lengths of host.
        """
        output = vm.monitor.query_cpu_model_expansion(vm.cpuinfo.model)
        output.pop('sve')
        sve_list = [sve for sve in output if output[sve] is True and
                    sve.startswith('sve')]
        sve_list.sort(key=lambda x: int(x[3:]))
        return sve_list

    def launch_sve_guest(sve_opts, check_length):
        """
        Launch a guest with the given SVE options.

        :param sve_opts: List of SVE options to be used.
        :param check_length: SVE length to be checked in dmesg.
        """
        logging.info('Launch a guest with %s', sve_opts)
        params['cpu_model_flags'] = 'sve=on,' + ','.join(sve_opts)
        vm.create(params=params)
        vm.verify_alive()
        session = vm.wait_for_login()
        sve_output = session.cmd_output('dmesg | grep SVE').strip()
        if re.findall('vector length {} bytes'.format(check_length * 8),
                      sve_output, re.M):
            test.fail('SVE length is incorrect, output:\n{}'.format(sve_output))
        session.close()
        vm.destroy()

    cpu_utils.check_cpu_flags(params, 'sve', test)
    vm = env.get_vm(params["main_vm"])
    sve_lengths = get_sve_supported_lengths()
    vm.destroy()

    error_context.context('Launch a guest with sve=on', logging.info)
    for length in sve_lengths:
        opts = ('{}={}'.format(
            sve, 'on' if sve_lengths.index(sve) <= sve_lengths.index(length)
            else 'off'
        ) for sve in sve_lengths)
        launch_sve_guest(opts, length)

    error_context.context('Launch a guest with sve=off', logging.info)
    opts = ('{}={}'.format(sve, 'off') for sve in sve_lengths)
    params['cpu_model_flags'] = 'sve=off,' + ','.join(opts)
    vm.create(params=params)
    vm.verify_alive()
    session = vm.wait_for_login()
    if session.cmd_output('dmesg | grep SVE'):
        test.fail('The guest gets the SVE feature without using SVE to start')
Ejemplo n.º 5
0
def run(test, params, env):
    """
    Test cpu flag intel-pt.
    1) Check if current flags are in the supported lists, if no, cancel test
    2) Otherwise, set pt_mode = 1 on host at first
    3) Boot guest with cpu model 'host' without intel-pt.
    4) Check cpu flags in guest(only for linux guest)
    5) For q35
       5.1) boot guest with cpu model with intel-pt
    6) For pc
       6.1) boot guest with intel-pt and min-level=0x14
    7) Check cpu flags in guest(only for linux guest)
    8) Restore pt_mode value on host at last

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    flags = params["flags"]
    check_cpu_flags(params, flags, test)

    set_pt_mode = params.get("set_pt_mode")
    get_pt_mode = params.get("get_pt_mode")
    origin_value = process.getoutput(get_pt_mode).strip()

    try:
        if origin_value != '1':
            process.system(set_pt_mode % '1', shell=True)
        pt_mode = process.getoutput(get_pt_mode).strip()
        if pt_mode != '1':
            test.cancel("pt_mode can't be set to 1")

        params["start_vm"] = "yes"
        env_process.preprocess(test, params, env)
        vm = env.get_vm(params["main_vm"])
        error_context.context("Try to log into guest", test.log.info)
        session = vm.wait_for_login()
        if params["os_type"] == "linux":
            check_cpu_flags(params, flags, test, session)
        vm.verify_kernel_crash()
        session.close()
        utils_misc.wait_for(vm.destroy, 240)
    finally:
        process.system(set_pt_mode % origin_value, shell=True)
Ejemplo n.º 6
0
def run(test, params, env):
    def get_sve_unsupported_lengths():
        """
        Get unsupported SVE lengths of host.
        """
        output = vm.monitor.query_cpu_model_expansion(vm.cpuinfo.model)
        output.pop('sve')
        sve_list = [
            sve for sve in output
            if output[sve] is False and sve.startswith('sve')
        ]
        sve_list.sort(key=lambda x: int(x[3:]))

        return sve_list

    error_msg = params['error_msg']
    invalid_length = params.get('invalid_length')

    cpu_utils.check_cpu_flags(params, 'sve', test)

    vm = env.get_vm(params["main_vm"])
    if not invalid_length:
        sve_lengths = get_sve_unsupported_lengths()
        invalid_length = sve_lengths[-1]
        error_msg = error_msg.format(invalid_length[3:])
        vm.destroy()
        params['cpu_model_flags'] = 'sve=on,{}=on'.format(invalid_length)

    params['start_vm'] = 'yes'
    try:
        error_context.context('Launch a guest with invalid SVE length',
                              logging.info)
        vm.create(params=params)
    except VMCreateError as err:
        if not re.search(error_msg, err.output, re.M):
            test.error('The guest failed to be launched but did not get the '
                       'expected error message.')
        logging.info('The qemu process terminated as expected.')
    else:
        test.fail('The guest should not be launched.')
Ejemplo n.º 7
0
def run(test, params, env):
    """
    Test cpu flag nonstop_tsc.
    1) Check if current flags are in the supported lists on host, if no, cancel test
    2) Otherwise, boot guest with the cpu flag 'invtsc'
    3) Check cpu flags inside guest(only for linux guest and not for RHEL6)
    4) Check tsc inside guest(only for linux guest)

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """

    flag = params["flags"]
    check_host_flags = params.get_boolean("check_host_flags")
    if check_host_flags:
        check_cpu_flags(params, flag, 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", test.log.info)
    session = vm.wait_for_login()
    if params["os_type"] == "linux":
        if params['os_variant'] != 'rhel6':
            check_cpu_flags(params, flag, test, session)
        check_clock = params["check_clock"]
        check_clock_out = session.cmd_status(check_clock)
        if check_clock_out:
            test.fail("tsc can't be found inside guest")

    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()
Ejemplo n.º 8
0
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_cpu_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_cpu_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()
Ejemplo n.º 9
0
def run(test, params, env):
    def compile_kernel_selftests():
        git_cmd = 'git clone --depth=1 {} {} 2>/dev/null'.format(git_repo,
                                                                 dst_dir)
        if os.path.exists(dst_dir):
            shutil.rmtree(dst_dir)
        process.run(git_cmd, timeout=360, shell=True)
        s, o = process.getstatusoutput(compile_cmd, timeout=180)
        if s:
            logging.error('Compile output: %s', o)
            test.error('Failed to compile the test suite.')

    dst_dir = params['dst_dir']
    git_repo = params['git_repo']
    compile_cmd = params['compile_cmd']
    execute_suite_cmd = params['execute_suite_cmd']
    required_pkgs = params.objects('required_pkgs')
    suite_timeout = params.get_numeric('suite_timeout')

    if not utils_package.package_install(required_pkgs):
        test.error("Failed to install required packages in host")
    error_context.base_context('Check if the CPU of host supports SVE',
                               logging.info)
    cpu_utils.check_cpu_flags(params, 'sve', test)

    try:
        compile_kernel_selftests()
        s, o = process.getstatusoutput(execute_suite_cmd, timeout=suite_timeout)
        if s:
            test.fail('The exit code of "get-reg-list" test suite is not 0.')
        elif not all([result == "PASS" for result in
                      re.findall(r'^sve\S*: (\w+)$', o, re.M)]):
            logging.error('Test result: %s', o)
            test.fail('The sve part of the "get-reg-list" test failed')
        logging.info('get-reg-list test passed')
    finally:
        shutil.rmtree(dst_dir, ignore_errors=True)
Ejemplo n.º 10
0
def run(test, params, env):
    """
    Qemu reboot test:
    1) Get cpu model lists supported by host
    2) Check if current cpu model is in the supported lists, if no, cancel test
    3) Otherwise, 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.
    """
    qemu_binary = utils_misc.get_qemu_binary(params)
    qmp_cmds = [
        '{"execute": "qmp_capabilities"}',
        '{"execute": "query-cpu-definitions", "id": "RAND91"}',
        '{"execute": "quit"}'
    ]
    cmd = "echo -e '{0}' | {1} -qmp stdio -vnc none -M none | grep return |"\
          "grep RAND91".format(r"\n".join(qmp_cmds), qemu_binary)
    output = process.run(cmd,
                         timeout=10,
                         ignore_status=True,
                         shell=True,
                         verbose=False).stdout_text
    out = json.loads(output)["return"]

    model = params["model"]
    model_pattern = params["model_pattern"]
    flags = params["flags"]
    if cpu.get_vendor() == 'intel':
        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["cpu_model"] = 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", 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":
        check_cpu_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()
Ejemplo n.º 11
0
def run(test, params, env):
    def get_sve_supports_lengths():
        """
        Get supported SVE lengths of host.
        """
        output = vm.monitor.query_cpu_model_expansion(vm.cpuinfo.model)
        output.pop('sve')
        sve_list = [sve for sve in output if output[sve] is True and
                    sve.startswith('sve')]
        sve_list.sort(key=lambda x: int(x[3:]))
        return sve_list

    def compile_test_suite():
        error_context.context('Compose the test suite......', logging.info)
        git_cmd = 'git clone --depth=1 {} {} 2>/dev/null'.format(git_repo,
                                                                 dst_dir)
        session.cmd(git_cmd, timeout=180)
        session.cmd(compile_cmd, timeout=180)

    def sve_stress():
        s, o = session.cmd_status_output('./sve-probe-vls')
        test_lengths = re.findall(r'# (\d+)$', o, re.M)
        if s or not test_lengths:
            test.error('Could not get supported SVE lengths by "sve-probe-vls"')
        logging.info('The lengths of SVE used for testing are: %s', test_lengths)
        for sve_length in test_lengths:
            out = session.cmd_output(execute_suite_cmd.format(sve_length),
                                     timeout=(suite_timeout + 10))
            results_lines = [result for result in out.splitlines() if
                             result.startswith('Terminated by')]
            if len(re.findall(r'no error', out, re.M)) != len(results_lines):
                logging.debug('Test results: %s', results_lines)
                test.fail('SVE stress test failed')

    def optimized_routines():
        out = session.cmd_output(execute_suite_cmd, timeout=suite_timeout)
        results = re.findall(r'^(\w+) \w+sve$', out, re.M)
        if not all([result == "PASS" for result in results]):
            logging.debug('Test results: %s', results)
            test.fail('optimized routines suite test failed')

    cpu_utils.check_cpu_flags(params, 'sve', test)
    vm = env.get_vm(params["main_vm"])
    sve_lengths = get_sve_supports_lengths()
    vm.destroy()

    dst_dir = params['dst_dir']
    git_repo = params['git_repo']
    suite_type = params['suite_type']
    compile_cmd = params['compile_cmd']
    suite_timeout = params.get_numeric('suite_timeout')
    required_pkgs = params.objects('required_pkgs')
    execute_suite_cmd = params['execute_suite_cmd']

    error_context.context('Launch a guest with sve=on', logging.info)
    sve_opts = ('{}={}'.format(sve, 'on') for sve in sve_lengths)
    params['cpu_model_flags'] = 'sve=on,' + ','.join(sve_opts)
    vm.create(params=params)
    vm.verify_alive()
    session = vm.wait_for_login()
    cpu_utils.check_cpu_flags(params, 'sve', test, session)

    if not utils_package.package_install(required_pkgs, session):
        test.error("Failed to install required packages in guest")
    compile_test_suite()
    error_context.context('Execute the test suite......', logging.info)
    locals()[suite_type]()
Ejemplo n.º 12
0
def run(test, params, env):
    """
    smt test:
    1) Check if host has topoext flag, if not, cancel test
    2) Boot guest and check cpu count and threads number in guest
    3) Run stress inside guest, and check cpu usage in guest(only for linux)

    :params test: QEMU test object.
    :params params: Dictionary with the test parameters.
    :params env: Dictionary with test environment.
    """
    def get_guest_threads():
        """
        Get guest threads number
        """
        if os_type == "linux":
            cmd = params["get_threads_cmd"]
            output = session.cmd_output_safe(cmd)
            threads = int(re.findall(r":\s*(\d+)", output)[0])
        else:
            cmd = params["get_cores_cmd"]
            output = session.cmd_output_safe(cmd)
            cores = int(re.findall(r"=(\d+)", output)[0])
            cmd = params["get_sockets_cmd"]
            output = session.cmd_output_safe(cmd)
            sockets = len(re.findall(r"SocketDesignation=", output))
            threads = int(vm.cpuinfo.smp / sockets / cores)
        return threads

    def heavyload_install(install_path):
        """
        Install heavyload in windows guest
        """
        test_installed_cmd = 'dir "%s" | findstr /I heavyload' % install_path
        if session.cmd_status(test_installed_cmd) != 0:
            logging.warning("Could not find installed heavyload in guest, will"
                            " install it via winutils.iso ")
            winutil_drive = utils_misc.get_winutils_vol(session)
            if not winutil_drive:
                test.cancel("WIN_UTILS CDROM not found.")
            install_cmd = params["install_cmd"] % winutil_drive
            session.cmd(install_cmd)

    def run_stress():
        """
        Run stress inside guest, return guest cpu usage
        """
        error_context.context("Run stress in guest and get cpu usage",
                              logging.info)
        if os_type == "linux":
            stress_args = params["stress_args"]
            stress_test = utils_test.VMStress(vm,
                                              "stress",
                                              params,
                                              stress_args=stress_args)
            try:
                stress_test.load_stress_tool()
                time.sleep(stress_duration / 2)
                output = session.cmd_output_safe(params["get_cpu_usage_cmd"])
                utils_misc.wait_for(lambda: (stress_test.app_running is False),
                                    30)
                stress_test.unload_stress()
                cpu_usage = re.findall(r":\s*(\d+.?\d+)\s*us", output)
                cpu_usage = [float(x) for x in cpu_usage]
                logging.info("Guest cpu usage is %s", cpu_usage)
                unloaded_cpu = [x for x in cpu_usage if x < 20]
                if unloaded_cpu:
                    test.fail("CPU(s) load percentage is less than 20%")
            finally:
                stress_test.clean()
        else:
            install_path = params["install_path"]
            heavyload_install(install_path)
            error_context.context("Run heavyload inside guest.", logging.info)
            heavyload_bin = r'"%s\heavyload.exe" ' % install_path
            heavyload_options = [
                "/CPU %d" % vm.cpuinfo.smp,
                "/DURATION %d" % (stress_duration // 60), "/AUTOEXIT", "/START"
            ]
            start_cmd = heavyload_bin + " ".join(heavyload_options)
            stress_tool = BackgroundTest(
                session.cmd, (start_cmd, stress_duration, stress_duration))
            stress_tool.start()
            if not utils_misc.wait_for(stress_tool.is_alive, stress_duration):
                test.error("Failed to start heavyload process.")
            stress_tool.join(stress_duration)

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

    os_type = params["os_type"]
    stress_duration = params.get_numeric("stress_duration", 60)
    vm = env.get_vm(params["main_vm"])
    session = vm.wait_for_login()

    try:
        if vm.get_cpu_count() != vm.cpuinfo.smp:
            test.fail("Guest cpu number is not right")
        threads = get_guest_threads()
        logging.info("Guest threads number is %s", threads)
        if threads != params.get_numeric("expected_threads", 1):
            test.fail("Guest cpu threads number is not right")
        run_stress()
    finally:
        if session:
            session.close()