Example #1
0
import argparse
import fnmatch
import json
import os
import shutil
import sys
from xml.dom import minidom

import devil_chromium
from devil.utils import cmd_helper
from pylib.constants import host_paths


_BUILD_UTILS_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build', 'android',
                                 'gyp')
with host_paths.SysPath(_BUILD_UTILS_PATH, 0):
  from util import build_utils

_JAVA_COVERAGE_METRICS = [
    'instruction', 'branch', 'line', 'complexity', 'method', 'class'
]
# Source paths should be passed to Jacoco in a way that the relative file paths
# reflect the class package name.
_PARTIAL_PACKAGE_NAMES = ['com/google', 'org/chromium']

# The sources_json_file is generated by jacoco_instr.py with source directories
# and input path to non-instrumented jars.
# e.g.
# 'source_dirs': [
#   "chrome/android/java/src/org/chromium/chrome/browser/toolbar/bottom",
#   "chrome/android/java/src/org/chromium/chrome/browser/ui/system",
Example #2
0
#! /usr/bin/env python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# pylint: disable=protected-access

import unittest

from pylib.base import output_manager
from pylib.base import output_manager_test_case
from pylib.constants import host_paths
from pylib.output import remote_output_manager

with host_paths.SysPath(host_paths.PYMOCK_PATH):
    import mock  # pylint: disable=import-error


@mock.patch('pylib.utils.google_storage_helper')
class RemoteOutputManagerTest(output_manager_test_case.OutputManagerTestCase):
    def setUp(self):
        self._output_manager = remote_output_manager.RemoteOutputManager(
            'this-is-a-fake-bucket')

    def testUsableTempFile(self, google_storage_helper_mock):
        del google_storage_helper_mock
        self.assertUsableTempFile(
            self._output_manager._CreateArchivedFile(
                'test_file', 'test_subdir', output_manager.Datatype.TEXT))

Example #3
0
import zipfile
import zlib

import devil_chromium
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
from devil.utils import lazy
import method_count
from pylib import constants
from pylib.constants import host_paths

_AAPT_PATH = lazy.WeakConstant(lambda: build_tools.GetPath('aapt'))
_BUILD_UTILS_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build',
                                 'android', 'gyp')

with host_paths.SysPath(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build')):
    import gn_helpers  # pylint: disable=import-error

with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
    import perf_tests_results_helper  # pylint: disable=import-error

with host_paths.SysPath(host_paths.TRACING_PATH):
    from tracing.value import convert_chart_json  # pylint: disable=import-error

with host_paths.SysPath(_BUILD_UTILS_PATH, 0):
    from util import build_utils  # pylint: disable=import-error
    from util import zipalign  # pylint: disable=import-error

zipalign.ApplyZipFileZipAlignFix()

# Captures an entire config from aapt output.
Example #4
0
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import contextlib
import logging
import os

from pylib.constants import host_paths

_COLORAMA_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party',
                              'colorama', 'src')

with host_paths.SysPath(_COLORAMA_PATH):
    import colorama


