def start_tcpdump(ad, test_name):
    """Start tcpdump on all interfaces

    Args:
        ad: android device object.
        test_name: tcpdump file name will have this
    """
    ad.log.info("Starting tcpdump on all interfaces")
    try:
        ad.adb.shell("killall -9 tcpdump")
    except AdbError:
        ad.log.warn("Killing existing tcpdump processes failed")
    out = ad.adb.shell("ls -l %s" % TCPDUMP_PATH)
    if "No such file" in out or not out:
        ad.adb.shell("mkdir %s" % TCPDUMP_PATH)
    else:
        ad.adb.shell("rm -rf %s/*" % TCPDUMP_PATH, ignore_status=True)

    begin_time = epoch_to_log_line_timestamp(get_current_epoch_time())
    begin_time = normalize_log_line_timestamp(begin_time)

    file_name = "%s/tcpdump_%s_%s.pcap" % (TCPDUMP_PATH, ad.serial, test_name)
    ad.log.info("tcpdump file is %s", file_name)
    cmd = "adb -s {} shell tcpdump -i any -s0 -w {}".format(
        ad.serial, file_name)
    try:
        return start_standing_subprocess(cmd, 5)
    except Exception:
        ad.log.exception('Could not start standing process %s' % repr(cmd))

    return None
예제 #2
0
 def bugreport(self, params, timeout=android_device.BUG_REPORT_TIMEOUT):
     expected = os.path.join(
         logging.log_path, "AndroidDevice%s" % self.serial,
         "test_something", "AndroidDevice%s_%s" %
         (self.serial,
          logger.normalize_log_line_timestamp(MOCK_ADB_LOGCAT_BEGIN_TIME)))
     assert expected in params, "Expected '%s', got '%s'." % (expected,
                                                              params)
    def take_bug_report(self,
                        test_name,
                        begin_time,
                        additional_log_objects=None):
        """Takes a bug report on the device and stores it in a file.

        Args:
            test_name: Name of the test case that triggered this bug report.
            begin_time: Epoch time when the test started.
            additional_log_objects: A list of additional objects in Fuchsia to
                query in the bug report.  Must be in the following format:
                /hub/c/scenic.cmx/[0-9]*/out/objects
        """
        if not additional_log_objects:
            additional_log_objects = []
        log_items = []
        matching_log_items = FUCHSIA_DEFAULT_LOG_ITEMS
        for additional_log_object in additional_log_objects:
            if additional_log_object not in matching_log_items:
                matching_log_items.append(additional_log_object)
        br_path = context.get_current_context().get_full_output_path()
        os.makedirs(br_path, exist_ok=True)
        time_stamp = acts_logger.normalize_log_line_timestamp(
            acts_logger.epoch_to_log_line_timestamp(begin_time))
        out_name = "FuchsiaDevice%s_%s" % (
            self.serial, time_stamp.replace(" ", "_").replace(":", "-"))
        out_name = "%s.txt" % out_name
        full_out_path = os.path.join(br_path, out_name)
        self.log.info("Taking bugreport for %s on FuchsiaDevice%s." %
                      (test_name, self.serial))
        system_objects = self.send_command_ssh('iquery --find /hub').stdout
        system_objects = system_objects.split()

        for matching_log_item in matching_log_items:
            for system_object in system_objects:
                if re.match(matching_log_item, system_object):
                    log_items.append(system_object)

        log_command = '%s %s' % (FUCHSIA_DEFAULT_LOG_CMD, ' '.join(log_items))
        bug_report_data = self.send_command_ssh(log_command).stdout

        bug_report_file = open(full_out_path, 'w')
        bug_report_file.write(bug_report_data)
        bug_report_file.close()
 def take_bt_snoop_log(self, custom_name=None):
     """Takes a the bt-snoop log from the device and stores it in a file
     in a pcap format.
     """
     bt_snoop_path = context.get_current_context().get_full_output_path()
     time_stamp = acts_logger.normalize_log_line_timestamp(
         acts_logger.epoch_to_log_line_timestamp(time.time()))
     out_name = "FuchsiaDevice%s_%s" % (
         self.serial, time_stamp.replace(" ", "_").replace(":", "-"))
     out_name = "%s.pcap" % out_name
     if custom_name:
         out_name = "%s.pcap" % custom_name
     else:
         out_name = "%s.pcap" % out_name
     full_out_path = os.path.join(bt_snoop_path, out_name)
     bt_snoop_data = self.send_command_ssh('bt-snoop-cli -d -f pcap').stdout
     bt_snoop_file = open(full_out_path, 'w')
     bt_snoop_file.write(bt_snoop_data)
     bt_snoop_file.close()
def take_bug_reports(ads, test_name, begin_time):
    """Takes bug reports on a list of android devices.

    If you want to take a bug report, call this function with a list of
    android_device objects in on_fail. But reports will be taken on all the
    devices in the list concurrently. Bug report takes a relative long
    time to take, so use this cautiously.

    Args:
        ads: A list of AndroidDevice instances.
        test_name: Name of the test case that triggered this bug report.
        begin_time: Logline format timestamp taken when the test started.
    """
    begin_time = acts_logger.normalize_log_line_timestamp(begin_time)

    def take_br(test_name, begin_time, ad):
        ad.take_bug_report(test_name, begin_time)

    args = [(test_name, begin_time, ad) for ad in ads]
    utils.concurrent_exec(take_br, args)
예제 #6
0
import mock
import os
import shutil
import tempfile
import unittest

from acts import logger
from acts.controllers import android_device
from acts.controllers.android_lib import errors

# Mock log path for a test run.
MOCK_LOG_PATH = "/tmp/logs/MockTest/xx-xx-xx_xx-xx-xx/"

# Mock start and end time of the adb cat.
MOCK_ADB_EPOCH_BEGIN_TIME = 191000123
MOCK_ADB_LOGCAT_BEGIN_TIME = logger.normalize_log_line_timestamp(
    logger.epoch_to_log_line_timestamp(MOCK_ADB_EPOCH_BEGIN_TIME))
MOCK_ADB_LOGCAT_END_TIME = "1970-01-02 21:22:02.000"

MOCK_SERIAL = 1
MOCK_RELEASE_BUILD_ID = "ABC1.123456.007"
MOCK_DEV_BUILD_ID = "ABC-MR1"
MOCK_NYC_BUILD_ID = "N4F27P"


def get_mock_ads(num):
    """Generates a list of mock AndroidDevice objects.

    The serial number of each device will be integer 0 through num - 1.

    Args:
        num: An integer that is the number of mock AndroidDevice objects to