Esempio n. 1
0
def netperf_stress(test, params, vm):
    """
    Netperf stress test.
    """
    n_client = utils_netperf.NetperfClient(
        vm.get_address(),
        params.get("client_path"),
        netperf_source=os.path.join(data_dir.get_deps_dir("netperf"),
                                    params.get("netperf_client_link")),
        client=params.get("shell_client"),
        port=params.get("shell_port"),
        username=params.get("username"),
        password=params.get("password"),
        prompt=params.get("shell_prompt"),
        linesep=params.get("shell_linesep", "\n").encode().decode(
            'unicode_escape'),
        status_test_command=params.get("status_test_command", ""),
        compile_option=params.get("compile_option", ""))
    n_server = utils_netperf.NetperfServer(
        utils_net.get_host_ip_address(params),
        params.get("server_path", "/var/tmp"),
        netperf_source=os.path.join(data_dir.get_deps_dir("netperf"),
                                    params.get("netperf_server_link")),
        password=params.get("hostpassword"),
        compile_option=params.get("compile_option", ""))

    try:
        n_server.start()
        # Run netperf with message size defined in range.
        netperf_test_duration = params.get_numeric("netperf_test_duration")
        test_protocols = params.get("test_protocol")
        netperf_output_unit = params.get("netperf_output_unit")
        test_option = params.get("test_option", "")
        test_option += " -l %s" % netperf_test_duration
        if params.get("netperf_remote_cpu") == "yes":
            test_option += " -C"
        if params.get("netperf_local_cpu") == "yes":
            test_option += " -c"
        if netperf_output_unit in "GMKgmk":
            test_option += " -f %s" % netperf_output_unit
        t_option = "%s -t %s" % (test_option, test_protocols)
        n_client.bg_start(utils_net.get_host_ip_address(params),
                          t_option,
                          params.get_numeric("netperf_para_sessions"),
                          params.get("netperf_cmd_prefix", ""),
                          package_sizes=params.get("netperf_sizes"))
        if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1,
                               "Wait netperf test start"):
            logging.info("Netperf test start successfully.")
        else:
            test.error("Can not start netperf client.")
        utils_misc.wait_for(lambda: not n_client.is_netperf_running(),
                            netperf_test_duration, 0, 5,
                            "Wait netperf test finish %ss" % netperf_test_duration)
        time.sleep(5)
    finally:
        n_server.stop()
        n_server.package.env_cleanup(True)
        n_client.package.env_cleanup(True)
Esempio n. 2
0
    def copy_network_script(env):
        deps_dir = virttest_data_dir.get_deps_dir()

        file_name = os.path.basename(setup_bridge_sh)
        br_file = os.path.join(deps_dir, file_name)
        for vm in get_live_vms(env):
            vm.copy_files_to(br_file, setup_bridge_sh)
Esempio n. 3
0
 def __init__(self, params, session):
     #fio_resource accept 'distro' or one specified fio package.
     #'distro' means use the fio binary provides by os, and the specified
     #package means use the specified package in deps.
     fio_resource = params.get("fio_resource", 'fio-3.13-48-ga819.tar.bz2')
     if fio_resource == 'distro':
         status, output = session.cmd_status_output('which fio')
         if status == 0:
             self.fio_path = output.strip()
             self.setup_orders = ()
         else:
             raise TestError('No available fio in the distro')
     else:
         host_path = os.path.join(data_dir.get_deps_dir(), 'fio',
                                  fio_resource)
         self.download_path = os.path.join('/home', fio_resource)
         self.fio_inst = os.path.join('/home', 'fio_inst')
         self.fio_path = '%s/bin/fio' % self.fio_inst
         scp_benckmark = attrgetter('scp_benckmark')
         unpack_file = attrgetter('unpack_file')
         install_timeout = params.get_numeric('fio_install_timeout', 300)
         install = attrgetter('install')
         self.setups = {scp_benckmark: (params.get('username'), params.get('password'),
                                        host_path, self.download_path),
                        unpack_file: (TAR_UNPACK, self.download_path, self.fio_inst),
                        install: (self.fio_inst, self.fio_inst, install_timeout)}
         self.setup_orders = (scp_benckmark, unpack_file, install)
Esempio n. 4
0
    def get_guest_cpuid(self, cpu_model, feature=None, extra_params=None):
        test_kernel_dir = os.path.join(data_dir.get_deps_dir(), "cpuid", "src")
        os.chdir(test_kernel_dir)
        utils.make("cpuid_dump_kernel.bin")

        vm_name = params['main_vm']
        params_b = params.copy()
        params_b["kernel"] = os.path.join(test_kernel_dir,
                                          "cpuid_dump_kernel.bin")
        params_b["cpu_model"] = cpu_model
        params_b["cpu_model_flags"] = feature
        del params_b["images"]
        del params_b["nics"]
        if extra_params:
            params_b.update(extra_params)
        env_process.preprocess_vm(self, params_b, env, vm_name)
        vm = env.get_vm(vm_name)
        dbg('is dead: %r', vm.is_dead())
        vm.create()
        self.vm = vm
        vm.resume()

        timeout = float(params.get("login_timeout", 240))
        f = lambda: re.search("==END TEST==", vm.serial_console.get_output())
        if not utils_misc.wait_for(f, timeout, 1):
            raise error.TestFail("Could not get test complete message.")

        test_output = parse_cpuid_dump(vm.serial_console.get_output())
        if test_output is None:
            raise error.TestFail(
                "Test output signature not found in "
                "output:\n %s", vm.serial_console.get_output())
        vm.destroy(gracefully=False)
        return test_output
Esempio n. 5
0
    def setup_service(setup_target):
        setup_timeout = int(params.get("setup_timeout", 360))
        if setup_target == "localhost":
            setup_func = _system_output
            os_type = "linux"
        else:
            setup_vm = env.get_vm(setup_target)
            setup_session = setup_vm.wait_for_login(timeout=timeout)
            setup_func = setup_session.cmd
            os_type = params["os_type"]

        setup_params = params.object_params(os_type)
        setup_cmd = setup_params.get("setup_cmd", "service SERVICE restart")
        prepare_cmd = setup_params.get("prepare_cmd")
        setup_cmd = re.sub("SERVICE", setup_params.get("service", ""),
                           setup_cmd)

        error_context.context("Set up %s service in %s"
                              % (setup_params.get("service"), setup_target),
                              logging.info)
        setup_func(setup_cmd, timeout=setup_timeout)
        if params.get("copy_ftp_site") and setup_target != "localhost":
            ftp_site = os.path.join(data_dir.get_deps_dir(), params.get("copy_ftp_site"))
            ftp_dir = params.get("ftp_dir")
            setup_vm.copy_files_to(ftp_site, ftp_dir)

        if prepare_cmd:
            setup_func(prepare_cmd, timeout=setup_timeout)
        if setup_target != "localhost":
            setup_session.close()
Esempio n. 6
0
    def setup_service(setup_target):
        setup_timeout = int(params.get("setup_timeout", 360))
        if setup_target == "localhost":
            setup_func = _system_output
            os_type = "linux"
        else:
            setup_vm = env.get_vm(setup_target)
            setup_session = setup_vm.wait_for_login(timeout=timeout)
            setup_func = setup_session.cmd
            os_type = params["os_type"]

        setup_params = params.object_params(os_type)
        setup_cmd = setup_params.get("setup_cmd", "service SERVICE restart")
        prepare_cmd = setup_params.get("prepare_cmd")
        setup_cmd = re.sub("SERVICE", setup_params.get("service", ""),
                           setup_cmd)

        error_context.context(
            "Set up %s service in %s" %
            (setup_params.get("service"), setup_target), logging.info)
        setup_func(setup_cmd, timeout=setup_timeout)
        if params.get("copy_ftp_site") and setup_target != "localhost":
            ftp_site = os.path.join(data_dir.get_deps_dir(),
                                    params.get("copy_ftp_site"))
            ftp_dir = params.get("ftp_dir")
            setup_vm.copy_files_to(ftp_site, ftp_dir)

        if prepare_cmd:
            setup_func(prepare_cmd, timeout=setup_timeout)
        if setup_target != "localhost":
            setup_session.close()
Esempio n. 7
0
    def get_guest_cpuid(self,
                        cpu_model,
                        feature=None,
                        extra_params=None,
                        qom_mode=False):
        if not qom_mode:
            test_kernel_dir = os.path.join(data_dir.get_deps_dir(), "cpuid",
                                           "src")
            build.make(test_kernel_dir, extra_args="cpuid_dump_kernel.bin")

        vm_name = params['main_vm']
        params_b = params.copy()
        if not qom_mode:
            params_b["kernel"] = os.path.join(test_kernel_dir,
                                              "cpuid_dump_kernel.bin")
        params_b["cpu_model"] = cpu_model
        params_b["cpu_model_flags"] = feature
        del params_b["images"]
        del params_b["nics"]
        if extra_params:
            params_b.update(extra_params)
        env_process.preprocess_vm(self, params_b, env, vm_name)
        vm = env.get_vm(vm_name)
        dbg('is dead: %r', vm.is_dead())
        vm.create()
        self.vm = vm
        if qom_mode:
            return get_qom_cpuid(self, vm)
        else:
            return get_test_kernel_cpuid(self, vm)
