Ejemplo n.º 1
0
    def setUp(self):
        """
        Setting up the env for the kernel building
        """
        smg = SoftwareManager()
        self.detected_distro = distro.detect()
        deps = ['gcc', 'make', 'automake', 'autoconf', 'time', 'bison', 'flex']
        if 'Ubuntu' in self.detected_distro.name:
            deps.extend(['libpopt0', 'libc6', 'libc6-dev', 'libpopt-dev',
                         'libcap-ng0', 'libcap-ng-dev', 'elfutils', 'libelf1',
                         'libnuma-dev', 'libfuse-dev', 'libssl-dev'])
        elif 'SuSE' in self.detected_distro.name:
            deps.extend(['libpopt0', 'glibc', 'glibc-devel',
                         'popt-devel', 'libcap2', 'libcap-devel',
                         'libcap-ng-devel', 'openssl-devel'])
        elif self.detected_distro.name in ['centos', 'fedora', 'rhel']:
            deps.extend(['popt', 'glibc', 'glibc-devel', 'libcap-ng',
                         'libcap', 'libcap-devel', 'elfutils-libelf',
                         'elfutils-libelf-devel', 'openssl-devel'])

        for package in deps:
            if not smg.check_installed(package) and not smg.install(package):
                self.cancel('%s is needed for the test to be run' % package)
        self.kernel_version = platform.uname()[2]
        self.iterations = self.params.get('runs', default=1)
        self.threads = self.params.get(
            'cpus', default=2 * cpu.online_count())
        self.location = self.params.get(
            'url', default='https://github.com/torvalds/linux/archive'
            '/master.zip')
        self.config_path = os.path.join('/boot/config-', self.kernel_version)
        # Uncompress the kernel archive to the work directory
        tarball = self.fetch_asset("kernbench.zip", locations=[self.location],
                                   expire='1d')
        archive.extract(tarball, self.workdir)
Ejemplo n.º 2
0
    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
        process.run("iptables -F", ignore_status=True)

        # Run heartbeat on host
        process.run(
            server_setup_cmd
            % (monitor_dir, threshold, monitor_log_file_server, monitor_port),
            shell=True)

        if stress_setup_cmd is not None:
            logging.info("Build stress on host")
            # Uncompress and build stress on host
            process.run(stress_setup_cmd % stress_dir, shell=True)

        logging.info("Run stress on host")
        # stress_threads = 2 * n_cpus
        threads_host = 2 * cpu.online_count()
        # Run stress test on host
        process.run(stress_cmd % (stress_dir, threads_host), shell=True)
Ejemplo n.º 3
0
def run(test, params, env):
    """
    vCPU offline/online test:
    1) Launch a guest with many CPU.
    2) Offline all CPUs except 0.
    3) Online them again.
    """
    host_cpu = cpu.online_count()
    cpu_range = range(host_cpu)
    cpu_list = "{}-{}".format(cpu_range[1], cpu_range[-1])
    params["smp"] = params["vcpu_maxcpus"] = host_cpu
    params["start_vm"] = "yes"
    vm = env.get_vm(params['main_vm'])
    vm.create(params=params)
    vm.verify_alive()
    session = vm.wait_for_login()

    error_context.base_context("Offline CPUs: {}".format(cpu_list),
                               logging.info)
    session.cmd("chcpu -d {}".format(cpu_list), timeout=len(cpu_range))
    if not check_if_vm_vcpu_match(1, vm):
        test.fail("CPU quantity on guest mismatch after offline")
    logging.info("{} have been offline.".format(cpu_list))

    error_context.context("Online CPUs: {}".format(cpu_list), logging.info)
    session.cmd("chcpu -e {}".format(cpu_list), timeout=len(cpu_range))
    if not check_if_vm_vcpu_match(host_cpu, vm):
        test.fail("CPU quantity on guest mismatch after online again")
    logging.info("{} have been online.".format(cpu_list))
