Exemplo n.º 1
0
def Main():
    chromedriver_map = {
        'win': 'chromedriver2.dll',
        'mac': 'chromedriver2.so',
        'linux': 'libchromedriver2.so',
    }
    chromedriver = chromedriver_map[util.GetPlatformName()]
    build_dir = chrome_paths.GetBuildDir([chromedriver])
    chrome_binary = _FindChromeBinary(build_dir)
    if util.IsLinux():
        # Set LD_LIBRARY_PATH to enable successful loading of shared object files,
        # when chromedriver2.so is not a static build.
        _AppendEnvironmentPath('LD_LIBRARY_PATH',
                               os.path.join(build_dir, 'lib'))
    elif util.IsWindows():
        # For Windows bots: add ant, java(jre) and the like to system path.
        _AddToolsToSystemPathForWindows()

    # Run python test for chromedriver.
    print '@@@BUILD_STEP chromedriver2_python_tests@@@'
    cmd = [
        sys.executable,
        os.path.join(_THIS_DIR, 'test.py'),
        os.path.join(build_dir, chromedriver),
    ]
    # Set the built chrome binary.
    if chrome_binary is not None:
        cmd.append(chrome_binary)
    if util.IsMac():
        # In Mac, chromedriver2.so is a 32-bit build, so run with the 32-bit python.
        os.environ['VERSIONER_PYTHON_PREFER_32_BIT'] = 'yes'
    code1 = util.RunCommand(cmd)
    if code1 != 0:
        print '@@@STEP_FAILURE@@@'

    # Run java tests for chromedriver.
    print '@@@BUILD_STEP chromedriver2_java_tests@@@'
    cmd = [
        sys.executable,
        os.path.join(_THIS_DIR, 'run_java_tests.py'),
        '--chromedriver_path=' + os.path.join(build_dir, chromedriver),
    ]
    # Set the built chrome binary.
    if chrome_binary is not None:
        cmd.append('--chrome_path=' + chrome_binary)
    code2 = util.RunCommand(cmd)
    if code2 != 0:
        print '@@@STEP_FAILURE@@@'

    return code1 or code2
Exemplo n.º 2
0
def main():
    parser = optparse.OptionParser()
    parser.add_option(
        '',
        '--android-package',
        help='Application package name, if running tests on Android.')
    parser.add_option('-r',
                      '--revision',
                      type='string',
                      default=None,
                      help='Chromium revision')
    options, _ = parser.parse_args()

    if options.android_package:
        Download()
    else:
        if options.revision is None:
            parser.error('Must supply a --revision')

        platform = util.GetPlatformName()
        if 'linux' in platform:
            Archive(options.revision)

    cmd = [
        sys.executable,
        os.path.join(_THIS_DIR, 'run_all_tests.py'),
    ]
    if options.android_package:
        cmd.append('--android-package=' + options.android_package)

    passed = (util.RunCommand(cmd) == 0)

    if not options.android_package and passed:
        MaybeRelease(options.revision)
Exemplo n.º 3
0
def _RunAntTest(test_dir, test_class, class_path, sys_props):
    """Runs a single Ant JUnit test suite and returns the |TestResult|s.

  Args:
    test_dir: the directory to run the tests in.
    test_class: the name of the JUnit test suite class to run.
    class_path: the Java class path used when running the tests.
    sys_props: Java system properties to set when running the tests.
  """
    def _CreateBuildConfig(test_name, results_file, class_path, junit_props,
                           sys_props):
        def _SystemPropToXml(prop):
            key, value = prop.split('=')
            return '<sysproperty key="%s" value="%s"/>' % (key, value)

        return '\n'.join([
            '<project>', '  <target name="test">',
            '    <junit %s>' % ' '.join(junit_props),
            '      <formatter type="xml"/>', '      <classpath>',
            '        <pathelement location="%s"/>' % class_path,
            '      </classpath>',
            '      ' + '\n      '.join(map(_SystemPropToXml, sys_props)),
            '      <test name="%s" outfile="%s"/>' % (test_name, results_file),
            '    </junit>', '  </target>', '</project>'
        ])

    def _ProcessResults(results_path):
        doc = minidom.parse(results_path)
        tests = []
        for test in doc.getElementsByTagName('testcase'):
            name = test.getAttribute('classname') + '.' + test.getAttribute(
                'name')
            time = test.getAttribute('time')
            failure = None
            error_nodes = test.getElementsByTagName('error')
            failure_nodes = test.getElementsByTagName('failure')
            if len(error_nodes) > 0:
                failure = error_nodes[0].childNodes[0].nodeValue
            elif len(failure_nodes) > 0:
                failure = failure_nodes[0].childNodes[0].nodeValue
            tests += [TestResult(name, time, failure)]
        return tests

    junit_props = [
        'printsummary="yes"', 'fork="yes"', 'haltonfailure="no"',
        'haltonerror="no"'
    ]

    ant_file = open(os.path.join(test_dir, 'build.xml'), 'w')
    ant_file.write(
        _CreateBuildConfig(test_class, 'results', class_path, junit_props,
                           sys_props))
    ant_file.close()

    util.RunCommand(['ant', 'test'], cwd=test_dir)
    return _ProcessResults(os.path.join(test_dir, 'results.xml'))