Esempio n. 8
0
def run(test, params, env):
    """
    Verify if guests using kvm-clock as the time source have a sane clock
    resolution.

    :param test: kvm test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    source_name = "clock_getres/clock_getres.c"
    source_name = os.path.join(data_dir.get_deps_dir(), source_name)
    dest_name = "/tmp/clock_getres.c"
    bin_name = "/tmp/clock_getres"

    if not os.path.isfile(source_name):
        raise error.TestError("Could not find %s" % source_name)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    vm.copy_files_to(source_name, dest_name)
    session.cmd("gcc -lrt -o %s %s" % (bin_name, dest_name))
    session.cmd(bin_name)
    logging.info("PASS: Guest reported appropriate clock resolution")
    sub_test = params.get("sub_test")
    if sub_test:
        error.context(
            "Run sub test '%s' after checking"
            " clock resolution" % sub_test, logging.info)
        utils_test.run_virt_sub_test(test, params, env, sub_test)
Esempio n. 9
0
def run(test, params, env):
    """
    Run kvm-unit-tests for Hyper-V testdev device

    1) compile kvm-unit-tests tools source code
    2) Run each unit tests by compiled binary tools
    3) For each unit test, compare the test result to expected value
    """
    tmp_dir = data_dir.get_tmp_dir()
    kvm_unit_tests_dir = data_dir.get_deps_dir("kvm_unit_tests")
    compile_cmd = params["compile_cmd"] % (tmp_dir, kvm_unit_tests_dir)
    test_cmd = params["test_cmd"]
    unit_tests_mapping = params["unit_tests_mapping"]
    skip_tests = params.get("skip_tests", "").split()
    cpu_flags = params["cpu_model_flags"]
    cpu_model = cpu.get_qemu_best_cpu_model(params)
    cpu_param = cpu_model + cpu_flags

    error_context.context("Copy & compile kvm-unit-test tools", logging.info)
    process.system(compile_cmd, shell=True)

    error_context.context("Run unit tests", logging.info)
    for unit_test, unit_test_result in json.loads(unit_tests_mapping).items():
        if unit_test in skip_tests:
            continue
        logging.info("Start running unit test %s" % unit_test)
        unit_test_cmd = test_cmd % (tmp_dir, unit_test, cpu_param)
        result_output = process.system_output(unit_test_cmd, shell=True)
        result_output = result_output.decode()
        find_result = re.findall('^%s' % unit_test_result[0], result_output,
                                 re.M)
        if len(find_result) != int(unit_test_result[1]):
            test.fail("Unit test result mismatch target, "
                      "target=%s, output=%s" %
                      (unit_test_result[1], result_output))
Esempio n. 10
0
    def watchdog_test_suit():
        """
        Run watchdog-test-framework to verify the function of emulated watchdog
        devices.
        Test steps of the framework are as follows:
        1) Set up the watchdog with a 30 second timeout.
        2) Ping the watchdog for 60 seconds.  During this time the guest should
        run normally.
        3) Stop pinging the watchdog and just count up.  If the virtual watchdog
        device is set correctly, then the watchdog action (eg. pause) should
        happen around the 30 second mark.
        """

        _watchdog_device_check(test, session, watchdog_device_type)
        watchdog_test_lib = params["watchdog_test_lib"]
        src_path = os.path.join(data_dir.get_deps_dir(), watchdog_test_lib)
        test_dir = os.path.basename(watchdog_test_lib)
        session.cmd_output("rm -rf /home/%s" % test_dir)
        vm.copy_files_to(src_path, "/home")
        session.cmd_output("cd /home/%s && make" % test_dir)
        try:
            session.cmd_output("./watchdog-test --yes &", timeout=130)
        except ShellTimeoutError:
            # To judge if watchdog action happens after 30s
            o = session.get_output().splitlines()[-1]
            if 27 <= int(o.rstrip("...")) <= 32:
                _action_check(test, session, watchdog_action)
            else:
                test.fail("Watchdog action doesn't happen after 30s.")
        else:
            test.fail("Watchdog test suit doesn't run successfully.")
        finally:
            vm.resume()
            session.cmd_output("pkill watchdog-test")
            session.cmd_output("rm -rf /home/%s" % test_dir)
Esempio n. 11
0
def run(test, params, env):
    """
    1) Boot guest with "-net user" and virtio-net backend
    2) Set MTU value in guest
    3) Compile the script and execute
    4) After the script runs, check whether the guest status is alive.
    5) If the guest is alive, check the product for security breaches
    :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"])
    login_timeout = params.get_numeric("login_timeout", 360)
    vm.wait_for_login(timeout=login_timeout)
    test_path = os.path.join(data_dir.get_deps_dir(), "netuser/exp.c")
    vm.copy_files_to(test_path, '~')
    vm.destroy()

    params["nettype"] = "user"
    params["vhost"] = ""
    params = params.object_params(vm.name)
    vm.create(params=params)
    serial_session = vm.wait_for_serial_login(timeout=login_timeout)

    def mtu_test():
        logging.info("Set mtu value and verfied")
        serial_session.cmd(params["fw_stop_cmd"], ignore_all_errors=True)
        guest_ifname = utils_net.get_linux_ifname(serial_session,
                                                  vm.get_mac_address(0))
        if guest_ifname != 'eth0':
            test.cancel("Guest device name is not expected")
        serial_session.cmd(params["set_mtu_cmd"] % guest_ifname)
        output = serial_session.cmd_output(params["check_mtu_cmd"] %
                                           guest_ifname)
        match_string = "mtu %s" % params["mtu_value"]
        if match_string not in output:
            test.fail("Guest mtu is not the expected value %s" %
                      params["mtu_value"])

    def pkg_buffer_test():
        logging.info("Compile the script and execute")
        serial_session.cmd("gcc -o ~/exp ~/exp.c")
        serial_session.sendline("~/exp")
        time.sleep(60)
        s = process.getstatusoutput(
            "ps -aux|grep /usr/bin/gnome-calculator |grep -v grep",
            timeout=60, shell=True)[0]
        if s == 0:
            test.fail("Virtual machine has security issues")
        serial_session.send_ctrl("^c")
        logging.info("send ctrl+c command to exit the current process.")
        vm.verify_kernel_crash()

    try:
        mtu_test()
        pkg_buffer_test()
    finally:
        serial_session.cmd("rm -rf ~/exp ~/exp.c",
                           timeout=login_timeout, ignore_all_errors=True)
        serial_session.close()
Esempio n. 12
0
def run(test, params, env):
    """
    Run Iometer for Windows on a Windows guest:

    1) Boot guest with additional disk
    2) Format the additional disk
    3) Install and register Iometer
    4) Perpare icf to Iometer.exe
    5) Run Iometer.exe with icf
    6) Copy result to host

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    # format the target disk
    utils_test.run_virt_sub_test(test, params, env, "format_disk")

    error_context.context("Install Iometer", logging.info)
    cmd_timeout = int(params.get("cmd_timeout", 360))
    ins_cmd = params["install_cmd"]
    vol_utils = utils_misc.get_winutils_vol(session)
    if not vol_utils:
        raise exceptions.TestError("WIN_UTILS CDROM not found")
    ins_cmd = re.sub("WIN_UTILS", vol_utils, ins_cmd)
    session.cmd(cmd=ins_cmd, timeout=cmd_timeout)
    time.sleep(0.5)

    error_context.context("Register Iometer", logging.info)
    reg_cmd = params["register_cmd"]
    reg_cmd = re.sub("WIN_UTILS", vol_utils, reg_cmd)
    session.cmd_output(cmd=reg_cmd, timeout=cmd_timeout)

    error_context.context("Prepare icf for Iometer", logging.info)
    icf_name = params["icf_name"]
    ins_path = params["install_path"]
    res_file = params["result_file"]
    icf_file = os.path.join(data_dir.get_deps_dir(), "iometer", icf_name)
    vm.copy_files_to(icf_file, "%s\\%s" % (ins_path, icf_name))

    # Run Iometer
    error_context.context("Start Iometer", logging.info)
    session.cmd("cd %s" % ins_path)
    logging.info("Change dir to: %s" % ins_path)
    run_cmd = params["run_cmd"]
    run_timeout = int(params.get("run_timeout", 1000))
    logging.info("Set Timeout: %ss" % run_timeout)
    run_cmd = run_cmd % (icf_name, res_file)
    logging.info("Execute Command: %s" % run_cmd)
    s, o = session.cmd_status_output(cmd=run_cmd, timeout=run_timeout)
    error_context.context("Copy result '%s' to host" % res_file, logging.info)
    vm.copy_files_from(res_file, test.resultsdir)

    if s != 0:
        raise exceptions.TestFail("iometer test failed. {}".format(o))
Esempio n. 13
0
def run(test, params, env):
    """
    Run Iometer for Windows on a Windows guest:

    1) Boot guest with additional disk
    2) Format the additional disk
    3) Install and register Iometer
    4) Perpare icf to Iometer.exe
    5) Run Iometer.exe with icf
    6) Copy result to host

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    # format the target disk
    utils_test.run_virt_sub_test(test, params, env, "format_disk")

    error_context.context("Install Iometer", logging.info)
    cmd_timeout = int(params.get("cmd_timeout", 360))
    ins_cmd = params["install_cmd"]
    vol_utils = utils_misc.get_winutils_vol(session)
    if not vol_utils:
        raise exceptions.TestError("WIN_UTILS CDROM not found")
    ins_cmd = re.sub("WIN_UTILS", vol_utils, ins_cmd)
    session.cmd(cmd=ins_cmd, timeout=cmd_timeout)
    time.sleep(0.5)

    error_context.context("Register Iometer", logging.info)
    reg_cmd = params["register_cmd"]
    reg_cmd = re.sub("WIN_UTILS", vol_utils, reg_cmd)
    session.cmd_output(cmd=reg_cmd, timeout=cmd_timeout)

    error_context.context("Prepare icf for Iometer", logging.info)
    icf_name = params["icf_name"]
    ins_path = params["install_path"]
    res_file = params["result_file"]
    icf_file = os.path.join(data_dir.get_deps_dir(), "iometer", icf_name)
    vm.copy_files_to(icf_file, "%s\\%s" % (ins_path, icf_name))

    # Run Iometer
    error_context.context("Start Iometer", logging.info)
    session.cmd("cd %s" % ins_path)
    logging.info("Change dir to: %s" % ins_path)
    run_cmd = params["run_cmd"]
    run_timeout = int(params.get("run_timeout", 1000))
    logging.info("Set Timeout: %ss" % run_timeout)
    run_cmd = run_cmd % (icf_name, res_file)
    logging.info("Execute Command: %s" % run_cmd)
    s, o = session.cmd_status_output(cmd=run_cmd, timeout=100)
    error_context.context("Copy result '%s' to host" % res_file, logging.info)
    vm.copy_files_from(res_file, test.resultsdir)

    if s != 0:
        raise exceptions.TestFail("iometer test failed. {}".format(o))
Esempio n. 14
0
def compile_nc_vsock(test, vm, session):
    """
    Copy and compile nc-vsock on both host and guest

    :param test: QEMU test object
    :param vm: Object qemu_vm.VM
    :param session: vm session
    :return: Path to binary nc-vsock or None if compile failed
    """
    nc_vsock_dir = '/home/'
    nc_vsock_bin = 'nc-vsock'
    nc_vsock_c = 'nc-vsock.c'
    src_file = os.path.join(data_dir.get_deps_dir("nc_vsock"), nc_vsock_c)
    bin_path = os.path.join(nc_vsock_dir, nc_vsock_bin)
    rm_cmd = 'rm -rf %s*' % bin_path
    session.cmd(rm_cmd)
    process.system(rm_cmd, shell=True, ignore_status=True)
    cmd_cp = "cp %s %s" % (src_file, nc_vsock_dir)
    process.system(cmd_cp)
    vm.copy_files_to(src_file, nc_vsock_dir)
    compile_cmd = "cd %s && gcc -o %s %s" % (nc_vsock_dir, nc_vsock_bin,
                                             nc_vsock_c)
    host_status = process.system(compile_cmd, shell=True)
    guest_status = session.cmd_status(compile_cmd)
    if (host_status or guest_status) != 0:
        process.system(rm_cmd, shell=True, ignore_status=True)
        session.cmd_output_safe(rm_cmd)
        session.close()
        test.error("Compile nc-vsock failed")
    return bin_path
Esempio n. 15
0
    def env_setup():
        """
        Prepare the test environment
        1) Set 1G hugepages and iommu enabled
        2) Copy testpmd script to guest

        """
        error_context.context("Setup env for guest")

        # setup hugepages
        session.cmd(params.get("env_hugepages_cmd"), ignore_all_errors=True)

        # install dpdk related packages
        install_dpdk()

        # install python pexpect
        session.cmd("`command -v pip pip3` install pexpect",
                    ignore_all_errors=True)

        # copy testpmd script to guest
        testpmd_exec = params.get("testpmd_exec")
        src = os.path.join(data_dir.get_deps_dir(),
                           "performance/%s" % testpmd_exec)
        dst = "/tmp/%s" % testpmd_exec
        vm.copy_files_to(src, dst, nic_index=0)

        return dst
