Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: build/android/pylib/gtest/test_package_apk.py

Issue 15930002: [Android] Force stop test app before launch (start -S) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit addressed Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 5
6 import logging 6 import logging
7 import os 7 import os
8 import shlex 8 import shlex
9 import sys 9 import sys
10 import tempfile 10 import tempfile
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 raise errors.DeviceUnresponsiveError( 71 raise errors.DeviceUnresponsiveError(
72 'Unable to find fifo on device %s ' % self._GetFifo()) 72 'Unable to find fifo on device %s ' % self._GetFifo())
73 args = shlex.split(self.adb.Adb()._target_arg) 73 args = shlex.split(self.adb.Adb()._target_arg)
74 args += ['shell', 'cat', self._GetFifo()] 74 args += ['shell', 'cat', self._GetFifo()]
75 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) 75 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile)
76 76
77 def ClearApplicationState(self): 77 def ClearApplicationState(self):
78 """Clear the application state.""" 78 """Clear the application state."""
79 self.adb.ClearApplicationState(self._apk_package_name) 79 self.adb.ClearApplicationState(self._apk_package_name)
80 80
81 def _StartActivity(self):
82 self.adb.StartActivity(
83 self._apk_package_name,
84 self._test_activity_name,
85 wait_for_completion=True,
86 action='android.intent.action.MAIN',
87 force_stop=True)
88
81 def GetAllTests(self): 89 def GetAllTests(self):
82 """Returns a list of all tests available in the test suite.""" 90 """Returns a list of all tests available in the test suite."""
83 self._CreateTestRunnerScript('--gtest_list_tests') 91 self._CreateTestRunnerScript('--gtest_list_tests')
84 try: 92 try:
85 self.tool.SetupEnvironment() 93 self.tool.SetupEnvironment()
86 # Clear and start monitoring logcat. 94 # Clear and start monitoring logcat.
87 self._ClearFifo() 95 self._ClearFifo()
88 self.adb.RunShellCommand( 96 self._StartActivity()
89 'am start -n ' + self._apk_package_name + '/' +
90 self._test_activity_name)
91 # Wait for native test to complete. 97 # Wait for native test to complete.
92 p = self._WatchFifo(timeout=30 * self.tool.GetTimeoutScale()) 98 p = self._WatchFifo(timeout=30 * self.tool.GetTimeoutScale())
93 p.expect("<<ScopedMainEntryLogger") 99 p.expect("<<ScopedMainEntryLogger")
94 p.close() 100 p.close()
95 finally: 101 finally:
96 self.tool.CleanUpEnvironment() 102 self.tool.CleanUpEnvironment()
97 # We need to strip the trailing newline. 103 # We need to strip the trailing newline.
98 content = [line.rstrip() for line in p.before.splitlines()] 104 content = [line.rstrip() for line in p.before.splitlines()]
99 ret = self._ParseGTestListTests(content) 105 ret = self._ParseGTestListTests(content)
100 return ret 106 return ret
101 107
102 def CreateTestRunnerScript(self, gtest_filter, test_arguments): 108 def CreateTestRunnerScript(self, gtest_filter, test_arguments):
103 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, 109 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter,
104 test_arguments)) 110 test_arguments))
105 111
106 def RunTestsAndListResults(self): 112 def RunTestsAndListResults(self):
107 try: 113 try:
108 self.tool.SetupEnvironment() 114 self.tool.SetupEnvironment()
109 self._ClearFifo() 115 self._ClearFifo()
110 self.adb.RunShellCommand( 116 self._StartActivity()
111 'am start -n ' + self._apk_package_name + '/' +
112 self._test_activity_name)
113 finally: 117 finally:
114 self.tool.CleanUpEnvironment() 118 self.tool.CleanUpEnvironment()
115 logfile = android_commands.NewLineNormalizer(sys.stdout) 119 logfile = android_commands.NewLineNormalizer(sys.stdout)
116 return self._WatchTestOutput(self._WatchFifo(timeout=10, logfile=logfile)) 120 return self._WatchTestOutput(self._WatchFifo(timeout=10, logfile=logfile))
117 121
118 def _NeedsInstall(self): 122 def _NeedsInstall(self):
119 pm_path_output = self.adb.RunShellCommand( 123 installed_apk_path = self.adb.GetApplicationPath(self._apk_package_name)
120 'pm path ' + self._apk_package_name) 124 if installed_apk_path:
121 if not pm_path_output: 125 return not self.adb.CheckMd5Sum(
126 self.test_suite_full, installed_apk_path, ignore_paths=True)
127 else:
122 return True 128 return True
123 # pm_path_output is of the form: "package:/path/to/foo.apk"
124 installed_apk_path = pm_path_output[0].split(':')[1]
125 return not self.adb.CheckMd5Sum(
126 self.test_suite_full, installed_apk_path, ignore_paths=True)
127 129
128 def StripAndCopyExecutable(self): 130 def StripAndCopyExecutable(self):
129 self.tool.CopyFiles() 131 self.tool.CopyFiles()
130 if self._NeedsInstall(): 132 if self._NeedsInstall():
131 # Always uninstall the previous one (by activity name); we don't 133 # Always uninstall the previous one (by activity name); we don't
132 # know what was embedded in it. 134 # know what was embedded in it.
133 self.adb.ManagedInstall(self.test_suite_full, False, 135 self.adb.ManagedInstall(self.test_suite_full, False,
134 package_name=self._apk_package_name) 136 package_name=self._apk_package_name)
135 137
136 def _GetTestSuiteBaseName(self): 138 def _GetTestSuiteBaseName(self):
137 """Returns the base name of the test suite.""" 139 """Returns the base name of the test suite."""
138 # APK test suite names end with '-debug.apk' 140 # APK test suite names end with '-debug.apk'
139 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] 141 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0]
OLDNEW
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698