Ejemplo n.º 1
0
 def test_s390x_cpu_online(self):
     with unittest.mock.patch('avocado.utils.cpu.platform.machine',
                              return_value='s390x'):
         with unittest.mock.patch('builtins.open',
                                  return_value=self._get_file_mock(s390x)):
             self.assertEqual(len(cpu.online_list()), 2)
         with unittest.mock.patch(
                 'builtins.open',
                 return_value=self._get_file_mock(s390x_2)):
             self.assertEqual(len(cpu.online_list()), 4)
Ejemplo n.º 2
0
 def test_s390x_cpu_online(self):
     with unittest.mock.patch(
         "avocado.utils.cpu.platform.machine", return_value="s390x"
     ):
         with unittest.mock.patch(
             "builtins.open", return_value=self._get_data_mock("s390x")
         ):
             self.assertEqual(len(cpu.online_list()), 2)
         with unittest.mock.patch(
             "builtins.open", return_value=self._get_data_mock("s390x_2")
         ):
             self.assertEqual(len(cpu.online_list()), 4)
Ejemplo n.º 3
0
 def test_x86_64_cpu_online(self):
     with unittest.mock.patch('avocado.utils.cpu.platform.machine',
                              return_value='x86_64'):
         with unittest.mock.patch(
                 'builtins.open',
                 return_value=self._get_data_mock('x86_64')):
             self.assertEqual(len(cpu.online_list()), 8)
Ejemplo n.º 4
0
 def test(self):
     """
     Validate the number of cpu idle states against device tree
     """
     for var in range(1, 10):
         cpu_num = random.choice(cpu.online_list())
         self.log.info("--------CPU: %s--------" % cpu_num)
         states = process.system_output("cpupower -c %s idle-info --silent"
                                        " | grep 'Number of idle states:' |"
                                        "awk '{print $5}'"
                                        % cpu_num, shell=True).decode("utf-8")
         cpu_idle_states = []
         for i in range(1, int(states)):
             val = process.system_output("cat /sys/devices/system/cpu/"
                                         "cpu%s/cpuidle/state%s/"
                                         "name" % (cpu_num, i)).decode("utf-8")
             if 'power8' in cpu.get_family():
                 val = self.set_idle_states(val)
             cpu_idle_states.append(val)
         devicetree_list = self.read_from_device_tree()
         res = self.cmp(cpu_idle_states, devicetree_list)
         if res == 0:
             self.log.info("PASS : Validated the idle states")
         else:
             self.log.info(" cpupower tool : %s and device tree"
                           ": %s" % (cpu_idle_states, devicetree_list))
             self.fail("FAIL: Please check the idle states")
Ejemplo n.º 5
0
    def test(self):

        mgen_flag = False
        mgen = os.path.join(self.sourcedir, 'mgen')
        self.numa_pid = process.SubProcess('numatop -d result_file',
                                           shell=True)
        self.numa_pid.start()

        # Run mgen for 5 seconds to generate a single snapshot of numatop
        process.run('%s -a 0 -c %s -t 5' % (mgen, cpu.online_list()[0]),
                    shell=True,
                    sudo=True)

        # Kill numatop recording after running mgen
        self.numa_pid.terminate()

        # Analyse record file for mgen record
        with open('%s/result_file' % self.sourcedir, 'r') as f_read:
            lines = f_read.readlines()
            for line in lines:
                if 'mgen' in line:
                    mgen_flag = True
                    break
        if not mgen_flag:
            self.fail('Numatop failed to record mgen latency. Please check '
                      'the record file: %s/result_file' % self.sourcedir)