Esempio n. 16
0
def run(test, params, env):
    """
    Runs CPU rdrand test:

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

    vm = env.get_vm(params["main_vm"])
    session = vm.wait_for_login()
    test_bin = params['test_bin']
    source_file = params['source_file']
    guest_path = params['guest_path']
    host_path = utils_misc.get_path(data_dir.get_deps_dir('rdrand'),
                                    source_file)
    vm.copy_files_to(host_path, '%s%s' % (guest_path, source_file))
    if params['os_type'] == 'linux':
        build_cmd = params.get('build_cmd', 'cd %s; gcc -lrt %s -o %s')
        error_context.context("build binary file 'rdrand'", logging.info)
        session.cmd(build_cmd % (guest_path, source_file, test_bin))
    s, o = session.cmd_status_output('%s%s' % (guest_path, test_bin))
    session.cmd(params['delete_cmd'])
    if s != 0:
        test.fail('rdrand failed with status %s' % s)
    if params['os_type'] == 'linux':
        try:
            if not int(float(o)) in range(-101, 101):
                test.fail('rdrand output is %s, which is not expected' % o)
        except ValueError as e:
            test.fail('rdrand should output a float: %s' % str(e))
Esempio n. 17
0
def run(test, params, env):
    """
    try to exploit the guest to test whether nx(cpu) bit takes effect.

    1) boot the guest
    2) cp the exploit prog into the guest
    3) run the exploit

    :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"])
    vm.verify_alive()
    session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))

    exploit_file = os.path.join(data_dir.get_deps_dir(), 'nx', 'x64_sc_rdo.c')
    dst_dir = '/tmp'

    error.context("Copy the Exploit file to guest.", logging.info)
    vm.copy_files_to(exploit_file, dst_dir)

    error.context("Build exploit program in guest.", logging.info)
    build_exploit = "gcc -o /tmp/nx_exploit /tmp/x64_sc_rdo.c"
    if session.cmd_status(build_exploit):
        raise error.TestError("Failed to build the exploit program")

    error.context("Run exploit program in guest.", logging.info)
    exec_exploit = "/tmp/nx_exploit"
    # if nx is enabled (by default), the program failed.
    # segmentation error. return value of shell is not zero.
    exec_res = session.cmd_status(exec_exploit)
    nx_on = params.get('nx_on', 'yes')
    if nx_on == 'yes':
        if exec_res:
            logging.info('NX works good.')
            error.context("Using execstack to remove the protection.",
                          logging.info)
            enable_exec = 'execstack -s /tmp/nx_exploit'
            if session.cmd_status(enable_exec):
                if session.cmd_status("execstack --help"):
                    msg = "Please make sure guest have execstack command."
                    raise error.TestError(msg)
                raise error.TestError('Failed to enable the execstack')

            if session.cmd_status(exec_exploit):
                raise error.TestFail('NX is still protecting. Error.')
            else:
                logging.info('NX is disabled as desired. good')
        else:
            raise error.TestFail('Fatal Error: NX does not protect anything!')
    else:
        if exec_res:
            msg = "qemu fail to disable 'nx' flag or the exploit is corrupted."
            raise error.TestError(msg)
        else:
            logging.info('NX is disabled, and this Test Case passed.')
    if session:
        session.close()
Esempio n. 18
0
    def get_guest_cpuid(self, cpu_model, feature=None, extra_params=None, qom_mode=False):
        if not qom_mode:
            test_kernel_dir = os.path.join(data_dir.get_deps_dir(), "cpuid", "src")
            os.chdir(test_kernel_dir)
            utils.make("cpuid_dump_kernel.bin")

        vm_name = params['main_vm']
        params_b = params.copy()
        if not qom_mode:
            params_b["kernel"] = os.path.join(
                test_kernel_dir, "cpuid_dump_kernel.bin")
        params_b["cpu_model"] = cpu_model
        params_b["cpu_model_flags"] = feature
        del params_b["images"]
        del params_b["nics"]
        if extra_params:
            params_b.update(extra_params)
        env_process.preprocess_vm(self, params_b, env, vm_name)
        vm = env.get_vm(vm_name)
        dbg('is dead: %r', vm.is_dead())
        vm.create()
        self.vm = vm
        if qom_mode:
            return get_qom_cpuid(self, vm)
        else:
            return get_test_kernel_cpuid(self, vm)
Esempio n. 19
0
def run(test, params, env):
    """
    Verify if guests using kvm-clock as the time source have a sane clock
    resolution.

    :param test: kvm test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    source_name = "clock_getres/clock_getres.c"
    source_name = os.path.join(data_dir.get_deps_dir(), source_name)
    dest_name = "/tmp/clock_getres.c"
    bin_name = "/tmp/clock_getres"

    if not os.path.isfile(source_name):
        raise error.TestError("Could not find %s" % source_name)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    vm.copy_files_to(source_name, dest_name)
    session.cmd("gcc -lrt -o %s %s" % (bin_name, dest_name))
    session.cmd(bin_name)
    logging.info("PASS: Guest reported appropriate clock resolution")
    sub_test = params.get("sub_test")
    if sub_test:
        error.context("Run sub test '%s' after checking"
                      " clock resolution" % sub_test, logging.info)
        utils_test.run_virt_sub_test(test, params, env, sub_test)
Esempio n. 20
0
def run(test, params, env):
    """
    Check kvm 0x40000001 inside guest.
    :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"])
    session = vm.wait_for_login()
    nums_cpu = str(vm.cpuinfo.smp)

    test_dir = params["test_dir"]
    source_file = params["source_file"]
    src_cpuid = os.path.join(data_dir.get_deps_dir(), source_file)
    vm.copy_files_to(src_cpuid, test_dir)
    guest_dir = "%s/cpuid-20201006" % test_dir
    try:
        session.cmd('tar -xzf %s/%s -C %s && cd %s && make' %
                    (test_dir, source_file, test_dir, guest_dir))
        check_cpuid = 'cd %s && ' % guest_dir + params["check_cpuid"]
        results = session.cmd_output(check_cpuid).strip()
        if results.split()[0] != nums_cpu:
            test.fail("some vcpu's cpuid has no eax=0x40000001.")
    finally:
        session.cmd("rm %s/cpuid* -rf" % test_dir)
        session.close()
Esempio n. 21
0
    def get_guest_cpuid(self, cpu_model, feature=None, extra_params=None):
        test_kernel_dir = os.path.join(data_dir.get_deps_dir(), "cpuid", "src")
        os.chdir(test_kernel_dir)
        utils.make("cpuid_dump_kernel.bin")

        vm_name = params['main_vm']
        params_b = params.copy()
        params_b["kernel"] = os.path.join(
            test_kernel_dir, "cpuid_dump_kernel.bin")
        params_b["cpu_model"] = cpu_model
        params_b["cpu_model_flags"] = feature
        del params_b["images"]
        del params_b["nics"]
        if extra_params:
            params_b.update(extra_params)
        env_process.preprocess_vm(self, params_b, env, vm_name)
        vm = env.get_vm(vm_name)
        dbg('is dead: %r', vm.is_dead())
        vm.create()
        self.vm = vm
        vm.resume()

        timeout = float(params.get("login_timeout", 240))
        f = lambda: re.search("==END TEST==", vm.serial_console.get_output())
        if not utils_misc.wait_for(f, timeout, 1):
            raise error.TestFail("Could not get test complete message.")

        test_output = parse_cpuid_dump(vm.serial_console.get_output())
        if test_output is None:
            raise error.TestFail("Test output signature not found in "
                                 "output:\n %s", vm.serial_console.get_output())
        vm.destroy(gracefully=False)
        return test_output
Esempio n. 22
0
    def watchdog_test_suit():
        """
        Run watchdog-test-framework to verify the function of emulated watchdog
        devices.
        Test steps of the framework are as follows:
        1) Set up the watchdog with a 30 second timeout.
        2) Ping the watchdog for 60 seconds.  During this time the guest should
        run normally.
        3) Stop pinging the watchdog and just count up.  If the virtual watchdog
        device is set correctly, then the watchdog action (eg. pause) should
        happen around the 30 second mark.
        """

        _watchdog_device_check(test, session, watchdog_device_type)
        watchdog_test_lib = params["watchdog_test_lib"]
        src_path = os.path.join(data_dir.get_deps_dir(), watchdog_test_lib)
        test_dir = os.path.basename(watchdog_test_lib)
        session.cmd_output("rm -rf /home/%s" % test_dir)
        vm.copy_files_to(src_path, "/home")
        session.cmd_output("cd /home/%s && make" % test_dir)
        try:
            session.cmd_output("./watchdog-test --yes &", timeout=130)
        except ShellTimeoutError:
            # To judge if watchdog action happens after 30s
            o = session.get_output().splitlines()[-1]
            if 27 <= int(o.rstrip("...")) <= 32:
                _action_check(test, session, watchdog_action)
            else:
                test.fail("Watchdog action doesn't happen after 30s.")
        else:
            test.fail("Watchdog test suit doesn't run successfully.")
        finally:
            vm.resume()
            session.cmd_output("pkill watchdog-test")
            session.cmd_output("rm -rf /home/%s" % test_dir)
Esempio n. 23
0
    def install_moongen(session, ip, user, port, password):
        """

        Install moogen on remote moongen host

        """

        # copy MoonGen.zip to remote moongen host
        moongen_pkg = params.get("moongen_pkg")
        local_path = os.path.join(data_dir.get_deps_dir(),
                                  "performance/%s" % moongen_pkg)
        remote.scp_to_remote(ip, shell_port, username, password, local_path,
                             "/home")

        # install moongen
        cmd_str = "rm -rf /home/MoonGen"
        cmd_str += " && unzip /home/%s -d /home" % params.get("moongen_pkg")
        cmd_str += " && cd /home/MoonGen && ./build.sh"
        if session.cmd_status(cmd_str, timeout=300) != 0:
            test.error("Fail to install program on monngen host")

        # set hugepages
        session.cmd(params.get("generator_hugepages_cmd"),
                    ignore_all_errors=True)

        # probe vfio and vfip-pci
        cmd_probe = "modprobe vfio; modprobe vfio-pci"
        session.cmd_status(cmd_probe, timeout=300)

        # bind nic
        moongen_dpdk_nic = params.get("moongen_dpdk_nic").split()
        for i in list(moongen_dpdk_nic):
            cmd_bind = "dpdk-devbind --bind=vfio-pci %s" % i
            if session.cmd_status(cmd_bind) != 0:
                test.error("Fail to bind nic %s on monngen host" % i)
Esempio n. 24
0
def compile_nc_vsock(test, vm, session):
    """
    Copy and compile nc-vsock on both host and guest

    :param test: QEMU test object
    :param vm: Object qemu_vm.VM
    :param session: vm session
    :return: Path to binary nc-vsock or None if compile failed
    """
    nc_vsock_dir = '/home/'
    nc_vsock_bin = 'nc-vsock'
    nc_vsock_c = 'nc-vsock.c'
    src_file = os.path.join(data_dir.get_deps_dir("nc_vsock"), nc_vsock_c)
    bin_path = os.path.join(nc_vsock_dir, nc_vsock_bin)
    rm_cmd = 'rm -rf %s*' % bin_path
    session.cmd(rm_cmd)
    process.system(rm_cmd, shell=True, ignore_status=True)
    cmd_cp = "cp %s %s" % (src_file, nc_vsock_dir)
    process.system(cmd_cp)
    vm.copy_files_to(src_file, nc_vsock_dir)
    compile_cmd = "cd %s && gcc -o %s %s" % (
        nc_vsock_dir, nc_vsock_bin, nc_vsock_c)
    host_status = process.system(compile_cmd, shell=True)
    guest_status = session.cmd_status(compile_cmd)
    if (host_status or guest_status) != 0:
        process.system(rm_cmd, shell=True, ignore_status=True)
        session.cmd_output_safe(rm_cmd)
        session.close()
        test.error("Compile nc-vsock failed")
    return bin_path
