def run(test, params, env):
    """
    Qemu memory hotplug test:
    1) Boot guest with -m option
    2) Hotplug memory to guest and check memory inside guest
    3) Run stress tests 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()
    mem_name = params["target_mems"]
    hotplug_test = MemoryHotplugTest(test, params, env)
    hotplug_test.hotplug_memory(vm, mem_name)
    hotplug_test.check_memory(vm)
    if params['os_type'] == 'linux':
        stress_args = params.get("stress_args")
        stress_test = utils_test.VMStress(vm,
                                          "stress",
                                          params,
                                          stress_args=stress_args)
        stress_test.load_stress_tool()
        time.sleep(60)
        stress_test.unload_stress()
Beispiel #2
0
def run(test, params, env):
    """
    General stress test for linux:
       1). Install stress if need
       2). Start stress process
       3). If no stress_time defined, keep stress until test_timeout;
       otherwise execute below steps after sleeping stress_time long
       4). Stop stress process
       5). Uninstall stress
       6). Verify guest kernel crash

    :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()
    stress = utils_test.VMStress(vm, 'stress')
    stress.load_stress_tool()
    stress_duration = int(params.get('stress_duration', 0))
    # NOTE: stress_duration = 0 ONLY for some legacy test cases using
    # autotest stress.control as their sub test.
    # Please DO define stress_duration to make sure the clean action
    # being performed, if your case can not be controlled by time,
    # use utils_test.VMStress() directly

    if stress_duration:
        time.sleep(stress_duration)
        stress.unload_stress()
        stress.clean()
        vm.verify_kernel_crash()
Beispiel #3
0
 def run_stress(test, params, env, vm):
     """
     Run stress in background
     """
     while True:
         if params['os_type'] == 'windows':
             utils_test.run_virt_sub_test(test, params, env,
                                          params.get("stress_test"))
         else:
             stress_bg = utils_test.VMStress(vm, "stress", params)
             stress_bg.load_stress_tool()
Beispiel #4
0
    def run_stress_in_vm(self, vm, params):
        """
        Load stress in VM.

        :param vm: VM object
        :param params: Test dict params
        :raise: exceptions.TestError if it fails to run stress tool
        """
        stress_package = params.get("stress_package", "stress")
        try:
            vm_stress = utils_test.VMStress(vm, stress_package, params)
            vm_stress.load_stress_tool()
        except utils_test.StressError as info:
            raise exceptions.TestError(info)