class ColorStreamHandler(logging.StreamHandler):
    """Handler that can be used to colorize logging output.

  Example using a specific logger:

    logger = logging.getLogger('my_logger')
    logger.addHandler(ColorStreamHandler())
    logger.info('message')

  Example using the root logger:

    ColorStreamHandler.MakeDefault()
    logging.info('message')
Example #5
0
#
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import collections
import optparse
import os
import re
import sys

from pylib import constants
from pylib.constants import host_paths

# Uses symbol.py from third_party/android_platform, not python's.
with host_paths.SysPath(host_paths.ANDROID_PLATFORM_DEVELOPMENT_SCRIPTS_PATH,
                        position=0):
    import symbol

_RE_ASAN = re.compile(r'(.*?)(#\S*?)\s+(\S*?)\s+\((.*?)\+(.*?)\)')


def _ParseAsanLogLine(line):
    m = re.match(_RE_ASAN, line)
    if not m:
        return None
    return {
        'prefix': m.group(1),
        'library': m.group(4),
        'pos': m.group(2),
        'rel_address': '%08x' % int(m.group(5), 16),
    }
Example #6
0
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import threading
import zlib

from profile_chrome import controllers
from profile_chrome import util

from pylib.constants import host_paths

with host_paths.SysPath(host_paths.DEVIL_PATH):
    from devil.utils import cmd_helper

_SYSTRACE_OPTIONS = [
    # Compress the trace before sending it over USB.
    '-z',
    # Use a large trace buffer to increase the polling interval.
    '-b',
    '16384'
]

# Interval in seconds for sampling systrace data.
_SYSTRACE_INTERVAL = 15

_TRACING_ON_PATH = '/sys/kernel/debug/tracing/tracing_on'


class SystraceController(controllers.BaseController):
    def __init__(self, device, categories, ring_buffer):
Example #7
0
import zipfile
import zlib

import devil_chromium
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
from devil.utils import lazy
import method_count
from pylib import constants
from pylib.constants import host_paths

_AAPT_PATH = lazy.WeakConstant(lambda: build_tools.GetPath('aapt'))
_BUILD_UTILS_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build',
                                 'android', 'gyp')

with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
    import perf_tests_results_helper  # pylint: disable=import-error

with host_paths.SysPath(host_paths.TRACING_PATH):
    from tracing.value import convert_chart_json  # pylint: disable=import-error

with host_paths.SysPath(_BUILD_UTILS_PATH, 0):
    from util import build_utils  # pylint: disable=import-error
    from util import zipalign  # pylint: disable=import-error

zipalign.ApplyZipFileZipAlignFix()

# Captures an entire config from aapt output.
_AAPT_CONFIG_PATTERN = r'config %s:(.*?)config [a-zA-Z-]+:'
# Matches string resource entries from aapt output.
_AAPT_ENTRY_RE = re.compile(
import zlib

import devil_chromium
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
from devil.utils import lazy
import method_count
from pylib import constants
from pylib.constants import host_paths

_AAPT_PATH = lazy.WeakConstant(lambda: build_tools.GetPath('aapt'))
_GRIT_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'tools', 'grit')

# Prepend the grit module from the source tree so it takes precedence over other
# grit versions that might present in the search path.
with host_paths.SysPath(_GRIT_PATH, 1):
    from grit.format import data_pack  # pylint: disable=import-error

with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
    import perf_tests_results_helper  # pylint: disable=import-error


# Python had a bug in zipinfo parsing that triggers on ChromeModern.apk
# https://bugs.python.org/issue14315
def _PatchedDecodeExtra(self):
    # Try to decode the extra field.
    extra = self.extra
    unpack = struct.unpack
    while len(extra) >= 4:
        tp, ln = unpack('<HH', extra[:4])
        if tp == 1:
import devil_chromium
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
from devil.utils import lazy
import method_count
from pylib import constants
from pylib.constants import host_paths

_AAPT_PATH = lazy.WeakConstant(lambda: build_tools.GetPath('aapt'))
_BUILD_UTILS_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build',
                                 'android', 'gyp')
_APK_PATCH_SIZE_ESTIMATOR_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT,
                                              'third_party',
                                              'apk-patch-size-estimator')

with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
    import perf_tests_results_helper  # pylint: disable=import-error

with host_paths.SysPath(_BUILD_UTILS_PATH, 0):
    from util import build_utils  # pylint: disable=import-error

with host_paths.SysPath(_APK_PATCH_SIZE_ESTIMATOR_PATH):
    import apk_patch_size_estimator  # pylint: disable=import-error


# Python had a bug in zipinfo parsing that triggers on ChromeModern.apk
# https://bugs.python.org/issue14315
def _PatchedDecodeExtra(self):
    # Try to decode the extra field.
    extra = self.extra
    unpack = struct.unpack
Example #10
0
# found in the LICENSE file.
"""Runs resource_sizes.py on two apks and outputs the diff."""

from __future__ import print_function

import argparse
import json
import logging
import os
import subprocess
import sys

from pylib.constants import host_paths
from pylib.utils import shared_preference_utils

with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
    import perf_tests_results_helper  # pylint: disable=import-error

with host_paths.SysPath(host_paths.TRACING_PATH):
    from tracing.value import convert_chart_json  # pylint: disable=import-error

_ANDROID_DIR = os.path.dirname(os.path.abspath(__file__))
with host_paths.SysPath(os.path.join(_ANDROID_DIR, 'gyp')):
    from util import build_utils  # pylint: disable=import-error

_BASE_CHART = {
    'format_version': '0.1',
    'benchmark_name': 'resource_sizes_diff',
    'benchmark_description': 'APK resource size diff information',
    'trace_rerun_options': [],
    'charts': {},
Example #11
0
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""//build/android implementations of //testing/skia_gold_common.

Used for interacting with the Skia Gold image diffing service.
"""