Ejemplo n.º 4
0
    def setUp(self):
        self.test_file = self.params.get('tmp_file', default='/tmp/dummy')
        self.duration = self.params.get('duration', default='30')
        self.threads = self.params.get(
            'threads', default=cpu.online_count())
        self.size = self.params.get(
            'memory_to_test', default=int(0.9 * memory.meminfo.MemFree.m))

        smm = SoftwareManager()
        for package in ['gcc', 'libtool', 'autoconf', 'automake', 'make']:
            if not smm.check_installed(package) and not smm.install(package):
                self.cancel("Failed to install %s, which is needed for"
                            "the test to be run" % package)

        if not os.path.exists(self.test_file):
            try:
                os.mknod(self.test_file)
            except OSError:
                self.cancel("Skipping test since test file creation failed")
        loc = ["https://github.com/stressapptest/"
               "stressapptest/archive/master.zip"]
        tarball = self.fetch_asset("stressapp.zip", locations=loc,
                                   expire='7d')
        archive.extract(tarball, self.workdir)
        self.sourcedir = os.path.join(self.workdir, 'stressapptest-master')

        os.chdir(self.sourcedir)
        process.run('./configure', shell=True)

        build.make(self.sourcedir)
Ejemplo n.º 5
0
 def core(self):
     """
     Tests the core in ppc64_cpu command.
     """
     op1 = process.system_output(
         "ppc64_cpu --cores-present",
         shell=True).decode("utf-8").strip().split()[-1]
     op2 = cpu.online_count() / int(self.key)
     self.equality_check("Core", op1, ceil(op2))
Ejemplo n.º 6
0
 def get_interrupts(string):
     """
     Find the string and return a list of CPU stats for it
     """
     int_op = genio.read_file("/proc/interrupts")
     for line in int_op.splitlines():
         if string in line:
             line = line.split()[1: cpu.online_count() + 1]
             return line
     return []
Ejemplo n.º 7
0
def run_aio_tests(target):
    """Compile the source code then run aio tests."""
    while True:
        path = yield
        with chcwd(path):
            LOG_JOB.debug("compile source code of QEMU")
            process.run("./configure")
            cpu_count = cpu.online_count()
            aio_path = "tests/test-aio"
            make_cmd = "make {aio_path} -j{cpu_count}".format(
                aio_path=aio_path, cpu_count=cpu_count)
            process.run(make_cmd)
            LOG_JOB.debug("run aio tests")
            result = process.run(aio_path)
        target.send(result.stdout_text)
Ejemplo n.º 8
0
    def setUp(self):
        """
        Verify :
        1. It is Power system and platform is Power NV.
        2. Cpupower tool is installed.
        """

        if 'ppc' not in distro.detect().arch:
            self.cancel("Processor is not ppc64")
        if not os.path.exists('/sys/devices/system/cpu/cpu0/cpufreq'):
            self.cancel('CPUFREQ is supported only on Power NV')

        smm = SoftwareManager()
        detected_distro = distro.detect()
        if 'Ubuntu' in detected_distro.name:
            deps = ['linux-tools-common', 'linux-tools-%s'
                    % platform.uname()[2]]
        elif detected_distro.name == "SuSE":
            deps = ['cpupower']
        else:
            deps = ['kernel-tools']
        for package in deps:
            if not smm.check_installed(package) and not smm.install(package):
                self.cancel('%s is needed for the test to be run' % package)

        fre_min = 0
        fre_max = 0
        freq_info = process.system_output(
            "cpupower frequency-info", shell=True).decode("utf-8")
        for line in str(freq_info).splitlines():
            if re.search('hardware limits:', line, re.IGNORECASE):
                frq = line.split(":")[1]
                frq_init = frq.split('-')[0]
                frq_last = frq.split('-')[1]
                fre_min = float(frq_init.split('GHz')[0])
                fre_max = float(frq_last.split('GHz')[0])
                break
        threshold = (fre_max - fre_min) * (10 ** 6)
        self.threshold = int(self.params.get("threshold", default=threshold))
        self.cpus = cpu.online_count()
        self.cpu_num = 0
        self.max_freq = 0
        self.quad_dict = {}
        self.max_freq_dict = {}
        self.quad_to_cpu_mapping()
