def Main(args, start_dir, top_level_dir, runner=None):
  """Unit test suite that collects all test cases for telemetry."""
  # Add unittest_data to the path so we can import packages from it.
  util.AddDirToPythonPath(util.GetUnittestDataDir())

  default_options = browser_options.BrowserFinderOptions()
  default_options.browser_type = 'any'

  parser = default_options.CreateParser('run_tests [options] [test names]')
  parser.add_option('--repeat-count', dest='run_test_repeat_count',
                    type='int', default=1,
                    help='Repeats each a provided number of times.')
  parser.add_option('-d', '--also-run-disabled-tests',
                    dest='run_disabled_tests',
                    action='store_true', default=False,
                    help='Also run tests decorated with @DisabledTest.')

  _, args = parser.parse_args(args)

  if default_options.verbosity == 0:
    logging.getLogger().setLevel(logging.WARN)

  from telemetry.core import browser_finder
  try:
    browser_to_create = browser_finder.FindBrowser(default_options)
  except browser_finder.BrowserFinderException, ex:
    logging.error(str(ex))
    return 1
Example #2
0
    def testDirAddedToPythonPath(self):
        old_sys_path = sys.path
        expected_path = os.path.abspath(os.path.join(*self._test_dir))

        util.AddDirToPythonPath(*self._test_dir)

        self.assertEquals(sys.path[0], expected_path)
        sys.path = old_sys_path
    def run(self, test, progress_reporters, repeat_count, args):
        util.AddDirToPythonPath(util.GetUnittestDataDir())
        result = TestResult(progress_reporters)
        result.startTestRun()
        try:
            options_for_unittests.Push(args)
            for _ in xrange(repeat_count):
                test(result)
        finally:
            options_for_unittests.Pop()
            result.stopTestRun()

        return result
Example #4
0
"""Interface for a USB-connected Monsoon power meter.

http://msoon.com/LabEquipment/PowerMonitor/
Currently Unix-only. Relies on fcntl, /dev, and /tmp.
"""

import collections
import logging
import os
import select
import struct
import time

from telemetry.core import util

util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'pyserial')
import serial  # pylint: disable=F0401
import serial.tools.list_ports

Power = collections.namedtuple('Power', ['amps', 'volts'])