import os
import shutil

from devil.utils import cmd_helper
from pylib.base.output_manager import Datatype
from pylib.constants import host_paths
from pylib.utils import repo_utils

with host_paths.SysPath(host_paths.TESTING_PATH):
    from skia_gold_common import skia_gold_session
    from skia_gold_common import skia_gold_session_manager
    from skia_gold_common import skia_gold_properties


class AndroidSkiaGoldSession(skia_gold_session.SkiaGoldSession):
    def _StoreDiffLinks(self, image_name, output_manager, output_dir):
        """See SkiaGoldSession._StoreDiffLinks for general documentation.

    |output_manager| must be a build.android.pylib.base.OutputManager instance.
    """
        given_path = closest_path = diff_path = None
        # The directory should contain "input-<hash>.png", "closest-<hash>.png",
        # and "diff.png".
        for f in os.listdir(output_dir):
Example #12
0
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import contextlib
import logging
import os

from pylib.constants import host_paths

_REQUESTS_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party',
                              'requests', 'src')
_APPURIFY_PYTHON_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party',
                                     'appurify-python', 'src')

with host_paths.SysPath(_REQUESTS_PATH), (
        host_paths.SysPath(_APPURIFY_PYTHON_PATH)):

    handlers_before = list(logging.getLogger().handlers)

    import appurify.api  # pylint: disable=import-error
    import appurify.utils  # pylint: disable=import-error

    handlers_after = list(logging.getLogger().handlers)
    new_handler = list(set(handlers_after) - set(handlers_before))
    while new_handler:
        logging.info("Removing logging handler.")
        logging.getLogger().removeHandler(new_handler.pop())

    api = appurify.api
    utils = appurify.utils
Example #13
0
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import contextlib
import logging
import os

from pylib.constants import host_paths

_COLORAMA_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party',
                              'colorama', 'src')

with host_paths.SysPath(_COLORAMA_PATH, position=0):
    import colorama

BACK = colorama.Back
FORE = colorama.Fore
STYLE = colorama.Style


class _ColorFormatter(logging.Formatter):
    # pylint does not see members added dynamically in the constructor.
    # pylint: disable=no-member
    color_map = {
        logging.DEBUG: (FORE.CYAN),
        logging.WARNING: (FORE.YELLOW),
        logging.ERROR: (FORE.RED),
        logging.CRITICAL: (BACK.RED),
    }
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os

from pylib.constants import host_paths
from pylib.local.device import local_device_environment

AVD_DIR_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'tools', 'android',
                            'avd')
with host_paths.SysPath(AVD_DIR_PATH):
    import avd  # pylint: disable=import-error


class LocalEmulatorEnvironment(local_device_environment.LocalDeviceEnvironment
                               ):
    def __init__(self, args, output_manager, error_func):
        super(LocalEmulatorEnvironment, self).__init__(args, output_manager,
                                                       error_func)
        self._avd_config = avd.AvdConfig(args.avd_config)
        self._emulator_instance = None

    #override
    def SetUp(self):
        self._avd_config.Install()
        self._emulator_instance = self._avd_config.StartInstance()
        self._device_serials = [self._emulator_instance.serial]
        super(LocalEmulatorEnvironment, self).SetUp()

    #override