Beispiel #5
0
 def run_stress():
     """
     Run stress inside guest, return guest cpu usage
     """
     error_context.context("Run stress in guest and get cpu usage",
                           logging.info)
     if os_type == "linux":
         stress_args = params["stress_args"]
         stress_test = utils_test.VMStress(vm,
                                           "stress",
                                           params,
                                           stress_args=stress_args)
         try:
             stress_test.load_stress_tool()
             time.sleep(stress_duration / 2)
             output = session.cmd_output_safe(params["get_cpu_usage_cmd"])
             utils_misc.wait_for(lambda: (stress_test.app_running is False),
                                 30)
             stress_test.unload_stress()
             cpu_usage = re.findall(r":\s*(\d+.?\d+)\s*us", output)
             cpu_usage = [float(x) for x in cpu_usage]
             logging.info("Guest cpu usage is %s", cpu_usage)
             unloaded_cpu = [x for x in cpu_usage if x < 20]
             if unloaded_cpu:
                 test.fail("CPU(s) load percentage is less than 20%")
         finally:
             stress_test.clean()
     else:
         install_path = params["install_path"]
         heavyload_install(install_path)
         error_context.context("Run heavyload inside guest.", logging.info)
         heavyload_bin = r'"%s\heavyload.exe" ' % install_path
         heavyload_options = [
             "/CPU %d" % vm.cpuinfo.smp,
             "/DURATION %d" % (stress_duration // 60), "/AUTOEXIT", "/START"
         ]
         start_cmd = heavyload_bin + " ".join(heavyload_options)
         stress_tool = BackgroundTest(
             session.cmd, (start_cmd, stress_duration, stress_duration))
         stress_tool.start()
         if not utils_misc.wait_for(stress_tool.is_alive, stress_duration):
             test.error("Failed to start heavyload process.")
         stress_tool.join(stress_duration)
Beispiel #6
0
    def run_stress():
        def heavyload_install():
            if session.cmd_status(test_install_cmd) != 0:
                logging.warning("Could not find installed heavyload in guest, "
                                "will install it via winutils.iso ")
                winutil_drive = utils_misc.get_winutils_vol(session)
                if not winutil_drive:
                    test.cancel("WIN_UTILS CDROM not found.")
                install_cmd = params["install_cmd"] % winutil_drive
                session.cmd(install_cmd)

        logging.info('Loading stress on guest.')
        stress_duration = params.get("stress_duration", 60)
        if params["os_type"] == "linux":
            params['stress_args'] = '--vm %s --vm-bytes 256M --timeout %s' % (
                mem // 512, stress_duration)
            stress = utils_test.VMStress(vm, 'stress', params)
            stress.load_stress_tool()
            time.sleep(stress_duration)
            stress.unload_stress()
        else:
            session = vm.wait_for_login()
            install_path = params["install_path"]
            test_install_cmd = 'dir "%s" | findstr /I heavyload' % install_path
            heavyload_install()
            heavyload_bin = r'"%s\heavyload.exe" ' % install_path
            heavyload_options = [
                "/MEMORY 100",
                "/DURATION %d" % (stress_duration // 60), "/AUTOEXIT", "/START"
            ]
            start_cmd = heavyload_bin + " ".join(heavyload_options)
            stress_tool = BackgroundTest(
                session.cmd, (start_cmd, stress_duration, stress_duration))
            stress_tool.start()
            if not utils_misc.wait_for(stress_tool.is_alive, 30):
                test.error("Failed to start heavyload process")
            stress_tool.join(stress_duration)
def run(test, params, env):
    """
    Run stress as a memory stress in guest for THP testing

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

    nr_ah = []

    debugfs_flag = 1
    debugfs_path = os.path.join(test.tmpdir, 'debugfs')
    mem = int(params.get("mem"))
    qemu_mem = int(params.get("qemu_mem", "64"))
    hugetlbfs_path = params.get("hugetlbfs_path", "/proc/sys/vm/nr_hugepages")
    vm = env.get_vm(params["main_vm"])

    error_context.context("smoke test setup")
    if not os.path.ismount(debugfs_path):
        if not os.path.isdir(debugfs_path):
            os.makedirs(debugfs_path)
        try:
            process.system("mount -t debugfs none %s" % debugfs_path,
                           shell=True)
        except Exception:
            debugfs_flag = 0

    try:
        # Allocated free memory to hugetlbfs
        mem_free = int(utils_memory.read_from_meminfo('MemFree')) / 1024
        mem_swap = int(utils_memory.read_from_meminfo('SwapFree')) / 1024
        hugepage_size = (int(utils_memory.read_from_meminfo('Hugepagesize')) /
                         1024)
        nr_hugetlbfs = (mem_free + mem_swap - mem - qemu_mem) / hugepage_size
        fd = open(hugetlbfs_path, "w")
        fd.write(str(nr_hugetlbfs))
        fd.close()

        error_context.context("Memory stress test")

        nr_ah.append(int(utils_memory.read_from_meminfo('AnonHugePages')))
        if nr_ah[0] <= 0:
            test.fail("VM is not using transparent hugepage")

        # Run stress memory heavy in guest
        test_mem = float(mem)*float(params.get("mem_ratio", 0.8))
        stress_args = "--cpu 4 --io 4 --vm 2 --vm-bytes %sM" % int(test_mem / 2)
        stress_test = utils_test.VMStress(vm, "stress", params, stress_args=stress_args)
        stress_test.load_stress_tool()
        time.sleep(int(params.get("stress_time", 120)))
        nr_ah.append(int(utils_memory.read_from_meminfo('AnonHugePages')))
        logging.debug("The huge page using for guest is: %s" % nr_ah)

        if nr_ah[1] <= nr_ah[0]:
            logging.warn(
                "VM don't use transparent hugepage while memory stress")

        if debugfs_flag == 1:
            if int(open(hugetlbfs_path, 'r').read()) <= 0:
                test.fail("KVM doesn't use transparenthugepage")

        logging.info("memory stress test finished")
        stress_test.unload_stress()
        stress_test.clean()
    finally:
        error_context.context("all tests cleanup")
        fd = open(hugetlbfs_path, "w")
        fd.write("0")
        fd.close()
        if os.path.ismount(debugfs_path):
            process.run("umount %s" % debugfs_path, shell=True)
        if os.path.isdir(debugfs_path):
            os.removedirs(debugfs_path)
Beispiel #8
0
def run(test, params, env):
    """
    Re-assign nr-hugepages

    1. Set up hugepage with 1G page size and hugepages=8
    2. Boot up guest using /mnt/kvm_hugepage as backend in QEMU CML
    3. Change the nr_hugepages after the guest boot up (6 and 10)
    4. Run the stress test **inside guest**
    5. change the nr_hugepages after the stress test (6 and 10)

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

    def set_hugepage():
        """Set nr_hugepages"""
        for h_size in (origin_nr - 2, origin_nr + 2):
            hp_config.target_hugepages = h_size
            hp_config.set_hugepages()
            if params.get('on_numa_node'):
                logging.info('Set hugepage size %s to target node %s' % (
                    h_size, target_node))
                hp_config.set_node_num_huge_pages(h_size, target_node,
                                                  hugepage_size)

    origin_nr = int(params['origin_nr'])
    host_numa_node = utils_misc.NumaInfo()
    mem = int(float(utils_misc.normalize_data_size("%sM" % params["mem"])))
    if params.get('on_numa_node'):
        for target_node in host_numa_node.get_online_nodes_withmem():
            node_mem_free = host_numa_node.read_from_node_meminfo(
                target_node, 'MemFree')
            if int(node_mem_free) > mem:
                params['target_nodes'] = target_node
                params["qemu_command_prefix"] = ("numactl --membind=%s" %
                                                 target_node)
                params['target_num_node%s' % target_node] = origin_nr
                break
            logging.info(
                'The free memory of node %s is %s, is not enough for'
                ' guest memory: %s' % (target_node, node_mem_free, mem))
        else:
            test.cancel("No node on your host has sufficient free memory for "
                        "this test.")
    hp_config = test_setup.HugePageConfig(params)
    hp_config.target_hugepages = origin_nr
    logging.info('Setup hugepage number to %s' % origin_nr)
    hp_config.setup()
    hugepage_size = utils_memory.get_huge_page_size()

    params['start_vm'] = "yes"
    vm_name = params['main_vm']
    env_process.preprocess_vm(test, params, env, vm_name)
    vm = env.get_vm(vm_name)
    params['stress_args'] = '--vm %s --vm-bytes 256M --timeout 30s' % (
            mem // 512)
    logging.info('Loading stress on guest.')
    stress = utils_test.VMStress(vm, 'stress', params)
    stress.load_stress_tool()
    time.sleep(30)
    stress.unload_stress()
    set_hugepage()
    hp_config.cleanup()
    vm.verify_kernel_crash()
Beispiel #9
0
def run(test, params, env):
    """
    Test migration under stress.
    """
    vm_names = params.get("vms").split()
    if len(vm_names) < 2:
        test.cancel("Provide enough vms for migration")

    src_uri = "qemu:///system"
    dest_uri = libvirt_vm.complete_uri(
        params.get("migrate_dest_host", "EXAMPLE"))
    if dest_uri.count('///') or dest_uri.count('EXAMPLE'):
        test.cancel("The dest_uri '%s' is invalid" % dest_uri)

    # Migrated vms' instance
    vms = env.get_all_vms()
    params["load_vms"] = list(vms)

    cpu = int(params.get("smp", 1))
    memory = int(params.get("mem")) * 1024
    stress_tool = params.get("stress_tool", "")
    remote_stress = params.get("migration_stress_remote", "no") == "yes"
    host_stress = params.get("migration_stress_host", "no") == "yes"
    vms_stress = params.get("migration_stress_vms", "no") == "yes"
    vm_bytes = params.get("stress_vm_bytes", "128M")
    stress_args = params.get("%s_args" % stress_tool)
    migration_type = params.get("migration_type")
    start_migration_vms = params.get("start_migration_vms", "yes") == "yes"
    thread_timeout = int(params.get("thread_timeout", 120))
    ubuntu_dep = ['build-essential', 'git']
    hstress = rstress = None
    vstress = {}

    # Set vm_bytes for start_cmd
    mem_total = utils_memory.memtotal()
    vm_reserved = len(vms) * memory
    if vm_bytes == "half":
        vm_bytes = (mem_total - vm_reserved) / 2
    elif vm_bytes == "shortage":
        vm_bytes = mem_total - vm_reserved + 524288
    if "vm-bytes" in stress_args:
        params["%s_args" % stress_tool] = stress_args % vm_bytes

    # Ensure stress tool is available in host
    if host_stress:
        # remove package manager installed tool to avoid conflict
        if not utils_package.package_remove(stress_tool):
            logging.error("Existing %s is not removed")
        if "stress-ng" in stress_tool and 'Ubuntu' in utils_misc.get_distro():
            params['stress-ng_dependency_packages_list'] = ubuntu_dep
        try:
            hstress = utils_test.HostStress(stress_tool, params)
            hstress.load_stress_tool()
        except utils_test.StressError as info:
            test.error(info)

    if remote_stress:
        try:
            server_ip = params['remote_ip']
            server_pwd = params['remote_pwd']
            server_user = params.get('remote_user', 'root')
            remote_session = remote.wait_for_login('ssh', server_ip, '22',
                                                   server_user, server_pwd,
                                                   r"[\#\$]\s*$")
            # remove package manager installed tool to avoid conflict
            if not utils_package.package_remove(stress_tool,
                                                session=remote_session):
                logging.error("Existing %s is not removed")
            if ("stess-ng" in stress_tool and 'Ubuntu'
                    in utils_misc.get_distro(session=remote_session)):
                params['stress-ng_dependency_packages_list'] = ubuntu_dep

            rstress = utils_test.HostStress(stress_tool,
                                            params,
                                            remote_server=True)
            rstress.load_stress_tool()
            remote_session.close()
        except utils_test.StressError as info:
            remote_session.close()
            test.error(info)

    for vm in vms:
        # Keep vm dead for edit
        if vm.is_alive():
            vm.destroy()
        set_cpu_memory(vm.name, cpu, memory)

    try:
        if start_migration_vms:
            for vm in vms:
                vm.start()
                session = vm.wait_for_login()
                # remove package manager installed tool to avoid conflict
                if not utils_package.package_remove(stress_tool,
                                                    session=session):
                    logging.error("Existing %s is not removed")
                # configure stress in VM
                if vms_stress:
                    if ("stress-ng" in stress_tool and 'Ubuntu'
                            in utils_misc.get_distro(session=session)):
                        params[
                            'stress-ng_dependency_packages_list'] = ubuntu_dep
                    try:
                        vstress[vm.name] = utils_test.VMStress(
                            vm, stress_tool, params)
                        vstress[vm.name].load_stress_tool()
                    except utils_test.StressError as info:
                        session.close()
                        test.error(info)
                session.close()

        do_stress_migration(vms, src_uri, dest_uri, migration_type, test,
                            params, thread_timeout)
    finally:
        logging.debug("Cleanup vms...")
        for vm in vms:
            utils_test.libvirt.MigrationTest().cleanup_dest_vm(
                vm, None, dest_uri)
            # Try to start vms in source once vms in destination are
            # cleaned up
            if not vm.is_alive():
                vm.start()
                vm.wait_for_login()
            try:
                if vstress[vm.name]:
                    vstress[vm.name].unload_stress()
            except KeyError:
                continue

        if rstress:
            rstress.unload_stress()

        if hstress:
            hstress.unload_stress()
    try:
        if start_migration_vms:
            for vm in vms:
                vm.start()
                session = vm.wait_for_login()
                # remove package manager installed tool to avoid conflict
                if not utils_package.package_remove(stress_tool, session=session):
                    logging.error("Existing %s is not removed")
                # configure stress in VM
                if vms_stress:
                    if("stress-ng" in stress_tool and
                       'Ubuntu' in utils_misc.get_distro(session=session)):
                        params['stress-ng_dependency_packages_list'] = ubuntu_dep
                    try:
                        vstress[vm.name] = utils_test.VMStress(vm, stress_tool, params)
                        vstress[vm.name].load_stress_tool()
                    except utils_test.StressError, info:
                        session.close()
                        test.error(info)
                session.close()

        do_stress_migration(vms, src_uri, dest_uri, migration_type, test,
                            params, thread_timeout)
    finally:
        logging.debug("Cleanup vms...")
        params["connect_uri"] = src_uri
        for vm in vms:
            utils_test.libvirt.MigrationTest().cleanup_dest_vm(vm, None,
                                                               dest_uri)
            # Try to start vms in source once vms in destination are
Beispiel #11
0
def run(test, params, env):
    """
    Steal time test:
    1) Boot two guests and bind to one same cpu
    2) Run stress inside both guests
    3) Check steal time in top inside guests
    4) Check if two qemu processes have equal cpu usage
    5) Check steal time in /proc/stat in guest
    6) Repeat step 4) after 60s, compare the steal time changed in two guests

    :params test: QEMU test object.
    :params params: Dictionary with the test parameters.
    :params env: Dictionary with test environment.
    """
    def get_stat_val():
        """
        Get steal time value in /proc/stat
        """
        stat_val = []
        for session in sessions:
            val = session.cmd_output(stat_cmd).split()[8]
            stat_val.append(int(val))
        return stat_val

    stress_args = params["stress_args"]
    stress_tests = []
    sessions = []
    vms = env.get_all_vms()

    error_context.context("Run stress in both guests", logging.info)
    for vm in vms:
        session = vm.wait_for_login()
        sessions.append(session)
        stress_test = utils_test.VMStress(vm,
                                          "stress",
                                          params,
                                          stress_args=stress_args)
        stress_test.load_stress_tool()
        stress_tests.append(stress_test)

    time.sleep(10)
    top_cmd = params["top_cmd"]
    stat_cmd = params["stat_cmd"]

    try:
        error_context.context("Check steal time in guests", logging.info)
        for session in sessions:
            output = session.cmd_output(top_cmd)
            top_st = re.findall(r",\s*(\d+.?\d+)\s*st", output)[0]
            if abs(float(top_st) - 50) > 10:
                test.fail("Guest steal time is not around 50")

        error_context.context("Check two qemu process cpu usage", logging.info)
        cmd = "top -n1 -b -p %s -p %s | grep qemu-kvm | awk '{print $9}'" \
              % (vms[0].get_pid(), vms[1].get_pid())
        cpu_usage = process.getoutput(cmd, shell=True).split()
        logging.info("QEMU cpu usage are %s", cpu_usage)
        cpu_usage = sorted([float(x) for x in cpu_usage])
        if sum(cpu_usage) < 80 or cpu_usage[0] < 40:
            test.fail("Two qemu process didn't get equal cpu usage")

        error_context.context("Check steal time in /proc/stat", logging.info)
        stat_val_pre = get_stat_val()
        logging.info("Steal time value in /proc/stat is %s", stat_val_pre)
        time.sleep(60)
        stat_val_post = get_stat_val()
        logging.info("After 60s, steal time value in /proc/stat is %s",
                     stat_val_post)

        delta = list(map(lambda x, y: y - x, stat_val_pre, stat_val_post))
        if abs(delta[0] - delta[1]) > sum(delta) / 2 * 0.1:
            test.fail("Guest steal time change in /proc/stat is not close")

    finally:
        for stress_test in stress_tests:
            stress_test.unload_stress()
 def _run_stress_test(self):
     """Run stress test before block-stream"""
     self.stress = utils_test.VMStress(self.main_vm, "stress", self.params)
     self.stress.load_stress_tool()
 def run_stress_test(self):
     self.stress_test = utils_test.VMStress(self.main_vm, "stress",
                                            self.params)
     self.stress_test.load_stress_tool()
def run(test, params, env):
    """
    Qemu hugepage memory stress test.
    Steps:
    1) System setup hugepages on host.
    2) Mount this hugepage to /mnt/kvm_hugepage.
    3) HugePages didn't leak when using non-existent mem-path.
    4) Run memory heavy stress inside guest.
    5) Check guest call trace in dmesg log.
    :params test: QEMU test object.
    :params params: Dictionary with the test parameters.
    :params env: Dictionary with test environment.
    """
    def heavyload_install():
        if session.cmd_status(test_installed_cmd) != 0:
            logging.warning("Could not find installed heavyload in guest, will"
                            " install it via winutils.iso ")
            winutil_drive = utils_misc.get_winutils_vol(session)
            if not winutil_drive:
                test.cancel("WIN_UTILS CDROM not found.")
            install_cmd = params["install_cmd"] % winutil_drive
            session.cmd(install_cmd)

    if params.get_boolean("non_existent_point"):
        dir = tempfile.mkdtemp(prefix='hugepage_')
        error_context.context("This path %s, doesn't mount hugepage." %
                              dir, logging.info)
        params["extra_params"] = " -mem-path %s" % dir
        params["start_vm"] = "yes"
        env_process.preprocess_vm(test, params, env, params["main_vm"])

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

    try:
        error_context.context("Run memory heavy stress in guest", logging.info)
        if os_type == "linux":
            stress_args = params["stress_custom_args"] % (
                    params.get_numeric("mem") / 512)
            stress_test = utils_test.VMStress(vm, "stress",
                                              params, stress_args=stress_args)
            try:
                stress_test.load_stress_tool()
                utils_misc.wait_for(lambda: (stress_test.app_running is False), 30)
                stress_test.unload_stress()
                utils_misc.verify_dmesg(session=session)
            finally:
                stress_test.clean()
        else:
            install_path = params["install_path"]
            test_installed_cmd = 'dir "%s" | findstr /I heavyload' % install_path
            heavyload_install()
            error_context.context("Run heavyload inside guest.", logging.info)
            heavyload_bin = r'"%s\heavyload.exe" ' % install_path
            heavyload_options = ["/MEMORY %d" % (params.get_numeric("mem") / 512),
                                 "/DURATION %d" % (stress_duration // 60),
                                 "/AUTOEXIT",
                                 "/START"]
            start_cmd = heavyload_bin + " ".join(heavyload_options)
            stress_tool = BackgroundTest(session.cmd, (start_cmd,
                                                       stress_duration, stress_duration))
            stress_tool.start()
            if not utils_misc.wait_for(stress_tool.is_alive, stress_duration):
                test.error("Failed to start heavyload process.")
            stress_tool.join(stress_duration)

        if params.get_boolean("non_existent_point"):
            error_context.context("Check large memory pages free on host.",
                                  logging.info)
            if utils_memory.get_num_huge_pages() != utils_memory.get_num_huge_pages_free():
                test.fail("HugePages leaked.")
    finally:
        session.close()
Beispiel #15
0
 def create_snapshot(self):
     error_context.context("do snaoshot during running stress in guest",
                           logging.info)
     stress_test = utils_test.VMStress(self.main_vm, "stress", self.params)
     stress_test.load_stress_tool()
     super(BlockdevSnapshotStressTest, self).create_snapshot()
 def load_stress(self):
     error_context.context("load stress app in guest", logging.info)
     stress_test = utils_test.VMStress(self.main_vm, "stress", self.params)
     stress_test.load_stress_tool()
Beispiel #17
0
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest (Windows only)
    3) run stress in background repeatly
    4) balloon memory in monitor in loop

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def check_bg_running():
        """
        Check the background test status in guest.
        :return: return True if find the process name; otherwise False
        """
        if params['os_type'] == 'windows':
            list_cmd = params.get("list_cmd", "wmic process get name")
            output = session.cmd_output_safe(list_cmd, timeout=60)
            process = re.findall("mplayer", output, re.M | re.I)
            return bool(process)
        else:
            return stress_bg.app_running()

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

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

    if params['os_type'] == 'windows':
        driver_name = params["driver_name"]
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, driver_name, timeout)
        balloon_test = BallooningTestWin(test, params, env)
    else:
        balloon_test = BallooningTestLinux(test, params, env)

    error_context.context("Run stress background", logging.info)
    stress_test = params.get("stress_test")
    if params['os_type'] == 'windows':
        utils_test.run_virt_sub_test(test, params, env, stress_test)
        if not utils_misc.wait_for(check_bg_running,
                                   first=2.0,
                                   text="wait for stress app to start",
                                   step=1.0,
                                   timeout=60):
            test.error("Run stress background failed")
    else:
        stress_bg = utils_test.VMStress(vm, "stress", params)
        stress_bg.load_stress_tool()

    repeat_times = int(params.get("repeat_times", 1000))
    min_sz, max_sz = balloon_test.get_memory_boundary()

    error_context.context("balloon vm memory in loop", logging.info)
    try:
        for i in range(1, int(repeat_times + 1)):
            logging.info("repeat times: %d" % i)
            balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
            if not check_bg_running():
                test.error("Background stress process is not alive")
    finally:
        if session:
            session.close()
Beispiel #18
0
def run(test, params, env):
    """
    :param test:   kvm test object
    :param params: Dictionary with the test parameters
    :param env:    Dictionary with test environment.
    The test will
    1. Create 'n' uperf server-client pairs,
    2. Configure iptables in guest and install uperf
    3. Kick start uperf run, wait for duration [customized given in uperf profile]
    4. After run, test will check for errors and make sure all guests are reachable.
    5. Cleanup temp files and iptable rules added before
    """

    stress_duration = int(params.get("stress_duration", "20"))
    ip_rule = params.get("ip_rule", "")
    stress_type = params.get("stress_type", "")
    need_profile = int(params.get("need_profile", 0))
    server_cmd = params.get("%s_server_cmd" % stress_type)
    client_cmd = params.get("%s_client_cmd" % stress_type)
    client_vms = []
    server_vms = []
    error = 0
    vms = env.get_all_vms()

    if (need_profile):
        profile = params.get("client_profile_%s" % stress_type)
        profile = os.path.join(data_dir.get_root_dir(), profile)
        profile_pattren = params.get("profile_pattren", "").split()

    for index, vm in enumerate(vms):
        if index % 2 != 0:
            # Process for client
            client_vms.append(vm)
        else:
            # Process for server
            server_vms.append(vm)
    pair_vms = zip(server_vms, client_vms)

    if len(server_vms) != len(client_vms):
        test.cancel("This test requires server and client vms in 1:1 ratio")

    if stress_type == "uperf":
        protocol = params.get("%s_protocol" % stress_type, "tcp")
        nthreads = params.get("nthreads", "32")
        client_cmd = client_cmd % os.path.basename(profile)
        if not profile.endswith(".xml"):
            logging.debug("Error: profile should be an xml: %s", profile)
            test.cancel("%s profile not valid", stress_type)
        profile_values = [nthreads, str(stress_duration), protocol]
        if len(profile_pattren) != len(profile_values):
            test.cancel(
                "Profile pattrens not matching values passed: fix the cfg file with right pattren"
            )
        profile_pattren.append('serverip')
        pat_repl = dict(zip(profile_pattren, profile_values))
    elif stress_type == "netperf":
        ports = params.get("ports", "16604")
        test_protocol = params.get("test_protocols", "TCP_STREAM")
        server_cmd = server_cmd.format(ports)
        client_cmd = client_cmd.format("{0}", ports, stress_duration,
                                       test_protocol)
    else:
        raise NotImplementedError

    for server_vm, client_vm in pair_vms:
        try:
            params['stress_cmds_%s' % stress_type] = server_cmd
            stress_server = utils_test.VMStress(server_vm, stress_type, params)
            params['server_pwd'] = params.get("password")
            # wait so that guests get ip address, else get_address will fail
            client_vm.wait_for_login().close()
            if ip_rule:
                for vm_ip in [
                        server_vm.get_address(),
                        client_vm.get_address()
                ]:
                    params['server_ip'] = vm_ip
                    Iptables.setup_or_cleanup_iptables_rules([ip_rule],
                                                             params=params,
                                                             cleanup=False)
            stress_server.load_stress_tool()
            if need_profile:
                profile_backup = profile + '.backup'
                shutil.copy(profile, profile_backup)
                pat_repl.update({"serverip": str(server_vm.get_address())})
                utils_test.prepare_profile(test, profile, pat_repl)
                client_vm.copy_files_to(profile, "/home", timeout=60)
                shutil.copy(profile_backup, profile)
                os.remove(profile_backup)
            else:
                client_cmd = client_cmd.format(str(server_vm.get_address()))
            params['stress_cmds_%s' % stress_type] = client_cmd
            stress_client = utils_test.VMStress(client_vm, stress_type, params)
            stress_client.load_stress_tool()
        except exceptions.TestError as err_msg:
            error = 1
            logging.error(err_msg)

    if stress_duration and not error:
        time.sleep(stress_duration)

    for vm in vms:
        try:
            s_ping, o_ping = utils_test.ping(vm.get_address(),
                                             count=10,
                                             timeout=20)
            logging.info(o_ping)
            if s_ping != 0:
                error = 1
                logging.error("%s seem to have gone out of network", vm.name)
            else:
                stress = utils_test.VMStress(vm, stress_type, params)
                stress.unload_stress()
                if ip_rule:
                    params['server_ip'] = vm.get_address()
                    Iptables.setup_or_cleanup_iptables_rules([ip_rule],
                                                             params=params,
                                                             cleanup=True)
                stress.clean()
                vm.verify_dmesg()
        except exceptions.TestError as err_msg:
            error = 1
            logging.error(err_msg)
        finally:
            if vm.exists() and vm.is_persistent():
                vm.undefine()
    if error:
        test.fail("%s run failed: see error messages above" % stress_type)
Beispiel #19
0
def run(test, params, env):
    """
    Qemu numa stress test:
    1) Boot up a guest and find the node it used
    2) Try to allocate memory in that node
    3) Run memory heavy stress inside guest
    4) Check the memory use status of qemu process
    5) Repeat step 2 ~ 4 several times


    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    host_numa_node = utils_misc.NumaInfo()
    if len(host_numa_node.online_nodes) < 2:
        test.cancel("Host only has one NUMA node, skipping test...")

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

    qemu_pid = vm.get_pid()

    if test_count < len(host_numa_node.online_nodes):
        test_count = len(host_numa_node.online_nodes)

    tmpfs_size = params.get_numeric("tmpfs_size")
    for node in host_numa_node.nodes:
        node_mem = int(host_numa_node.read_from_node_meminfo(node, "MemTotal"))
        if tmpfs_size == 0:
            tmpfs_size = node_mem
    tmpfs_path = params.get("tmpfs_path", "tmpfs_numa_test")
    tmpfs_path = utils_misc.get_path(data_dir.get_tmp_dir(), tmpfs_path)
    tmpfs_write_speed = get_tmpfs_write_speed()
    dd_timeout = tmpfs_size / tmpfs_write_speed * 1.5
    mount_fs_size = "size=%dK" % tmpfs_size
    memory_file = utils_misc.get_path(tmpfs_path, "test")
    dd_cmd = "dd if=/dev/urandom of=%s bs=1k count=%s" % (memory_file,
                                                          tmpfs_size)
    utils_memory.drop_caches()

    if utils_memory.freememtotal() < tmpfs_size:
        test.cancel("Host does not have enough free memory to run the test, "
                    "skipping test...")

    if not os.path.isdir(tmpfs_path):
        os.mkdir(tmpfs_path)

    test_mem = float(params.get("mem")) * float(params.get("mem_ratio", 0.8))
    stress_args = "--cpu 4 --io 4 --vm 2 --vm-bytes %sM" % int(test_mem / 2)
    most_used_node, memory_used = max_mem_map_node(host_numa_node, qemu_pid)

    for test_round in range(test_count):
        if os.path.exists(memory_file):
            os.remove(memory_file)
        utils_memory.drop_caches()
        if utils_memory.freememtotal() < tmpfs_size:
            test.error("Don't have enough memory to execute this "
                       "test after %s round" % test_round)
        error_context.context("Executing stress test round: %s" % test_round,
                              logging.info)
        numa_node_malloc = most_used_node
        numa_dd_cmd = "numactl -m %s %s" % (numa_node_malloc, dd_cmd)
        error_context.context(
            "Try to allocate memory in node %s" % numa_node_malloc,
            logging.info)
        try:
            utils_misc.mount("none", tmpfs_path, "tmpfs", perm=mount_fs_size)
            funcatexit.register(env, params.get("type"), utils_misc.umount,
                                "none", tmpfs_path, "tmpfs")
            process.system(numa_dd_cmd, timeout=dd_timeout, shell=True)
        except Exception as error_msg:
            if "No space" in str(error_msg):
                pass
            else:
                test.fail("Can not allocate memory in node %s."
                          " Error message:%s" %
                          (numa_node_malloc, str(error_msg)))
        error_context.context("Run memory heavy stress in guest", logging.info)
        stress_test = utils_test.VMStress(vm,
                                          "stress",
                                          params,
                                          stress_args=stress_args)
        stress_test.load_stress_tool()
        error_context.context("Get the qemu process memory use status",
                              logging.info)
        node_after, memory_after = max_mem_map_node(host_numa_node, qemu_pid)
        if node_after == most_used_node and memory_after >= memory_used:
            test.fail("Memory still stick in node %s" % numa_node_malloc)
        else:
            most_used_node = node_after
            memory_used = memory_after
        stress_test.unload_stress()
        stress_test.clean()
        utils_misc.umount("none", tmpfs_path, "tmpfs")
        funcatexit.unregister(env, params.get("type"), utils_misc.umount,
                              "none", tmpfs_path, "tmpfs")
        session.cmd("sync; echo 3 > /proc/sys/vm/drop_caches")
        utils_memory.drop_caches()

    session.close()
Beispiel #20
0
def run(test, params, env):
    """
    Do network stress test when under memory stress
    1) Boot a guest with vhost=on
    2) swapoff in guest
    3) flood ping from guest to host
    4) do stress test

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

    def flood_ping(session, host_ip, os_type="linux"):
        """
        Do flood ping from guest to host

        :param session: session to send flood ping
        :param host_ip: the IP of the host
        """
        flood_minutes = int(params["flood_minutes"])
        logging.info("Flood ping for %s minutes", flood_minutes)
        try:
            utils_net.ping(host_ip, flood=True,
                           session=session, timeout=flood_minutes * 60)
        except aexpect.ExpectProcessTerminatedError:
            if os_type == "windows":
                session.close()
                session = vm.wait_for_login(timeout=timeout)
                pass
        return session

    def load_stress():
        """
        Load background IO/CPU/Memory stress in guest

        """
        error_context.context("launch stress app in guest", logging.info)
        args = (test, params, env, params["stress_test"])
        bg_test = utils_test.BackgroundTest(
            utils_test.run_virt_sub_test, args)
        bg_test.start()
        if not utils_misc.wait_for(bg_test.is_alive, first=10,
                                   step=3, timeout=100):
            test.fail("background test start failed")

    def unload_stress(session):
        """
        Stop stress app

        :param session: guest session
        """
        error_context.context("stop stress app in guest", logging.info)
        cmd = params.get("stop_cmd")
        session.sendline(cmd)

    timeout = float(params.get("login_timeout", 240))
    vm = env.get_vm(params["main_vm"])
    host_ip = utils_net.get_host_ip_address(params)
    session = vm.wait_for_login(timeout=timeout)

    os_type = params["os_type"]
    if os_type == "linux":
        session.cmd("swapoff -a", timeout=300)

    error_context.context("Run memory heavy stress in guest", logging.info)
    if os_type == "linux":
        test_mem = params.get("memory", 256)
        stress_args = "--cpu 4 --io 4 --vm 2 --vm-bytes %sM" % int(test_mem)
        stress_test = utils_test.VMStress(vm, "stress", params, stress_args=stress_args)
        stress_test.load_stress_tool()
    else:
        load_stress()
    session = flood_ping(session, host_ip, os_type)
    if os_type == "linux":
        stress_test.unload_stress()
        stress_test.clean()
    else:
        unload_stress(session)

    error_context.context("Ping test after flood ping,"
                          " Check if the network is still alive",
                          logging.info)
    count = params["count"]
    timeout = float(count) * 2
    status, output = utils_net.ping(host_ip, count, session=session,
                                    timeout=timeout)
    if status != 0:
        test.fail("Ping failed, status: %s,"
                  " output: %s" % (status, output))

    session.close()
