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