Skip to content

Commit

Permalink
Attempt to switch telemetry to typ again.
Browse files Browse the repository at this point in the history
TBR=dtu@chromium.org, phajdan.jr@chromium.org
BUG=388256

Review URL: https://codereview.chromium.org/708443003

Cr-Commit-Position: refs/heads/master@{#303141}
  • Loading branch information
dpranke authored and Commit bot committed Nov 7, 2014
1 parent 4c3b71b commit 122c806
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 510 deletions.
24 changes: 15 additions & 9 deletions tools/perf/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ This script DOES NOT run benchmarks. run_benchmark does that.
"""

import os
import subprocess
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'telemetry'))

from telemetry.unittest import gtest_progress_reporter
from telemetry.unittest import run_tests
if __name__ == '__main__':
perf_dir = os.path.dirname(os.path.realpath(__file__))
telemetry_dir = os.path.realpath(os.path.join(perf_dir, '..', 'telemetry'))

env = os.environ.copy()
if 'PYTHONPATH' in env:
env['PYTHONPATH'] = env['PYTHONPATH'] + os.pathsep + telemetry_dir
else:
env['PYTHONPATH'] = telemetry_dir

if __name__ == '__main__':
base_dir = os.path.dirname(os.path.realpath(__file__))
progress_reporters = [
gtest_progress_reporter.GTestProgressReporter(sys.stdout)]
run_tests.config = run_tests.Config(base_dir, [base_dir], progress_reporters)
sys.exit(run_tests.RunTestsCommand.main())
path_to_run_tests = os.path.join(telemetry_dir, 'telemetry', 'unittest',
'run_tests.py')
argv = ['--top-level-dir', perf_dir] + sys.argv[1:]
ret = subprocess.call([sys.executable, path_to_run_tests] + argv, env=env)
print 'run_tests exiting, ret = %d' % ret
sys.exit(ret)
4 changes: 3 additions & 1 deletion tools/telemetry/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def _CommonChecks(input_api, output_api):
return results

def GetPathsToPrepend(input_api):
return [input_api.PresubmitLocalPath()]
return [input_api.PresubmitLocalPath(),
os.path.join(input_api.PresubmitLocalPath(), os.path.pardir,
os.path.pardir, 'third_party', 'typ')]

def RunWithPrependedPath(prepended_path, fn, *args):
old_path = sys.path
Expand Down
47 changes: 17 additions & 30 deletions tools/telemetry/bootstrap_deps
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,23 @@
# This file specifies dependencies required to bootstrap Telemetry. It is in a
# minimal version of the format used by other DEPS files that gclient can read,
# but it should only be used to bootstrap Telemetry *outside* of a normal
# Chrome checkout.
# Chrome checkout. In particular, the normal 'value' part of the python
# dict is not used and hence does not contain real URLs for the repos.

deps = {
"src/tools/telemetry":
"https://src.chromium.org/chrome/trunk/src/tools/telemetry",

"src/build/android":
"https://src.chromium.org/chrome/trunk/src/build/android",
"src/build/util":
"https://src.chromium.org/chrome/trunk/src/build/util",
"src/chrome/test/data/extensions/profiles":
"https://src.chromium.org/chrome/trunk/src/chrome/test/data/extensions/profiles",
"src/third_party/android_testrunner":
"https://src.chromium.org/chrome/trunk/src/third_party/android_testrunner",
"src/third_party/android_tools/sdk/platform-tools":
"https://src.chromium.org/chrome/trunk/src/third_party/android_tools/sdk/platform-tools",
"src/third_party/chromite/ssh_keys":
"https://src.chromium.org/chrome/trunk/src/third_party/chromite/ssh_keys",
"src/third_party/flot/jquery.flot.min.js":
"https://src.chromium.org/chrome/trunk/src/third_party/flot/jquery.flot.min.js",
"src/third_party/WebKit/PerformanceTests/resources/jquery.tablesorter.min.js":
"https://src.chromium.org/blink/trunk/PerformanceTests/resources/jquery.tablesorter.min.js",
"src/third_party/WebKit/PerformanceTests/resources/statistics.js":
"https://src.chromium.org/blink/trunk/PerformanceTests/resources/statistics.js",
"src/third_party/webpagereplay":
"https://web-page-replay.googlecode.com/svn/trunk",
"src/third_party/trace-viewer":
"https://trace-viewer.googlecode.com/svn/trunk",
"src/tools/crx_id":
"https://src.chromium.org/chrome/trunk/src/tools/crx_id",
"src/tools/perf/unit-info.json":
"https://src.chromium.org/chrome/trunk/src/tools/perf/unit-info.json"
"src/tools/telemetry": "",
"src/build/android": "",
"src/build/util": "",
"src/chrome/test/data/extensions/profiles": "",
"src/third_party/android_testrunner": "",
"src/third_party/android_tools/sdk/platform-tools": "",
"src/third_party/chromite/ssh_keys": "",
"src/third_party/flot/jquery.flot.min.js": "",
"src/third_party/WebKit/PerformanceTests/resources/jquery.tablesorter.min.js": "",
"src/third_party/WebKit/PerformanceTests/resources/statistics.js": "",
"src/third_party/webpagereplay": "",
"src/third_party/trace-viewer": "",
"src/third_party/typ": "",
"src/tools/crx_id": "",
"src/tools/perf/unit-info.json": "",
}
23 changes: 15 additions & 8 deletions tools/telemetry/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@

import os
import sys

from telemetry.unittest import gtest_progress_reporter
from telemetry.unittest import run_tests
import subprocess


if __name__ == '__main__':
base_dir = os.path.dirname(os.path.realpath(__file__))
progress_reporters = [
gtest_progress_reporter.GTestProgressReporter(sys.stdout)]
run_tests.config = run_tests.Config(base_dir, [base_dir], progress_reporters)
sys.exit(run_tests.RunTestsCommand.main())
telemetry_dir = os.path.dirname(os.path.realpath(__file__))

env = os.environ.copy()
if 'PYTHONPATH' in env:
env['PYTHONPATH'] = env['PYTHONPATH'] + os.pathsep + telemetry_dir
else:
env['PYTHONPATH'] = telemetry_dir

path_to_run_tests = os.path.join(telemetry_dir, 'telemetry', 'unittest',
'run_tests.py')
argv = ['--top-level-dir', telemetry_dir] + sys.argv[1:]
ret = subprocess.call([sys.executable, path_to_run_tests] + argv, env=env)
print 'run_tests exiting, ret = %d' % ret
sys.exit(ret)
78 changes: 63 additions & 15 deletions tools/telemetry/telemetry/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ def wrapper(*args, **kwargs):
return _Enabled


# TODO(dpranke): Remove if we don't need this.
def Isolated(*args):
"""Decorator for noting that tests must be run in isolation.
The test will be run by itself (not concurrently with any other tests)
if ANY of the args match the browser type, OS name, or OS version."""
def _Isolated(func):
if not isinstance(func, types.FunctionType):
func._isolated_strings = isolated_strings
return func
@functools.wraps(func)
def wrapper(*args, **kwargs):
func(*args, **kwargs)
wrapper._isolated_strings = isolated_strings
return wrapper
if len(args) == 1 and callable(args[0]):
isolated_strings = []
return _Isolated(args[0])
isolated_strings = list(args)
for isolated_string in isolated_strings:
# TODO(tonyg): Validate that these strings are recognized.
assert isinstance(isolated_string, str), 'Isolated accepts a list of strs'
return _Isolated


def IsEnabled(test, possible_browser):
"""Returns True iff |test| is enabled given the |possible_browser|.
Expand All @@ -102,6 +127,11 @@ def IsEnabled(test, possible_browser):
_enabled_strings attributes.
possible_browser: A PossibleBrowser to check whether |test| may run against.
"""
should_skip, _ = ShouldSkip(test, possible_browser)
return not should_skip

def ShouldSkip(test, possible_browser):
"""Returns whether the test should be skipped and the reason for it."""
platform_attributes = [a.lower() for a in [
possible_browser.browser_type,
possible_browser.platform.GetOSName(),
Expand All @@ -120,28 +150,46 @@ def IsEnabled(test, possible_browser):
if hasattr(test, '_disabled_strings'):
disabled_strings = test._disabled_strings
if not disabled_strings:
return False # No arguments to @Disabled means always disable.
return True, '' # No arguments to @Disabled means always disable.
for disabled_string in disabled_strings:
if disabled_string in platform_attributes:
print (
'Skipping %s because it is disabled for %s. '
'You are running %s.' % (name,
' and '.join(disabled_strings),
' '.join(platform_attributes)))
return False
return (True,
'Skipping %s because it is disabled for %s. '
'You are running %s.' % (name,
' and '.join(disabled_strings),
' '.join(platform_attributes)))

if hasattr(test, '_enabled_strings'):
enabled_strings = test._enabled_strings
if not enabled_strings:
return True # No arguments to @Enabled means always enable.
return False, None # No arguments to @Enabled means always enable.
for enabled_string in enabled_strings:
if enabled_string in platform_attributes:
return False, None
return (True,
'Skipping %s because it is only enabled for %s. '
'You are running %s.' % (name,
' or '.join(enabled_strings),
' '.join(platform_attributes)))
return False, None

return False, None

def ShouldBeIsolated(test, possible_browser):
platform_attributes = [a.lower() for a in [
possible_browser.browser_type,
possible_browser.platform.GetOSName(),
possible_browser.platform.GetOSVersionName(),
]]
if possible_browser.supports_tab_control:
platform_attributes.append('has tabs')

if hasattr(test, '_isolated_strings'):
isolated_strings = test._isolated_strings
if not isolated_strings:
return True # No arguments to @Isolated means always isolate.
for isolated_string in isolated_strings:
if isolated_string in platform_attributes:
return True
print (
'Skipping %s because it is only enabled for %s. '
'You are running %s.' % (name,
' or '.join(enabled_strings),
' '.join(platform_attributes)))
return False

return True
return False
45 changes: 33 additions & 12 deletions tools/telemetry/telemetry/unittest/browser_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,49 @@
from telemetry.unittest import options_for_unittests
from telemetry.util import path

current_browser_options = None
current_browser = None


def teardown_browser():
global current_browser
global current_browser_options

if current_browser:
current_browser.Close()
current_browser = None
current_browser_options = None


class BrowserTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
global current_browser
global current_browser_options

options = options_for_unittests.GetCopy()

cls.CustomizeBrowserOptions(options.browser_options)
browser_to_create = browser_finder.FindBrowser(options)
if not browser_to_create:
raise Exception('No browser found, cannot continue test.')
if not current_browser or (current_browser_options !=
options.browser_options):
if current_browser:
teardown_browser()

cls._browser = None
try:
cls._browser = browser_to_create.Create(options)
except:
cls.tearDownClass()
raise
browser_to_create = browser_finder.FindBrowser(options)
if not browser_to_create:
raise Exception('No browser found, cannot continue test.')

try:
current_browser = browser_to_create.Create(options)
current_browser_options = options.browser_options
except:
cls.tearDownClass()
raise
cls._browser = current_browser

@classmethod
def tearDownClass(cls):
if cls._browser:
cls._browser.Close()
cls._browser = None
pass

@classmethod
def CustomizeBrowserOptions(cls, options):
Expand Down
Loading

0 comments on commit 122c806

Please sign in to comment.