Beispiel #21
0
def run(test, params, env):
    """
    General stress test for linux:
       1). Install stress if need
       2). Start stress process
       3). If no stress_duration defined, keep stress until test_timeout;
       otherwise execute below steps after sleeping stress_duration long
       4). Stop stress process
       5). Uninstall stress
       6). Verify guest kernel crash

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

    stress_duration = int(params.get("stress_duration", "0"))
    # NOTE: stress_duration = 0 ONLY for some legacy test cases using
    # autotest stress.control as their sub test.
    # Please DO define stress_duration to make sure the clean action
    # being performed, if your case can not be controlled by time,
    # use utils_test.VMStress() directly
    stress_type = params.get("stress_type", "stress")
    vms = env.get_all_vms()
    up_time = {}
    error = False
    stress_server = {}
    stress_pkg_name = params.get("stress_pkg_name", "stress-1.0.4.tar.gz")
    stress_root_dir = os.path.join(data_dir.get_deps_dir(), "stress")
    stress_file = os.path.join(stress_root_dir, stress_pkg_name)

    for vm in vms:
        try:
            up_time[vm.name] = vm.uptime()
            stress_server[vm.name] = utils_test.VMStress(
                vm,
                stress_type,
                params,
                download_type="tarball",
                downloaded_file_path=stress_file)
            stress_server[vm.name].load_stress_tool()
        except exceptions.TestError as err_msg:
            error = True
            logging.error(err_msg)

    if stress_duration:
        time.sleep(stress_duration)
        for vm in vms:
            try:
                s_ping, o_ping = utils_test.ping(vm.get_address(),
                                                 count=5,
                                                 timeout=20)
                if s_ping != 0:
                    error = True
                    logging.error("%s seem to have gone out of network",
                                  vm.name)
                    continue
                uptime = vm.uptime()
                if up_time[vm.name] > uptime:
                    error = True
                    logging.error(
                        "%s seem to have rebooted during the stress run",
                        vm.name)
                stress_server[vm.name].unload_stress()
                stress_server[vm.name].clean()
                vm.verify_dmesg()
            except exceptions.TestError as err_msg:
                error = True
                logging.error(err_msg)

    if error:
        test.fail("Run failed: see error messages above")
 def stress_test(self):
     """Run stress testing on vm"""
     self.stress = utils_test.VMStress(self.main_vm, "stress", self.params)
     self.stress.load_stress_tool()