Esempio n. 25
0
        def test(self, test, params, env):
            iperf_src_path = os.path.join(data_dir.get_deps_dir(), "iperf")
            self.iperf_b_path = os.path.join("iperf-2.0.4", "src", "iperf")

            error.context("Install iperf to vms machine.")
            utils_misc.ForAllP(self.machines).compile_autotools_app_tar(
                iperf_src_path, "iperf-2.0.4.tar.gz")

            allow_iperf_firewall(self.host)
            utils_misc.ForAllP(self.mvms).cmd("iptables -F")

            self.start_servers()

            # Test TCP bandwidth
            error.context("Test iperf bandwidth tcp.")
            speeds = self.test_bandwidth()
            logging.info("TCP Bandwidth from vm->host: %s", speeds[0])
            logging.info("TCP Bandwidth from host->vm: %s", speeds[1])
            logging.info("TCP Bandwidth from vm->vm: %s", speeds[2])

            # test udp bandwidth limited to 1Gb
            error.context("Test iperf bandwidth udp.")
            speeds = self.test_bandwidth("-u -b 1G")
            logging.info("UDP Bandwidth from vm->host: %s", speeds[0])
            logging.info("UDP Bandwidth from host->vm: %s", speeds[1])
            logging.info("UDP Bandwidth from vm->vm: %s", speeds[2])
Esempio n. 26
0
        def test(self, test, params, env):
            iperf_src_path = os.path.join(data_dir.get_deps_dir(), "iperf")
            self.iperf_b_path = os.path.join("iperf-2.0.4", "src", "iperf")

            error.context("Install iperf to vms machine.")
            utils_misc.ForAllP(
                self.machines).compile_autotools_app_tar(iperf_src_path,
                                                         "iperf-2.0.4.tar.gz")

            allow_iperf_firewall(self.host)
            utils_misc.ForAllP(self.mvms).cmd("iptables -F")

            self.start_servers()

            # Test TCP bandwidth
            error.context("Test iperf bandwidth tcp.")
            speeds = self.test_bandwidth()
            logging.info("TCP Bandwidth from vm->host: %s", speeds[0])
            logging.info("TCP Bandwidth from host->vm: %s", speeds[1])
            logging.info("TCP Bandwidth from vm->vm: %s", speeds[2])

            # test udp bandwidth limited to 1Gb
            error.context("Test iperf bandwidth udp.")
            speeds = self.test_bandwidth("-u -b 1G")
            logging.info("UDP Bandwidth from vm->host: %s", speeds[0])
            logging.info("UDP Bandwidth from host->vm: %s", speeds[1])
            logging.info("UDP Bandwidth from vm->vm: %s", speeds[2])
