| 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 logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import shlex | 10 import shlex |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 self.suite_path = os.path.join( | 37 self.suite_path = os.path.join( |
| 38 constants.GetOutDirectory(), '%s_apk' % suite_name, | 38 constants.GetOutDirectory(), '%s_apk' % suite_name, |
| 39 '%s-debug.apk' % suite_name) | 39 '%s-debug.apk' % suite_name) |
| 40 self._package_info = constants.PACKAGE_INFO['gtest'] | 40 self._package_info = constants.PACKAGE_INFO['gtest'] |
| 41 | 41 |
| 42 def _CreateCommandLineFileOnDevice(self, device, options): | 42 def _CreateCommandLineFileOnDevice(self, device, options): |
| 43 command_line_file = tempfile.NamedTemporaryFile() | 43 command_line_file = tempfile.NamedTemporaryFile() |
| 44 # GTest expects argv[0] to be the executable path. | 44 # GTest expects argv[0] to be the executable path. |
| 45 command_line_file.write(self.suite_name + ' ' + options) | 45 command_line_file.write(self.suite_name + ' ' + options) |
| 46 command_line_file.flush() | 46 command_line_file.flush() |
| 47 device.old_interface.PushIfNeeded( | 47 device.PushChangedFiles( |
| 48 command_line_file.name, | 48 command_line_file.name, |
| 49 self._package_info.cmdline_file) | 49 self._package_info.cmdline_file) |
| 50 | 50 |
| 51 def _GetFifo(self): | 51 def _GetFifo(self): |
| 52 # The test.fifo path is determined by: | 52 # The test.fifo path is determined by: |
| 53 # testing/android/java/src/org/chromium/native_test/ | 53 # testing/android/java/src/org/chromium/native_test/ |
| 54 # ChromeNativeTestActivity.java and | 54 # ChromeNativeTestActivity.java and |
| 55 # testing/android/native_test_launcher.cc | 55 # testing/android/native_test_launcher.cc |
| 56 return '/data/data/' + self._package_info.package + '/files/test.fifo' | 56 return '/data/data/' + self._package_info.package + '/files/test.fifo' |
| 57 | 57 |
| 58 def _ClearFifo(self, device): | 58 def _ClearFifo(self, device): |
| 59 device.RunShellCommand('rm -f ' + self._GetFifo()) | 59 device.RunShellCommand('rm -f ' + self._GetFifo()) |
| 60 | 60 |
| 61 def _WatchFifo(self, device, timeout, logfile=None): | 61 def _WatchFifo(self, device, timeout, logfile=None): |
| 62 for i in range(10): | 62 for i in range(10): |
| 63 if device.old_interface.FileExistsOnDevice(self._GetFifo()): | 63 if device.FileExists(self._GetFifo()): |
| 64 logging.info('Fifo created.') | 64 logging.info('Fifo created.') |
| 65 break | 65 break |
| 66 time.sleep(i) | 66 time.sleep(i) |
| 67 else: | 67 else: |
| 68 raise device_errors.DeviceUnreachableError( | 68 raise device_errors.DeviceUnreachableError( |
| 69 'Unable to find fifo on device %s ' % self._GetFifo()) | 69 'Unable to find fifo on device %s ' % self._GetFifo()) |
| 70 args = shlex.split(device.old_interface.Adb()._target_arg) | 70 args = shlex.split(device.old_interface.Adb()._target_arg) |
| 71 args += ['shell', 'cat', self._GetFifo()] | 71 args += ['shell', 'cat', self._GetFifo()] |
| 72 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 72 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
| 73 | 73 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 self._StartActivity(device) | 126 self._StartActivity(device) |
| 127 finally: | 127 finally: |
| 128 self.tool.CleanUpEnvironment() | 128 self.tool.CleanUpEnvironment() |
| 129 logfile = android_commands.NewLineNormalizer(sys.stdout) | 129 logfile = android_commands.NewLineNormalizer(sys.stdout) |
| 130 return self._WatchFifo(device, timeout=10, logfile=logfile) | 130 return self._WatchFifo(device, timeout=10, logfile=logfile) |
| 131 | 131 |
| 132 #override | 132 #override |
| 133 def Install(self, device): | 133 def Install(self, device): |
| 134 self.tool.CopyFiles() | 134 self.tool.CopyFiles() |
| 135 device.Install(self.suite_path) | 135 device.Install(self.suite_path) |
| OLD | NEW |