Exemplo n.º 4
0
def RunJavaTests(chromedriver, chrome):
  print '@@@BUILD_STEP chromedriver2_java_tests@@@'
  cmd = [
    sys.executable,
    os.path.join(_THIS_DIR, 'run_java_tests.py'),
    '--chromedriver=' + chromedriver,
    '--chrome=' + chrome,
  ]
  code = util.RunCommand(cmd)
  if code:
    print '@@@STEP_FAILURE@@@'
  return code
def KillChromes():
    chrome_map = {
        'win': 'chrome.exe',
        'mac': 'Chromium',
        'linux': 'chrome',
    }
    if util.IsWindows():
        cmd = ['taskkill', '/F', '/IM']
    else:
        cmd = ['killall', '-9']
    cmd.append(chrome_map[util.GetPlatformName()])
    util.RunCommand(cmd)
Exemplo n.º 6
0
def RunJavaTests(chromedriver,
                 chrome=None,
                 chrome_version=None,
                 android_package=None):
    version_info = ''
    if chrome_version:
        version_info = '(v%s)' % chrome_version
    print '@@@BUILD_STEP chromedriver2_java_tests%s@@@' % version_info
    code = util.RunCommand(
        _GenerateTestCommand('run_java_tests.py', chromedriver, chrome,
                             chrome_version, android_package))
    if code:
        print '@@@STEP_FAILURE@@@'
    return code
Exemplo n.º 7
0
def MaybeRelease(revision):
  # Version is embedded as: const char kChromeDriverVersion[] = "0.1";
  with open(os.path.join(_THIS_DIR, 'version.cc'), 'r') as f:
    version_line = filter(lambda x: 'kChromeDriverVersion' in x, f.readlines())
  version = version_line[0].split('"')[1]

  # This assumes the bitness of python is the same as the built ChromeDriver.
  bitness = '32'
  if sys.maxint > 2**32:
    bitness = '64'
  zip_name = 'experimental_chromedriver2_%s%s_%s.zip' % (
      util.GetPlatformName(), bitness, version)

  site = 'https://code.google.com/p/chromedriver/downloads/list'
  s = urllib2.urlopen(site)
  downloads = s.read()
  s.close()

  if zip_name in downloads:
    return 0

  print '@@@BUILD_STEP releasing %s@@@' % zip_name
  if util.IsWindows():
    server_orig_name = 'chromedriver2_server.exe'
    server_name = 'chromedriver.exe'
  else:
    server_orig_name = 'chromedriver2_server'
    server_name = 'chromedriver'
  server = os.path.join(chrome_paths.GetBuildDir([server_orig_name]),
                        server_orig_name)

  print 'Zipping ChromeDriver server', server
  temp_dir = util.MakeTempDir()
  zip_path = os.path.join(temp_dir, zip_name)
  f = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
  f.write(server, server_name)
  f.close()

  cmd = [
    sys.executable,
    os.path.join(_THIS_DIR, 'third_party', 'googlecode',
                 'googlecode_upload.py'),
    '--summary', 'alpha version of ChromeDriver2 r%s' % revision,
    '--project', 'chromedriver',
    '--user', '*****@*****.**',
    '--label', 'Release-Alpha',
    zip_path
  ]
  if util.RunCommand(cmd):
    print '@@@STEP_FAILURE@@@'