Esempio n. 27
0
def run(test, params, env):
    """
    try to exploit the guest to test whether nx(cpu) bit takes effect.

    1) boot the guest
    2) cp the exploit prog into the guest
    3) run the exploit

    :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"])
    vm.verify_alive()
    session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))

    exploit_file = os.path.join(data_dir.get_deps_dir(), "nx", "x64_sc_rdo.c")
    dst_dir = "/tmp"

    error.context("Copy the Exploit file to guest.", logging.info)
    vm.copy_files_to(exploit_file, dst_dir)

    error.context("Build exploit program in guest.", logging.info)
    build_exploit = "gcc -o /tmp/nx_exploit /tmp/x64_sc_rdo.c"
    if session.cmd_status(build_exploit):
        raise error.TestError("Failed to build the exploit program")

    error.context("Run exploit program in guest.", logging.info)
    exec_exploit = "/tmp/nx_exploit"
    # if nx is enabled (by default), the program failed.
    # segmentation error. return value of shell is not zero.
    exec_res = session.cmd_status(exec_exploit)
    nx_on = params.get("nx_on", "yes")
    if nx_on == "yes":
        if exec_res:
            logging.info("NX works good.")
            error.context("Using execstack to remove the protection.", logging.info)
            enable_exec = "execstack -s /tmp/nx_exploit"
            if session.cmd_status(enable_exec):
                if session.cmd_status("execstack --help"):
                    msg = "Please make sure guest have execstack command."
                    raise error.TestError(msg)
                raise error.TestError("Failed to enable the execstack")

            if session.cmd_status(exec_exploit):
                raise error.TestFail("NX is still protecting. Error.")
            else:
                logging.info("NX is disabled as desired. good")
        else:
            raise error.TestFail("Fatal Error: NX does not protect anything!")
    else:
        if exec_res:
            msg = "qemu fail to disable 'nx' flag or the exploit is corrupted."
            raise error.TestError(msg)
        else:
            logging.info("NX is disabled, and this Test Case passed.")
    if session:
        session.close()
Esempio n. 28
0
 def receive_data(session, serial_receive_cmd, data_file):
     output = session.cmd_output(serial_receive_cmd, timeout=30)
     d_file = os.path.join(data_dir.get_deps_dir("win_serial"), data_file)
     ori_data = file(data_file, "r").read()
     if ori_data.strip() != output.strip():
         err = "Data lost during transfer. Origin data is:\n%s" % ori_data
         err += "Guest receive data:\n%s" % output
         raise error.TestFail(err)
 def receive_data(session, serial_receive_cmd, data_file):
     output = session.cmd_output(serial_receive_cmd, timeout=30)
     d_file = os.path.join(data_dir.get_deps_dir("win_serial"), data_file)
     ori_data = file(data_file, "r").read()
     if ori_data.strip() != output.strip():
         err = "Data lost during transfer. Origin data is:\n%s" % ori_data
         err += "Guest receive data:\n%s" % output
         raise error.TestFail(err)
Esempio n. 30
0
 def _run_sg_luns():
     file_name = "guest_sg_luns.sh"
     guest_dir = "/tmp/"
     deps_dir = virttest_data_dir.get_deps_dir()
     host_file = os.path.join(deps_dir, file_name)
     guest_file = guest_dir + file_name
     vm.copy_files_to(host_file, guest_dir)
     session.sendline("$SHELL " + guest_file)
Esempio n. 31
0
    def check_cpuid_dump(self):
        """
        Compare full CPUID dump data
        """
        machine_type = params.get("machine_type_to_check", "")
        kvm_enabled = params.get("enable_kvm", "yes") == "yes"

        ignore_cpuid_leaves = params.get("ignore_cpuid_leaves", "")
        ignore_cpuid_leaves = ignore_cpuid_leaves.split()
        whitelist = []
        for l in ignore_cpuid_leaves:
            l = l.split(',')
            # syntax of ignore_cpuid_leaves:
            # <in_eax>[,<in_ecx>[,<register>[ ,<bit>]]] ...
            for i in 0, 1, 3:  # integer fields:
                if len(l) > i:
                    l[i] = int(l[i], 0)
            whitelist.append(tuple(l))

        if not machine_type:
            raise error.TestNAError("No machine_type_to_check defined")
        cpu_model_flags = params.get('cpu_model_flags', '')
        full_cpu_model_name = cpu_model
        if cpu_model_flags:
            full_cpu_model_name += ','
            full_cpu_model_name += cpu_model_flags.lstrip(',')
        ref_file = os.path.join(data_dir.get_deps_dir(), 'cpuid',
                                "cpuid_dumps", kvm_enabled and "kvm"
                                or "nokvm", machine_type,
                                '%s-dump.txt' % (full_cpu_model_name))
        if not os.path.exists(ref_file):
            raise error.TestNAError("no cpuid dump file: %s" % (ref_file))
        reference = open(ref_file, 'r').read()
        if not reference:
            raise error.TestNAError("no cpuid dump data on file: %s" %
                                    (ref_file))
        reference = parse_cpuid_dump(reference)
        if reference is None:
            raise error.TestNAError(
                "couldn't parse reference cpuid dump from file; %s" %
                (ref_file))
        try:
            out = get_guest_cpuid(self,
                                  cpu_model,
                                  cpu_model_flags + ',enforce',
                                  extra_params=dict(machine_type=machine_type,
                                                    smp=1))
        except virt_vm.VMStartError, e:
            if "host doesn't support requested feature:" in e.reason \
                or ("host cpuid" in e.reason and
                    ("lacks requested flag" in e.reason or
                     "flag restricted to guest" in e.reason)) \
                    or ("Unable to find CPU definition:" in e.reason):
                raise error.TestNAError("Can't run CPU model %s on this host" %
                                        (full_cpu_model_name))
            else:
                raise
Esempio n. 32
0
    def copy_network_script(env):
        login_timeout = params.get_numeric("login_timeout", 360)
        deps_dir = virttest_data_dir.get_deps_dir()

        file_name = os.path.basename(setup_bridge_sh)
        br_file = os.path.join(deps_dir, file_name)
        for vm in get_live_vms(env):
            vm.wait_for_login(timeout=login_timeout)
            vm.copy_files_to(br_file, setup_bridge_sh)
Esempio n. 33
0
def get_keycode_cfg(filename):
    """
    Get keyname to keycode cfg table.
    :param filename: filename that key to keycode file.
    """
    keycode_cfg_path = os.path.join(data_dir.get_deps_dir("key_keycode"), filename)
    print(keycode_cfg_path)
    with open(keycode_cfg_path) as f:
        return json.load(f)
Esempio n. 34
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)
Esempio n. 35
0
def netperf_setup(test, params, env):
    """
    Setup netperf in guest.

    Copy netperf package into guest. Install netperf in guest (linux only).
    """
    params["start_vm"] = "yes"
    params["image_snapshot"] = "no"
    vm_name = params.get("main_vm")
    env_process.preprocess_vm(test, params, env, vm_name)
    vm = env.get_vm(vm_name)
    vm.verify_alive()
    session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
    try:
        if params.get("os_type") == "linux":
            netperf_link = params["netperf_link"]
            netperf_path = params["netperf_path"]
            src_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                    netperf_link)
            vm.copy_files_to(src_link, netperf_path, timeout=60)
            setup_cmd = params.get("setup_cmd")
            (status, output) = session.cmd_status_output(setup_cmd %
                                                         netperf_path,
                                                         timeout=600)
            if status != 0:
                err = "Fail to setup netperf on guest os."
                err += " Command output:\n%s" % output
                test.error(err)
        elif params.get("os_type") == "windows":
            # TODO, not suppoted by now
            s_link = params.get("netperf_server_link_win",
                                "netserver-2.6.0.exe")
            src_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                    s_link)
            netperf_path = params["netperf_path"]
            vm.copy_files_to(src_link, netperf_path, timeout=60)
            s_link = params.get("netperf_client_link_win", "netperf.exe")
            src_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                    s_link)
            vm.copy_files_to(src_link, netperf_path, timeout=60)
    finally:
        if session:
            session.close()
        vm.destroy()
Esempio n. 36
0
def netperf_setup(test, params, env):
    """
    Setup netperf in guest.

    Copy netperf package into guest. Install netperf in guest (linux only).
    """
    params["start_vm"] = "yes"
    params["image_snapshot"] = "no"
    vm_name = params.get("main_vm")
    env_process.preprocess_vm(test, params, env, vm_name)
    vm = env.get_vm(vm_name)
    vm.verify_alive()
    session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
    try:
        if params.get("os_type") == "linux":
            netperf_link = params["netperf_link"]
            netperf_path = params["netperf_path"]
            src_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                    netperf_link)
            vm.copy_files_to(src_link, netperf_path, timeout=60)
            setup_cmd = params.get("setup_cmd")
            (status, output) = session.cmd_status_output(setup_cmd %
                                                         netperf_path,
                                                         timeout=600)
            if status != 0:
                err = "Fail to setup netperf on guest os."
                err += " Command output:\n%s" % output
                test.error(err)
        elif params.get("os_type") == "windows":
            # TODO, not suppoted by now
            s_link = params.get("netperf_server_link_win",
                                "netserver-2.6.0.exe")
            src_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                    s_link)
            netperf_path = params["netperf_path"]
            vm.copy_files_to(src_link, netperf_path, timeout=60)
            s_link = params.get("netperf_client_link_win", "netperf.exe")
            src_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                    s_link)
            vm.copy_files_to(src_link, netperf_path, timeout=60)
    finally:
        if session:
            session.close()
        vm.destroy()
Esempio n. 37
0
def run(test, params, env):
    """
    Timer device tscwrite test:

    1) Check for an appropriate clocksource on host.
    2) Boot the guest.
    3) Download and compile the newest msr-tools.
    4) Execute cmd in guest.

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    error_context.context("Check for an appropriate clocksource on host",
                          logging.info)
    host_cmd = "cat /sys/devices/system/clocksource/"
    host_cmd += "clocksource0/current_clocksource"
    if "tsc" not in process.getoutput(host_cmd):
        test.cancel("Host must use 'tsc' clocksource")

    error_context.context("Boot the guest", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    error_context.context("Download and compile the newest msr-tools",
                          logging.info)
    tarball = params["tarball"]
    compile_cmd = params["compile_cmd"]
    msr_name = params["msr_name"]
    tarball = os.path.join(data_dir.get_deps_dir(), tarball)
    msr_dir = "/tmp/"
    vm.copy_files_to(tarball, msr_dir)
    session.cmd("cd %s && tar -zxvf %s" % (msr_dir, os.path.basename(tarball)))
    session.cmd("cd %s && %s" % (msr_name, compile_cmd))

    error_context.context("Execute cmd in guest", logging.info)
    cmd = "dmesg -c > /dev/null"
    session.cmd(cmd)

    date_cmd = "strace date 2>&1 | egrep 'clock_gettime|gettimeofday' | wc -l"
    output = session.cmd(date_cmd)
    if '0' not in output:
        test.fail("Test failed before run msr tools. Output: '%s'" % output)

    msr_tools_cmd = params["msr_tools_cmd"]
    session.cmd(msr_tools_cmd)

    cmd = "dmesg"
    session.cmd(cmd)

    output = session.cmd(date_cmd)
    if "1" not in output:
        test.fail("Test failed after run msr tools. Output: '%s'" % output)
Esempio n. 38
0
 def dlink_preprcess(download_link):
     """
     Preprocess the download link
     """
     if not download_link:
         raise error.TestNAError("Can not get the netperf download_link")
     if not utils.is_url(download_link):
         download_link = utils_misc.get_path(data_dir.get_deps_dir(),
                                             download_link)
     return download_link
Esempio n. 39
0
 def dlink_preprcess(download_link):
     """
     Preprocess the download link
     """
     if not download_link:
         raise error.TestNAError("Can not get the netperf download_link")
     if not utils.is_url(download_link):
         download_link = utils_misc.get_path(data_dir.get_deps_dir(),
                                             download_link)
     return download_link
Esempio n. 40
0
    def check_cpuid_dump(self):
        """
        Compare full CPUID dump data
        """
        machine_type = params.get("machine_type_to_check", "")
        kvm_enabled = params.get("enable_kvm", "yes") == "yes"

        ignore_cpuid_leaves = params.get("ignore_cpuid_leaves", "")
        ignore_cpuid_leaves = ignore_cpuid_leaves.split()
        whitelist = []
        for l in ignore_cpuid_leaves:
            l = l.split(',')
            # syntax of ignore_cpuid_leaves:
            # <in_eax>[,<in_ecx>[,<register>[ ,<bit>]]] ...
            for i in 0, 1, 3:  # integer fields:
                if len(l) > i:
                    l[i] = int(l[i], 0)
            whitelist.append(tuple(l))

        if not machine_type:
            raise error.TestNAError("No machine_type_to_check defined")
        cpu_model_flags = params.get('cpu_model_flags', '')
        full_cpu_model_name = cpu_model
        if cpu_model_flags:
            full_cpu_model_name += ','
            full_cpu_model_name += cpu_model_flags.lstrip(',')
        ref_file = os.path.join(data_dir.get_deps_dir(), 'cpuid',
                                "cpuid_dumps",
                                kvm_enabled and "kvm" or "nokvm",
                                machine_type, '%s-dump.txt' % (full_cpu_model_name))
        if not os.path.exists(ref_file):
            raise error.TestNAError("no cpuid dump file: %s" % (ref_file))
        reference = open(ref_file, 'r').read()
        if not reference:
            raise error.TestNAError(
                "no cpuid dump data on file: %s" % (ref_file))
        reference = parse_cpuid_dump(reference)
        if reference is None:
            raise error.TestNAError(
                "couldn't parse reference cpuid dump from file; %s" % (ref_file))
        try:
            out = get_guest_cpuid(
                self, cpu_model, cpu_model_flags + ',enforce',
                extra_params=dict(machine_type=machine_type, smp=1))
        except virt_vm.VMStartError, e:
            if "host doesn't support requested feature:" in e.reason \
                or ("host cpuid" in e.reason and
                    ("lacks requested flag" in e.reason or
                     "flag restricted to guest" in e.reason)) \
                    or ("Unable to find CPU definition:" in e.reason):
                raise error.TestNAError(
                    "Can't run CPU model %s on this host" % (full_cpu_model_name))
            else:
                raise
Esempio n. 41
0
def run(test, params, env):
    """
    vpum cpu cycles checking between host and guest:
    1) boot guest
    2) check cpu cycles for host
    3) check cpu cycles for guest and compare with host

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    tmp_dir = params.get("tmp_dir")
    timeout = params.get_numeric("login_timeout", 360)
    test_cmd = params.get("test_cmd")
    build_cmd = params.get("build_cmd")
    vm_arch = params["vm_arch_name"]
    host_arch = arch.ARCH
    src_dir = os.path.join(data_dir.get_deps_dir(), 'million')
    src_file = os.path.join(src_dir, "million-%s.s" % host_arch)
    dst_file = os.path.join(tmp_dir, "million-%s.s" % host_arch)

    if not utils_package.package_install("perf"):
        test.error("Install dependency packages failed")
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login(timeout=timeout)
    error_context.context("build binary file 'million' in host", test.log.info)
    copyfile(src_file, dst_file)
    s, o = process.getstatusoutput(build_cmd % host_arch)
    if s:
        test.fail("Failed to build test command")

    error_context.context("running test command in host", test.log.info)
    s, o = process.getstatusoutput(test_cmd)
    if s:
        test.fail("Failed to run test command")

    host_cpu_cycles = re.findall(r"(\d+) *instructions:u", o, re.M)

    if not utils_package.package_install("perf", session):
        test.error("Install dependency packages failed")
    src_file = os.path.join(src_dir, "million-%s.s" % vm_arch)
    error_context.context("transfer '%s' to guest('%s')" %
                          (src_file, dst_file), test.log.info)
    vm.copy_files_to(src_file, tmp_dir, timeout=timeout)

    error_context.context("build binary file 'million' in guest", test.log.info)
    session.cmd(build_cmd % vm_arch)

    error_context.context("running test command in guest", test.log.info)
    output = session.cmd_output(test_cmd, timeout=timeout)
    guest_cpu_cycles = re.findall(r"(\d+) *instructions:u", output, re.M)
    if host_cpu_cycles != guest_cpu_cycles:
        test.fail("cpu cycles is different between host and guest ")
Esempio n. 42
0
def run(test, params, env):
    """
    Build and install packages from git on the client or guest VM

    Supported configurations:
    build_install_pkg: name of the package to get from git, build and install

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

    # Collect test parameters
    pkgName = params.get("build_install_pkg")
    script = params.get("script")
    vm_name = params.get("vm_name")
    dst_dir = params.get("dst_dir")

    # Path of the script on the VM
    vm_script_path = os.path.join(dst_dir, script)

    # Get root session for the VM
    (vm, vm_root_session) = connect_to_vm(vm_name, env, params)

    # location of the script on the host
    host_script_path = os.path.join(data_dir.get_deps_dir(), "spice", script)

    logging.info(
        "Transferring the script to %s," "destination directory: %s, source script location: %s",
        vm_name,
        vm_script_path,
        host_script_path,
    )

    vm.copy_files_to(host_script_path, vm_script_path, timeout=60)
    time.sleep(5)

    # All packages require spice-protocol
    build_install_spiceprotocol(vm_root_session, vm_script_path, params)

    # Run build_install.py script
    if pkgName == "xf86-video-qxl":
        build_install_qxl(vm_root_session, vm_script_path, params)
    elif pkgName == "spice-vd-agent":
        build_install_vdagent(vm_root_session, vm_script_path, params)
    elif pkgName == "spice-gtk":
        build_install_spicegtk(vm_root_session, vm_script_path, params)
    elif pkgName == "virt-viewer":
        build_install_virtviewer(vm_root_session, vm_script_path, params)
    else:
        logging.info("Not supported right now")
        raise error.TestFail("Incorrect Test_Setup")

    utils_spice.clear_interface(vm)
Esempio n. 43
0
    def copy_file_from_deps(file_name, sub_dir, dst_dir="/tmp"):
        """
        Copy a file from deps directory

        param file_name: the file name
        param sub_dir: sub directory that contain the file
        param dst_dir: the target directory the file copied to
        """
        src_full_path = os.path.join(data_dir.get_deps_dir(sub_dir), file_name)
        dst_full_path = os.path.join(dst_dir, file_name)
        shutil.copyfile(src_full_path, dst_full_path)
        return dst_full_path
Esempio n. 44
0
    def install_stress_app(session):
        """
        Install stress app in guest.
        """
        stress_path = data_dir.get_deps_dir("stress")
        stress_guest_path = params["tmp_dir"]
        logging.info("Copy stress package to guest.")
        session.cmd_status_output("mkdir -p %s" % stress_guest_path)
        vm.copy_files_to(stress_path, stress_guest_path)
        session.cmd(params["install_cmd"])

        logging.info("Install app successed")
Esempio n. 45
0
    def env_setup(session, ip, user, port, password):
        error_context.context("Setup env for %s" % ip)
        if params.get("env_setup_cmd"):
            ssh_cmd(session, params.get("env_setup_cmd"), ignore_status=True)

        pkg = params["netperf_pkg"]
        pkg = os.path.join(data_dir.get_deps_dir(), pkg)
        remote.scp_to_remote(ip, shell_port, username, password, pkg, "/tmp")
        ssh_cmd(session, params.get("setup_cmd"))

        agent_path = os.path.join(test.virtdir, "scripts/netperf_agent.py")
        remote.scp_to_remote(ip, shell_port, username, password,
                             agent_path, "/tmp")
Esempio n. 46
0
def deploy_test_form(test, guest_vm, params):
    """
    Copy wxPython Test form to guest VM.
    Test form is copied to /tmp directory.

    :param test
    :param guest_vm - vm object
    :param params
    """

    script = params.get("guest_script")
    script_path = os.path.join(data_dir.get_deps_dir(), "spice", script)
    guest_vm.copy_files_to(script_path, "/tmp/%s" % params.get("guest_script"),
                           timeout=60)
Esempio n. 47
0
    def fio_install(tarball):
        """
        check whether fio is installed in guest, if no, install it, if yes, do nothing.

        :param tarball: fio tar package
        """
        if session.cmd_status(check_install_fio):
            tarball = os.path.join(data_dir.get_deps_dir(), tarball)
            if os_type == "linux":
                vm.copy_files_to(tarball, "/tmp")
                session.cmd("cd /tmp/ && tar -zxvf /tmp/%s" % os.path.basename(tarball), cmd_timeout)
                session.cmd("cd %s && %s" % (fio_path, compile_cmd), cmd_timeout)
            elif os_type == "windows":
                session.cmd("md %s" % fio_path)
                vm.copy_files_to(tarball, fio_path)
Esempio n. 48
0
    def check_tray_status_test(vm, qemu_cdrom_device, guest_cdrom_device,
                               max_times, iso_image_new):
        """
        Test cdrom tray status reporting function.
        """
        error.context("Change cdrom media via monitor", logging.info)
        iso_image_orig = get_cdrom_file(vm, qemu_cdrom_device)
        if not iso_image_orig:
            raise error.TestError("no media in cdrom")
        vm.change_media(qemu_cdrom_device, iso_image_new)
        is_opened = is_tray_opened(vm, qemu_cdrom_device)
        if is_opened:
            raise error.TestFail("cdrom tray not opened after change media")
        try:
            error.context("Copy test script to guest")
            tray_check_src = params.get("tray_check_src")
            if tray_check_src:
                tray_check_src = os.path.join(data_dir.get_deps_dir(), "cdrom",
                                              tray_check_src)
                vm.copy_files_to(tray_check_src, params["tmp_dir"])

            if is_tray_opened(vm, qemu_cdrom_device) is None:
                logging.warn("Tray status reporting is not supported by qemu!")
                logging.warn("cdrom_test_tray_status test is skipped...")
                return

            error.context("Eject the cdrom in guest %s times" % max_times,
                          logging.info)
            session = vm.wait_for_login(timeout=login_timeout)
            for i in range(1, max_times):
                session.cmd(params["eject_cdrom_cmd"] % guest_cdrom_device)
                if not is_tray_opened(vm, qemu_cdrom_device):
                    raise error.TestFail("Monitor reports tray closed"
                                         " when ejecting (round %s)" % i)
                if params["os_type"] != "windows":
                    cmd = "dd if=%s of=/dev/null count=1" % guest_cdrom_device
                else:
                    # windows guest does not support auto close door when reading
                    # cdrom, so close it by eject command;
                    cmd = params["close_cdrom_cmd"] % guest_cdrom_device
                session.cmd(cmd)
                if is_tray_opened(vm, qemu_cdrom_device):
                    raise error.TestFail("Monitor reports tray opened when close"
                                         " cdrom in guest (round %s)" % i)
                time.sleep(workaround_eject_time)
        finally:
            vm.change_media(qemu_cdrom_device, iso_image_orig)
Esempio n. 49
0
    def env_setup(session, ip, user, port, password):
        error_context.context("Setup env for %s" % ip)
        ssh_cmd(session, "iptables -F", ignore_status=True)
        ssh_cmd(session, "service iptables stop", ignore_status=True)
        ssh_cmd(session, "systemctl stop firewalld.service",
                ignore_status=True)
        ssh_cmd(session, "echo 2 > /proc/sys/net/ipv4/conf/all/arp_ignore")
        ssh_cmd(session, "echo 0 > /sys/kernel/mm/ksm/run", ignore_status=True)

        pkg = params["netperf_pkg"]
        pkg = os.path.join(data_dir.get_deps_dir(), pkg)
        remote.scp_to_remote(ip, shell_port, username, password, pkg, "/tmp")
        ssh_cmd(session, params.get("setup_cmd"))

        agent_path = os.path.join(test.virtdir, "scripts/netperf_agent.py")
        remote.scp_to_remote(ip, shell_port, username, password,
                             agent_path, "/tmp")
Esempio n. 50
0
def run(test, params, env):
    """
    Test tap device deleted after vm quit with error

    1) Boot a with invaild params.
    1) Check qemu-kvm quit with error.
    2) Check vm tap device delete from ovs bridge.

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

    def get_ovs_ports(ovs):
        cmd = "ovs-vsctl list-ports %s" % ovs
        return set(utils.system_output(cmd).splitlines())

    os_dep.command("ovs-vsctl")
    netdst = params.get("netdst")
    if netdst not in utils.system_output("ovs-vsctl list-br"):
        raise error.TestError("%s isn't is openvswith bridge" % netdst)

    deps_dir = data_dir.get_deps_dir("ovs")
    nic_script = utils_misc.get_path(deps_dir, params["nic_script"])
    nic_downscript = utils_misc.get_path(deps_dir, params["nic_downscript"])
    params["nic_script"] = nic_script
    params["nic_downscript"] = nic_downscript

    params["qemu_command_prefix"] = "export SHELL=/usr/bin/bash;"
    params["start_vm"] = "yes"
    params["nettype"] = "bridge"
    params["nic_model"] = "virtio-net-pci"

    try:
        ports = get_ovs_ports(netdst)
        env_process.preprocess_vm(test, params, env, params["main_vm"])
        env.get_vm(params["main_vm"])
    except virt_vm.VMStartError:
        ports = get_ovs_ports(netdst) - ports
        if ports:
            for p in ports:
                utils.system("ovs-vsctl del-if %s %s" % (netdst, p))
            raise error.TestFail("%s not delete after qemu quit." % ports)
    else:
        raise error.TestFail("Qemu should quit with error")
def run(test, params, env):
    """
    Time clock offset check test (only for Linux guest):

    1) boot guest with '-rtc base=utc,clock=host,driftfix=slew'
    2) build binary 'clktest' in guest
    3) check clock offset with ./clktest

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    check_timeout = int(params.get("check_timeout", "600"))
    tmp_dir = params.get("tmp_dir", "/tmp")

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    test_cmd = params.get("test_cmd", "./clktest")
    if session.get_command_status("test -x %s" % test_cmd):
        src_dir = os.path.join(data_dir.get_deps_dir(), 'timedrift')
        src_file = os.path.join(src_dir, "clktest.c")
        dst_file = os.path.join(tmp_dir, "clktest.c")
        error.context("transfer '%s' to guest('%s')" % (src_file, dst_file),
                      logging.info)
        vm.copy_files_to(src_file, tmp_dir, timeout=120)

        build_cmd = params.get("build_cmd", "gcc -lrt clktest.c -o clktest")
        error.context("build binary file 'clktest'", logging.info)
        session.cmd(build_cmd)

    error.context("check clock offset via `clktest`", logging.info)
    logging.info("set check timeout to %s seconds", check_timeout)
    try:
        session.cmd_output(test_cmd, timeout=check_timeout)
    except aexpect.ShellTimeoutError, msg:
        if 'Interval is' in msg.output:
            raise error.TestFail(msg.output)
        pass
