Beispiel #1
0
 def start(self, test):
     result = utils.system("mount | grep '%s'" % self.mountpoint,
                           ignore_status=True)
     if result:
         utils.system('mount -t debugfs debugfs /sys/kernel/debug')
     device = self.get_device(test)
     self.blktrace_job = utils.BgJob('%s /dev/%s' % (self.blktrace, device))
Beispiel #2
0
    def start(self, test):
        """
        Start ftrace profiler

        :param test: Autotest test in which the profiler will operate on.
        """
        # Make sure debugfs is mounted and tracing disabled.
        utils.system('%s reset' % self.trace_cmd)

        output_dir = os.path.join(test.profdir, 'ftrace')
        if not os.path.isdir(output_dir):
            os.makedirs(output_dir)
        self.output = os.path.join(output_dir, 'trace.dat')
        cmd = [self.trace_cmd, 'record', '-o', self.output]
        cmd += self.trace_cmd_args
        self.record_job = utils.BgJob(self.join_command(cmd),
                                      stderr_tee=utils.TEE_TO_LOGS)

        # Wait for tracing to be enabled. If trace-cmd dies before enabling
        # tracing, then there was a problem.
        tracing_on = os.path.join(self.tracing_dir, 'tracing_on')
        while (self.record_job.sp.poll() is None and
               utils.read_file(tracing_on).strip() != '1'):
            time.sleep(0.1)
        if self.record_job.sp.poll() is not None:
            utils.join_bg_jobs([self.record_job])
            raise error.CmdError(self.record_job.command,
                                 self.record_job.sp.returncode,
                                 'trace-cmd exited early.')
    def netload_kill_problem(session_serial):
        netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2")
        setup_cmd = params.get("setup_cmd")
        clean_cmd = params.get("clean_cmd")
        firewall_flush = "iptables -F"

        try:
            utils.run(firewall_flush)
        except Exception:
            logging.warning("Could not flush firewall rules on host")

        try:
            session_serial.cmd(firewall_flush)
        except aexpect.ShellError:
            logging.warning("Could not flush firewall rules on guest")

        for i in params.get("netperf_files").split():
            vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp")

        guest_ip = vm.get_address(0)
        server_ip = get_corespond_ip(guest_ip)

        logging.info("Setup and run netperf on host and guest")
        session_serial.cmd(setup_cmd % "/tmp", timeout=200)
        utils.run(setup_cmd % netperf_dir)

        try:
            session_serial.cmd(clean_cmd)
        except Exception:
            pass
        session_serial.cmd(params.get("netserver_cmd") % "/tmp")

        utils.run(clean_cmd, ignore_status=True)
        utils.run(params.get("netserver_cmd") % netperf_dir)

        server_netperf_cmd = params.get(
            "netperf_cmd") % (netperf_dir, "TCP_STREAM",
                              guest_ip, params.get("packet_size", "1500"))
        guest_netperf_cmd = params.get("netperf_cmd") % ("/tmp", "TCP_STREAM",
                                                         server_ip, params.get("packet_size", "1500"))

        env.stop_tcpdump()

        try:
            logging.info("Start heavy network load host <=> guest.")
            session_serial.sendline(guest_netperf_cmd)
            utils.BgJob(server_netperf_cmd)

            # Wait for create big network usage.
            time.sleep(10)
            kill_and_check(vm)

        finally:
            utils.run(clean_cmd, ignore_status=True)
            env.start_tcpdump()
