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 TestPackageExecutable to help run stand-alone executables.""" | 5 """Defines TestPackageExecutable to help run stand-alone executables.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 import tempfile | 10 import tempfile |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 # name. We only care that there is no process with the given name, so | 86 # name. We only care that there is no process with the given name, so |
87 # we can safely eat the exception. | 87 # we can safely eat the exception. |
88 pass | 88 pass |
89 | 89 |
90 #override | 90 #override |
91 def CreateCommandLineFileOnDevice(self, device, test_filter, test_arguments): | 91 def CreateCommandLineFileOnDevice(self, device, test_filter, test_arguments): |
92 tool_wrapper = self.tool.GetTestWrapper() | 92 tool_wrapper = self.tool.GetTestWrapper() |
93 sh_script_file = tempfile.NamedTemporaryFile() | 93 sh_script_file = tempfile.NamedTemporaryFile() |
94 # We need to capture the exit status from the script since adb shell won't | 94 # We need to capture the exit status from the script since adb shell won't |
95 # propagate to us. | 95 # propagate to us. |
96 sh_script_file.write('cd %s\n' | 96 sh_script_file.write( |
97 '%s' | 97 'cd %s\n' |
98 '%s %s/%s --gtest_filter=%s %s\n' | 98 '%s' |
99 'echo $? > %s' % | 99 '%s LD_LIBRARY_PATH=%s/%s_deps %s/%s --gtest_filter=%s %s\n' |
100 (constants.TEST_EXECUTABLE_DIR, | 100 'echo $? > %s' % |
101 self._AddNativeCoverageExports(device), | 101 (constants.TEST_EXECUTABLE_DIR, |
102 tool_wrapper, constants.TEST_EXECUTABLE_DIR, | 102 self._AddNativeCoverageExports(device), |
103 self.suite_name, | 103 tool_wrapper, |
104 test_filter, test_arguments, | 104 constants.TEST_EXECUTABLE_DIR, |
105 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) | 105 self.suite_name, |
| 106 constants.TEST_EXECUTABLE_DIR, |
| 107 self.suite_name, |
| 108 test_filter, test_arguments, |
| 109 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) |
106 sh_script_file.flush() | 110 sh_script_file.flush() |
107 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) | 111 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) |
108 device.PushChangedFiles([( | 112 device.PushChangedFiles([( |
109 sh_script_file.name, | 113 sh_script_file.name, |
110 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')]) | 114 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')]) |
111 logging.info('Conents of the test runner script: ') | 115 logging.info('Conents of the test runner script: ') |
112 for line in open(sh_script_file.name).readlines(): | 116 for line in open(sh_script_file.name).readlines(): |
113 logging.info(' ' + line.rstrip()) | 117 logging.info(' ' + line.rstrip()) |
114 | 118 |
115 #override | 119 #override |
116 def GetAllTests(self, device): | 120 def GetAllTests(self, device): |
117 all_tests = device.RunShellCommand( | 121 cmd = '%s %s/%s --gtest_list_tests' % (self.tool.GetTestWrapper(), |
118 '%s %s/%s --gtest_list_tests' % | 122 constants.TEST_EXECUTABLE_DIR, self.suite_name) |
119 (self.tool.GetTestWrapper(), | 123 lib_path = '%s/%s_deps' % (constants.TEST_EXECUTABLE_DIR, self.suite_name) |
120 constants.TEST_EXECUTABLE_DIR, | 124 (exit_code, output) = device.old_interface.GetAndroidToolStatusAndOutput( |
121 self.suite_name)) | 125 cmd, lib_path=lib_path) |
122 return self._ParseGTestListTests(all_tests) | 126 if exit_code != 0: |
| 127 raise Exception( |
| 128 'Failed to start binary:\n%s' % '\n'.join(output)) |
| 129 return self._ParseGTestListTests(output) |
123 | 130 |
124 #override | 131 #override |
125 def SpawnTestProcess(self, device): | 132 def SpawnTestProcess(self, device): |
126 args = ['adb', '-s', str(device), 'shell', 'sh', | 133 args = ['adb', '-s', str(device), 'shell', 'sh', |
127 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] | 134 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] |
128 logging.info(args) | 135 logging.info(args) |
129 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout) | 136 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout) |
130 | 137 |
131 #override | 138 #override |
132 def Install(self, device): | 139 def Install(self, device): |
133 if self.tool.NeedsDebugInfo(): | 140 if self.tool.NeedsDebugInfo(): |
134 target_name = self.suite_path | 141 target_name = self.suite_path |
135 else: | 142 else: |
136 target_name = self.suite_path + '_stripped' | 143 target_name = self.suite_path + '_stripped' |
137 if not os.path.isfile(target_name): | 144 if not os.path.isfile(target_name): |
138 raise Exception('Did not find %s, build target %s' % | 145 raise Exception('Did not find %s, build target %s' % |
139 (target_name, self.suite_name + '_stripped')) | 146 (target_name, self.suite_name + '_stripped')) |
140 | 147 |
141 target_mtime = os.stat(target_name).st_mtime | 148 target_mtime = os.stat(target_name).st_mtime |
142 source_mtime = os.stat(self.suite_path).st_mtime | 149 source_mtime = os.stat(self.suite_path).st_mtime |
143 if target_mtime < source_mtime: | 150 if target_mtime < source_mtime: |
144 raise Exception( | 151 raise Exception( |
145 'stripped binary (%s, timestamp %d) older than ' | 152 'stripped binary (%s, timestamp %d) older than ' |
146 'source binary (%s, timestamp %d), build target %s' % | 153 'source binary (%s, timestamp %d), build target %s' % |
147 (target_name, target_mtime, self.suite_path, source_mtime, | 154 (target_name, target_mtime, self.suite_path, source_mtime, |
148 self.suite_name + '_stripped')) | 155 self.suite_name + '_stripped')) |
149 | 156 |
150 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_name | 157 test_binary_path = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_name |
151 device.PushChangedFiles([(target_name, test_binary)]) | 158 device.PushChangedFiles([(target_name, test_binary_path)]) |
| 159 deps_path = self.suite_path + '_deps' |
| 160 if os.path.isdir(deps_path): |
| 161 device.PushChangedFiles([(deps_path, test_binary_path + '_deps')]) |
OLD | NEW |