Esempio n. 52
0
    def setup_gagent_in_host(self, session, params, vm):
        error_context.context("download qemu-ga.msi to host", logging.info)
        deps = params["deps"]
        gagent_download_cmd = params["gagent_download_cmd"]
        if deps == "yes":
            deps_dir = data_dir.get_deps_dir("windows_ga_install")
            gagent_download_cmd = gagent_download_cmd % deps_dir
        utils.run(gagent_download_cmd,
                  float(params.get("login_timeout", 360)))
        gagent_host_path = params["gagent_host_path"]
        if not os.path.exists(gagent_host_path):
            raise error.TestFail("qemu-ga install program is not exist, maybe "
                                 "the program is not successfully downloaded ")
        gagent_guest_dir = params["gagent_guest_dir"]
#        gagent_remove_service_cmd = params["gagent_remove_service_cmd"]
        s, o = session.cmd_status_output("mkdir %s" % gagent_guest_dir)
        if bool(s) and str(s) != "1":
            raise error.TestError("Could not create qemu-ga directory in "
                                  "VM '%s', detail: '%s'" % (vm.name, o))
        error_context.context("Copy qemu guest agent program to guest", logging.info)
        vm.copy_files_to(gagent_host_path, gagent_guest_dir)
Esempio n. 53
0
def prepare_image(params):
    """
    (1) Create a image
    (2) Create file system on the image
    """
    params["image_path"] = utils_test.libguestfs.preprocess_image(params)

    if not params.get("image_path"):
        raise error.TestFail("Image could not be created for some reason.")

    tarball_file = params.get("tarball_file")
    if tarball_file:
        tarball_path = os.path.join(data_dir.get_deps_dir(), "tarball", tarball_file)
    params["tarball_path"] = tarball_path

    gf = utils_test.libguestfs.GuestfishTools(params)
    status, output = gf.create_fs()
    if status is False:
        gf.close_session()
        raise error.TestFail(output)
    gf.close_session()
Esempio n. 54
0
    def set_time(self, nsec, session=None):
        """
        Change host/guest time, if session is not None, change guest time,
        else change host time;

        :param nsec: float seconds, if nsec >0 forward else backward time;
        :param session: ShellSession object;
        """
        src_file = os.path.join(data_dir.get_deps_dir(), "change_time.py")
        python_bin = "python"
        if session:
            dst_dir = self.params["tmp_dir"]
            dst_file = "%s/change_time.py" % dst_dir
            python_bin = self.params["python_bin"]
            if self.is_windows_guest():
                dst_file = r"%s\change_time.py" % dst_dir
            vm = self.get_vm()
            vm.copy_files_to(src_file, dst_dir)
        else:
            dst_file = src_file
        set_time_cmd = "%s %s %s" % (python_bin, dst_file, float(nsec))
        return self.execute(set_time_cmd, session)
Esempio n. 55
0
def install_cpuflags_util_on_vm(test, vm, dst_dir, extra_flags=None):
    """
    Install stress to vm.

    :param vm: virtual machine.
    :param dst_dir: Installation path.
    :param extra_flags: Extraflags for gcc compiler.
    """
    if not extra_flags:
        extra_flags = ""

    cpuflags_src = data_dir.get_deps_dir("cpu_flags")
    cpuflags_dst = os.path.join(dst_dir, "cpu_flags")
    session = vm.wait_for_login()
    session.cmd("rm -rf %s" %
                (cpuflags_dst))
    session.cmd("sync")
    vm.copy_files_to(cpuflags_src, dst_dir)
    session.cmd("sync")
    session.cmd("cd %s; cd src; make EXTRA_FLAGS='%s';" %
                (cpuflags_dst, extra_flags))
    session.cmd("sync")
    session.close()