Beispiel #4
0
def run(test, params, env):
    """
    Qemu reboot test:
    1) Boot up a windows guest.
    2) Run stress tool on host.
    3) After guest starts up, start the ftrace.
    4) Reboot VM inside guest.
    5.1) If the guest reboot successfully, then stop the trace-cmd and remove
         the trace.dat file.
    5.2) If guest hang, stop the trace-cmd and generate the readable report
         file.
    6) if 5.2, Check whether the trace.txt includes the error log.
    7) Repeat step 3~6.

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def find_trace_cmd():
        if utils.system("ps -a | grep trace-cmd", ignore_status=True):
            return False
        else:
            return True

    if os.system("which trace-cmd"):
        raise error.TestNAError("Please install trace-cmd.")

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

    reboot_method = params["reboot_method"]
    stress_cmd = params.get("stress_cmd", "stress --vm 4 --vm-bytes 1000M")

    trace_o = os.path.join(test.debugdir, "trace.dat")
    trace_cmd = "trace-cmd record -b 20000 -e kvm -o %s" % trace_o
    trace_cmd = params.get("trace_cmd", trace_cmd)
    re_trace = params.get("re_trace", "kvm_inj_exception:    #GP")

    report_file = os.path.join(test.debugdir, "trace.txt")
    trace_report_cmd = "trace-cmd report -i %s > %s " % (trace_o, report_file)
    try:
        error.context("Run stress tool on host.", logging.info)
        stress_job = utils.BgJob(stress_cmd)
        # Reboot the VM
        for num in xrange(int(params.get("reboot_count", 1))):
            error.context("Reboot guest '%s'. Repeat %d" % (vm.name, num + 1),
                          logging.info)
            trace_job = utils.BgJob(trace_cmd)
            try:
                session = vm.reboot(session, reboot_method, 0, timeout)
            except Exception, err:
                txt = "stop the trace-cmd and generate the readable report."
                error.context(txt, logging.info)
                os.kill(trace_job.sp.pid, signal.SIGINT)
                if not utils_misc.wait_for(lambda: not find_trace_cmd(), 180,
                                           60, 3):
                    logging.warn("trace-cmd could not finish after 120s.")
                trace_job = None
                utils.system(trace_report_cmd)
                report_txt = file(report_file).read()
                txt = "Check whether the trace.txt includes the error log."
                error.context(txt, logging.info)
                if re.findall(re_trace, report_txt, re.S):
                    msg = "Found %s in trace log %s" % (re_trace, report_file)
                    logging.info(msg)
                    error.TestFail(msg)
            else:
                txt = "stop the trace-cmd and remove the trace.dat file."
                error.context(txt, logging.info)
                os.kill(trace_job.sp.pid, signal.SIGINT)
                if not utils_misc.wait_for(lambda: not find_trace_cmd(), 120,
                                           60, 3):
                    logging.warn("trace-cmd could not finish after 120s.")
                trace_job = None
                utils.system("rm -rf %s" % trace_o, timeout=60)
    finally:
        if session:
            session.close()
        if stress_job and stress_job.sp.poll() is None:
            utils_misc.kill_process_tree(stress_job.sp.pid, 9)
        if trace_job:
            if trace_job.sp.poll() is None:
                os.kill(trace_job.sp.pid, signal.SIGINT)
    def netload_kill_problem(session_serial):
        setup_cmd = params.get("setup_cmd")
        clean_cmd = params.get("clean_cmd")
        firewall_flush = params.get("firewall_flush", "service iptables stop")
        error.context("Stop firewall in guest and host.", logging.info)
        try:
            utils.run(firewall_flush)
        except Exception:
            logging.warning("Could not stop firewall in host")

        try:
            session_serial.cmd(firewall_flush)
        except Exception:
            logging.warning("Could not stop firewall in guest")

        netperf_links = params["netperf_links"].split()
        remote_dir = params.get("remote_dir", "/var/tmp")
        # netperf_links support multi links. In case we need apply patchs to
        # netperf or need copy other files.
        for netperf_link in netperf_links:
            if utils.is_url(netperf_link):
                download_dir = data_dir.get_download_dir()
                netperf_link = utils.unmap_url_cache(download_dir,
                                                     netperf_link)
                netperf_dir = download_dir
            elif netperf_link:
                netperf_link = utils_misc.get_path(data_dir.get_deps_dir(),
                                                   netperf_link)
            vm.copy_files_to(netperf_link, remote_dir)
            utils.force_copy(netperf_link, remote_dir)

        guest_ip = vm.get_address(0)
        server_ip = utils_net.get_correspond_ip(guest_ip)

        error.context("Setup and run netperf server in host and guest",
                      logging.info)
        session_serial.cmd(setup_cmd % remote_dir, timeout=200)
        utils.run(setup_cmd % remote_dir, timeout=200)

        try:
            session_serial.cmd(clean_cmd)
        except Exception:
            pass
        session_serial.cmd(params.get("netserver_cmd") % remote_dir)

        utils.run(clean_cmd, ignore_status=True)
        utils.run(params.get("netserver_cmd") % remote_dir)
        p_size = params.get("packet_size", "1500")
        host_netperf_cmd = params.get("netperf_cmd") % (
            remote_dir, "TCP_STREAM", guest_ip, p_size)
        guest_netperf_cmd = params.get("netperf_cmd") % (
            remote_dir, "TCP_STREAM", server_ip, p_size)
        try:
            error.context("Start heavy network load host <=> guest.",
                          logging.info)
            session_serial.sendline(guest_netperf_cmd)
            utils.BgJob(host_netperf_cmd)

            # Wait for create big network usage.
            time.sleep(10)
            msg = "During netperf running, Check that we can kill VM with signal 0"
            error.context(msg, logging.info)
            kill_and_check(vm)

        finally:
            error.context("Clean up netperf server in host and guest.",
                          logging.info)
            utils.run(clean_cmd, ignore_status=True)
            try:
                session_serial.cmd(clean_cmd)
            except Exception:
                pass