Ejemplo n.º 9
0
    def host_stress_event(self, event):
        """
        Host Stress events

        :param event: event name
        """
        for itr in range(self.host_iterations):
            if "cpu_freq_governor" in event:
                cpu.set_freq_governor() if hasattr(
                    cpu, 'set_freq_governor') else cpu.set_cpufreq_governor()
                LOG.debug(
                    "Current governor: %s",
                    cpu.get_freq_governor()
                    if hasattr(cpu, 'get_freq_governor') else
                    cpu.get_cpufreq_governor())
                time.sleep(self.event_sleep_time)
            elif "cpu_idle" in event:
                idlestate = cpu.get_idle_state() if hasattr(
                    cpu, 'get_idle_state') else cpu.get_cpuidle_state()
                cpu.set_idle_state() if hasattr(
                    cpu, 'set_idle_state') else cpu.set_cpuidle_state()
                time.sleep(self.event_sleep_time)
                cpu.set_idle_state(setstate=idlestate) if hasattr(
                    cpu, 'set_idle_state') else cpu.set_cpuidle_state(
                        setstate=idlestate)
                time.sleep(self.event_sleep_time)
            elif "cpuoffline" in event:
                online_count = cpu.online_count() if hasattr(
                    cpu, 'online_count') else cpu.online_cpus_count()
                processor = self.host_cpu_list[random.randint(
                    0, online_count - 1)]
                cpu.offline(processor)
                time.sleep(self.event_sleep_time)
                cpu.online(processor)
            else:
                raise NotImplementedError
            time.sleep(self.itr_sleep_time)
