Skip to content

Commit

Permalink
[chromedriver] Flush stdout when printing buildbot annotations.
Browse files Browse the repository at this point in the history
R=chrisgao@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201904 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kkania@chromium.org committed May 23, 2013
1 parent aa3030b commit 307ef81
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 44 deletions.
36 changes: 36 additions & 0 deletions chrome/test/chromedriver/chrome_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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.

"""Paths to common resources in the Chrome repository."""

import os


_THIS_DIR = os.path.abspath(os.path.dirname(__file__))


def GetSrc():
"""Returns the path to the root src directory."""
return os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir)


def GetTestData():
"""Returns the path to the src/chrome/test/data directory."""
return os.path.join(GetSrc(), 'chrome', 'test', 'data')


def GetBuildDir(required_paths):
"""Returns the preferred build directory that contains given paths."""
dirs = ['out', 'build', 'xcodebuild', 'sconsbuild']
rel_dirs = [os.path.join(x, 'Release') for x in dirs]
debug_dirs = [os.path.join(x, 'Debug') for x in dirs]
full_dirs = [os.path.join(GetSrc(), x) for x in rel_dirs + debug_dirs]
for build_dir in full_dirs:
for required_path in required_paths:
if not os.path.exists(os.path.join(build_dir, required_path)):
break
else:
return build_dir
raise RuntimeError('Cannot find build directory containing ' +
', '.join(required_paths))
25 changes: 12 additions & 13 deletions chrome/test/chromedriver/run_all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import os
import sys

_THIS_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib'))

from common import chrome_paths
from common import util

import archive
import chrome_paths
import util

_THIS_DIR = os.path.abspath(os.path.dirname(__file__))


