| 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 itertools |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import posixpath | 11 import posixpath |
| 12 import shlex | 12 import shlex |
| 13 import sys | 13 import sys |
| 14 import tempfile | 14 import tempfile |
| 15 import time | 15 import time |
| 16 | 16 |
| 17 from pylib import android_commands | |
| 18 from pylib import constants | 17 from pylib import constants |
| 19 from pylib import pexpect | 18 from pylib import pexpect |
| 20 from pylib.device import device_errors | 19 from pylib.device import device_errors |
| 21 from pylib.device import intent | 20 from pylib.device import intent |
| 22 from pylib.gtest import gtest_test_instance | 21 from pylib.gtest import gtest_test_instance |
| 23 from pylib.gtest import local_device_gtest_run | 22 from pylib.gtest import local_device_gtest_run |
| 24 from pylib.gtest.test_package import TestPackage | 23 from pylib.gtest.test_package import TestPackage |
| 25 | 24 |
| 26 | 25 |
| 27 class TestPackageApk(TestPackage): | 26 class TestPackageApk(TestPackage): |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 63 |
| 65 def _WatchFifo(self, device, timeout, logfile=None): | 64 def _WatchFifo(self, device, timeout, logfile=None): |
| 66 for i in range(100): | 65 for i in range(100): |
| 67 if device.FileExists(self._GetFifo()): | 66 if device.FileExists(self._GetFifo()): |
| 68 logging.info('Fifo created. Slept for %f secs' % (i * 0.5)) | 67 logging.info('Fifo created. Slept for %f secs' % (i * 0.5)) |
| 69 break | 68 break |
| 70 time.sleep(0.5) | 69 time.sleep(0.5) |
| 71 else: | 70 else: |
| 72 raise device_errors.DeviceUnreachableError( | 71 raise device_errors.DeviceUnreachableError( |
| 73 'Unable to find fifo on device %s ' % self._GetFifo()) | 72 'Unable to find fifo on device %s ' % self._GetFifo()) |
| 74 args = shlex.split(device.old_interface.Adb()._target_arg) | 73 args = ['-s', device.adb.GetDeviceSerial(), 'shell', 'cat', self._GetFifo()] |
| 75 args += ['shell', 'cat', self._GetFifo()] | |
| 76 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 74 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
| 77 | 75 |
| 78 def _StartActivity(self, device, force_stop=True): | 76 def _StartActivity(self, device, force_stop=True): |
| 79 device.StartActivity( | 77 device.StartActivity( |
| 80 intent.Intent(package=self._package_info.package, | 78 intent.Intent(package=self._package_info.package, |
| 81 activity=self._package_info.activity, | 79 activity=self._package_info.activity, |
| 82 action='android.intent.action.MAIN', | 80 action='android.intent.action.MAIN', |
| 83 extras=self._extras), | 81 extras=self._extras), |
| 84 # No wait since the runner waits for FIFO creation anyway. | 82 # No wait since the runner waits for FIFO creation anyway. |
| 85 blocking=False, | 83 blocking=False, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 def SpawnTestProcess(self, device): | 134 def SpawnTestProcess(self, device): |
| 137 try: | 135 try: |
| 138 self.tool.SetupEnvironment() | 136 self.tool.SetupEnvironment() |
| 139 self._ClearFifo(device) | 137 self._ClearFifo(device) |
| 140 # Doesn't need to stop an Activity because ClearApplicationState() is | 138 # Doesn't need to stop an Activity because ClearApplicationState() is |
| 141 # always called before this call and so it is already stopped at this | 139 # always called before this call and so it is already stopped at this |
| 142 # point. | 140 # point. |
| 143 self._StartActivity(device, force_stop=False) | 141 self._StartActivity(device, force_stop=False) |
| 144 finally: | 142 finally: |
| 145 self.tool.CleanUpEnvironment() | 143 self.tool.CleanUpEnvironment() |
| 146 logfile = android_commands.NewLineNormalizer(sys.stdout) | 144 logfile = self._NewLineNormalizer(sys.stdout) |
| 147 return self._WatchFifo(device, timeout=10, logfile=logfile) | 145 return self._WatchFifo(device, timeout=10, logfile=logfile) |
| 148 | 146 |
| 147 class _NewLineNormalizer(object): |
| 148 def __init__(self, output): |
| 149 self._output = output |
| 150 |
| 151 def write(self, data): |
| 152 data = data.replace('\r\r\n', '\n') |
| 153 self._output.write(data) |
| 154 |
| 155 def flush(self): |
| 156 self._output.flush() |
| 157 |
| 149 #override | 158 #override |
| 150 def Install(self, device): | 159 def Install(self, device): |
| 151 self.tool.CopyFiles(device) | 160 self.tool.CopyFiles(device) |
| 152 device.Install(self.suite_path) | 161 device.Install(self.suite_path) |
| 153 | 162 |
| 154 #override | 163 #override |
| 155 def PullAppFiles(self, device, files, directory): | 164 def PullAppFiles(self, device, files, directory): |
| 156 local_device_gtest_run.PullAppFilesImpl( | 165 local_device_gtest_run.PullAppFilesImpl( |
| 157 device, self._package_info.package, files, directory) | 166 device, self._package_info.package, files, directory) |
| OLD | NEW |