Ejemplo n.º 6
0
    def setUp(self):
        """
        Setup checks :
        0. Processor should be ppc64.
        1. Install perf package
        2. Check for hv_24x7/hv_gpci cpumask
        3. Offline the cpumask CPU and check cpumask moved to new CPU or not
        """
        smm = SoftwareManager()
        processor_type = genio.read_file("/proc/cpuinfo")

        detected_distro = distro.detect()
        # Offline cpu list during the test
        self.cpu_off = []

        if 'ppc64' not in detected_distro.arch:
            self.cancel("Processor is not PowerPC")
        for line in processor_type.splitlines():
            if 'revision' in line:
                self.rev = (line.split(':')[1])
                if '0080' not in self.rev:
                    self.cancel("Test is supported only on Power10")

        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'])
        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)

        hv24x7_present = False
        hvgpci_present = False
        self.hv24x7_cpumask = False
        self.hvpgci_cpumask = False

        hv24x7_present, self.hv24x7_cpumask = self._check_file("hv_24x7")
        hvgpci_present, self.hvpgci_cpumask = self._check_file("hv_gpci")

        # To proceed with the test we need either of hv_24x7 or hv_gpci
        if not (hv24x7_present and hvgpci_present):
            self.fail("hv_24x7 and hv_gpci both events not found")

        # Collect the cpu list
        self.online_cpus = cpu.online_list()
        self.log.info("Online CPU list: %s" % self.online_cpus)

        # Clear the dmesg to capture the delta at the end of the test.
        dmesg.clear_dmesg()
Ejemplo n.º 7
0
def get_cpustats(vm, cpu=None):
    """
    Get the cpustats output of a given domain
    :param vm: VM domain
    :param cpu: Host cpu index, default all cpus
    :return: dict of cpu stats values
    result format:
    {0:[vcputime,emulatortime,cputime]
    ..
    'total':[cputime]}
     """
    host_cpu_online = utils.online_list() if hasattr(
        utils, 'online_list') else utils.cpu_online_list()
    cpustats = {}
    if cpu:
        cpustats[cpu] = []
        option = "--start %s --count 1" % cpu
        result = virsh.cpu_stats(vm.name, option)
        if result.exit_status != 0:
            logging.error("cpu stats command failed: %s", result.stderr_text)
            return None
        output = result.stdout_text.strip().split()
        if re.match("CPU%s" % cpu, output[0]):
            cpustats[cpu] = [
                float(output[5]),  # vcputime
                float(output[2]) - float(output[5]),  # emulator
                float(output[2])
            ]  # cputime

    else:
        for i in range(len(host_cpu_online)):
            cpustats[host_cpu_online[i]] = []
            option = "--start %s --count 1" % host_cpu_online[i]
            result = virsh.cpu_stats(vm.name, option)
            if result.exit_status != 0:
                logging.error("cpu stats command failed: %s",
                              result.stderr_text)
                return None
            output = result.stdout_text.strip().split()
            if re.match("CPU%s" % host_cpu_online[i], output[0]):
                cpustats[host_cpu_online[i]] = [
                    float(output[5]),
                    float(output[2]) - float(output[5]),
                    float(output[2])
                ]
    result = virsh.cpu_stats(vm.name, "--total")
    cpustats["total"] = []
    if result.exit_status != 0:
        logging.error("cpu stats command failed: %s", result.stderr_text)
        return None
    output = result.stdout_text.strip().split()
    cpustats["total"] = [float(output[2])]  # cputime
    return cpustats
Ejemplo n.º 8
0
    def test_disable_enable_cpu():
        """
        Test disable a host cpu and check nodeinfo result
        """
        online_list = cputils.online_list()
        # Choose the last online host cpu to offline
        cputils.offline(online_list[-1])

        cmd_result = virsh.nodeinfo(ignore_status=True)
        output_check(cmd_result.stdout_text.strip())

        # Make the last host cpu online again
        cputils.online(online_list[-1])
