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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 # The test.fifo path is determined by: | 48 # The test.fifo path is determined by: |
49 # testing/android/java/src/org/chromium/native_test/ | 49 # testing/android/java/src/org/chromium/native_test/ |
50 # ChromeNativeTestActivity.java and | 50 # ChromeNativeTestActivity.java and |
51 # testing/android/native_test_launcher.cc | 51 # testing/android/native_test_launcher.cc |
52 return '/data/data/' + self._package_info.package + '/files/test.fifo' | 52 return '/data/data/' + self._package_info.package + '/files/test.fifo' |
53 | 53 |
54 def _ClearFifo(self, device): | 54 def _ClearFifo(self, device): |
55 device.RunShellCommand('rm -f ' + self._GetFifo()) | 55 device.RunShellCommand('rm -f ' + self._GetFifo()) |
56 | 56 |
57 def _WatchFifo(self, device, timeout, logfile=None): | 57 def _WatchFifo(self, device, timeout, logfile=None): |
58 for i in range(10): | 58 for i in range(110): |
jbudorick
2015/01/16 14:21:41
110...?
Jaekyun Seok (inactive)
2015/01/18 23:01:18
I just wanted to keep the total possible sleep tim
jbudorick
2015/01/20 14:11:23
Just make it 100.
Jaekyun Seok (inactive)
2015/01/20 22:00:23
I will do that.
| |
59 if device.FileExists(self._GetFifo()): | 59 if device.FileExists(self._GetFifo()): |
60 logging.info('Fifo created.') | 60 logging.info('Fifo created. Slept for %f secs' % (i * 0.5)) |
61 break | 61 break |
62 time.sleep(i) | 62 time.sleep(0.5) |
63 else: | 63 else: |
64 raise device_errors.DeviceUnreachableError( | 64 raise device_errors.DeviceUnreachableError( |
65 'Unable to find fifo on device %s ' % self._GetFifo()) | 65 'Unable to find fifo on device %s ' % self._GetFifo()) |
66 args = shlex.split(device.old_interface.Adb()._target_arg) | 66 args = shlex.split(device.old_interface.Adb()._target_arg) |
67 args += ['shell', 'cat', self._GetFifo()] | 67 args += ['shell', 'cat', self._GetFifo()] |
68 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 68 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
69 | 69 |
70 def _StartActivity(self, device): | 70 def _StartActivity(self, device, force_stop=True): |
71 device.StartActivity( | 71 device.StartActivity( |
72 intent.Intent(package=self._package_info.package, | 72 intent.Intent(package=self._package_info.package, |
73 activity=self._package_info.activity, | 73 activity=self._package_info.activity, |
74 action='android.intent.action.MAIN'), | 74 action='android.intent.action.MAIN'), |
75 # No wait since the runner waits for FIFO creation anyway. | 75 # No wait since the runner waits for FIFO creation anyway. |
76 blocking=False, | 76 blocking=False, |
77 force_stop=True) | 77 force_stop=force_stop) |
78 | 78 |
79 #override | 79 #override |
80 def ClearApplicationState(self, device): | 80 def ClearApplicationState(self, device): |
81 device.ClearApplicationState(self._package_info.package) | 81 # The package always exists at this point. |
82 device.ClearApplicationState(self._package_info.package, | |
83 package_check_needed=False) | |
82 # Content shell creates a profile on the sdscard which accumulates cache | 84 # Content shell creates a profile on the sdscard which accumulates cache |
83 # files over time. | 85 # files over time. |
84 if self.suite_name == 'content_browsertests': | 86 if self.suite_name == 'content_browsertests': |
85 try: | 87 try: |
86 device.RunShellCommand( | 88 device.RunShellCommand( |
87 'rm -r %s/content_shell' % device.GetExternalStoragePath(), | 89 'rm -r %s/content_shell' % device.GetExternalStoragePath(), |
88 timeout=60 * 2) | 90 timeout=60 * 2) |
89 except device_errors.CommandFailedError: | 91 except device_errors.CommandFailedError: |
90 # TODO(jbudorick) Handle this exception appropriately once the | 92 # TODO(jbudorick) Handle this exception appropriately once the |
91 # conversions are done. | 93 # conversions are done. |
(...skipping 20 matching lines...) Expand all Loading... | |
112 self.tool.CleanUpEnvironment() | 114 self.tool.CleanUpEnvironment() |
113 # We need to strip the trailing newline. | 115 # We need to strip the trailing newline. |
114 content = [line.rstrip() for line in p.before.splitlines()] | 116 content = [line.rstrip() for line in p.before.splitlines()] |
115 return gtest_test_instance.ParseGTestListTests(content) | 117 return gtest_test_instance.ParseGTestListTests(content) |
116 | 118 |
117 #override | 119 #override |
118 def SpawnTestProcess(self, device): | 120 def SpawnTestProcess(self, device): |
119 try: | 121 try: |
120 self.tool.SetupEnvironment() | 122 self.tool.SetupEnvironment() |
121 self._ClearFifo(device) | 123 self._ClearFifo(device) |
122 self._StartActivity(device) | 124 # Doesn't need to stop an Activity because ClearApplicationState() is |
125 # always called before this call and so it is already stopped at this | |
126 # point. | |
127 self._StartActivity(device, force_stop=False) | |
123 finally: | 128 finally: |
124 self.tool.CleanUpEnvironment() | 129 self.tool.CleanUpEnvironment() |
125 logfile = android_commands.NewLineNormalizer(sys.stdout) | 130 logfile = android_commands.NewLineNormalizer(sys.stdout) |
126 return self._WatchFifo(device, timeout=10, logfile=logfile) | 131 return self._WatchFifo(device, timeout=10, logfile=logfile) |
127 | 132 |
128 #override | 133 #override |
129 def Install(self, device): | 134 def Install(self, device): |
130 self.tool.CopyFiles(device) | 135 self.tool.CopyFiles(device) |
131 device.Install(self.suite_path) | 136 device.Install(self.suite_path) |
OLD | NEW |