Example #15
0
from pylib.base import base_test_result
from pylib.base import test_exception
from pylib.base import test_instance
from pylib.constants import host_paths
from pylib.instrumentation import test_result
from pylib.instrumentation import instrumentation_parser
from pylib.symbols import deobfuscator
from pylib.symbols import stack_symbolizer
from pylib.utils import dexdump
from pylib.utils import instrumentation_tracing
from pylib.utils import proguard
from pylib.utils import shared_preference_utils
from pylib.utils import test_filter


with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
  import unittest_util # pylint: disable=import-error

# Ref: http://developer.android.com/reference/android/app/Activity.html
_ACTIVITY_RESULT_CANCELED = 0
_ACTIVITY_RESULT_OK = -1

_COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter'
_DEFAULT_ANNOTATIONS = [
    'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'IntegrationTest']
_EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [
    'DisabledTest', 'FlakyTest', 'Manual']
_VALID_ANNOTATIONS = set(_DEFAULT_ANNOTATIONS +
                         _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS)

_EXTRA_DRIVER_TEST_LIST = (
Example #16
0
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""//build/android implementations of //testing/skia_gold_common.

Used for interacting with the Skia Gold image diffing service.
"""

import os
import shutil

from devil.utils import cmd_helper
from pylib.base.output_manager import Datatype
from pylib.constants import host_paths
from pylib.utils import repo_utils

with host_paths.SysPath(host_paths.BUILD_PATH):
  from skia_gold_common import skia_gold_session
  from skia_gold_common import skia_gold_session_manager
  from skia_gold_common import skia_gold_properties


class AndroidSkiaGoldSession(skia_gold_session.SkiaGoldSession):
  def _StoreDiffLinks(self, image_name, output_manager, output_dir):
    """See SkiaGoldSession._StoreDiffLinks for general documentation.

    |output_manager| must be a build.android.pylib.base.OutputManager instance.
    """
    given_path = closest_path = diff_path = None
    # The directory should contain "input-<hash>.png", "closest-<hash>.png",
    # and "diff.png".
    for f in os.listdir(output_dir):
Example #17
0
from pylib.base import output_manager
from pylib.constants import host_paths
from pylib.instrumentation import instrumentation_test_instance
from pylib.local.device import local_device_environment
from pylib.local.device import local_device_test_run
from pylib.output import remote_output_manager
from pylib.utils import instrumentation_tracing
from pylib.utils import shared_preference_utils

from py_trace_event import trace_event
from py_trace_event import trace_time
from py_utils import contextlib_ext
from py_utils import tempfile_ext
import tombstones

with host_paths.SysPath(
        os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party'), 0):
    import jinja2  # pylint: disable=import-error
    import markupsafe  # pylint: disable=import-error,unused-import

_JINJA_TEMPLATE_DIR = os.path.join(host_paths.DIR_SOURCE_ROOT, 'build',
                                   'android', 'pylib', 'instrumentation')
_JINJA_TEMPLATE_FILENAME = 'render_test.html.jinja'

_TAG = 'test_runner_py'

TIMEOUT_ANNOTATIONS = [
    ('Manual', 10 * 60 * 60),
    ('IntegrationTest', 30 * 60),
    ('External', 10 * 60),
    ('EnormousTest', 10 * 60),
    ('LargeTest', 5 * 60),
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Unittests for test_dispatcher.py."""

# pylint: disable=no-self-use
# pylint: disable=protected-access

import unittest

from pylib.base import base_test_result
from pylib.base import test_collection
from pylib.base import test_dispatcher
from pylib.constants import host_paths

with host_paths.SysPath(host_paths.DEVIL_PATH):
  from devil.android import device_utils
  from devil.android.sdk import adb_wrapper
  from devil.constants import exit_codes
  from devil.utils import watchdog_timer

with host_paths.SysPath(host_paths.PYMOCK_PATH):
  import mock # pylint: disable=import-error


class TestException(Exception):
  pass


def _MockDevice(serial):
  d = mock.MagicMock(spec=device_utils.DeviceUtils)