Ejemplo n.º 9
0
 def test_cpumask_cpu_off(self):
     # Get the online cpu list
     online_cpus = cpu.online_list()
     self.log.info("Online CPU list: %s" % online_cpus)
     pmu1 = list(self.all_events.keys())[0]
     disable_cpu = self._get_cpumask(pmu1)
     # Disable cpu with one PMU cpumask
     if cpu.offline(disable_cpu):
         self.fail("Can't offline cpumask cpu %s" % disable_cpu)
     current_cpu = self._get_cpumask(pmu1)
     self.log.info("Current CPU: %s" % current_cpu)
     self._check_cpumask()
     # After confirming cpu got disabled, enable back
     if current_cpu in online_cpus and disable_cpu != current_cpu:
         if cpu.online(disable_cpu):
             self.fail("Can't online cpu %s" % disable_cpu)
Ejemplo n.º 10
0
 def __init__(self, params, env):
     """
     :param params: test param
     """
     self.host_cpu_list = cpu.online_list() if hasattr(
         cpu, 'online_list') else cpu.cpu_online_list()
     self.iterations = int(params.get("stress_itrs", 1))
     self.host_iterations = int(params.get("host_event_itrs", 10))
     self.event_sleep_time = int(params.get("event_sleep_time", 10))
     self.itr_sleep_time = int(params.get("itr_sleep_time", 10))
     self.ignore_status = params.get("ignore_status", "no") == "yes"
     self.vms = env.get_all_vms()
     self.params = params
     self.host_events = params.get("host_stress_events", "")
     if self.host_events:
         self.host_events = self.host_events.split(',')
     else:
         self.host_events = []
     self.threads = []
Ejemplo n.º 11
0
 def _process_lscpu(self):
     output = process.system_output("lscpu", shell=True, ignore_status=True)
     for line in output.decode().splitlines():
         self.total_cpus = cpu.total_count()
         self.online_cpus = cpu.online_list()
         if 'Model name:' in line:
             self.model = line.split(':')[1].split('(')[0].strip().lower()
             self.log.info("CPU model %s" % self.model)
         if 'Physical chips:' in line:
             self.pchips = int(line.split(':')[1].strip())
             self.log.info("Physical Chips %s" % self.pchips)
         if 'Physical sockets:' in line:
             self.psockets = int(line.split(':')[1].strip())
             self.log.info("Physical Sockets %s" % self.psockets)
         if 'Physical cores/chip:' in line:
             self.pcorechips = int(line.split(':')[1].strip())
             self.log.info("Physical cores/chip %s" % self.pcorechips)
         nodesysfs = '/sys/devices/system/node/'
         for nodefile in os.listdir(nodesysfs):
             if 'node' in nodefile:
                 filename = os.path.join(nodesysfs, nodefile, 'cpulist')
                 self.node_cpu_dict[nodefile] = genio.read_file(filename)
                 self.log.info("Nodes and CPU list: %s" % self.node_cpu_dict)
Ejemplo n.º 12
0
    def test_disable_enable_cpu():
        """
        Test disable a host cpu and check nodeinfo result

        :return: test.fail if CPU(s) number is not expected
        """
        ret_before_disable = virsh.nodeinfo(ignore_status=True, debug=True)
        cpus_nodeinfo_before = _check_nodeinfo(
            ret_before_disable.stdout_text.strip(), "CPU(s)", 2)

        online_list = cputils.online_list()
        # Choose the last online host cpu to offline
        cputils.offline(online_list[-1])

        ret_after_disable = virsh.nodeinfo(ignore_status=True, debug=True)
        cpus_nodeinfo_after = _check_nodeinfo(
            ret_after_disable.stdout_text.strip(), "CPU(s)", 2)
        if int(cpus_nodeinfo_before) != int(cpus_nodeinfo_after) + 1:
            test.fail("CPU(s) should be '%d' after 1 cpu is disabled, "
                      "but found '%s'" %
                      (int(cpus_nodeinfo_before) - 1, cpus_nodeinfo_after))
        # Make the last host cpu online again
        cputils.online(online_list[-1])