def _AppendEnvironmentPath(env_name, path):
Expand Down Expand Up @@ -68,12 +66,12 @@ def RunPythonTests(chromedriver, chrome=None, chrome_version=None,
version_info = ''
if chrome_version_name:
version_info = '(v%s)' % chrome_version_name
print '@@@BUILD_STEP python_tests%s@@@' % version_info
util.MarkBuildStepStart('python_tests%s' % version_info)
code = util.RunCommand(
_GenerateTestCommand('run_py_tests.py', chromedriver, chrome,
chrome_version, android_package))
if code:
print '\n@@@STEP_FAILURE@@@'
util.MarkBuildStepError()
return code


Expand All @@ -82,20 +80,20 @@ def RunJavaTests(chromedriver, chrome=None, chrome_version=None,
version_info = ''
if chrome_version_name:
version_info = '(v%s)' % chrome_version_name
print '@@@BUILD_STEP java_tests%s@@@' % version_info
util.MarkBuildStepStart('java_tests%s' % version_info)
code = util.RunCommand(
_GenerateTestCommand('run_java_tests.py', chromedriver, chrome,
chrome_version, android_package))
if code:
print '@@@STEP_FAILURE@@@'
util.MarkBuildStepError()
return code


def RunCppTests(cpp_tests):
print '@@@BUILD_STEP chromedriver2_tests@@@'
util.MarkBuildStepStart('chromedriver2_tests')
code = util.RunCommand([cpp_tests])
if code:
print '@@@STEP_FAILURE@@@'
util.MarkBuildStepError()
return code


Expand Down Expand Up @@ -167,7 +165,8 @@ def main():
if version_name == 'HEAD':
version_name = version[1]
download_site = archive.Site.SNAPSHOT
chrome_path = archive.DownloadChrome(version[1], util.MakeTempDir(),
chrome_path = archive.DownloadChrome(version[1],
util.MakeTempDir(),
download_site)
code1 = RunPythonTests(chromedriver, chrome=chrome_path,
chrome_version=version[0],
Expand Down
23 changes: 10 additions & 13 deletions chrome/test/chromedriver/run_buildbot_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
import urllib2
import zipfile

_THIS_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib'))

from common import chrome_paths
from common import util

import archive
import chrome_paths
import util

_THIS_DIR = os.path.abspath(os.path.dirname(__file__))
GS_BUCKET = 'gs://chromedriver-prebuilts'
GS_ZIP_PREFIX = 'chromedriver2_prebuilts'
SLAVE_SCRIPT_DIR = os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir,
Expand All @@ -34,7 +31,7 @@


def Archive(revision):
print '@@@BUILD_STEP archive@@@'
util.MarkBuildStepStart('archive')
prebuilts = ['libchromedriver2.so', 'chromedriver2_server',
'chromedriver2_unittests', 'chromedriver2_tests']
build_dir = chrome_paths.GetBuildDir(prebuilts[0:1])
Expand All @@ -54,11 +51,11 @@ def Archive(revision):
'--dest_gsbase=%s' % GS_BUCKET
]
if util.RunCommand(cmd):
print '@@@STEP_FAILURE@@@'
util.MarkBuildStepError()


def Download():
print '@@@BUILD_STEP Download chromedriver prebuilts@@@'
util.MarkBuildStepStart('Download chromedriver prebuilts')

temp_dir = util.MakeTempDir()
zip_path = os.path.join(temp_dir, 'chromedriver2_prebuilts.zip')
Expand All @@ -70,7 +67,7 @@ def Download():
'--dst=%s' % zip_path
]
if util.RunCommand(cmd):
print '@@@STEP_FAILURE@@@'
util.MarkBuildStepError()

build_dir = chrome_paths.GetBuildDir(['host_forwarder'])
print 'Unzipping prebuilts %s to %s' % (zip_path, build_dir)
Expand Down Expand Up @@ -101,7 +98,7 @@ def MaybeRelease(revision):
if zip_name in downloads:
return 0

print '@@@BUILD_STEP releasing %s@@@' % zip_name
util.MarkBuildStepStart('releasing %s' % zip_name)
if util.IsWindows():
server_orig_name = 'chromedriver2_server.exe'
server_name = 'chromedriver.exe'
Expand Down Expand Up @@ -130,7 +127,7 @@ def MaybeRelease(revision):
]
with open(os.devnull, 'wb') as no_output:
if subprocess.Popen(cmd, stdout=no_output, stderr=no_output).wait():
print '@@@STEP_FAILURE@@@'
util.MarkBuildStepError()


def KillChromes():
Expand All @@ -157,7 +154,7 @@ def CleanTmpDir():


def WaitForLatestSnapshot(revision):
print '@@@BUILD_STEP wait_for_snapshot@@@'
util.MarkBuildStepStart('wait_for_snapshot')
while True:
snapshot_revision = archive.GetLatestRevision(archive.Site.SNAPSHOT)
if snapshot_revision >= revision:
Expand Down
14 changes: 5 additions & 9 deletions chrome/test/chromedriver/run_java_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
import sys
import xml.dom.minidom as minidom

_THIS_DIR = os.path.abspath(os.path.dirname(__file__))

sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib'))

from common import chrome_paths
from common import util

import chrome_paths
import test_environment
import util


class TestResult(object):
Expand Down Expand Up @@ -206,12 +201,13 @@ def PrintTestResults(results):

print 'Ran %s tests' % len(results)
print 'Failed %s:' % len(failures)
util.AddBuildStepText('failed %s/%s' % (len(failures), len(results))
for result in failures:
print '=' * 80
print '=' * 10, result.GetName(), '(%ss)' % result.GetTime()
print result.GetFailureMessage()
if failures:
print '@@@STEP_TEXT@Failed %s tests@@@' % len(failures)
if len(failures) < 10:
util.AddBuildStepText('.'.join(result.GetName.split('.')[-2:]))
print 'Rerun failing tests with filter:', ':'.join(failureNames)
return len(failures)

Expand Down
15 changes: 6 additions & 9 deletions chrome/test/chromedriver/run_py_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@
import time
import unittest

_THIS_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib'))

_TEST_DATA_DIR = os.path.join(_THIS_DIR, os.pardir, 'data', 'chromedriver')

from common import chrome_paths
from common import unittest_util
from common import util

import chrome_paths
import chromedriver
import unittest_util
import util
from webelement import WebElement
import webserver

_THIS_DIR = os.path.abspath(os.path.dirname(__file__))
_TEST_DATA_DIR = os.path.join(_THIS_DIR, os.pardir, 'data', 'chromedriver')

if util.IsLinux():
sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir,
'build', 'android'))
Expand Down
130 changes: 130 additions & 0 deletions chrome/test/chromedriver/unittest_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# 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.

