| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Defines TestPackageApk to help run APK-based native tests.""" | 5 """Defines TestPackageApk to help run APK-based native tests.""" |
| 6 # pylint: disable=W0212 | 6 # pylint: disable=W0212 |
| 7 | 7 |
| 8 import itertools |
| 8 import logging | 9 import logging |
| 9 import os | 10 import os |
| 11 import posixpath |
| 10 import shlex | 12 import shlex |
| 11 import sys | 13 import sys |
| 12 import tempfile | 14 import tempfile |
| 13 import time | 15 import time |
| 14 | 16 |
| 15 from pylib import android_commands | 17 from pylib import android_commands |
| 16 from pylib import constants | 18 from pylib import constants |
| 17 from pylib import pexpect | 19 from pylib import pexpect |
| 18 from pylib.device import device_errors | 20 from pylib.device import device_errors |
| 19 from pylib.device import intent | 21 from pylib.device import intent |
| 20 from pylib.gtest import gtest_test_instance | 22 from pylib.gtest import gtest_test_instance |
| 23 from pylib.gtest import local_device_gtest_run |
| 21 from pylib.gtest.test_package import TestPackage | 24 from pylib.gtest.test_package import TestPackage |
| 22 | 25 |
| 23 | 26 |
| 24 class TestPackageApk(TestPackage): | 27 class TestPackageApk(TestPackage): |
| 25 """A helper class for running APK-based native tests.""" | 28 """A helper class for running APK-based native tests.""" |
| 26 | 29 |
| 27 def __init__(self, suite_name): | 30 def __init__(self, suite_name): |
| 28 """ | 31 """ |
| 29 Args: | 32 Args: |
| 30 suite_name: Name of the test suite (e.g. base_unittests). | 33 suite_name: Name of the test suite (e.g. base_unittests). |
| 31 """ | 34 """ |
| 32 TestPackage.__init__(self, suite_name) | 35 TestPackage.__init__(self, suite_name) |
| 36 self.suite_path = os.path.join( |
| 37 constants.GetOutDirectory(), '%s_apk' % suite_name, |
| 38 '%s-debug.apk' % suite_name) |
| 33 if suite_name == 'content_browsertests': | 39 if suite_name == 'content_browsertests': |
| 34 self.suite_path = os.path.join( | |
| 35 constants.GetOutDirectory(), 'apks', '%s.apk' % suite_name) | |
| 36 self._package_info = constants.PACKAGE_INFO['content_browsertests'] | 40 self._package_info = constants.PACKAGE_INFO['content_browsertests'] |
| 37 elif suite_name == 'components_browsertests': | 41 elif suite_name == 'components_browsertests': |
| 38 self.suite_path = os.path.join( | |
| 39 constants.GetOutDirectory(), 'apks', '%s.apk' % suite_name) | |
| 40 self._package_info = constants.PACKAGE_INFO['components_browsertests'] | 42 self._package_info = constants.PACKAGE_INFO['components_browsertests'] |
| 41 else: | 43 else: |
| 42 self.suite_path = os.path.join( | |
| 43 constants.GetOutDirectory(), '%s_apk' % suite_name, | |
| 44 '%s-debug.apk' % suite_name) | |
| 45 self._package_info = constants.PACKAGE_INFO['gtest'] | 44 self._package_info = constants.PACKAGE_INFO['gtest'] |
| 46 | 45 |
| 47 def _CreateCommandLineFileOnDevice(self, device, options): | 46 def _CreateCommandLineFileOnDevice(self, device, options): |
| 48 device.WriteFile(self._package_info.cmdline_file, | 47 device.WriteFile(self._package_info.cmdline_file, |
| 49 self.suite_name + ' ' + options) | 48 self.suite_name + ' ' + options) |
| 50 | 49 |
| 51 def _GetFifo(self): | 50 def _GetFifo(self): |
| 52 # The test.fifo path is determined by: | 51 # The test.fifo path is determined by: |
| 53 # testing/android/native_test/java/src/org/chromium/native_test/ | 52 # testing/android/native_test/java/src/org/chromium/native_test/ |
| 54 # NativeTestActivity.java and | 53 # NativeTestActivity.java and |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 self._StartActivity(device, force_stop=False) | 137 self._StartActivity(device, force_stop=False) |
| 139 finally: | 138 finally: |
| 140 self.tool.CleanUpEnvironment() | 139 self.tool.CleanUpEnvironment() |
| 141 logfile = android_commands.NewLineNormalizer(sys.stdout) | 140 logfile = android_commands.NewLineNormalizer(sys.stdout) |
| 142 return self._WatchFifo(device, timeout=10, logfile=logfile) | 141 return self._WatchFifo(device, timeout=10, logfile=logfile) |
| 143 | 142 |
| 144 #override | 143 #override |
| 145 def Install(self, device): | 144 def Install(self, device): |
| 146 self.tool.CopyFiles(device) | 145 self.tool.CopyFiles(device) |
| 147 device.Install(self.suite_path) | 146 device.Install(self.suite_path) |
| 147 |
| 148 #override |
| 149 def PullAppFiles(self, device, files, directory): |
| 150 local_device_gtest_run.PullAppFilesImpl( |
| 151 device, self._package_info.package, files, directory) |
| OLD | NEW |