Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / build / android / pylib / gtest / setup.py
index e89846e..3206bda 100644 (file)
@@ -5,21 +5,20 @@
 """Generates test runner factory and tests for GTests."""
 # pylint: disable=W0212
 
-import fnmatch
-import glob
 import logging
 import os
-import shutil
 import sys
 
-from pylib import cmd_helper
 from pylib import constants
+from pylib import valgrind_tools
 
 from pylib.base import base_test_result
 from pylib.base import test_dispatcher
+from pylib.device import device_utils
 from pylib.gtest import test_package_apk
 from pylib.gtest import test_package_exe
 from pylib.gtest import test_runner
+from pylib.utils import isolator
 
 sys.path.insert(0,
                 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib',
@@ -39,35 +38,14 @@ _ISOLATE_FILE_PATHS = {
     'media_perftests': 'media/media_perftests.isolate',
     'media_unittests': 'media/media_unittests.isolate',
     'net_unittests': 'net/net_unittests.isolate',
-    'ui_unittests': 'ui/ui_unittests.isolate',
+    'sql_unittests': 'sql/sql_unittests.isolate',
+    'ui_base_unittests': 'ui/base/ui_base_tests.isolate',
+    'ui_unittests': 'ui/base/ui_base_tests.isolate',
     'unit_tests': 'chrome/unit_tests.isolate',
     'webkit_unit_tests':
       'third_party/WebKit/Source/web/WebKitUnitTests.isolate',
 }
 
-# Paths relative to third_party/webrtc/ (kept separate for readability).
-_WEBRTC_ISOLATE_FILE_PATHS = {
-    'audio_decoder_unittests':
-      'modules/audio_coding/neteq/audio_decoder_unittests.isolate',
-    'common_audio_unittests': 'common_audio/common_audio_unittests.isolate',
-    'common_video_unittests': 'common_video/common_video_unittests.isolate',
-    'modules_tests': 'modules/modules_tests.isolate',
-    'modules_unittests': 'modules/modules_unittests.isolate',
-    'system_wrappers_unittests':
-      'system_wrappers/source/system_wrappers_unittests.isolate',
-    'test_support_unittests': 'test/test_support_unittests.isolate',
-    'tools_unittests': 'tools/tools_unittests.isolate',
-    'video_engine_tests': 'video_engine_tests.isolate',
-    'video_engine_core_unittests':
-      'video_engine/video_engine_core_unittests.isolate',
-    'voice_engine_unittests': 'voice_engine/voice_engine_unittests.isolate',
-    'webrtc_perf_tests': 'webrtc_perf_tests.isolate',
-}
-
-# Append the WebRTC tests with the full path from Chromium's src/ root.
-for webrtc_test, isolate_path in _WEBRTC_ISOLATE_FILE_PATHS.items():
-  _ISOLATE_FILE_PATHS[webrtc_test] = 'third_party/webrtc/%s' % isolate_path
-
 # Used for filtering large data deps at a finer grain than what's allowed in
 # isolate files since pushing deps to devices is expensive.
 # Wildcards are allowed.
@@ -90,9 +68,6 @@ _DEPS_EXCLUSION_LIST = [
     'webkit/data/ico_decoder',
 ]
 
-_ISOLATE_SCRIPT = os.path.join(
-    constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client', 'isolate.py')
-
 
 def _GenerateDepsDirUsingIsolate(suite_name, isolate_file_path=None):
   """Generate the dependency dir for the test suite using isolate.
@@ -102,9 +77,6 @@ def _GenerateDepsDirUsingIsolate(suite_name, isolate_file_path=None):
     isolate_file_path: .isolate file path to use. If there is a default .isolate
                        file path for the suite_name, this will override it.
   """
-  if os.path.isdir(constants.ISOLATE_DEPS_DIR):
-    shutil.rmtree(constants.ISOLATE_DEPS_DIR)
-
   if isolate_file_path:
     if os.path.isabs(isolate_file_path):
       isolate_abs_path = isolate_file_path
@@ -120,77 +92,18 @@ def _GenerateDepsDirUsingIsolate(suite_name, isolate_file_path=None):
 
   isolated_abs_path = os.path.join(
       constants.GetOutDirectory(), '%s.isolated' % suite_name)
-  assert os.path.exists(isolate_abs_path)
-  # This needs to be kept in sync with the cmd line options for isolate.py
-  # in src/build/isolate.gypi.
-  isolate_cmd = [
-      'python', _ISOLATE_SCRIPT,
-      'remap',
-      '--isolate', isolate_abs_path,
-      '--isolated', isolated_abs_path,
-      '--outdir', constants.ISOLATE_DEPS_DIR,
-
-      '--path-variable', 'DEPTH', constants.DIR_SOURCE_ROOT,
-      '--path-variable', 'PRODUCT_DIR', constants.GetOutDirectory(),
-
-      '--config-variable', 'OS', 'android',
-      '--config-variable', 'chromeos', '0',
-      '--config-variable', 'component', 'static_library',
-      '--config-variable', 'icu_use_data_file_flag', '1',
-      '--config-variable', 'use_openssl', '0',
-  ]
-  assert not cmd_helper.RunCmd(isolate_cmd)
+  assert os.path.exists(isolate_abs_path), 'Cannot find %s' % isolate_abs_path
 
+  i = isolator.Isolator(constants.ISOLATE_DEPS_DIR)
+  i.Clear()
+  i.Remap(isolate_abs_path, isolated_abs_path)
   # We're relying on the fact that timestamps are preserved
   # by the remap command (hardlinked). Otherwise, all the data
   # will be pushed to the device once we move to using time diff
   # instead of md5sum. Perform a sanity check here.
-  for root, _, filenames in os.walk(constants.ISOLATE_DEPS_DIR):
-    if filenames:
-      linked_file = os.path.join(root, filenames[0])
-      orig_file = os.path.join(
-          constants.DIR_SOURCE_ROOT,
-          os.path.relpath(linked_file, constants.ISOLATE_DEPS_DIR))
-      if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino:
-        break
-      else:
-        raise Exception('isolate remap command did not use hardlinks.')
-
-  # Delete excluded files as defined by _DEPS_EXCLUSION_LIST.
-  old_cwd = os.getcwd()
-  try:
-    os.chdir(constants.ISOLATE_DEPS_DIR)
-    excluded_paths = [x for y in _DEPS_EXCLUSION_LIST for x in glob.glob(y)]
-    if excluded_paths:
-      logging.info('Excluding the following from dependency list: %s',
-                   excluded_paths)
-    for p in excluded_paths:
-      if os.path.isdir(p):
-        shutil.rmtree(p)
-      else:
-        os.remove(p)
-  finally:
-    os.chdir(old_cwd)
-
-  # On Android, all pak files need to be in the top-level 'paks' directory.
-  paks_dir = os.path.join(constants.ISOLATE_DEPS_DIR, 'paks')
-  os.mkdir(paks_dir)
-
-  deps_out_dir = os.path.join(
-      constants.ISOLATE_DEPS_DIR,
-      os.path.relpath(os.path.join(constants.GetOutDirectory(), os.pardir),
-                      constants.DIR_SOURCE_ROOT))
-  for root, _, filenames in os.walk(deps_out_dir):
-    for filename in fnmatch.filter(filenames, '*.pak'):
-      shutil.move(os.path.join(root, filename), paks_dir)
-
-  # Move everything in PRODUCT_DIR to top level.
-  deps_product_dir = os.path.join(deps_out_dir, constants.GetBuildType())
-  if os.path.isdir(deps_product_dir):
-    for p in os.listdir(deps_product_dir):
-      shutil.move(os.path.join(deps_product_dir, p), constants.ISOLATE_DEPS_DIR)
-    os.rmdir(deps_product_dir)
-    os.rmdir(deps_out_dir)
+  i.VerifyHardlinks()
+  i.PurgeExcluded(_DEPS_EXCLUSION_LIST)
+  i.MoveOutputDeps()
 
 
 def _GetDisabledTestsFilterFromFile(suite_name):
@@ -230,11 +143,16 @@ def _GetTests(test_options, test_package, devices):
   Returns:
     A list of all the tests in the test suite.
   """
+  class TestListResult(base_test_result.BaseTestResult):
+    def __init__(self):
+      super(TestListResult, self).__init__(
+          'gtest_list_tests', base_test_result.ResultType.PASS)
+      self.test_list = []
+
   def TestListerRunnerFactory(device, _shard_index):
     class TestListerRunner(test_runner.TestRunner):
       def RunTest(self, _test):
-        result = base_test_result.BaseTestResult(
-            'gtest_list_tests', base_test_result.ResultType.PASS)
+        result = TestListResult()
         self.test_package.Install(self.device)
         result.test_list = self.test_package.GetAllTests(self.device)
         results = base_test_result.TestRunResults()
@@ -301,6 +219,19 @@ def _FilterDisabledTests(tests, suite_name, has_gtest_filter):
   return tests
 
 
+def PushDataDeps(device, test_options, test_package):
+  valgrind_tools.PushFilesForTool(test_options.tool, device)
+  if os.path.exists(constants.ISOLATE_DEPS_DIR):
+    device_dir = (
+        constants.TEST_EXECUTABLE_DIR
+        if test_package.suite_name == 'breakpad_unittests'
+        else device.GetExternalStoragePath())
+    device.PushChangedFiles([
+        (os.path.join(constants.ISOLATE_DEPS_DIR, p),
+         '%s/%s' % (device_dir, p))
+        for p in os.listdir(constants.ISOLATE_DEPS_DIR)])
+
+
 def Setup(test_options, devices):
   """Create the test runner factory and tests.
 
@@ -313,17 +244,24 @@ def Setup(test_options, devices):
   """
   test_package = test_package_apk.TestPackageApk(test_options.suite_name)
   if not os.path.exists(test_package.suite_path):
-    test_package = test_package_exe.TestPackageExecutable(
+    exe_test_package = test_package_exe.TestPackageExecutable(
         test_options.suite_name)
-    if not os.path.exists(test_package.suite_path):
+    if not os.path.exists(exe_test_package.suite_path):
       raise Exception(
-          'Did not find %s target. Ensure it has been built.'
-          % test_options.suite_name)
+          'Did not find %s target. Ensure it has been built.\n'
+          '(not found at %s or %s)'
+          % (test_options.suite_name,
+             test_package.suite_path,
+             exe_test_package.suite_path))
+    test_package = exe_test_package
   logging.warning('Found target %s', test_package.suite_path)
 
   _GenerateDepsDirUsingIsolate(test_options.suite_name,
                                test_options.isolate_file_path)
 
+  device_utils.DeviceUtils.parallel(devices).pMap(
+      PushDataDeps, test_options, test_package)
+
   tests = _GetTests(test_options, test_package, devices)
 
   # Constructs a new TestRunner with the current options.