OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Runs all ChromeDriver end to end tests.""" | 6 """Runs all ChromeDriver end to end tests.""" |
7 | 7 |
8 import atexit | |
8 import optparse | 9 import optparse |
9 import os | 10 import os |
11 import shutil | |
10 import sys | 12 import sys |
11 | 13 |
12 _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | 14 _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
13 sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib')) | 15 sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib')) |
14 | 16 |
15 from common import chrome_paths | 17 from common import chrome_paths |
16 from common import util | 18 from common import util |
17 import continuous_archive | 19 import continuous_archive |
18 | 20 |
19 | 21 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 | 86 |
85 | 87 |
86 def RunCppTests(cpp_tests): | 88 def RunCppTests(cpp_tests): |
87 print '@@@BUILD_STEP chromedriver2_tests@@@' | 89 print '@@@BUILD_STEP chromedriver2_tests@@@' |
88 code = util.RunCommand([cpp_tests]) | 90 code = util.RunCommand([cpp_tests]) |
89 if code: | 91 if code: |
90 print '@@@STEP_FAILURE@@@' | 92 print '@@@STEP_FAILURE@@@' |
91 return code | 93 return code |
92 | 94 |
93 | 95 |
96 def KillChromes(chrome_path): | |
kkania
2013/04/29 18:25:43
i think it would make more sense to put all this i
chrisgao (Use stgao instead)
2013/04/29 22:10:26
Done.
| |
97 if util.IsWindows(): | |
98 util.RunCommand(['taskkill', '/F', '/IM', os.path.basename(chrome_path)]) | |
99 else: | |
100 util.RunCommand(['pkill', '-9', os.path.basename(chrome_path)]) | |
chrisgao (Use stgao instead)
2013/04/27 00:48:43
Is there a way to kill the chrome processes based
craigdh
2013/04/29 17:31:40
This also doesn't work on Android, for obvious rea
chrisgao (Use stgao instead)
2013/04/29 22:10:26
Right, let us just ignore Android.
| |
101 | |
102 | |
103 def CleanTmpDir(): | |
104 tmp_dir = os.path.dirname(util.MakeTempDir()) | |
105 print 'cleaning temp directory:', tmp_dir | |
106 for file_name in os.listdir(tmp_dir): | |
107 if not os.path.isdir(os.path.join(tmp_dir, file_name)): | |
108 continue | |
109 if file_name.startswith('jetty-0.0.0.0-') or file_name.startswith('tmp'): | |
110 print 'deleting sub-directory', file_name | |
111 shutil.rmtree(os.path.join(tmp_dir, file_name), True) | |
112 | |
113 | |
94 def main(): | 114 def main(): |
95 parser = optparse.OptionParser() | 115 parser = optparse.OptionParser() |
96 parser.add_option( | 116 parser.add_option( |
97 '', '--android-package', | 117 '', '--android-package', |
98 help='Application package name, if running tests on Android.') | 118 help='Application package name, if running tests on Android.') |
99 # Option 'chrome-version' is for desktop only. | 119 # Option 'chrome-version' is for desktop only. |
100 parser.add_option( | 120 parser.add_option( |
101 '', '--chrome-version', | 121 '', '--chrome-version', |
102 help='Version of chrome, e.g., \'HEAD\', \'27\', or \'26\'.' | 122 help='Version of chrome, e.g., \'HEAD\', \'27\', or \'26\'.' |
103 'Default is to run tests against all of these versions.' | 123 'Default is to run tests against all of these versions.' |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 chromedriver_server = os.path.join(build_dir, server_name) | 155 chromedriver_server = os.path.join(build_dir, server_name) |
136 | 156 |
137 if util.IsLinux(): | 157 if util.IsLinux(): |
138 # Set LD_LIBRARY_PATH to enable successful loading of shared object files, | 158 # Set LD_LIBRARY_PATH to enable successful loading of shared object files, |
139 # when chromedriver2.so is not a static build. | 159 # when chromedriver2.so is not a static build. |
140 _AppendEnvironmentPath('LD_LIBRARY_PATH', os.path.join(build_dir, 'lib')) | 160 _AppendEnvironmentPath('LD_LIBRARY_PATH', os.path.join(build_dir, 'lib')) |
141 elif util.IsWindows(): | 161 elif util.IsWindows(): |
142 # For Windows bots: add ant, java(jre) and the like to system path. | 162 # For Windows bots: add ant, java(jre) and the like to system path. |
143 _AddToolsToSystemPathForWindows() | 163 _AddToolsToSystemPathForWindows() |
144 | 164 |
165 CleanTmpDir() | |
166 atexit.register(CleanTmpDir) | |
craigdh
2013/04/29 17:31:40
It would be more pythonic to have a try/finally bl
chrisgao (Use stgao instead)
2013/04/29 22:10:26
Done.
| |
145 if options.android_package: | 167 if options.android_package: |
146 os.environ['PATH'] += os.pathsep + os.path.join(_THIS_DIR, 'chrome') | 168 os.environ['PATH'] += os.pathsep + os.path.join(_THIS_DIR, 'chrome') |
147 code1 = RunPythonTests(chromedriver, | 169 code1 = RunPythonTests(chromedriver, |
148 android_package=options.android_package) | 170 android_package=options.android_package) |
149 code2 = RunJavaTests(chromedriver_server, | 171 code2 = RunJavaTests(chromedriver_server, |
150 android_package=options.android_package) | 172 android_package=options.android_package) |
151 return code1 or code2 | 173 return code1 or code2 |
152 else: | 174 else: |
153 chrome_tip_of_tree = os.path.join(build_dir, chrome_name) | 175 chrome_tip_of_tree = os.path.join(build_dir, chrome_name) |
154 cpp_tests = os.path.join(build_dir, cpp_tests_name) | 176 cpp_tests = os.path.join(build_dir, cpp_tests_name) |
155 | 177 |
156 chrome_26 = continuous_archive.DownloadChrome( | 178 chrome_26 = continuous_archive.DownloadChrome( |
157 continuous_archive.CHROME_26_REVISION, util.MakeTempDir()) | 179 continuous_archive.CHROME_26_REVISION, util.MakeTempDir()) |
158 chrome_27 = continuous_archive.DownloadChrome( | 180 chrome_27 = continuous_archive.DownloadChrome( |
159 continuous_archive.CHROME_27_REVISION, util.MakeTempDir()) | 181 continuous_archive.CHROME_27_REVISION, util.MakeTempDir()) |
160 chrome_path_versions = [ | 182 chrome_path_versions = [ |
161 {'path': chrome_tip_of_tree, 'version': 'HEAD'}, | 183 {'path': chrome_tip_of_tree, 'version': 'HEAD'}, |
162 {'path': chrome_27, 'version': '27'}, | 184 {'path': chrome_27, 'version': '27'}, |
163 {'path': chrome_26, 'version': '26'}, | 185 {'path': chrome_26, 'version': '26'}, |
164 ] | 186 ] |
165 code = 0 | 187 code = 0 |
166 for chrome in chrome_path_versions: | 188 for chrome in chrome_path_versions: |
167 if options.chrome_version and chrome['version'] != options.chrome_version: | 189 if options.chrome_version and chrome['version'] != options.chrome_version: |
168 continue | 190 continue |
169 | 191 |
170 code1 = RunPythonTests(chromedriver, chrome=chrome['path'], | 192 code1 = RunPythonTests(chromedriver, chrome=chrome['path'], |
171 chrome_version=chrome['version']) | 193 chrome_version=chrome['version']) |
172 code2 = RunJavaTests(chromedriver_server, chrome=chrome['path'], | 194 code2 = RunJavaTests(chromedriver_server, chrome=chrome['path'], |
173 chrome_version=chrome['version']) | 195 chrome_version=chrome['version']) |
196 KillChromes(chrome['path']) | |
174 code = code or code1 or code2 | 197 code = code or code1 or code2 |
175 return RunCppTests(cpp_tests) or code | 198 return RunCppTests(cpp_tests) or code |
176 | 199 |
177 | 200 |
178 if __name__ == '__main__': | 201 if __name__ == '__main__': |
179 sys.exit(main()) | 202 sys.exit(main()) |
OLD | NEW |