Esempio n. 56
0
    def check_cpuid_dump(self):
        """
        Compare full CPUID dump data
        """
        machine_type = params.get("machine_type_to_check", "")
        kvm_enabled = params.get("enable_kvm", "yes") == "yes"

        ignore_cpuid_leaves = params.get("ignore_cpuid_leaves", "")
        ignore_cpuid_leaves = ignore_cpuid_leaves.split()
        whitelist = []
        for leaf in ignore_cpuid_leaves:
            leaf = leaf.split(',')
            # syntax of ignore_cpuid_leaves:
            # <in_eax>[,<in_ecx>[,<register>[ ,<bit>]]] ...
            for i in 0, 1, 3:  # integer fields:
                if len(leaf) > i:
                    leaf[i] = int(leaf[i], 0)
            whitelist.append(tuple(leaf))

        if not machine_type:
            raise error.TestNAError("No machine_type_to_check defined")
        cpu_model_flags = params.get('cpu_model_flags', '')
        full_cpu_model_name = cpu_model
        if cpu_model_flags:
            full_cpu_model_name += ','
            full_cpu_model_name += cpu_model_flags.lstrip(',')
        ref_file = os.path.join(data_dir.get_deps_dir(), 'cpuid',
                                "cpuid_dumps",
                                kvm_enabled and "kvm" or "nokvm",
                                machine_type, '%s-dump.txt' % (full_cpu_model_name))
        if not os.path.exists(ref_file):
            raise error.TestNAError("no cpuid dump file: %s" % (ref_file))
        reference = open(ref_file, 'r').read()
        if not reference:
            raise error.TestNAError(
                "no cpuid dump data on file: %s" % (ref_file))
        reference = parse_cpuid_dump(reference)
        if reference is None:
            raise error.TestNAError(
                "couldn't parse reference cpuid dump from file; %s" % (ref_file))
        qom_mode = params.get('qom_mode', "no").lower() == 'yes'
        if not qom_mode:
            cpu_model_flags += ',enforce'
        try:

            out = get_guest_cpuid(
                self, cpu_model, cpu_model_flags,
                extra_params=dict(machine_type=machine_type, smp=1),
                qom_mode=qom_mode)
        except (virt_vm.VMStartError, virt_vm.VMCreateError) as e:
            output = getattr(e, 'reason', getattr(e, 'output', ''))
            if "host doesn't support requested feature:" in output \
                or ("host cpuid" in output and
                    ("lacks requested flag" in output or
                     "flag restricted to guest" in output)) \
                    or ("Unable to find CPU definition:" in output):
                raise error.TestNAError(
                    "Can't run CPU model %s on this host" % (full_cpu_model_name))
            else:
                raise
        dbg('ref_file: %r', ref_file)
        dbg('ref: %r', reference)
        dbg('out: %r', out)
        ok = True
        for k in reference.keys():
            in_eax, in_ecx, reg = k
            diffs = compare_cpuid_output(reference[k], out.get(k))
            for d in diffs:
                bit, vreference, vout = d
                whitelisted = (in_eax,) in whitelist \
                    or (in_eax, in_ecx) in whitelist \
                    or (in_eax, in_ecx, reg) in whitelist \
                    or (in_eax, in_ecx, reg, bit) in whitelist
                silent = False

                if vout is None and params.get('ok_missing', 'no') == 'yes':
                    whitelisted = True
                    silent = True

                if not silent:
                    info(
                        "Non-matching bit: CPUID[0x%x,0x%x].%s[%d]: found %s instead of %s%s",
                        in_eax, in_ecx, reg, bit, vout, vreference,
                        whitelisted and " (whitelisted)" or "")

                if not whitelisted:
                    ok = False
        if not ok:
            raise error.TestFail("Unexpected CPUID data")
Esempio n. 57
0
def run(test, params, env):
    """
    Run netperf stress on server and client side.

    1) Start multi vm(s) guest.
    2) Select multi vm(s) or host to setup netperf server/client.
    3) Run netperf stress test.
    4) Finish test until timeout env["netperf_run"] is False.

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    login_timeout = float(params.get("login_timeout", 360))

    netperf_server = params.get("netperf_server").split()
    netperf_client = params.get("netperf_client").split()
    guest_username = params.get("username", "")
    guest_password = params.get("password", "")
    host_password = params.get("hostpassword", "redhat")
    shell_client = params.get("shell_client")
    shell_port = params.get("shell_port")
    os_type = params.get("os_type")
    compile_option_client = params.get("compile_option_client", "")
    compile_option_server = params.get("compile_option_server", "")
    host_ip = utils_net.get_host_ip_address(params)

    vms = params.get("vms")
    server_infos = []
    client_infos = []
    for server in netperf_server:
        s_info = {}
        if server in vms:
            server_vm = env.get_vm(server)
            server_vm.verify_alive()
            session = server_vm.wait_for_login(timeout=login_timeout)
            session.cmd("service iptables stop; iptables -F",
                        ignore_all_errors=True)
            server_ip = server_vm.get_address()
            s_info["ip"] = server_ip
            s_info["os_type"] = params.get("os_type_%s" % server, os_type)
            s_info["username"] = params.get("username_%s" % server,
                                            guest_username)
            s_info["password"] = params.get("password_%s" % server,
                                            guest_password)
            s_info["shell_client"] = params.get("shell_client_%s" % server,
                                                shell_client)
            s_info["shell_port"] = params.get("shell_port_%s" % server,
                                              shell_port)
        else:
            if server == "localhost":
                s_info["ip"] = host_ip
                s_info["password"] = params.get("password_%s" % server,
                                                host_password)
            else:
                s_info["ip"] = server
                s_info["password"] = params.get("password_%s" % server,
                                                "redhat")
            s_info["os_type"] = params.get("os_type_%s" % server, "linux")
            s_info["username"] = params.get("username_%s" % server,
                                            "root")
            s_info["shell_client"] = params.get("shell_client_%s" % server,
                                                "ssh")
            s_info["shell_port"] = params.get("shell_port_%s" % server,
                                              "22")
        server_infos.append(s_info)

    for client in netperf_client:
        c_info = {}
        if client in vms:
            client_vm = env.get_vm(client)
            client_vm.verify_alive()
            session = client_vm.wait_for_login(timeout=login_timeout)
            session.cmd("service iptables stop; iptables -F",
                        ignore_all_errors=True)
            client_ip = client_vm.get_address()
            c_info["ip"] = client_ip
            c_info["os_type"] = params.get("os_type_%s" % client, os_type)
            c_info["username"] = params.get("username_%s" % client,
                                            guest_username)
            c_info["password"] = params.get("password_%s" % client,
                                            guest_password)
            c_info["shell_client"] = params.get("shell_client_%s" % client,
                                                shell_client)
            c_info["shell_port"] = params.get("shell_port_%s" % client,
                                              shell_port)
        else:
            if client == "localhost":
                c_info["ip"] = host_ip
                c_info["password"] = params.get("password_%s" % client,
                                                host_password)
            else:
                c_info["ip"] = client
                c_info["password"] = params.get("password_%s" % client,
                                                "redhat")
            c_info["os_type"] = params.get("os_type_%s" % client, "linux")
            c_info["username"] = params.get("username_%s" % client,
                                            "root")
            c_info["shell_client"] = params.get("shell_client_%s" % client,
                                                "ssh")
            c_info["shell_port"] = params.get("shell_port_%s" % client,
                                              "23")
        client_infos.append(c_info)

    netperf_link = params.get("netperf_link")
    netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link)
    md5sum = params.get("pkg_md5sum")
    netperf_server_link = params.get("netperf_server_link_win", netperf_link)
    netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                       netperf_server_link)
    server_md5sum = params.get("server_md5sum")
    netperf_client_link = params.get("netperf_client_link_win", netperf_link)
    netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                       netperf_client_link)
    client_md5sum = params.get("client_md5sum")

    server_path_linux = params.get("server_path", "/var/tmp")
    client_path_linux = params.get("client_path", "/var/tmp")
    server_path_win = params.get("server_path_win", "c:\\")
    client_path_win = params.get("client_path_win", "c:\\")

    netperf_clients = []
    netperf_servers = []
    for c_info in client_infos:
        if c_info["os_type"] == "windows":
            netperf_link_c = netperf_client_link
            client_path = client_path_win
            md5sum = client_md5sum
        else:
            netperf_link_c = netperf_link
            client_path = client_path_linux
        n_client = utils_netperf.NetperfClient(c_info["ip"],
                                               client_path,
                                               md5sum, netperf_link_c,
                                               client=c_info["shell_client"],
                                               port=c_info["shell_port"],
                                               username=c_info["username"],
                                               password=c_info["password"],
                                               compile_option=compile_option_client)
        netperf_clients.append(n_client)

    for s_info in server_infos:
        if s_info["os_type"] == "windows":
            netperf_link_s = netperf_server_link
            server_path = server_path_win
            md5sum = server_md5sum
        else:
            netperf_link_s = netperf_link
            server_path = server_path_linux
        n_server = utils_netperf.NetperfServer(s_info["ip"],
                                               server_path,
                                               md5sum, netperf_link_s,
                                               client=s_info["shell_client"],
                                               port=s_info["shell_port"],
                                               username=s_info["username"],
                                               password=s_info["password"],
                                               compile_option=compile_option_server)
        netperf_servers.append(n_server)

    # Get range of message size.
    try:
        for n_server in netperf_servers:
            n_server.start()
        # Run netperf with message size defined in range.
        netperf_test_duration = int(params.get("netperf_test_duration", 60))
        netperf_para_sess = params.get("netperf_para_sessions", "1")
        test_protocols = params.get("test_protocols", "TCP_STREAM")
        netperf_cmd_prefix = params.get("netperf_cmd_prefix", "")
        netperf_output_unit = params.get("netperf_output_unit", " ")
        netperf_package_sizes = params.get("netperf_package_sizes")
        test_option = params.get("test_option", "")
        test_option += " -l %s" % netperf_test_duration
        if params.get("netperf_remote_cpu") == "yes":
            test_option += " -C"
        if params.get("netperf_local_cpu") == "yes":
            test_option += " -c"
        if netperf_output_unit in "GMKgmk":
            test_option += " -f %s" % netperf_output_unit
        start_time = time.time()
        stop_time = start_time + netperf_test_duration
        num = 0
        s_len = len(server_infos)
        for protocol in test_protocols.split():
            error.context("Testing %s protocol" % protocol, logging.info)
            t_option = "%s -t %s" % (test_option, protocol)
            for n_client in netperf_clients:
                index = num % s_len
                server_ip = server_infos[index]["ip"]
                n_client.bg_start(server_ip, t_option,
                                  netperf_para_sess, netperf_cmd_prefix,
                                  package_sizes=netperf_package_sizes)
                if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1,
                                       "Wait netperf test start"):
                    logging.info("Netperf test start successfully.")
                else:
                    raise error.TestError("Can not start netperf client.")
                num += 1
            # here when set a run flag, when other case call this case as a
            # subprocess backgroundly, can set this run flag to False to stop
            # the stress test.
            env["netperf_run"] = True
            for n_client in netperf_clients:
                if n_client.is_netperf_running():
                    left_time = stop_time - time.time()
                    utils_misc.wait_for(lambda: not
                                        n_client.is_netperf_running(),
                                        left_time, 0, 5,
                                        "Wait netperf test finish %ss" % left_time)
    finally:
        for n_server in netperf_servers:
            if n_server:
                n_server.stop()
            n_server.package.env_cleanup(True)
        for n_client in netperf_clients:
            if n_client:
                n_client.package.env_cleanup(True)
        env["netperf_run"] = False
        if session:
            session.close()
Esempio n. 58
0
                                                  params, session)),
                                     timeout=10)
        if not cdroms:
            raise error.TestFail("Not readable cdrom found in your guest")
        cdrom = cdroms[0]
        mount_cmd = params.get("cd_mount_cmd") % cdrom
        (status, output) = session.cmd_status_output(mount_cmd, timeout=360)
        if status:
            msg = "Unable to mount cdrom. "
            msg += "command: %s\nOutput: %s" % (mount_cmd, output)
            raise error.TestError(msg)

    else:
        error.context("lock cdrom in guest", logging.info)
        tmp_dir = params.get("tmp_dir", "c:\\")
        eject_tool = utils_misc.get_path(data_dir.get_deps_dir(),
                                         "cdrom/eject.exe")
        vm.copy_files_to(eject_tool, tmp_dir)
        output = session.cmd("wmic cdrom get Drive", timeout=120)
        cd_vol = re.findall("[d-z]:", output, re.I)[0]
        lock_cmd = "%s\\eject.exe -i on %s" % (tmp_dir, cd_vol)
        (status, output) = session.cmd_status_output(lock_cmd)
        if status:
            msg = "Unable to lock cdrom. command: %s\n" % lock_cmd
            msg += "Output: %s" % output
            raise error.TestError(msg)

    if not check_block_locked(device_name):
        raise error.TestFail("device is not locked after mount it in guest.")

    error.context("Change media of cdrom", logging.info)
Esempio n. 59
0
def run(test, params, env):
    """
    soft lockup/drift test with stress.

    1) Boot up a VM.
    2) Build stress on host and guest.
    3) run heartbeat with the given options on server and host.
    3) Run for a relatively long time length. ex: 12, 18 or 24 hours.
    4) Output the test result and observe drift.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    stress_setup_cmd = params.get("stress_setup_cmd", None)
    stress_cmd = params.get("stress_cmd")
    server_setup_cmd = params.get("server_setup_cmd")
    drift_cmd = params.get("drift_cmd")
    kill_stress_cmd = params.get("kill_stress_cmd")
    kill_monitor_cmd = params.get("kill_monitor_cmd")

    threshold = int(params.get("stress_threshold"))
    monitor_log_file_server = params.get("monitor_log_file_server")
    monitor_log_file_client = params.get("monitor_log_file_client")
    test_length = int(3600 * float(params.get("test_length")))
    monitor_port = int(params.get("monitor_port"))

    vm = env.get_vm(params["main_vm"])
    login_timeout = int(params.get("login_timeout", 360))
    auto_dir = os.environ.get("AUTODIR", os.environ.get("AUTOTEST_PATH"))
    stress_dir = os.path.join(auto_dir, "tests", "stress")
    monitor_dir = params.get("monitor_dir", os.path.join(test.virtdir, 'deps'))

    def _kill_guest_programs(session, kill_stress_cmd, kill_monitor_cmd):
        logging.info("Kill stress and monitor on guest")
        try:
            session.cmd(kill_stress_cmd)
        except Exception:
            pass
        try:
            session.cmd(kill_monitor_cmd)
        except Exception:
            pass

    def _kill_host_programs(kill_stress_cmd, kill_monitor_cmd):
        logging.info("Kill stress and monitor on host")
        utils.run(kill_stress_cmd, ignore_status=True)
        utils.run(kill_monitor_cmd, ignore_status=True)

    def host():
        logging.info("Setup monitor server on host")
        # Kill previous instances of the host load programs, if any
        _kill_host_programs(kill_stress_cmd, kill_monitor_cmd)
        # Cleanup previous log instances
        if os.path.isfile(monitor_log_file_server):
            os.remove(monitor_log_file_server)
        # Opening firewall ports on host
        utils.run("iptables -F", ignore_status=True)

        # Run heartbeat on host
        utils.run(server_setup_cmd % (monitor_dir, threshold,
                                      monitor_log_file_server, monitor_port))

        if not stress_setup_cmd is None:
            logging.info("Build stress on host")
            # Uncompress and build stress on host
            utils.run(stress_setup_cmd % stress_dir)

        logging.info("Run stress on host")
        # stress_threads = 2 * n_cpus
        threads_host = 2 * utils.count_cpus()
        # Run stress test on host
        utils.run(stress_cmd % (stress_dir, threads_host))

    def guest():
        try:
            host_ip = socket.gethostbyname(socket.gethostname())
        except socket.error:
            try:
                # Hackish, but works well on stand alone (laptop) setups
                # with access to the internet. If this fails, well, then
                # not much else can be done...
                s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                s.connect(("redhat.com", 80))
                host_ip = s.getsockname()[0]
            except socket.error, (value, e):
                raise error.TestError("Could not determine host IP: %d %s" %
                                      (value, e))

        # Now, starting the guest
        vm.verify_alive()
        session = vm.wait_for_login(timeout=login_timeout)

        # Kill previous instances of the load programs, if any
        _kill_guest_programs(session, kill_stress_cmd, kill_monitor_cmd)
        # Clean up previous log instances
        session.cmd("rm -f %s" % monitor_log_file_client)

        # Opening firewall ports on guest
        try:
            session.cmd("iptables -F")
        except Exception:
            pass

        # Get monitor files and copy them from host to guest
        monitor_path = os.path.join(data_dir.get_deps_dir(), 'softlockup',
                                    'heartbeat_slu.py')
        vm.copy_files_to(monitor_path, "/tmp")

        logging.info("Setup monitor client on guest")
        # Start heartbeat on guest
        session.cmd(params.get("client_setup_cmd") %
                    ("/tmp", host_ip, monitor_log_file_client, monitor_port))

        if not stress_setup_cmd is None:
            # Copy, uncompress and build stress on guest
            stress_source = params.get("stress_source")
            stress_path = os.path.join(stress_dir, stress_source)
            vm.copy_files_to(stress_path, "/tmp")
            logging.info("Build stress on guest")
            session.cmd(stress_setup_cmd % "/tmp", timeout=200)

        logging.info("Run stress on guest")
        # stress_threads = 2 * n_vcpus
        threads_guest = 2 * int(params.get("smp", 1))
        # Run stress test on guest
        session.cmd(stress_cmd % ("/tmp", threads_guest))

        # Wait and report
        logging.debug("Wait for %d s", test_length)
        time.sleep(test_length)

        # Kill instances of the load programs on both guest and host
        _kill_guest_programs(session, kill_stress_cmd, kill_monitor_cmd)
        _kill_host_programs(kill_stress_cmd, kill_monitor_cmd)

        # Collect drift
        drift = utils.system_output(drift_cmd % monitor_log_file_server)
        logging.info("Drift noticed: %s", drift)