Exemplo n.º 8
0
def RunPythonTests(chromedriver, chrome):
  print '@@@BUILD_STEP chromedriver2_python_tests@@@'
  cmd = [
    sys.executable,
    os.path.join(_THIS_DIR, 'run_py_tests.py'),
    '--chromedriver=' + chromedriver,
    '--chrome=' + chrome,
  ]
  if util.IsMac():
    # In Mac, chromedriver2.so is a 32-bit build, so run with the 32-bit python.
    os.environ['VERSIONER_PYTHON_PREFER_32_BIT'] = 'yes'
  code = util.RunCommand(cmd)
  if code:
    print '@@@STEP_FAILURE@@@'
  return code
Exemplo n.º 9
0
def RunPythonTests(chromedriver,
                   chrome=None,
                   chrome_version=None,
                   android_package=None):
    version_info = ''
    if chrome_version:
        version_info = '(v%s)' % chrome_version
    print '@@@BUILD_STEP chromedriver2_python_tests%s@@@' % version_info
    if util.IsMac():
        # In Mac, chromedriver2.so is a 32-bit build, so run with the 32-bit python.
        os.environ['VERSIONER_PYTHON_PREFER_32_BIT'] = 'yes'
    code = util.RunCommand(
        _GenerateTestCommand('run_py_tests.py', chromedriver, chrome,
                             chrome_version, android_package))
    if code:
        print '\n@@@STEP_FAILURE@@@'
    return code
Exemplo n.º 10
0
def Main():
  print '@@@BUILD_STEP chromedriver2_tests@@@'
  chromedriver_map = {
    'win': 'chromedriver2.dll',
    'mac': 'chromedriver2.so',
    'linux': 'libchromedriver2.so',
  }
  chromedriver = chromedriver_map[util.GetPlatformName()]
  build_dir = chrome_paths.GetBuildDir([chromedriver])
  cmd = [
    sys.executable,
    os.path.join(_THIS_DIR, 'test.py'),
    os.path.join(build_dir, chromedriver),
  ]
  code = util.RunCommand(cmd)
  if code != 0:
    print '@@@STEP_FAILURE@@@'
  return code
Exemplo n.º 11
0
def main():
  parser = optparse.OptionParser()
  parser.add_option(
      '-r', '--revision', type='string', default=None,
      help='Chromium revision')
  options, _ = parser.parse_args()
  if options.revision is None:
    parser.error('Must supply a --revision')

  platform = util.GetPlatformName()
  if 'linux' in platform:
    Archive(options.revision)
  cmd = [
    sys.executable,
    os.path.join(_THIS_DIR, 'run_all_tests.py'),
  ]
  passed = (util.RunCommand(cmd) == 0)
  if passed:
    MaybeRelease(options.revision)
Exemplo n.º 12
0
def Download():
    print '@@@BUILD_STEP Download chromedriver prebuilts@@@'

    temp_dir = util.MakeTempDir()
    zip_path = os.path.join(temp_dir, 'chromedriver2_prebuilts.zip')
    cmd = [
        sys.executable, DOWNLOAD_SCRIPT,
        '--url=%s' % GS_BUCKET,
        '--partial-name=%s' % GS_ZIP_PREFIX,
        '--dst=%s' % zip_path
    ]
    if util.RunCommand(cmd):
        print '@@@STEP_FAILURE@@@'

    build_dir = chrome_paths.GetBuildDir(['host_forwarder'])
    print 'Unzipping prebuilts %s to %s' % (zip_path, build_dir)
    f = zipfile.ZipFile(zip_path, 'r')
    f.extractall(build_dir)
    f.close()
    # Workaround for Python bug: http://bugs.python.org/issue15795
    os.chmod(os.path.join(build_dir, 'chromedriver2_server'), 0700)
Exemplo n.º 13
0
def Archive(revision):
  print '@@@BUILD_STEP archive@@@'
  prebuilts = ['libchromedriver2.so', 'chromedriver2_server',
               'chromedriver2_unittests', 'chromedriver2_tests']
  build_dir = chrome_paths.GetBuildDir(prebuilts[0:1])
  zip_name = '%s_r%s.zip' % (GS_ZIP_PREFIX, revision)
  temp_dir = util.MakeTempDir()
  zip_path = os.path.join(temp_dir, zip_name)
  print 'Zipping prebuilts %s' % zip_path
  f = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
  for prebuilt in prebuilts:
    f.write(os.path.join(build_dir, prebuilt), prebuilt)
  f.close()

  cmd = [
    sys.executable,
    UPLOAD_SCRIPT,
    '--source_filepath=%s' % zip_path,
    '--dest_gsbase=%s' % GS_BUCKET
  ]
  if util.RunCommand(cmd):
    print '@@@STEP_FAILURE@@@'
