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 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 | 29 |
30 def __init__(self, suite_name): | 30 def __init__(self, suite_name): |
31 """ | 31 """ |
32 Args: | 32 Args: |
33 suite_name: Name of the test suite (e.g. base_unittests). | 33 suite_name: Name of the test suite (e.g. base_unittests). |
34 """ | 34 """ |
35 TestPackage.__init__(self, suite_name) | 35 TestPackage.__init__(self, suite_name) |
36 self.suite_path = os.path.join( | 36 self.suite_path = os.path.join( |
37 constants.GetOutDirectory(), '%s_apk' % suite_name, | 37 constants.GetOutDirectory(), '%s_apk' % suite_name, |
38 '%s-debug.apk' % suite_name) | 38 '%s-debug.apk' % suite_name) |
39 if suite_name == 'content_browsertests': | 39 if suite_name == 'content_browsertests': |
jbudorick
2015/06/19 15:15:19
We do some special-casing for our browser test sui
aberent
2015/06/19 17:59:39
Done. You are right, I was thinking we might have
| |
40 self._package_info = constants.PACKAGE_INFO['content_browsertests'] | 40 self._package_info = constants.PACKAGE_INFO['content_browsertests'] |
41 elif suite_name == 'components_browsertests': | 41 elif suite_name == 'components_browsertests': |
42 self._package_info = constants.PACKAGE_INFO['components_browsertests'] | 42 self._package_info = constants.PACKAGE_INFO['components_browsertests'] |
43 else: | 43 else: |
44 self._package_info = constants.PACKAGE_INFO['gtest'] | 44 self._package_info = constants.PACKAGE_INFO['gtest'] |
45 | 45 |
46 def _CreateCommandLineFileOnDevice(self, device, options): | 46 def _CreateCommandLineFileOnDevice(self, device, options): |
47 device.WriteFile(self._package_info.cmdline_file, | 47 device.WriteFile(self._package_info.cmdline_file, |
48 self.suite_name + ' ' + options) | 48 self.suite_name + ' ' + options) |
49 | 49 |
(...skipping 13 matching lines...) Expand all Loading... | |
63 logging.info('Fifo created. Slept for %f secs' % (i * 0.5)) | 63 logging.info('Fifo created. Slept for %f secs' % (i * 0.5)) |
64 break | 64 break |
65 time.sleep(0.5) | 65 time.sleep(0.5) |
66 else: | 66 else: |
67 raise device_errors.DeviceUnreachableError( | 67 raise device_errors.DeviceUnreachableError( |
68 'Unable to find fifo on device %s ' % self._GetFifo()) | 68 'Unable to find fifo on device %s ' % self._GetFifo()) |
69 args = shlex.split(device.old_interface.Adb()._target_arg) | 69 args = shlex.split(device.old_interface.Adb()._target_arg) |
70 args += ['shell', 'cat', self._GetFifo()] | 70 args += ['shell', 'cat', self._GetFifo()] |
71 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 71 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
72 | 72 |
73 def _StartActivity(self, device, force_stop=True): | 73 def _StartActivity(self, device, tests_run_in_subthread=False, |
74 force_stop=True): | |
75 if tests_run_in_subthread: | |
76 extras = {'RunInSubThread':''} | |
jbudorick
2015/06/19 15:15:19
nit: space after :
aberent
2015/06/19 17:59:40
Done.
| |
77 else: | |
78 extras = [] | |
74 device.StartActivity( | 79 device.StartActivity( |
75 intent.Intent(package=self._package_info.package, | 80 intent.Intent(package=self._package_info.package, |
76 activity=self._package_info.activity, | 81 activity=self._package_info.activity, |
77 action='android.intent.action.MAIN'), | 82 action='android.intent.action.MAIN', |
83 extras=extras), | |
78 # No wait since the runner waits for FIFO creation anyway. | 84 # No wait since the runner waits for FIFO creation anyway. |
79 blocking=False, | 85 blocking=False, |
80 force_stop=force_stop) | 86 force_stop=force_stop) |
81 | 87 |
82 #override | 88 #override |
83 def ClearApplicationState(self, device): | 89 def ClearApplicationState(self, device): |
84 device.ClearApplicationState(self._package_info.package) | 90 device.ClearApplicationState(self._package_info.package) |
85 # Content shell creates a profile on the sdscard which accumulates cache | 91 # Content shell creates a profile on the sdscard which accumulates cache |
86 # files over time. | 92 # files over time. |
87 if self.suite_name == 'content_browsertests': | 93 if self.suite_name == 'content_browsertests': |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 p = self._WatchFifo(device, timeout=30 * self.tool.GetTimeoutScale()) | 126 p = self._WatchFifo(device, timeout=30 * self.tool.GetTimeoutScale()) |
121 p.expect('<<ScopedMainEntryLogger') | 127 p.expect('<<ScopedMainEntryLogger') |
122 p.close() | 128 p.close() |
123 finally: | 129 finally: |
124 self.tool.CleanUpEnvironment() | 130 self.tool.CleanUpEnvironment() |
125 # We need to strip the trailing newline. | 131 # We need to strip the trailing newline. |
126 content = [line.rstrip() for line in p.before.splitlines()] | 132 content = [line.rstrip() for line in p.before.splitlines()] |
127 return gtest_test_instance.ParseGTestListTests(content) | 133 return gtest_test_instance.ParseGTestListTests(content) |
128 | 134 |
129 #override | 135 #override |
130 def SpawnTestProcess(self, device): | 136 def SpawnTestProcess(self, device, tests_run_in_subthread=False): |
131 try: | 137 try: |
132 self.tool.SetupEnvironment() | 138 self.tool.SetupEnvironment() |
133 self._ClearFifo(device) | 139 self._ClearFifo(device) |
134 # Doesn't need to stop an Activity because ClearApplicationState() is | 140 # Doesn't need to stop an Activity because ClearApplicationState() is |
135 # 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 |
136 # point. | 142 # point. |
137 self._StartActivity(device, force_stop=False) | 143 self._StartActivity(device, tests_run_in_subthread, force_stop=False ) |
138 finally: | 144 finally: |
139 self.tool.CleanUpEnvironment() | 145 self.tool.CleanUpEnvironment() |
140 logfile = android_commands.NewLineNormalizer(sys.stdout) | 146 logfile = android_commands.NewLineNormalizer(sys.stdout) |
141 return self._WatchFifo(device, timeout=10, logfile=logfile) | 147 return self._WatchFifo(device, timeout=10, logfile=logfile) |
142 | 148 |
143 #override | 149 #override |
144 def Install(self, device): | 150 def Install(self, device): |
145 self.tool.CopyFiles(device) | 151 self.tool.CopyFiles(device) |
146 device.Install(self.suite_path) | 152 device.Install(self.suite_path) |
147 | 153 |
148 #override | 154 #override |
149 def PullAppFiles(self, device, files, directory): | 155 def PullAppFiles(self, device, files, directory): |
150 local_device_gtest_run.PullAppFilesImpl( | 156 local_device_gtest_run.PullAppFilesImpl( |
151 device, self._package_info.package, files, directory) | 157 device, self._package_info.package, files, directory) |
OLD | NEW |