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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 """ | 27 """ |
28 Args: | 28 Args: |
29 suite_name: Name of the test suite (e.g. base_unittests). | 29 suite_name: Name of the test suite (e.g. base_unittests). |
30 """ | 30 """ |
31 TestPackage.__init__(self, suite_name) | 31 TestPackage.__init__(self, suite_name) |
32 product_dir = os.path.join(cmd_helper.OutDirectory.get(), | 32 product_dir = os.path.join(cmd_helper.OutDirectory.get(), |
33 constants.GetBuildType()) | 33 constants.GetBuildType()) |
34 if suite_name == 'content_browsertests': | 34 if suite_name == 'content_browsertests': |
35 self.suite_path = os.path.join( | 35 self.suite_path = os.path.join( |
36 product_dir, 'apks', '%s.apk' % suite_name) | 36 product_dir, 'apks', '%s.apk' % suite_name) |
37 self._test_apk_package_name = constants.BROWSERTEST_TEST_PACKAGE_NAME | 37 self._package_info = constants.PACKAGE_INFO['content_browsertests'] |
38 self._test_activity_name = constants.BROWSERTEST_TEST_ACTIVITY_NAME | |
39 self._command_line_file = constants.BROWSERTEST_COMMAND_LINE_FILE | |
40 else: | 38 else: |
41 self.suite_path = os.path.join( | 39 self.suite_path = os.path.join( |
42 product_dir, '%s_apk' % suite_name, '%s-debug.apk' % suite_name) | 40 product_dir, '%s_apk' % suite_name, '%s-debug.apk' % suite_name) |
43 self._test_apk_package_name = constants.GTEST_TEST_PACKAGE_NAME | 41 self._package_info = constants.PACKAGE_INFO['gtest'] |
44 self._test_activity_name = constants.GTEST_TEST_ACTIVITY_NAME | |
45 self._command_line_file = constants.GTEST_COMMAND_LINE_FILE | |
46 | 42 |
47 def _CreateCommandLineFileOnDevice(self, adb, options): | 43 def _CreateCommandLineFileOnDevice(self, adb, options): |
48 command_line_file = tempfile.NamedTemporaryFile() | 44 command_line_file = tempfile.NamedTemporaryFile() |
49 # GTest expects argv[0] to be the executable path. | 45 # GTest expects argv[0] to be the executable path. |
50 command_line_file.write(self.suite_name + ' ' + options) | 46 command_line_file.write(self.suite_name + ' ' + options) |
51 command_line_file.flush() | 47 command_line_file.flush() |
52 adb.PushIfNeeded(command_line_file.name, | 48 adb.PushIfNeeded(command_line_file.name, |
53 constants.TEST_EXECUTABLE_DIR + '/' + | 49 self._package_info.cmdline_file) |
54 self._command_line_file) | |
55 | 50 |
56 def _GetFifo(self): | 51 def _GetFifo(self): |
57 # The test.fifo path is determined by: | 52 # The test.fifo path is determined by: |
58 # testing/android/java/src/org/chromium/native_test/ | 53 # testing/android/java/src/org/chromium/native_test/ |
59 # ChromeNativeTestActivity.java and | 54 # ChromeNativeTestActivity.java and |
60 # testing/android/native_test_launcher.cc | 55 # testing/android/native_test_launcher.cc |
61 return '/data/data/' + self._test_apk_package_name + '/files/test.fifo' | 56 return '/data/data/' + self._package_info.package + '/files/test.fifo' |
62 | 57 |
63 def _ClearFifo(self, adb): | 58 def _ClearFifo(self, adb): |
64 adb.RunShellCommand('rm -f ' + self._GetFifo()) | 59 adb.RunShellCommand('rm -f ' + self._GetFifo()) |
65 | 60 |
66 def _WatchFifo(self, adb, timeout, logfile=None): | 61 def _WatchFifo(self, adb, timeout, logfile=None): |
67 for i in range(10): | 62 for i in range(10): |
68 if adb.FileExistsOnDevice(self._GetFifo()): | 63 if adb.FileExistsOnDevice(self._GetFifo()): |
69 logging.info('Fifo created.') | 64 logging.info('Fifo created.') |
70 break | 65 break |
71 time.sleep(i) | 66 time.sleep(i) |
72 else: | 67 else: |
73 raise errors.DeviceUnresponsiveError( | 68 raise errors.DeviceUnresponsiveError( |
74 'Unable to find fifo on device %s ' % self._GetFifo()) | 69 'Unable to find fifo on device %s ' % self._GetFifo()) |
75 args = shlex.split(adb.Adb()._target_arg) | 70 args = shlex.split(adb.Adb()._target_arg) |
76 args += ['shell', 'cat', self._GetFifo()] | 71 args += ['shell', 'cat', self._GetFifo()] |
77 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 72 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
78 | 73 |
79 def _StartActivity(self, adb): | 74 def _StartActivity(self, adb): |
80 adb.StartActivity( | 75 adb.StartActivity( |
81 self._test_apk_package_name, | 76 self._package_info.package, |
82 self._test_activity_name, | 77 self._package_info.activity, |
83 wait_for_completion=True, | 78 wait_for_completion=True, |
84 action='android.intent.action.MAIN', | 79 action='android.intent.action.MAIN', |
85 force_stop=True) | 80 force_stop=True) |
86 | 81 |
87 #override | 82 #override |
88 def ClearApplicationState(self, adb): | 83 def ClearApplicationState(self, adb): |
89 adb.ClearApplicationState(self._test_apk_package_name) | 84 adb.ClearApplicationState(self._package_info.package) |
90 # Content shell creates a profile on the sdscard which accumulates cache | 85 # Content shell creates a profile on the sdscard which accumulates cache |
91 # files over time. | 86 # files over time. |
92 if self.suite_name == 'content_browsertests': | 87 if self.suite_name == 'content_browsertests': |
93 adb.RunShellCommand( | 88 adb.RunShellCommand( |
94 'rm -r %s/content_shell' % adb.GetExternalStorage(), | 89 'rm -r %s/content_shell' % adb.GetExternalStorage(), |
95 timeout_time=60 * 2) | 90 timeout_time=60 * 2) |
96 | 91 |
97 #override | 92 #override |
98 def CreateCommandLineFileOnDevice(self, adb, test_filter, test_arguments): | 93 def CreateCommandLineFileOnDevice(self, adb, test_filter, test_arguments): |
99 self._CreateCommandLineFileOnDevice( | 94 self._CreateCommandLineFileOnDevice( |
(...skipping 25 matching lines...) Expand all Loading... |
125 self._StartActivity(adb) | 120 self._StartActivity(adb) |
126 finally: | 121 finally: |
127 self.tool.CleanUpEnvironment() | 122 self.tool.CleanUpEnvironment() |
128 logfile = android_commands.NewLineNormalizer(sys.stdout) | 123 logfile = android_commands.NewLineNormalizer(sys.stdout) |
129 return self._WatchFifo(adb, timeout=10, logfile=logfile) | 124 return self._WatchFifo(adb, timeout=10, logfile=logfile) |
130 | 125 |
131 #override | 126 #override |
132 def Install(self, adb): | 127 def Install(self, adb): |
133 self.tool.CopyFiles() | 128 self.tool.CopyFiles() |
134 adb.ManagedInstall(self.suite_path, False, | 129 adb.ManagedInstall(self.suite_path, False, |
135 package_name=self._test_apk_package_name) | 130 package_name=self._package_info.package) |
OLD | NEW |