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 shutil | 9 import shutil |
10 import sys | 10 import sys |
11 import tempfile | 11 import tempfile |
12 | 12 |
13 from pylib import cmd_helper | 13 from pylib import cmd_helper |
14 from pylib import constants | 14 from pylib import constants |
15 from pylib import pexpect | 15 from pylib import pexpect |
16 | 16 |
17 from test_package import TestPackage | 17 from test_package import TestPackage |
18 | 18 |
19 | 19 |
20 class TestPackageExecutable(TestPackage): | 20 class TestPackageExecutable(TestPackage): |
21 """A helper class for running stand-alone executables.""" | 21 """A helper class for running stand-alone executables.""" |
22 | 22 |
23 _TEST_RUNNER_RET_VAL_FILE = 'gtest_retval' | 23 _TEST_RUNNER_RET_VAL_FILE = 'gtest_retval' |
24 | 24 |
25 def __init__(self, adb, device, test_suite, tool, symbols_dir=None): | 25 def __init__(self, adb, device, suite_path_full, tool, symbols_dir=None): |
26 """ | 26 """ |
27 Args: | 27 Args: |
28 adb: ADB interface the tests are using. | 28 adb: ADB interface the tests are using. |
29 device: Device to run the tests. | 29 device: Device to run the tests. |
30 test_suite: A specific test suite to run, empty to run all. | 30 suite_path_full: Absolute path to a specific test suite to run, |
| 31 empty to run all. |
31 tool: Name of the Valgrind tool. | 32 tool: Name of the Valgrind tool. |
32 symbols_dir: Directory to put the stripped binaries. | 33 symbols_dir: Directory to put the stripped binaries. |
33 """ | 34 """ |
34 TestPackage.__init__(self, adb, device, test_suite, tool) | 35 TestPackage.__init__(self, adb, device, suite_path_full, tool) |
35 self.symbols_dir = symbols_dir | 36 self.symbols_dir = symbols_dir |
36 | 37 |
37 def _GetTestSuiteBaseName(self): | 38 def _GetTestSuiteBaseName(self): |
38 """Returns the base name of the test suite.""" | 39 """Returns the base name of the test suite.""" |
39 return os.path.basename(self.test_suite) | 40 return os.path.basename(self.suite_path) |
40 | 41 |
41 #override | 42 #override |
42 def GetGTestReturnCode(self): | 43 def GetGTestReturnCode(self): |
43 ret = None | 44 ret = None |
44 ret_code = 1 # Assume failure if we can't find it | 45 ret_code = 1 # Assume failure if we can't find it |
45 ret_code_file = tempfile.NamedTemporaryFile() | 46 ret_code_file = tempfile.NamedTemporaryFile() |
46 try: | 47 try: |
47 if not self.adb.Adb().Pull( | 48 if not self.adb.Adb().Pull( |
48 constants.TEST_EXECUTABLE_DIR + '/' + | 49 constants.TEST_EXECUTABLE_DIR + '/' + |
49 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, | 50 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, |
(...skipping 23 matching lines...) Expand all Loading... |
73 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: ' | 74 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: ' |
74 'No native coverage.') | 75 'No native coverage.') |
75 return '' | 76 return '' |
76 export_string = ('export GCOV_PREFIX="%s/gcov"\n' % | 77 export_string = ('export GCOV_PREFIX="%s/gcov"\n' % |
77 self.adb.GetExternalStorage()) | 78 self.adb.GetExternalStorage()) |
78 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth | 79 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth |
79 return export_string | 80 return export_string |
80 | 81 |
81 #override | 82 #override |
82 def ClearApplicationState(self): | 83 def ClearApplicationState(self): |
83 self.adb.KillAllBlocking(self.test_suite_basename, 30) | 84 self.adb.KillAllBlocking(self.suite_basename, 30) |
84 | 85 |
85 #override | 86 #override |
86 def CreateCommandLineFileOnDevice(self, test_filter, test_arguments): | 87 def CreateCommandLineFileOnDevice(self, test_filter, test_arguments): |
87 tool_wrapper = self.tool.GetTestWrapper() | 88 tool_wrapper = self.tool.GetTestWrapper() |
88 sh_script_file = tempfile.NamedTemporaryFile() | 89 sh_script_file = tempfile.NamedTemporaryFile() |
89 # We need to capture the exit status from the script since adb shell won't | 90 # We need to capture the exit status from the script since adb shell won't |
90 # propagate to us. | 91 # propagate to us. |
91 sh_script_file.write('cd %s\n' | 92 sh_script_file.write('cd %s\n' |
92 '%s' | 93 '%s' |
93 '%s %s/%s --gtest_filter=%s %s\n' | 94 '%s %s/%s --gtest_filter=%s %s\n' |
94 'echo $? > %s' % | 95 'echo $? > %s' % |
95 (constants.TEST_EXECUTABLE_DIR, | 96 (constants.TEST_EXECUTABLE_DIR, |
96 self._AddNativeCoverageExports(), | 97 self._AddNativeCoverageExports(), |
97 tool_wrapper, constants.TEST_EXECUTABLE_DIR, | 98 tool_wrapper, constants.TEST_EXECUTABLE_DIR, |
98 self.test_suite_basename, | 99 self.suite_basename, |
99 test_filter, test_arguments, | 100 test_filter, test_arguments, |
100 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) | 101 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) |
101 sh_script_file.flush() | 102 sh_script_file.flush() |
102 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) | 103 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) |
103 self.adb.PushIfNeeded( | 104 self.adb.PushIfNeeded( |
104 sh_script_file.name, | 105 sh_script_file.name, |
105 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh') | 106 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh') |
106 logging.info('Conents of the test runner script: ') | 107 logging.info('Conents of the test runner script: ') |
107 for line in open(sh_script_file.name).readlines(): | 108 for line in open(sh_script_file.name).readlines(): |
108 logging.info(' ' + line.rstrip()) | 109 logging.info(' ' + line.rstrip()) |
109 | 110 |
110 #override | 111 #override |
111 def GetAllTests(self): | 112 def GetAllTests(self): |
112 all_tests = self.adb.RunShellCommand( | 113 all_tests = self.adb.RunShellCommand( |
113 '%s %s/%s --gtest_list_tests' % | 114 '%s %s/%s --gtest_list_tests' % |
114 (self.tool.GetTestWrapper(), | 115 (self.tool.GetTestWrapper(), |
115 constants.TEST_EXECUTABLE_DIR, | 116 constants.TEST_EXECUTABLE_DIR, |
116 self.test_suite_basename)) | 117 self.suite_basename)) |
117 return self._ParseGTestListTests(all_tests) | 118 return self._ParseGTestListTests(all_tests) |
118 | 119 |
119 #override | 120 #override |
120 def SpawnTestProcess(self): | 121 def SpawnTestProcess(self): |
121 args = ['adb', '-s', self.device, 'shell', 'sh', | 122 args = ['adb', '-s', self.device, 'shell', 'sh', |
122 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] | 123 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] |
123 logging.info(args) | 124 logging.info(args) |
124 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout) | 125 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout) |
125 | 126 |
126 #override | 127 #override |
127 def Install(self): | 128 def Install(self): |
128 if self.tool.NeedsDebugInfo(): | 129 if self.tool.NeedsDebugInfo(): |
129 target_name = self.test_suite | 130 target_name = self.suite_path |
130 else: | 131 else: |
131 target_name = self.test_suite + '_' + self.device + '_stripped' | 132 target_name = self.suite_path + '_' + self.device + '_stripped' |
132 should_strip = True | 133 should_strip = True |
133 if os.path.isfile(target_name): | 134 if os.path.isfile(target_name): |
134 logging.info('Found target file %s' % target_name) | 135 logging.info('Found target file %s' % target_name) |
135 target_mtime = os.stat(target_name).st_mtime | 136 target_mtime = os.stat(target_name).st_mtime |
136 source_mtime = os.stat(self.test_suite).st_mtime | 137 source_mtime = os.stat(self.suite_path).st_mtime |
137 if target_mtime > source_mtime: | 138 if target_mtime > source_mtime: |
138 logging.info('Target mtime (%d) is newer than source (%d), assuming ' | 139 logging.info('Target mtime (%d) is newer than source (%d), assuming ' |
139 'no change.' % (target_mtime, source_mtime)) | 140 'no change.' % (target_mtime, source_mtime)) |
140 should_strip = False | 141 should_strip = False |
141 | 142 |
142 if should_strip: | 143 if should_strip: |
143 logging.info('Did not find up-to-date stripped binary. Generating a ' | 144 logging.info('Did not find up-to-date stripped binary. Generating a ' |
144 'new one (%s).' % target_name) | 145 'new one (%s).' % target_name) |
145 # Whenever we generate a stripped binary, copy to the symbols dir. If we | 146 # Whenever we generate a stripped binary, copy to the symbols dir. If we |
146 # aren't stripping a new binary, assume it's there. | 147 # aren't stripping a new binary, assume it's there. |
147 if self.symbols_dir: | 148 if self.symbols_dir: |
148 if not os.path.exists(self.symbols_dir): | 149 if not os.path.exists(self.symbols_dir): |
149 os.makedirs(self.symbols_dir) | 150 os.makedirs(self.symbols_dir) |
150 shutil.copy(self.test_suite, self.symbols_dir) | 151 shutil.copy(self.suite_path, self.symbols_dir) |
151 strip = os.environ['STRIP'] | 152 strip = os.environ['STRIP'] |
152 cmd_helper.RunCmd([strip, self.test_suite, '-o', target_name]) | 153 cmd_helper.RunCmd([strip, self.suite_path, '-o', target_name]) |
153 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.test_suite_basename | 154 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_basename |
154 self.adb.PushIfNeeded(target_name, test_binary) | 155 self.adb.PushIfNeeded(target_name, test_binary) |
OLD | NEW |