Exemplo n.º 14
0
def Archive(revision):
  print '@@@BUILD_STEP archive@@@'
  prebuilts = ['libchromedriver2.so', 'chromedriver2_server',
               'chromedriver2_unittests', 'chromedriver2_tests']
  build_dir = chrome_paths.GetBuildDir(prebuilts[0:1])
  zip_name = 'chromedriver2_prebuilts_r%s.zip' % revision
  temp_dir = util.MakeTempDir()
  zip_path = os.path.join(temp_dir, zip_name)
  print 'Zipping prebuilts %s' % zip_path
  f = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
  for prebuilt in prebuilts:
    f.write(os.path.join(build_dir, prebuilt), prebuilt)
  f.close()

  gs_bucket = 'gs://chromedriver-prebuilts'
  cmd = [
    sys.executable,
    '../../../scripts/slave/skia/upload_to_bucket.py',
    '--source_filepath=%s' % zip_path,
    '--dest_gsbase=%s' % gs_bucket
  ]
  if util.RunCommand(cmd):
    print '@@@STEP_FAILURE@@@'
Exemplo n.º 15
0
def RunCppTests(cpp_tests):
    print '@@@BUILD_STEP chromedriver2_tests@@@'
    code = util.RunCommand([cpp_tests])
    if code:
        print '@@@STEP_FAILURE@@@'
    return code
Exemplo n.º 16
0
def _RunAntTest(test_dir, test_class, class_path, sys_props, jvm_args, verbose):
  """Runs a single Ant JUnit test suite and returns the |TestResult|s.

  Args:
    test_dir: the directory to run the tests in.
    test_class: the name of the JUnit test suite class to run.
    class_path: the Java class path used when running the tests, colon delimited
    sys_props: Java system properties to set when running the tests.
    jvm_args: Java VM command line args to use.
    verbose: whether the output should be verbose.

  Returns:
    A list of |TestResult|s.
  """
  def _CreateBuildConfig(test_name, results_file, class_path, junit_props,
                         sys_props, jvm_args):
    def _SystemPropToXml(prop):
      key, value = prop.split('=')
      return '<sysproperty key="%s" value="%s"/>' % (key, value)
    def _JvmArgToXml(arg):
      return '<jvmarg value="%s"/>' % arg
    return '\n'.join([
        '<project>',
        '  <target name="test">',
        '    <junit %s>' % ' '.join(junit_props),
        '      <formatter type="xml"/>',
        '      <classpath>',
        '        <pathelement path="%s"/>' % class_path,
        '      </classpath>',
        '      ' + '\n      '.join(map(_SystemPropToXml, sys_props)),
        '      ' + '\n      '.join(map(_JvmArgToXml, jvm_args)),
        '      <test name="%s" outfile="%s"/>' % (test_name, results_file),
        '    </junit>',
        '  </target>',
        '</project>'])

  def _ProcessResults(results_path):
    doc = minidom.parse(results_path)
    tests = []
    for test in doc.getElementsByTagName('testcase'):
      name = test.getAttribute('classname') + '.' + test.getAttribute('name')
      time = test.getAttribute('time')
      failure = None
      error_nodes = test.getElementsByTagName('error')
      failure_nodes = test.getElementsByTagName('failure')
      if error_nodes:
        failure = error_nodes[0].childNodes[0].nodeValue
      elif failure_nodes:
        failure = failure_nodes[0].childNodes[0].nodeValue
      tests += [TestResult(name, time, failure)]
    return tests

  junit_props = ['printsummary="yes"',
                 'fork="yes"',
                 'haltonfailure="no"',
                 'haltonerror="no"']
  if verbose:
    junit_props += ['showoutput="yes"']

  ant_file = open(os.path.join(test_dir, 'build.xml'), 'w')
  ant_file.write(_CreateBuildConfig(
      test_class, 'results', class_path, junit_props, sys_props, jvm_args))
  ant_file.close()

  if util.IsWindows():
    ant_name = 'ant.bat'
  else:
    ant_name = 'ant'
  code = util.RunCommand([ant_name, 'test'], cwd=test_dir)
  if code != 0:
    print 'FAILED to run java tests of %s through ant' % test_class
    return
  return _ProcessResults(os.path.join(test_dir, 'results.xml'))