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 | 6 |
6 import logging | 7 import logging |
7 import os | 8 import os |
8 import shutil | 9 import shutil |
9 import sys | 10 import sys |
10 import tempfile | 11 import tempfile |
11 | 12 |
12 from pylib import cmd_helper | 13 from pylib import cmd_helper |
13 from pylib import constants | 14 from pylib import constants |
14 from pylib import pexpect | 15 from pylib import pexpect |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 83 |
83 def GetAllTests(self): | 84 def GetAllTests(self): |
84 """Returns a list of all tests available in the test suite.""" | 85 """Returns a list of all tests available in the test suite.""" |
85 all_tests = self.adb.RunShellCommand( | 86 all_tests = self.adb.RunShellCommand( |
86 '%s %s/%s --gtest_list_tests' % | 87 '%s %s/%s --gtest_list_tests' % |
87 (self.tool.GetTestWrapper(), | 88 (self.tool.GetTestWrapper(), |
88 constants.TEST_EXECUTABLE_DIR, | 89 constants.TEST_EXECUTABLE_DIR, |
89 self.test_suite_basename)) | 90 self.test_suite_basename)) |
90 return self._ParseGTestListTests(all_tests) | 91 return self._ParseGTestListTests(all_tests) |
91 | 92 |
92 def CreateTestRunnerScript(self, gtest_filter, test_arguments): | 93 def CreateTestRunnerScript(self, test_filter, test_arguments): |
93 """Creates a test runner script and pushes to the device. | 94 """Creates a test runner script and pushes to the device. |
94 | 95 |
95 Args: | 96 Args: |
96 gtest_filter: A gtest_filter flag. | 97 test_filter: A test_filter flag. |
97 test_arguments: Additional arguments to pass to the test binary. | 98 test_arguments: Additional arguments to pass to the test binary. |
98 """ | 99 """ |
99 tool_wrapper = self.tool.GetTestWrapper() | 100 tool_wrapper = self.tool.GetTestWrapper() |
100 sh_script_file = tempfile.NamedTemporaryFile() | 101 sh_script_file = tempfile.NamedTemporaryFile() |
101 # We need to capture the exit status from the script since adb shell won't | 102 # We need to capture the exit status from the script since adb shell won't |
102 # propagate to us. | 103 # propagate to us. |
103 sh_script_file.write('cd %s\n' | 104 sh_script_file.write('cd %s\n' |
104 '%s' | 105 '%s' |
105 '%s %s/%s --gtest_filter=%s %s\n' | 106 '%s %s/%s --gtest_filter=%s %s\n' |
106 'echo $? > %s' % | 107 'echo $? > %s' % |
107 (constants.TEST_EXECUTABLE_DIR, | 108 (constants.TEST_EXECUTABLE_DIR, |
108 self._AddNativeCoverageExports(), | 109 self._AddNativeCoverageExports(), |
109 tool_wrapper, constants.TEST_EXECUTABLE_DIR, | 110 tool_wrapper, constants.TEST_EXECUTABLE_DIR, |
110 self.test_suite_basename, | 111 self.test_suite_basename, |
111 gtest_filter, test_arguments, | 112 test_filter, test_arguments, |
112 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) | 113 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) |
113 sh_script_file.flush() | 114 sh_script_file.flush() |
114 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) | 115 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) |
115 self.adb.PushIfNeeded( | 116 self.adb.PushIfNeeded( |
116 sh_script_file.name, | 117 sh_script_file.name, |
117 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh') | 118 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh') |
118 logging.info('Conents of the test runner script: ') | 119 logging.info('Conents of the test runner script: ') |
119 for line in open(sh_script_file.name).readlines(): | 120 for line in open(sh_script_file.name).readlines(): |
120 logging.info(' ' + line.rstrip()) | 121 logging.info(' ' + line.rstrip()) |
121 | 122 |
122 def RunTestsAndListResults(self): | 123 def RunTestsAndListResults(self): |
123 """Runs all the tests and checks for failures. | 124 """Runs all the tests and checks for failures. |
124 | 125 |
125 Returns: | 126 Returns: |
126 A TestRunResults object. | 127 A TestRunResults object. |
127 """ | 128 """ |
(...skipping 29 matching lines...) Expand all Loading... |
157 os.makedirs(self.symbols_dir) | 158 os.makedirs(self.symbols_dir) |
158 shutil.copy(self.test_suite, self.symbols_dir) | 159 shutil.copy(self.test_suite, self.symbols_dir) |
159 strip = os.environ['STRIP'] | 160 strip = os.environ['STRIP'] |
160 cmd_helper.RunCmd([strip, self.test_suite, '-o', target_name]) | 161 cmd_helper.RunCmd([strip, self.test_suite, '-o', target_name]) |
161 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.test_suite_basename | 162 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.test_suite_basename |
162 self.adb.PushIfNeeded(target_name, test_binary) | 163 self.adb.PushIfNeeded(target_name, test_binary) |
163 | 164 |
164 def _GetTestSuiteBaseName(self): | 165 def _GetTestSuiteBaseName(self): |
165 """Returns the base name of the test suite.""" | 166 """Returns the base name of the test suite.""" |
166 return os.path.basename(self.test_suite) | 167 return os.path.basename(self.test_suite) |
OLD | NEW |