示例#1
0
    def setUp(self):
        smm = SoftwareManager()
        dist = distro.detect()
        memsize = int(memory.freememtotal() * 1024 * 0.2)
        self.nr_pages = self.params.get('nr_pages',
                                        default=memsize /
                                        memory.get_page_size())
        self.map_type = self.params.get('map_type', default='private')

        if len(memory.numa_nodes()) < 2:
            self.cancel('Test requires two numa nodes to run')

        pkgs = ['gcc', 'make']
        if dist.name == "Ubuntu":
            pkgs.extend(['libpthread-stubs0-dev', 'libnuma-dev'])
        elif dist.name in ["centos", "rhel", "fedora"]:
            pkgs.extend(['numactl-devel'])
        else:
            pkgs.extend(['libnuma-devel'])

        for package in pkgs:
            if not smm.check_installed(package) and not smm.install(package):
                self.cancel('%s is needed for the test to be run' % package)

        for file_name in ['util.c', 'numa_test.c', 'Makefile']:
            self.copyutil(file_name)

        build.make(self.teststmpdir)
    def setUp(self):
        """
        Setup checks :
        0. Processor should be ppc64.
        1. Perf package
        2. 24x7 is not supported on guest
        3. 24x7 is present
        4. Performance measurement is enabled in LPAR through BMC
        """
        smm = SoftwareManager()
        detected_distro = distro.detect()
        if 'ppc64' not in detected_distro.arch:
            self.cancel("Processor is not PowerPC")
        deps = ['gcc', 'make']
        if 'Ubuntu' in detected_distro.name:
            deps.extend(
                ['linux-tools-common',
                 'linux-tools-%s' % platform.uname()[2]])
        elif detected_distro.name in ['rhel', 'SuSE', 'fedora', 'centos']:
            deps.extend(['perf', 'numactl'])
        else:
            self.cancel("Install the package for perf supported by %s" %
                        detected_distro.name)
        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)

        cpu_family = cpu.get_family()
        perf_args = "perf stat -v -e"
        if cpu_family == 'power8':
            perf_stat = "%s hv_24x7/HPM_0THRD_NON_IDLE_CCYC" % perf_args
        elif cpu_family == 'power9':
            perf_stat = "%s hv_24x7/CPM_TLBIE" % perf_args
        elif cpu_family == 'power10':
            perf_stat = "%s hv_24x7/CPM_TLBIE_FIN" % perf_args
        event_sysfs = "/sys/bus/event_source/devices/hv_24x7"

        # Check if this is a guest
        # 24x7 is not suported on guest
        if "emulated by" in cpu._get_info():
            self.cancel("This test is not supported on guest")

        # Check if 24x7 is present
        if os.path.exists(event_sysfs):
            self.log.info('hv_24x7 present')
        else:
            self.cancel("%s doesn't exist.This test is supported"
                        " only on PowerVM" % event_sysfs)

        # Performance measurement has to be enabled in lpar through BMC
        # Check if its enabled
        result_perf = process.run("%s,domain=2,core=1/ sleep 1" % perf_stat,
                                  ignore_status=True)
        if "operations is limited" in result_perf.stderr.decode("utf-8"):
            self.cancel("Please enable LPAR to allow collecting"
                        " the 24x7 counters info")

        # Getting the number of cores
        output = process.run("lscpu")
        for line in output.stdout.decode("utf-8").split('\n'):
            if 'Core(s) per socket:' in line:
                self.cores = int(line.split(':')[1].strip())

        # Getting the number of chips available in the machine
        self.chip = memory.numa_nodes()

        # Collect all hv_24x7 events
        self.list_of_hv_24x7_events = []
        for lne in process.get_command_output_matching('perf list', 'hv_24x7'):
            lne = lne.split(',')[0].split('/')[1]
            self.list_of_hv_24x7_events.append(lne)

        # Clear the dmesg to capture the delta at the end of the test.
        process.run("dmesg -C", sudo=True)
示例#3
0
def run(test, params, env):
    """
    Qemu memory hotplug test:
    1) Boot guest with -m option.
    2) Hotplug memory with invalid params.
    3) Check qemu prompt message.
    4) Check vm is alive after hotplug.

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    @error_context.context_aware
    def _hotplug_memory(vm, name):
        hotplug_test = MemoryHotplugTest(test, params, env)
        devices = vm.devices.memory_define_by_params(params, name)
        for dev in devices:
            if isinstance(dev, qdevices.Dimm):
                if params["set_addr"] == "yes":
                    addr = params["addr_dimm_%s" % name]
                else:
                    addr = hotplug_test.get_mem_addr(vm, dev.get_qid())
                dev.set_param("addr", addr)
            error_context.context(
                "Hotplug %s '%s' to VM" % ("pc-dimm", dev.get_qid()),
                logging.info)
            vm.devices.simple_hotplug(dev, vm.monitor)
            hotplug_test.update_vm_after_hotplug(vm, dev)
        return devices

    def collect_hotplug_info():
        details = {}
        for target_mem in params.objects("target_mems"):
            try:
                _hotplug_memory(vm, target_mem)
            except Exception as e:
                error_context.context("Error happen %s: %s" % (target_mem, e),
                                      logging.info)
                details.update({target_mem: str(e)})
            else:
                error_context.context("Hotplug memory successful",
                                      logging.info)
                details.update({target_mem: "Hotplug memory successful"})
        return details

    def check_msg(keywords, msg):
        if not re.search(r"%s" % keywords, msg):
            test.fail(
                "No valid keywords were found in the qemu prompt message")

    if params["size_mem"] == "<overcommit>":
        overcommit_mem = normalize_data_size("%sK" % (memory.memtotal() * 2),
                                             "G")
        params["size_mem"] = "%sG" % round(float(overcommit_mem))
    if params["policy_mem"] == "bind":
        params["host-nodes"] = str(max(memory.numa_nodes()) + 1)
    params["start_vm"] = "yes"
    env_process.preprocess_vm(test, params, env, params["main_vm"])
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    vm.wait_for_login()

    msg = collect_hotplug_info()
    if len(params.objects("target_mems")) == 1:
        error_context.context("Check qemu prompt message.", logging.info)
        check_msg(params["keywords"], msg[params["target_mems"]])
    else:
        for target_mem in params.objects("target_mems"):
            mem_params = params.object_params(target_mem)
            error_context.context(
                "Check %s qemu prompt "
                "message." % target_mem, logging.info)
            check_msg(mem_params["keywords"], msg[target_mem])