def run(test, params, env):
    """
    Execute the libguestfs-test-tool unittest inside L1 guest.

    1) Launch a guest and check if libguestfs-tools is installed.
    2) Execute the libguestfs-test-tool directly launching qemu.
    3) Analyze the result of libguestfs-test-tool.
    4) Check the nested file exists.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    kvm_module = arch.get_kvm_module_list()[-1].replace('-', '_')
    is_kvm_mode = params["nested_flag"] == "nested_flag_on"
    nested_file = os.path.join("/sys/module/", kvm_module,
                               "parameters/nested")
    unittest_timeout = params.get_numeric("unittest_timeout")

    cpu_vendor = cpu.get_vendor()
    cpu_arch = cpu.get_arch()
    if cpu_arch == "powerpc" and int(cpu.get_family().strip("power")) < 9:
        test.cancel("Nested feature requires a POWER9 CPU")
    elif cpu_arch == "x86_64":
        flag = "vmx" if cpu_vendor == "intel" else "svm"
        params["cpu_model_flags"] = params["cpu_model_flags"].format(flag)

    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.context("Check if libguestfs-tools is installed.",
                          logging.info)
    sm = utils_package.RemotePackageMgr(session, "libguestfs-tools")
    if not (sm.is_installed("libguestfs-tools") or sm.install()):
        test.cancel("Unable to install libguestfs-tools inside guest.")

    try:
        error_context.context("Execute the libguestfs-test-tool unittest "
                              "directly launching qemu.", logging.info)
        stderr_file = "/tmp/lgf_stderr"
        lgf_cmd = ("LIBGUESTFS_BACKEND=direct libguestfs-test-tool "
                   "--timeout {} 2> {}".format(unittest_timeout,
                                               stderr_file))
        lgf_s, lgf_o = session.cmd_status_output(lgf_cmd,
                                                 timeout=unittest_timeout)
        logging.debug("libguestfs-test-tool stdout:\n%s", lgf_o)
        lgf_stderr = session.cmd_output("cat " + stderr_file)
        lgf_tcg = re.search("Back to tcg accelerator", lgf_stderr)

        error_context.context("Analyze the libguestfs-test-tool test result.",
                              logging.info)
        fail_msg = ("the exit status is non-zero" if lgf_s else
                    "back to tcg accelerator" if lgf_tcg and is_kvm_mode else "")
        if fail_msg:
            logging.debug("libguestfs-test-tool stderr:\n%s", lgf_stderr)
            test.fail("libguestfs-test-tool execution failed due to: %s. "
                      % fail_msg)

        error_context.context("Check the nested file status.", logging.info)
        file_s, file_o = session.cmd_status_output("cat " + nested_file)
        if re.match(r"[1Y]", file_o) and is_kvm_mode:
            logging.info("Guest runs with nested flag, the nested feature has "
                         "been enabled.")
        elif file_s == 1 and not is_kvm_mode:
            logging.info("Guest runs without nested flag, so the nested file "
                         "does not exist.")
        else:
            logging.error("Nested file status: %s, output: %s", file_s, file_o)
            test.fail("Getting the status of nested file has unexpected "
                      "result.")
    finally:
        session.cmd("rm -f " + stderr_file, ignore_all_errors=True)
        session.close()
Пример #2
0
 def test_cpu_arch_risc_v(self):
     with unittest.mock.patch('builtins.open',
                              return_value=self._get_data_mock('risc_v')):
         self.assertEqual(cpu.get_arch(), "riscv")
class CpupowerMonitor(Test):

    """
    Test to validate idle states using cpupowe monitor tool.
    """

    def setUp(self):
        sm = SoftwareManager()
        for package in ['gcc', 'make']:
            if not sm.check_installed(package) and not sm.install(package):
                self.cancel("%s is needed for the test to be run" % package)
        output = self.run_cmd_out("cpupower idle-info --silent")
        for line in output.splitlines():
            if 'Available idle states: ' in line:
                self.states_list = (line.split('Available idle states: ')[-1]).split()
                break
        self.log.info("Idle states on the system are: ", self.states_list)
        self.run_cmd_out("cpupower monitor")

    def run_cmd_out(self, cmd):
        return process.system_output(cmd, shell=True, ignore_status=True,
                                     sudo=True).decode("utf-8")

    def check_zero_nonzero(self, stop_state_index):
        output = self.run_cmd_out("cpupower monitor")
        if "CORE" in output:
            stop_state_index = stop_state_index + 2
        values_list = []
        split_index = 2
        if 'WARNING' in output:
            split_index = 3
        for line in output.splitlines()[split_index:]:
            stop_state_values = line.split('|')
            values_list.append(stop_state_values[stop_state_index].strip())
        for value in values_list:
            if float(value) != 0.00:
                return 1
        return 0

    def test_workload(self):

        """
        This test covers:
        1. Collect cpupower monitor output.
        2. Run ebizzy workload.
        3. Check if cpus have not entered idle states while running ebizzy.
        4. Wait till ebizzy stops.
        5. Check if cpus enters idle states.
        """

        tarball = self.fetch_asset('http://sourceforge.net/projects/ebizzy/'
                                   'files/ebizzy/0.3/ebizzy-0.3.tar.gz')
        archive.extract(tarball, self.workdir)
        self.sourcedir = os.path.join(self.workdir, 'ebizzy-0.3')
        os.chdir(self.sourcedir)
        process.run('./configure', shell=True)
        build.make(self.sourcedir)
        self.run_cmd_out("cpupower monitor")
        self.log.info("============ Starting ebizzy tests ==============")
        obj = process.SubProcess('./ebizzy -t 1000 -S 100 &', verbose=False,
                                 shell=True)
        obj.start()
        time.sleep(2)
        for i in range(len(self.states_list)):
            zero_nonzero = self.check_zero_nonzero(i + 1)
            if zero_nonzero:
                self.fail("cpus entered idle states during ebizzy workload")
            self.log.info("no cpus entered idle states while running ebizzy")
        time.sleep(100)
        zero_nonzero = 0
        for i in range(len(self.states_list)):
            zero_nonzero = zero_nonzero + self.check_zero_nonzero(i + 1)
        if not zero_nonzero:
            self.fail("cpus have not entered idle states after killing ebizzy workload")
        self.log.info("cpus have entered idle states after killing work load")

    def test_disable_idlestate(self):

        """
        1. Collect list of supported idle states.
        2. Disable first idle state and check if cpus have not entered first idle state.
        3. Enable all idle states.
        4. Disable second idle state and check if cpus have not entered first idle state.
        5. Repeat test for all states.
        """

        for i in range(len(self.states_list)):
            process.run('cpupower -c all idle-set -d %s' % i, shell=True)
            time.sleep(5)
            zero_nonzero = self.check_zero_nonzero(i + 1)
            if zero_nonzero:
                self.fail("cpus have entered the disabled idle states.")
            self.log.info("cpus have not entered disabled idle states")
            process.run('cpupower -c all idle-set -E', shell=True)

    @skipIf("powerpc" not in cpu.get_arch(), "Skip, SMT specific tests")
    def test_idlestate_smt(self):

        """
        1. Set smt mode to off.
        2. Run test_workload.
        3. Run test_disable_idlestate.
        4. Repeat test for smt=2. 4.
        """

        for i in ['off', '2', '4', 'on']:
            process.run('ppc64_cpu --smt=%s' % i, shell=True)
            self.test_workload()
            self.test_disable_idlestate()
        process.run('ppc64_cpu --smt=on', shell=True)

    def test_idlestate_single_core(self):

        """
        1. Set single core online.
        2. Run test_workload.
        3. Run test_disable_idlestate.
        4. Repeat test with smt=off, single core
        """

        process.run('ppc64_cpu --cores-on=1', shell=True)
        self.test_workload()
        self.test_disable_idlestate()
        process.run('ppc64_cpu --cores-on=all', shell=True)
        process.run('ppc64_cpu --smt=on', shell=True)
Пример #4
0
 def test_cpu_arch_s390(self):
     with unittest.mock.patch(
             'builtins.open',
             return_value=self._get_data_mock('s390x')):
         self.assertEqual(cpu.get_arch(), "s390")
Пример #5
0
 def test_cpu_arch_arm_v8(self):
     with unittest.mock.patch('builtins.open',
                              return_value=self._get_data_mock('armv8')):
         self.assertEqual(cpu.get_arch(), "aarch64")
Пример #6
0
 def test_cpu_arch_power9(self):
     with unittest.mock.patch('builtins.open',
                              return_value=self._get_data_mock('power9')):
         self.assertEqual(cpu.get_arch(), "powerpc")
Пример #7
0
 def test_cpu_arch_x86_64(self):
     with unittest.mock.patch('builtins.open',
                              return_value=self._get_data_mock('x86_64')):
         self.assertEqual(cpu.get_arch(), "x86_64")
Пример #8
0
 def test_cpu_arch_i386(self):
     with unittest.mock.patch('builtins.open',
                              return_value=self._get_data_mock('i386')):
         self.assertEqual(cpu.get_arch(), "i386")
Пример #9
0
 def test_cpu_arch_arm_v7(self):
     with unittest.mock.patch('builtins.open',
                              return_value=self._get_file_mock(armv7)):
         self.assertEqual(cpu.get_arch(), "arm")
Пример #10
0
 def test_cpu_arch_arm_v7(self):
     with unittest.mock.patch(
         "builtins.open", return_value=self._get_data_mock("armv7")
     ):
         self.assertEqual(cpu.get_arch(), "arm")