def run(test, params, env):
    """
    QEMU flow caches stress test test

    1) Make sure nf_conntrack is disabled in host and guest.
       If nf_conntrack is enabled in host, skip this case.
    2) Boot guest with vhost=on/off.
    3) Enable multi queues support in guest (optional).
    4) After installation of netperf, run netserver in host.
    5) Run netperf TCP_CRR protocal test in guest.
    6) Transfer file between guest and host.
    7) Check the md5 of copied file.

    This is a sample QEMU test, so people can get used to some of the test APIs.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    msg = "Make sure nf_conntrack is disabled in host and guest."
    error_context.context(msg, logging.info)
    if "nf_conntrack" in process.system_output("lsmod"):
        err = "nf_conntrack load in host, skip this case"
        test.cancel(err)

    params["start_vm"] = "yes"
    error_context.context("Boot up guest", logging.info)
    env_process.preprocess_vm(test, params, env, params["main_vm"])
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)
    if "nf_conntrack" in session.cmd_output("lsmod"):
        msg = "Unload nf_conntrack module in guest."
        error_context.context(msg, logging.info)
        black_str = "#disable nf_conntrack\\nblacklist nf_conntrack\\n" \
                    "blacklist nf_conntrack_ipv6\\nblacklist xt_conntrack\\n" \
                    "blacklist nf_conntrack_ftp\\nblacklist xt_state\\n" \
                    "blacklist iptable_nat\\nblacklist ipt_REDIRECT\\n" \
                    "blacklist nf_nat\\nblacklist nf_conntrack_ipv4"
        cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str
        session.cmd(cmd)
        session = vm.reboot(session, timeout=timeout)
        if "nf_conntrack" in session.cmd_output("lsmod"):
            err = "Fail to unload nf_conntrack module in guest."
            test.error(err)

    netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"),
                                       params["netperf_link"])
    md5sum = params.get("pkg_md5sum")
    win_netperf_link = params.get("win_netperf_link")
    if win_netperf_link:
        win_netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"),
                                               win_netperf_link)
    win_netperf_md5sum = params.get("win_netperf_md5sum")
    server_path = params.get("server_path", "/var/tmp/")
    client_path = params.get("client_path", "/var/tmp/")
    win_netperf_path = params.get("win_netperf_path", "c:\\")
    client_num = params.get("netperf_client_num", 520)
    netperf_timeout = int(params.get("netperf_timeout", 600))
    netperf_client_ip = vm.get_address()
    host_ip = utils_net.get_host_ip_address(params)
    netperf_server_ip = params.get("netperf_server_ip", host_ip)

    username = params.get("username", "root")
    password = params.get("password", "123456")
    passwd = params.get("hostpasswd", "123456")
    client = params.get("shell_client", "ssh")
    port = params.get("shell_port", "22")
    prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#")
    linesep = params.get(
        "shell_linesep", "\n").encode().decode('unicode_escape')
    status_test_command = params.get("status_test_command", "echo $?")

    compile_option_client = params.get("compile_option_client", "")
    compile_option_server = params.get("compile_option_server", "")

    if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux":
        error_context.context("Enable multi queues support in guest.",
                              logging.info)
        guest_mac = vm.get_mac_address()
        ifname = utils_net.get_linux_ifname(session, guest_mac)
        cmd = "ethtool -L %s combined  %s" % (ifname, params.get("queues"))
        status, out = session.cmd_status_output(cmd)
        msg = "Fail to enable multi queues support in guest."
        msg += "Command %s fail output: %s" % (cmd, out)
        test.error(msg)

    if params.get("os_type") == "linux":
        session.cmd("iptables -F", ignore_all_errors=True)
        g_client_link = netperf_link
        g_client_path = client_path
        g_md5sum = md5sum
    elif params.get("os_type") == "windows":
        g_client_link = win_netperf_link
        g_client_path = win_netperf_path
        g_md5sum = win_netperf_md5sum

    error_context.context("Setup netperf in guest and host", logging.info)
    netperf_client = utils_netperf.NetperfClient(netperf_client_ip,
                                                 g_client_path,
                                                 g_md5sum, g_client_link,
                                                 username=username,
                                                 password=password,
                                                 prompt=prompt,
                                                 linesep=linesep,
                                                 status_test_command=status_test_command,
                                                 compile_option=compile_option_client)

    netperf_server = utils_netperf.NetperfServer(netperf_server_ip,
                                                 server_path,
                                                 md5sum,
                                                 netperf_link,
                                                 client, port,
                                                 password=passwd,
                                                 prompt=prompt,
                                                 linesep=linesep,
                                                 status_test_command=status_test_command,
                                                 compile_option=compile_option_server)
    try:
        error_context.base_context("Run netperf test between host and guest.")
        error_context.context("Start netserver in host.", logging.info)
        netperf_server.start()

        error_context.context("Start Netperf in guest for %ss."
                              % netperf_timeout, logging.info)
        test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout
        netperf_client.bg_start(netperf_server_ip, test_option, client_num)

        utils_misc.wait_for(lambda: not netperf_client.is_netperf_running(),
                            timeout=netperf_timeout, first=590, step=2)

        utils_test.run_file_transfer(test, params, env)
    finally:
        netperf_server.stop()
        netperf_client.package.env_cleanup(True)
        if session:
            session.close()