class Monsoon:
    """Provides a simple class to use the power meter.

  mon = monsoon.Monsoon()
  mon.SetVoltage(3.7)
  mon.StartDataCollection()
  mydata = []
  while len(mydata) < 1000:
    mydata.extend(mon.CollectData())
Example #5
0
# Copyright (c) 2012 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.

from telemetry.core import util

# TODO(tonyg): Move webpagereplay.py to a common location.
util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'chrome', 'test',
                        'functional')
import webpagereplay  # pylint: disable=F0401


def GetChromeFlags(replay_host, http_port, https_port):
    return webpagereplay.GetChromeFlags(replay_host, http_port, https_port)


class ReplayServer(object):
    def __init__(self, browser_backend, path, is_record_mode, is_append_mode,
                 make_javascript_deterministic):
        self._browser_backend = browser_backend
        self._forwarder = None
        self._web_page_replay = None
        self._is_record_mode = is_record_mode
        self._is_append_mode = is_append_mode

        self._forwarder = browser_backend.CreateForwarder(
            util.PortPair(browser_backend.webpagereplay_local_http_port,
                          browser_backend.webpagereplay_remote_http_port),
            util.PortPair(browser_backend.webpagereplay_local_https_port,
                          browser_backend.webpagereplay_remote_https_port))
# Copyright (c) 2012 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.
from __future__ import absolute_import

from telemetry.core import util

util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'util', 'lib',
                        'common')
import perf_tests_results_helper  # pylint: disable=F0401


FlattenList = \
    perf_tests_results_helper.FlattenList
GeomMeanAndStdDevFromHistogram = \
    perf_tests_results_helper.GeomMeanAndStdDevFromHistogram
PrintPerfResult = \
    perf_tests_results_helper.PrintPerfResult
PrintPages = \
    perf_tests_results_helper.PrintPages
Example #7
0
# Copyright (c) 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 os
import signal
import sys

from telemetry.core import exceptions
from telemetry.core import util
from telemetry.core.platform import profiler

# pexpect is not available on all platforms so use the third_party version.
util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'third_party', 'pexpect')
try:
  import pexpect  # pylint: disable=F0401
except ImportError:
  pass


class _SingleProcessIprofilerProfiler(object):
  """An internal class for using iprofiler for a given process."""
  def __init__(self, pid, output_path):
    self._output_path = output_path
    output_dir = os.path.dirname(self._output_path)
    output_file = os.path.basename(self._output_path)
    self._proc = pexpect.spawn(
        'iprofiler', ['-timeprofiler', '-T', '300', '-a', str(pid),
                      '-d', output_dir, '-o', output_file],
        timeout=300)
    while True:
Example #8
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.

from telemetry.core import util


util.AddDirToPythonPath(util.GetChromiumSrcDir(),
                        'third_party', 'py_trace_event', 'src')
from trace_event import *  # pylint: disable=import-error, wildcard-import
from telemetry.core import util
from telemetry import decorators
from telemetry.internal.forwarders import android_forwarder
from telemetry.internal.image_processing import video
from telemetry.internal.platform import android_device
from telemetry.internal.platform import linux_based_platform_backend
from telemetry.internal.platform.power_monitor import android_dumpsys_power_monitor
from telemetry.internal.platform.power_monitor import android_temperature_monitor
from telemetry.internal.platform.power_monitor import monsoon_power_monitor
from telemetry.internal.platform.power_monitor import power_monitor_controller
from telemetry.internal.platform.profiler import android_prebuilt_profiler_helper
from telemetry.internal.util import exception_formatter
from telemetry.internal.util import external_modules

psutil = external_modules.ImportOptionalModule('psutil')
util.AddDirToPythonPath(util.GetChromiumSrcDir(),
                        'third_party', 'webpagereplay')
import adb_install_cert
import certutils
import platformsettings

# Get build/android scripts into our path.
util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
from pylib import constants
from pylib import screenshot
from pylib.device import battery_utils
from pylib.device import device_errors
from pylib.device import device_utils
from pylib.perf import cache_control
from pylib.perf import perf_control
from pylib.perf import thermal_throttle
Example #10
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.
from __future__ import absolute_import

import socket

from telemetry.core import util

util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party',
                        'websocket-client')
# pylint: disable=unused-import
from websocket import create_connection as _create_connection
from websocket import WebSocketException
from websocket import WebSocketTimeoutException


def create_connection(*args, **kwargs):
    sockopt = kwargs.get('sockopt', [])

    # By default, we set SO_REUSEADDR on all websockets used by Telemetry.
    # This prevents spurious address in use errors on Windows.
    #
    # TODO(tonyg): We may want to set SO_NODELAY here as well.
    sockopt.append((socket.SOL_SOCKET, socket.SO_REUSEADDR, 1))

    kwargs['sockopt'] = sockopt
    return _create_connection(*args, **kwargs)
Example #11
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 unittest

from telemetry.core import util
from telemetry.core.platform import android_device
from telemetry.core.platform import android_platform_backend
from telemetry import decorators
from telemetry.unittest_util import options_for_unittests
from telemetry.unittest_util import system_stub

util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock')
import mock  # pylint: disable=F0401

util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
from pylib.device import battery_utils  # pylint: disable=F0401


class AndroidPlatformBackendTest(unittest.TestCase):
    def setUp(self):
        self._options = options_for_unittests.GetCopy()
        self._stubs = system_stub.Override(android_platform_backend, [
            'perf_control', 'thermal_throttle', 'adb_commands', 'certutils',
            'adb_install_cert', 'platformsettings'
        ])

        # Skip _FixPossibleAdbInstability by setting psutil to None.
        self._actual_ps_util = android_platform_backend.psutil
        android_platform_backend.psutil = None
Example #12
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.
from __future__ import absolute_import

from telemetry.core import util

util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'tools')
from crx_id import crx_id  # pylint: disable=F0401

GetCRXAppID = crx_id.GetCRXAppID
HasPublicKey = crx_id.HasPublicKey
Example #13
0
# Copyright (c) 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.

from telemetry.core import util

# Bring in tvcm module for basic JS components capabilities.
util.AddDirToPythonPath(
    util.GetChromiumSrcDir(),
    'third_party', 'trace-viewer', 'third_party', 'tvcm')

# Bring in trace_viewer module for the UI features that are part of the trace
# viewer.
util.AddDirToPythonPath(
    util.GetChromiumSrcDir(),
    'third_party', 'trace-viewer')
Example #14
0
# Copyright 2012 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 sys

from telemetry.core import util
from telemetry import decorators
from telemetry.internal.browser import browser_finder
from telemetry.internal.browser import browser_finder_exceptions
from telemetry.internal.browser import browser_options
from telemetry.internal.platform import device_finder
from telemetry.internal.util import command_line
from telemetry.testing import browser_test_case
from telemetry.testing import options_for_unittests

util.AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'typ')

import typ


class RunTestsCommand(command_line.OptparseCommand):
    """Run unit tests"""

    usage = '[test_name ...] [<options>]'

    def __init__(self):
        super(RunTestsCommand, self).__init__()
        self.stream = sys.stdout

    @classmethod
    def CreateParser(cls):
Example #15
0
import os
import re
import signal
import subprocess
import sys
import tempfile

from pylib.device import device_errors  # pylint: disable=F0401

from telemetry.core import platform
from telemetry.core.platform import profiler
from telemetry.core.platform.profiler import android_profiling_helper
from telemetry.core import util
from telemetry.util import support_binaries

util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
from pylib.perf import perf_control  # pylint: disable=F0401

_PERF_OPTIONS = [
    # In perf 3.13 --call-graph requires an argument, so use the -g short-hand
    # which does not.
    '-g',
    # Increase sampling frequency for better coverage.
    '--freq',
    '2000',
]

_PERF_OPTIONS_ANDROID = [
    # Increase priority to avoid dropping samples. Requires root.
    '--realtime',
    '80',
Example #16
0
# found in the LICENSE file.
"""Finds desktop browsers that can be controlled by telemetry."""

import logging
import os
import sys

from telemetry.core import browser
from telemetry.core import possible_browser
from telemetry.core import platform
from telemetry.core import util
from telemetry.core.backends.webdriver import webdriver_ie_backend
from telemetry.page import cloud_storage

# Try to import the selenium python lib which may be not available.
util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'third_party', 'webdriver',
                        'pylib')
try:
    from selenium import webdriver  # pylint: disable=F0401
except ImportError:
    webdriver = None

ALL_BROWSER_TYPES = ''
if webdriver:
    ALL_BROWSER_TYPES = ['internet-explorer', 'internet-explorer-x64']
else:
    logging.warning('Webdriver backend is unsupported without selenium pylib. '
                    'For installation of selenium pylib, please refer to '
                    'https://code.google.com/p/selenium/wiki/PythonBindings.')


class PossibleWebDriverBrowser(possible_browser.PossibleBrowser):
Example #17
0
# Copyright 2015 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 unittest

from telemetry.core import util
from telemetry.internal.results import page_test_results
from telemetry.page import page
from telemetry.timeline import memory_dump_event
from telemetry.web_perf.metrics import memory_timeline
from telemetry.web_perf import timeline_interaction_record

util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock')
import mock


def MockProcessDumpEvent(dump_id, name, start, memory_usage):
  process_dump = mock.Mock()
  process_dump.dump_id = dump_id
  process_dump.process_name = name
  process_dump.start = start
  if memory_usage is None:
    process_dump.has_mmaps = False
    memory_usage = {}
  else:
    process_dump.has_mmaps = True
  if not isinstance(memory_usage, dict):
    memory_usage = dict.fromkeys(memory_timeline.DEFAULT_METRICS, memory_usage)
  process_dump.GetMemoryUsage = mock.Mock(return_value=memory_usage)
Example #18
0
import logging
import os
import random
import shutil
import StringIO
import sys
import tempfile

from catapult_base import cloud_storage
from telemetry.core import util
from telemetry.internal.util import file_handle
from telemetry.timeline import trace_data as trace_data_module
from telemetry import value as value_module

# Bring in tv module for transforming raw trace to html form.
util.AddDirToPythonPath(
    util.GetChromiumSrcDir(), 'third_party', 'catapult')

from tracing.build import trace2html


class TraceValue(value_module.Value):
  def __init__(self, page, trace_data, important=False, description=None):
    """A value that contains a TraceData object and knows how to
    output it.

    Adding TraceValues and outputting as JSON will produce a directory full of
    HTML files called trace_files. Outputting as chart JSON will also produce
    an index, files.html, linking to each of these files.
    """
    super(TraceValue, self).__init__(
        page, name='trace', units='', important=important,