"""Utilities for dealing with the python unittest module."""

import fnmatch
import sys
import unittest


class _TextTestResult(unittest._TextTestResult):
"""A test result class that can print formatted text results to a stream.
Results printed in conformance with gtest output format, like:
[ RUN ] autofill.AutofillTest.testAutofillInvalid: "test desc."
[ OK ] autofill.AutofillTest.testAutofillInvalid
[ RUN ] autofill.AutofillTest.testFillProfile: "test desc."
[ OK ] autofill.AutofillTest.testFillProfile
[ RUN ] autofill.AutofillTest.testFillProfileCrazyCharacters: "Test."
[ OK ] autofill.AutofillTest.testFillProfileCrazyCharacters
"""
def __init__(self, stream, descriptions, verbosity):
unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
self._fails = set()

def _GetTestURI(self, test):
return '%s.%s.%s' % (test.__class__.__module__,
test.__class__.__name__,
test._testMethodName)

def getDescription(self, test):
return '%s: "%s"' % (self._GetTestURI(test), test.shortDescription())

def startTest(self, test):
unittest.TestResult.startTest(self, test)
self.stream.writeln('[ RUN ] %s' % self.getDescription(test))

def addSuccess(self, test):
unittest.TestResult.addSuccess(self, test)
self.stream.writeln('[ OK ] %s' % self._GetTestURI(test))

def addError(self, test, err):
unittest.TestResult.addError(self, test, err)
self.stream.writeln('[ ERROR ] %s' % self._GetTestURI(test))
self._fails.add(self._GetTestURI(test))

def addFailure(self, test, err):
unittest.TestResult.addFailure(self, test, err)
self.stream.writeln('[ FAILED ] %s' % self._GetTestURI(test))
self._fails.add(self._GetTestURI(test))

def getRetestFilter(self):
return ':'.join(self._fails)


class TextTestRunner(unittest.TextTestRunner):
"""Test Runner for displaying test results in textual format.
Results are displayed in conformance with google test output.
"""

def __init__(self, verbosity=1):
unittest.TextTestRunner.__init__(self, stream=sys.stderr,
verbosity=verbosity)

def _makeResult(self):
return _TextTestResult(self.stream, self.descriptions, self.verbosity)


def GetTestsFromSuite(suite):
"""Returns all the tests from a given test suite."""
tests = []
for x in suite:
if isinstance(x, unittest.TestSuite):
tests += GetTestsFromSuite(x)
else:
tests += [x]
return tests


def GetTestNamesFromSuite(suite):
"""Returns a list of every test name in the given suite."""
return map(lambda x: GetTestName(x), GetTestsFromSuite(suite))


def GetTestName(test):
"""Gets the test name of the given unittest test."""
return '.'.join([test.__class__.__module__,
test.__class__.__name__,
test._testMethodName])


def FilterTestSuite(suite, gtest_filter):
"""Returns a new filtered tests suite based on the given gtest filter.
See http://code.google.com/p/googletest/wiki/AdvancedGuide
for gtest_filter specification.
"""
return unittest.TestSuite(FilterTests(GetTestsFromSuite(suite), gtest_filter))


def FilterTests(all_tests, gtest_filter):
"""Returns a filtered list of tests based on the given gtest filter.
See http://code.google.com/p/googletest/wiki/AdvancedGuide
for gtest_filter specification.
"""
pattern_groups = gtest_filter.split('-')
positive_patterns = pattern_groups[0].split(':')
negative_patterns = None
if len(pattern_groups) > 1:
negative_patterns = pattern_groups[1].split(':')

tests = []
for test in all_tests:
test_name = GetTestName(test)
# Test name must by matched by one positive pattern.
for pattern in positive_patterns:
if fnmatch.fnmatch(test_name, pattern):
break
else:
continue
# Test name must not be matched by any negative patterns.
for pattern in negative_patterns or []:
if fnmatch.fnmatch(test_name, pattern):
break
else:
tests += [test]
return tests
Loading

0 comments on commit 307ef81

Please sign in to comment.