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 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import shlex | 9 import shlex |
10 import sys | 10 import sys |
11 import tempfile | 11 import tempfile |
12 import time | 12 import time |
13 | 13 |
14 from pylib import android_commands | 14 from pylib import android_commands |
15 from pylib import constants | 15 from pylib import constants |
16 from pylib import pexpect | 16 from pylib import pexpect |
17 from pylib.android_commands import errors | 17 from pylib.android_commands import errors |
18 | 18 |
19 from test_package import TestPackage | 19 from test_package import TestPackage |
20 | 20 |
21 | 21 |
22 class TestPackageApk(TestPackage): | 22 class TestPackageApk(TestPackage): |
23 """A helper class for running APK-based native tests.""" | 23 """A helper class for running APK-based native tests.""" |
24 | 24 |
25 def __init__(self, adb, device, test_suite, tool, test_apk_package_name, | 25 def __init__(self, adb, device, suite_path_full, tool, test_apk_package_name, |
26 test_activity_name, command_line_file): | 26 test_activity_name, command_line_file): |
27 """ | 27 """ |
28 Args: | 28 Args: |
29 adb: ADB interface the tests are using. | 29 adb: ADB interface the tests are using. |
30 device: Device to run the tests. | 30 device: Device to run the tests. |
31 test_suite: A specific test suite to run, empty to run all. | 31 suite_path_full: Absolute path to a specific test suite to run, |
| 32 empty to run all. |
| 33 Ex: '/foo/bar/base_unittests-debug.apk', for which |
| 34 self.suite_path_full = '/foo/bar/base_unittests-debug.apk' |
| 35 self.suite_path = '/foo/bar/base_unittests-debug' |
| 36 self.suite_basename = 'base_unittests' |
| 37 self.suite_dirname = '/foo/bar' |
32 tool: Name of the Valgrind tool. | 38 tool: Name of the Valgrind tool. |
33 test_apk_package_name: Apk package name for tests running in APKs. | 39 test_apk_package_name: Apk package name for tests running in APKs. |
34 test_activity_name: Test activity to invoke for APK tests. | 40 test_activity_name: Test activity to invoke for APK tests. |
35 command_line_file: Filename to use to pass arguments to tests. | 41 command_line_file: Filename to use to pass arguments to tests. |
36 """ | 42 """ |
37 TestPackage.__init__(self, adb, device, test_suite, tool) | 43 TestPackage.__init__(self, adb, device, suite_path_full, tool) |
38 self._test_apk_package_name = test_apk_package_name | 44 self._test_apk_package_name = test_apk_package_name |
39 self._test_activity_name = test_activity_name | 45 self._test_activity_name = test_activity_name |
40 self._command_line_file = command_line_file | 46 self._command_line_file = command_line_file |
41 | 47 |
42 def _CreateCommandLineFileOnDevice(self, options): | 48 def _CreateCommandLineFileOnDevice(self, options): |
43 command_line_file = tempfile.NamedTemporaryFile() | 49 command_line_file = tempfile.NamedTemporaryFile() |
44 # GTest expects argv[0] to be the executable path. | 50 # GTest expects argv[0] to be the executable path. |
45 command_line_file.write(self.test_suite_basename + ' ' + options) | 51 command_line_file.write(self.suite_basename + ' ' + options) |
46 command_line_file.flush() | 52 command_line_file.flush() |
47 self.adb.PushIfNeeded(command_line_file.name, | 53 self.adb.PushIfNeeded(command_line_file.name, |
48 constants.TEST_EXECUTABLE_DIR + '/' + | 54 constants.TEST_EXECUTABLE_DIR + '/' + |
49 self._command_line_file) | 55 self._command_line_file) |
50 | 56 |
51 def _GetGTestReturnCode(self): | 57 def _GetGTestReturnCode(self): |
52 return None | 58 return None |
53 | 59 |
54 def _GetFifo(self): | 60 def _GetFifo(self): |
55 # The test.fifo path is determined by: | 61 # The test.fifo path is determined by: |
(...skipping 24 matching lines...) Expand all Loading... |
80 self._test_activity_name, | 86 self._test_activity_name, |
81 wait_for_completion=True, | 87 wait_for_completion=True, |
82 action='android.intent.action.MAIN', | 88 action='android.intent.action.MAIN', |
83 force_stop=True) | 89 force_stop=True) |
84 | 90 |
85 def _NeedsInstall(self): | 91 def _NeedsInstall(self): |
86 installed_apk_path = self.adb.GetApplicationPath( | 92 installed_apk_path = self.adb.GetApplicationPath( |
87 self._test_apk_package_name) | 93 self._test_apk_package_name) |
88 if installed_apk_path: | 94 if installed_apk_path: |
89 return not self.adb.CheckMd5Sum( | 95 return not self.adb.CheckMd5Sum( |
90 self.test_suite_full, installed_apk_path, ignore_paths=True) | 96 self.suite_path_full, installed_apk_path, ignore_paths=True) |
91 else: | 97 else: |
92 return True | 98 return True |
93 | 99 |
94 def _GetTestSuiteBaseName(self): | 100 def _GetTestSuiteBaseName(self): |
95 """Returns the base name of the test suite.""" | 101 """Returns the base name of the test suite.""" |
96 # APK test suite names end with '-debug.apk' | 102 # APK test suite names end with '-debug.apk' |
97 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] | 103 return os.path.basename(self.suite_path).rsplit('-debug', 1)[0] |
98 | 104 |
99 #override | 105 #override |
100 def ClearApplicationState(self): | 106 def ClearApplicationState(self): |
101 self.adb.ClearApplicationState(self._test_apk_package_name) | 107 self.adb.ClearApplicationState(self._test_apk_package_name) |
102 | 108 |
103 #override | 109 #override |
104 def CreateCommandLineFileOnDevice(self, test_filter, test_arguments): | 110 def CreateCommandLineFileOnDevice(self, test_filter, test_arguments): |
105 self._CreateCommandLineFileOnDevice( | 111 self._CreateCommandLineFileOnDevice( |
106 '--gtest_filter=%s %s' % (test_filter, test_arguments)) | 112 '--gtest_filter=%s %s' % (test_filter, test_arguments)) |
107 | 113 |
(...skipping 25 matching lines...) Expand all Loading... |
133 self.tool.CleanUpEnvironment() | 139 self.tool.CleanUpEnvironment() |
134 logfile = android_commands.NewLineNormalizer(sys.stdout) | 140 logfile = android_commands.NewLineNormalizer(sys.stdout) |
135 return self._WatchFifo(timeout=10, logfile=logfile) | 141 return self._WatchFifo(timeout=10, logfile=logfile) |
136 | 142 |
137 #override | 143 #override |
138 def Install(self): | 144 def Install(self): |
139 self.tool.CopyFiles() | 145 self.tool.CopyFiles() |
140 if self._NeedsInstall(): | 146 if self._NeedsInstall(): |
141 # Always uninstall the previous one (by activity name); we don't | 147 # Always uninstall the previous one (by activity name); we don't |
142 # know what was embedded in it. | 148 # know what was embedded in it. |
143 self.adb.ManagedInstall(self.test_suite_full, False, | 149 self.adb.ManagedInstall(self.suite_path_full, False, |
144 package_name=self._test_apk_package_name) | 150 package_name=self._test_apk_package_name) |
145 | |
OLD | NEW |