Ejemplo n.º 10
0
def run(test, params, env):
    """
    Check the TSC(time stamp counter) frequency of guest and host whether match
    or not

    1) Test the vcpus' TSC of host by C the program
    2) Copy the C code to the guest, complie and run it to get the vcpus' TSC
       of guest
    3) Sleep sometimes and get the TSC of host and guest again
    4) Compute the TSC frequency of host and guest
    5) Compare the frequency deviation between host and guest with standard

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

    drift_threshold = float(params.get("drift_threshold"))
    interval = float(params.get("interval"))
    cpu_chk_cmd = params.get("cpu_chk_cmd")
    tsc_cmd_guest = params.get("tsc_cmd_guest", "./a.out")
    tsc_cmd_host = params.get("tsc_cmd_host", "./a.out")
    tsc_freq_path = os.path.join(data_dir.get_deps_dir(),
                                 'timedrift/get_tsc.c')
    host_freq = 0

    def get_tsc(machine="host", i=0):
        tsc_cmd = tsc_cmd_guest
        if tsc_cmd == "host":
            tsc_cmd = tsc_cmd_host
        cmd = "taskset %s %s" % (1 << i, tsc_cmd)
        if machine == "host":
            result = process.run(cmd, ignore_status=True)
            s, o = result.exit_status, result.stdout
        else:
            s, o = session.cmd_status_output(cmd)
        if s != 0:
            test.error("Fail to get tsc of host, ncpu: %d" % i)
        o = re.findall(r"(\d+)", o)[0]
        return float(o)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

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

    if not os.path.exists(tsc_cmd_guest):
        process.run("gcc %s" % tsc_freq_path)

    ncpu = cpu.online_count()

    test.log.info("Interval is %s", interval)
    test.log.info("Determine the TSC frequency in the host")
    for i in range(ncpu):
        tsc1 = get_tsc("host", i)
        time.sleep(interval)
        tsc2 = get_tsc("host", i)

        delta = tsc2 - tsc1
        test.log.info("Host TSC delta for cpu %s is %s", i, delta)
        if delta < 0:
            test.error("Host TSC for cpu %s warps %s" % (i, delta))

        host_freq += delta / ncpu
    test.log.info("Average frequency of host's cpus: %s", host_freq)

    if session.cmd_status("test -x %s" % tsc_cmd_guest):
        vm.copy_files_to(tsc_freq_path, '/tmp/get_tsc.c')
        if session.cmd_status("gcc /tmp/get_tsc.c") != 0:
            test.error("Fail to compile program on guest")

    s, guest_ncpu = session.cmd_status_output(cpu_chk_cmd)
    if s != 0:
        test.error("Fail to get cpu number of guest")

    success = True
    for i in range(int(guest_ncpu)):
        tsc1 = get_tsc("guest", i)
        time.sleep(interval)
        tsc2 = get_tsc("guest", i)

        delta = tsc2 - tsc1
        test.log.info("Guest TSC delta for vcpu %s is %s", i, delta)
        if delta < 0:
            test.log.error("Guest TSC for vcpu %s warps %s", i, delta)

        ratio = 100 * (delta - host_freq) / host_freq
        test.log.info("TSC drift ratio for vcpu %s is %s", i, ratio)
        if abs(ratio) > drift_threshold:
            test.log.error("TSC drift found for vcpu %s ratio %s", i, ratio)
            success = False

    if not success:
        test.fail("TSC drift found for the guest, please check the "
                  "log for details")

    session.close()
Ejemplo n.º 11
0
def run(test, params, env):
    """
    NIC option check test.
    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def test_netperf():
        """
        Netperf stress test for nic option.
        """
        netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                           params.get("netperf_client_link"))
        client_path = params.get("client_path")

        n_client = utils_netperf.NetperfClient(
            vm.get_address(),
            client_path,
            netperf_source=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 = int(
                params.get("netperf_test_duration", 180))
            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_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
            for protocol in test_protocols.split():
                error_context.context("Testing %s protocol" % protocol,
                                      logging.info)
                t_option = "%s -t %s" % (test_option, protocol)
                n_client.bg_start(utils_net.get_host_ip_address(params),
                                  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:
                    test.error("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

                netperf_test_duration = stop_time - time.time()
                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)

    def test_ping():
        """
        Ping test for nic option.
        """
        package_sizes = params.objects("ping_sizes")
        if params["os_type"] == "windows":
            ifname = utils_net.get_windows_nic_attribute(
                session=session,
                key="netenabled",
                value=True,
                target="netconnectionID")
        else:
            ifname = utils_net.get_linux_ifname(session, vm.get_mac_address())
        dest = utils_net.get_host_ip_address(params)

        for size in package_sizes:
            error_context.context(
                "Test ping from '%s' to host '%s' on guest '%s'"
                " with package size %s. " % (ifname, dest, vm.name, size),
                logging.info)
            status, output = utils_net.ping(dest=dest,
                                            count=10,
                                            packetsize=size,
                                            session=session,
                                            timeout=30)
            if status:
                test.fail("%s ping %s unexpected, output %s" %
                          (vm.name, dest, output))
            if params["os_type"] == "windows":
                # windows guest get loss=0 when ping failed sometime,
                # need further check
                loss = utils_test.get_loss_ratio(output)
                if loss or "TTL" in output:
                    pass
                else:
                    test.fail("Guest ping test hit unexpected loss, "
                              "error_info: %s" % output)

    check_type = params.get("check_type")
    smp_value = params.get_numeric("smp") or params.get_numeric("vcpu_maxcpus")
    if cpu.online_count() < 2 * smp_value:
        test.cancel("The number of smp counts in this host is not big enough")
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_serial_login()
    try:
        if params["os_type"] == "windows":
            error_context.context("Verify if netkvm.sys is enabled in guest",
                                  logging.info)
            session = utils_test.qemu.windrv_check_running_verifier(
                session, vm, test, "netkvm")
        func_name = {"ping": test_ping, "netperf": test_netperf}
        func_name[check_type]()
    finally:
        session.close()
Ejemplo n.º 12
0
def run(test, params, env):
    """
    ple test:
    1) Check if ple is enabled on host, if not, enable it
    2) Boot guest and run unixbench inside guest
    3) Record benchmark scores and shutdown guest
    4) Disable ple on host
    5) Boot guest and run unixbench inside guest again
    6) Compare benchmark scores with step 3)
    7) Restore env, set ple back

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def reload_module(value):
        """
        Reload module
        """
        process.system("rmmod %s" % module)
        cmd = "modprobe %s %s=%s" % (module, mod_param, value)
        process.system(cmd)

    def run_unixbench(cmd):
        """
        Run unixbench inside guest, return benchmark scores
        """
        error_context.context("Run unixbench inside guest", logging.info)
        output = session.cmd_output_safe(cmd, timeout=4800)
        scores = re.findall(r"System Benchmarks Index Score\s+(\d+\.?\d+)",
                            output)
        return [float(i) for i in scores]

    module = params["module_name"]
    mod_param = params["mod_param"]
    read_cmd = "cat /sys/module/%s/parameters/%s" % (module, mod_param)
    origin_ple = process.getoutput(read_cmd)
    error_context.context("Enable ple on host if it's disabled", logging.info)
    if origin_ple == 0:
        reload_module(params["ple_value"])

    host_cpu_count = cpu.online_count()
    params["smp"] = host_cpu_count
    params["vcpu_maxcpus"] = host_cpu_count
    params["start_vm"] = "yes"
    env_process.preprocess_vm(test, params, env, params["main_vm"])

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login()
    session.cmd(params["get_unixbench"])
    try:
        cmd = params["run_unixbench"]
        scores_on = run_unixbench(cmd)
        logging.info("Unixbench scores are %s when ple is on" % scores_on)
        vm.destroy()

        error_context.context("Disable ple on host", logging.info)
        reload_module(0)
        vm.create(params=params)
        session = vm.wait_for_login()
        scores_off = run_unixbench(cmd)
        logging.info("Unixbench scores are %s when ple is off" % scores_off)
        scores_off = [x*0.96 for x in scores_off]
        if scores_on[0] < scores_off[0] or scores_on[1] < scores_off[1]:
            test.fail("Scores is much lower when ple is on than off")
    finally:
        session.cmd_output_safe("rm -rf %s" % params["unixbench_dir"])
        session.close()
        vm.destroy()
        reload_module(origin_ple)
Ejemplo n.º 13
0
def run(test, params, env):
    """
    NIC option check test.
    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def test_netperf():
        """
        Netperf stress test for nic option.
        """
        netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"),
                                           params.get("netperf_client_link"))
        client_path = params.get("client_path")

        n_client = utils_netperf.NetperfClient(
            vm.get_address(),
            client_path,
            netperf_source=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.
            test_duration = int(params.get("netperf_test_duration", 180))
            deviation_time = params.get_numeric("deviation_time")
            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_sizes")
            test_option = params.get("test_option", "")
            test_option += " -l %s" % 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
            num = 0
            for protocol in test_protocols.split():
                error_context.context("Testing %s protocol" % protocol,
                                      logging.info)
                t_option = "%s -t %s" % (test_option, protocol)
                n_client.bg_start(utils_net.get_host_ip_address(params),
                                  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, 3,
                                       "Wait netperf test start"):
                    logging.info("Netperf test start successfully.")
                else:
                    test.error("Can not start netperf client.")
                num += 1
                start_time = time.time()
                # 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
                duration = time.time() - start_time
                max_run_time = test_duration + deviation_time
                while duration < max_run_time:
                    time.sleep(10)
                    duration = time.time() - start_time
                    status = n_client.is_netperf_running()
                    if not status and duration < test_duration - 10:
                        test.fail("netperf terminated unexpectedly")
                    logging.info("Wait netperf test finish %ss", duration)
                if n_client.is_netperf_running():
                    test.fail("netperf still running, netperf hangs")
                else:
                    logging.info("netperf runs successfully")
        finally:
            n_server.stop()
            n_server.cleanup(True)
            n_client.cleanup(True)

    def test_ping():
        """
        Ping test for nic option.
        """
        package_sizes = params.objects("ping_sizes")
        guest_ip = vm.get_address()

        for size in package_sizes:
            error_context.context(
                "From host ping to '%s' with guest '%s'"
                " with package size %s. " % (vm.name, guest_ip, size),
                logging.info)
            status, output = utils_net.ping(guest_ip,
                                            count=10,
                                            packetsize=size,
                                            timeout=30)
            if status != 0:
                test.fail("host ping %s unexpected, output %s" %
                          (guest_ip, output))

    check_type = params.get("check_type")
    smp_value = params.get_numeric("smp") or params.get_numeric("vcpu_maxcpus")
    if cpu.online_count() < 2 * smp_value:
        test.cancel("The number of smp counts in this host is not big enough")
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_serial_login()
    try:
        match_string = "unable to start vhost net"
        output = vm.process.get_output()
        if match_string in output:
            test.fail("Qemu output error info: %s" % output)
        if params["os_type"] == "windows":
            driver_verifier = params["driver_verifier"]
            error_context.context("Verify if netkvm.sys is enabled in guest",
                                  logging.info)
            session = utils_test.qemu.windrv_check_running_verifier(
                session, vm, test, driver_verifier)
        func_name = {"ping": test_ping, "netperf": test_netperf}
        func_name[check_type]()
    finally:
        session.close()
Ejemplo n.º 14
0
def run(test, params, env):
    """
    Test hotplug maximum vCPU device.

    1) Launch a guest without vCPU device.
    2) Hotplug all vCPU devices and check successfully or not. (qemu side)
    3) Check if the number of CPUs in guest changes accordingly. (guest side)
    4) Reboot guest.
    5) Hotunplug all vCPU devices and check successfully or not. (qemu side)

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    os_type = params["os_type"]
    machine_type = params["machine_type"]
    reboot_timeout = params.get_numeric("reboot_timeout")
    mismatch_text = "Actual number of guest CPUs is not equal to the expected"
    not_equal_text = "CPU quantity mismatched! Guest got %s but expected is %s"
    # Many vCPUs will be plugged, it takes some time to bring them online.
    verify_wait_timeout = params.get_numeric("verify_wait_timeout", 300)
    qemu_binary = utils_misc.get_qemu_binary(params)
    machine_info = utils_qemu.get_machines_info(qemu_binary)[machine_type]
    machine_info = re.search(r'\(alias of (\S+)\)', machine_info)
    current_machine = machine_info.group(1) if machine_info else machine_type
    supported_maxcpus = (params.get_numeric("vcpu_maxcpus")
                         or utils_qemu.get_maxcpus_hard_limit(
                             qemu_binary, current_machine))
    if not params.get_boolean("allow_pcpu_overcommit"):
        supported_maxcpus = min(supported_maxcpus, cpu.online_count())

    logging.info("Define the CPU topology of guest")
    vcpu_devices = []
    if (cpu.get_vendor() == "amd" and params.get_numeric("vcpu_threads") != 1):
        test.cancel("AMD cpu does not support multi threads")
    elif machine_type.startswith("pseries"):
        host_kernel_ver = uname()[2].split("-")[0]
        if params.get_numeric("vcpu_threads") == 8:
            supported_maxcpus -= divmod(supported_maxcpus, 8)[1]
            vcpu_devices = [
                "vcpu%d" % c for c in range(1, supported_maxcpus // 8)
            ]
        # The maximum value of vcpu_id in 'linux-3.x' is 2048, so
        # (vcpu_id * ms->smp.threads / spapr->vsmt) <= 256, need to adjust it
        elif (supported_maxcpus > 256
              and host_kernel_ver not in VersionInterval("[4, )")):
            supported_maxcpus = 256
    vcpu_devices = vcpu_devices or [
        "vcpu%d" % vcpu for vcpu in range(1, supported_maxcpus)
    ]
    params["vcpu_maxcpus"] = str(supported_maxcpus)
    params["vcpu_devices"] = " ".join(vcpu_devices)
    params["start_vm"] = "yes"

    vm = env.get_vm(params["main_vm"])
    vm.create(params=params)
    vm.verify_alive()
    session = vm.wait_for_login()
    cpuinfo = vm.cpuinfo
    smp = cpuinfo.smp
    vcpus_count = vm.params.get_numeric("vcpus_count")

    error_context.context("Hotplug all vCPU devices", logging.info)
    for vcpu_device in vcpu_devices:
        vm.hotplug_vcpu_device(vcpu_device)

    error_context.context("Check Number of vCPU in guest", logging.info)
    if not utils_misc.wait_for(lambda: vm.get_cpu_count() == supported_maxcpus,
                               verify_wait_timeout,
                               first=5,
                               step=10):
        logging.error(not_equal_text, vm.get_cpu_count(), supported_maxcpus)
        test.fail(mismatch_text)
    logging.info("CPU quantity is as expected: %s", supported_maxcpus)

    error_context.context("Check CPU topology of guest", logging.info)
    if not cpu_utils.check_guest_cpu_topology(session, os_type, cpuinfo):
        test.fail("CPU topology of guest is not as expected.")
    session = vm.reboot(session, timeout=reboot_timeout)
    if not cpu_utils.check_guest_cpu_topology(session, os_type, cpuinfo):
        test.fail("CPU topology of guest is not as expected after reboot.")

    error_context.context("Hotunplug all vCPU devices", logging.info)
    for vcpu_device in reversed(vcpu_devices):
        vm.hotunplug_vcpu_device(vcpu_device, 10 * vcpus_count)
    if not utils_misc.wait_for(lambda: vm.get_cpu_count() == smp,
                               verify_wait_timeout,
                               first=5,
                               step=10):
        logging.error(not_equal_text, vm.get_cpu_count(), smp)
        test.fail(mismatch_text)
    logging.info("CPU quantity is as expected after hotunplug: %s", smp)
    session.close()
Ejemplo n.º 15
0
def run(test, params, env):
    """
    Check guest gets correct vcpu num, cpu cores, processors, sockets, siblings

    1) Boot guest with options: -smp n,cores=x,threads=y,sockets=z...
    2) Check cpu topology

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

    def check(p_name, exp, check_cmd):
        """
        Check the cpu property inside guest
        :param p_name: Property name
        :param exp: The expect value
        :param check_cmd: The param to get check command
        """
        res = session.cmd_output(params[check_cmd]).strip()
        if int(res) != int(exp):
            test.fail('The vcpu %s number inside guest is %s,'
                      ' while it is set to %s' % (p_name, res, exp))

    vm_name = params['main_vm']
    os_type = params['os_type']
    vcpu_threads_list = [1, 2]
    if params['machine_type'] == 'pseries':
        vcpu_threads_list = [1, 2, 4, 8]
    host_cpu = cpu.online_count()
    params['vcpu_cores'] = vcpu_cores = random.randint(1, min(6, host_cpu//2))
    for vcpu_threads in vcpu_threads_list:
        vcpu_sockets = min(max(host_cpu // (vcpu_cores * vcpu_threads), 1),
                           random.randint(1, 6))
        vcpu_sockets = 2 if (os_type == 'Windows' and
                             vcpu_sockets > 2) else vcpu_sockets
        params['vcpu_sockets'] = vcpu_sockets
        params['vcpu_threads'] = vcpu_threads
        params['smp'] = params['vcpu_maxcpus'] = (vcpu_cores *
                                                  vcpu_threads * vcpu_sockets)
        params['start_vm'] = 'yes'
        try:
            env_process.preprocess_vm(test, params, env, vm_name)
        except Exception as e:
            # The cpu topology sometimes will be changed by
            # qemu_vm.VM.make_create_command, and thus cause qemu vm fail to
            # start, which is expected; Modify the value and restart vm in
            # this case, and verify cpu topology inside guest after that
            if 'qemu-kvm: cpu topology' in str(e):
                sockets = int(re.findall(r'sockets\s+\((\d)\)', str(e))[0])
                threads = int(re.findall(r'threads\s+\((\d)\)', str(e))[0])
                cores = int(re.findall(r'cores\s+\((\d)\)', str(e))[0])
                params['smp'] = params['vcpu_maxcpus'] = (sockets *
                                                          threads * cores)
                env_process.preprocess_vm(test, params, env, vm_name)
            else:
                raise
        vm = env.get_vm(vm_name)
        session = vm.wait_for_login()
        check_guest_cpu_topology(session, os_type, vm.cpuinfo)
        if params.get('check_siblings_cmd'):
            check('sibling', vcpu_threads * vcpu_cores, 'check_siblings_cmd')
        vm.destroy()
Ejemplo n.º 16
0
def run(test, params, env):
    """
    Run kernbench for performance testing.

    1) Set up testing environment.
    2) Get a kernel code.
    3) Make the kernel with kernbench -M or time make -j 2*smp

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def download_if_not_exists():
        if not os.path.exists(file_name):
            cmd = "wget -t 10 -c -P %s %s" % (tmp_dir, file_link)
            process.system(cmd)

    def cmd_status_output(cmd, timeout=360):
        s = 0
        o = ""
        if "guest" in test_type:
            (s, o) = session.cmd_status_output(cmd, timeout=timeout)
        else:
            cmd_result = process.run(cmd, ignore_status=True, shell=True)
            (s, o) = cmd_result.exit_status, cmd_result.stdout
        return (s, o)

    def check_ept():
        output = process.system_output("grep 'flags' /proc/cpuinfo")
        flags = output.splitlines()[0].split(':')[1].split()
        need_ept = params.get("need_ept", "no")
        if 'ept' not in flags and "yes" in need_ept:
            test.cancel("This test requires a host that supports EPT")
        elif 'ept' in flags and "no" in need_ept:
            cmd = "modprobe -r kvm_intel && modprobe kvm_intel ept=0"
            process.system(cmd, timeout=100, shell=True)
        elif 'ept' in flags and "yes" in need_ept:
            cmd = "modprobe -r kvm_intel && modprobe kvm_intel ept=1"
            process.system(cmd, timeout=100, shell=True)

    def install_gcc():
        logging.info("Update gcc to request version....")
        cmd = "rpm -q gcc"
        cpp_link = params.get("cpp_link")
        gcc_link = params.get("gcc_link")
        libgomp_link = params.get("libgomp_link")
        libgcc_link = params.get("libgcc_link")
        (s, o) = cmd_status_output(cmd)
        if s:
            cmd = "rpm -ivh %s --nodeps; rpm -ivh %s --nodeps; rpm -ivh %s"\
                  " --nodeps; rpm -ivh %s --nodeps" % (libgomp_link,
                                                       libgcc_link, cpp_link, gcc_link)
        else:
            gcc = o.splitlines()[0].strip()
            if gcc in gcc_link:
                cmd = "rpm -e %s && rpm -ivh %s" % (gcc, gcc_link)
            else:
                cmd = "rpm -ivh %s --nodeps; rpm -ivh %s --nodeps; rpm -ivh"\
                      " %s --nodeps; rpm -ivh %s --nodeps" % (libgomp_link,
                                                              libgcc_link, cpp_link, gcc_link)
        (s, o) = cmd_status_output(cmd)
        if s:
            logging.debug("Fail to install gcc.output:%s" % o)

    def record_result(result):
        re_result = params.get("re_result")
        (m_value, s_value) = re.findall(re_result, result)[0]
        s_value = float(m_value) * 60 + float(s_value)
        shortname = params.get("shortname")
        result_str = "%s: %ss\n" % (shortname, s_value)
        result_file = params.get("result_file")
        f1 = open(result_file, "a+")
        result = f1.read()
        result += result_str
        f1.write(result_str)
        f1.close()
        open(os.path.basename(result_file), 'w').write(result)
        logging.info("Test result got from %s:\n%s" % (result_file, result))

    test_type = params.get("test_type")
    guest_thp_cmd = params.get("guest_thp_cmd")
    cmd_timeout = int(params.get("cmd_timeout", 1200))
    tmp_dir = params.get("tmp_dir", "/tmp/kernbench/")
    check_ept()
    vm_name = params.get("main_vm", "vm1")
    cpu_multiplier = int(params.get("cpu_multiplier", 2))
    session = None
    if "guest" in test_type:
        env_process.preprocess_vm(test, params, env, vm_name)
        vm = env.get_vm(params["main_vm"])
        vm.verify_alive()
        session = vm.wait_for_login(
            timeout=int(params.get("login_timeout", 360)))

    # Create tmp folder and download files if need.
    if not os.path.exists(tmp_dir):
        process.system("mkdir %s" % tmp_dir)
    files = params.get("files_need").split()
    for file in files:
        file_link = params.get("%s_link" % file)
        file_name = os.path.join(tmp_dir, os.path.basename(file_link))
        download_if_not_exists()

    if "guest" in test_type:
        logging.info("test in guest")
        vm.copy_files_to(tmp_dir, os.path.dirname(tmp_dir))
        if guest_thp_cmd is not None:
            session.cmd_output(guest_thp_cmd)
    try:
        if params.get("update_gcc") and params.get("update_gcc") == "yes":
            install_gcc()
        pre_cmd = params.get("pre_cmd")
        (s, o) = cmd_status_output(pre_cmd, timeout=cmd_timeout)
        if s:
            test.error("Fail command:%s\nOutput: %s" % (pre_cmd, o))

        if "guest" in test_type:
            cpu_num = params.get("smp")
        else:
            cpu_num = cpu.online_count()
        test_cmd = params.get("test_cmd") % (int(cpu_num) * cpu_multiplier)
        logging.info("Start making the kernel ....")
        (s, o) = cmd_status_output(test_cmd, timeout=cmd_timeout)
        if s:
            test.error("Fail command:%s\n Output:%s" % (test_cmd, o))
        else:
            logging.info("Output for command %s is:\n %s" % (test_cmd, o))
            record_result(o)
    finally:
        if params.get("post_cmd"):
            cmd_status_output(params.get("post_cmd"), timeout=cmd_timeout)
        if session:
            session.close()