Ejemplo n.º 13
0
def run(test, params, env):
    """
    Check the timedrift on all the guests when attached all guests to CPUs

    1) boot the multi guests, e.g., boot 4 vms
    2) pin every guest process to one physical CPU
    3) reboot one of the guests, or change the time of one guest
    4) check the timedrift on all the guests

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    def verify_guest_clock_source(session, expected):
        """
        :param session: VM session
        :param expected: expected clocksource
        """
        if expected not in session.cmd(clocksource_cmd):
            test.fail("Guest doesn't use '%s' clocksource" % expected)

    ntp_cmd = params["ntp_cmd"]
    ntp_stop_cmd = params["ntp_stop_cmd"]
    ntp_query_cmd = params["ntp_query_cmd"]
    ntp_service = params["ntp_service"]
    clocksource = params.get("clocksource", "kvm-clock")
    clocksource_cmd = params["clocksource_cmd"]
    expected_time_drift = params["expected_time_drift"]
    same_cpu = params["same_cpu"]

    error_context.context("Sync host time with ntp server", logging.info)
    service_manager = service.ServiceManager()
    service_manager.stop(ntp_service)
    process.system(ntp_cmd, shell=True)

    error_context.context("Boot four guests", logging.info)
    params["start_vm"] = "yes"
    vms = params.get("vms").split()
    vm_obj = []
    sessions = []
    host_cpu_list = cpu.online_list()
    if same_cpu == "no":
        if len(host_cpu_list) < len(vms):
            test.cancel("There aren't enough physical cpus to pin all guests")
    for vm_name in vms:
        env_process.preprocess_vm(test, params, env, vm_name)
        vm = env.get_vm(vm_name)
        vm.verify_alive()
        vm_obj.append(vm)
        sessions.append(vm.wait_for_login())

    error_context.context("Pin guest to physical cpu", logging.info)
    for vmid, se in enumerate(sessions):
        # Get the respective vm object
        cpu_id = vmid if same_cpu == "no" else 0
        process.system("taskset -cp %s %s" %
                       (host_cpu_list[cpu_id], vm_obj[vmid].get_pid()),
                       shell=True)
        error_context.context("Check the current clocksource", logging.info)
        currentsource = se.cmd_output_safe(clocksource_cmd)
        if clocksource not in currentsource:
            error_context.context(
                "Update guest kernel cli to %s" % clocksource, logging.info)
            utils_time.update_clksrc(vm_obj[vmid], clksrc=clocksource)
            verify_guest_clock_source(se, clocksource)
        error_context.context("Stop ntp service in guest", logging.info)
        status, output = se.cmd_status_output(ntp_stop_cmd)

    vmid_test = random.randint(0, len(vms) - 1)
    vm = vm_obj[vmid_test]
    se = sessions[vmid_test]
    if same_cpu == "no":
        error_context.context("Reboot one of the guests", logging.info)
        se = vm.reboot(se)
        status, output = se.cmd_status_output(ntp_stop_cmd)
        sessions[vmid_test] = se
    else:
        error_context.context("Change time in one of the guests", logging.info)
        change_time_cmd = params["change_time_cmd"]
        se.cmd_output_safe(change_time_cmd)

    error_context.context("Check the timedrift on all the guests",
                          logging.info)
    fail_offset = []
    for vmid, se in enumerate(sessions):
        if same_cpu == "yes" and vmid == vmid_test:
            continue
        output = se.cmd_output_safe(ntp_query_cmd)
        offset = float(re.findall(r"[+-]?(\d+\.\d+)", output, re.M)[-1])
        logging.info("The time drift of guest %s is %ss.", vmid, offset)
        if offset > float(expected_time_drift):
            fail_offset.append((vmid, offset))
    if fail_offset:
        test.fail("The time drift of following guests %s are larger than 5s." %
                  fail_offset)
Ejemplo n.º 14
0
 def __get_random_cpu():
     """
     Get random online cpu
     """
     return random.choice(cpu.online_list())