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 """Sets environment variables needed to run a chromium unit test.""" | 6 """Sets environment variables needed to run a chromium unit test.""" |
7 | 7 |
8 import os | 8 import os |
9 import stat | 9 import stat |
10 import subprocess | 10 import subprocess |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 msan_options.append('detect_leaks=1') | 117 msan_options.append('detect_leaks=1') |
118 extra_env['MSAN_OPTIONS'] = ' '.join(msan_options) | 118 extra_env['MSAN_OPTIONS'] = ' '.join(msan_options) |
119 | 119 |
120 if tsan: | 120 if tsan: |
121 tsan_options = symbolization_options[:] | 121 tsan_options = symbolization_options[:] |
122 extra_env['TSAN_OPTIONS'] = ' '.join(tsan_options) | 122 extra_env['TSAN_OPTIONS'] = ' '.join(tsan_options) |
123 | 123 |
124 return extra_env | 124 return extra_env |
125 | 125 |
126 | 126 |
127 def get_sanitizer_symbolize_command(json_path=None): | 127 def get_sanitizer_symbolize_command(json_path=None, executable_path=None): |
128 """Construct the command to invoke offline symbolization script.""" | 128 """Construct the command to invoke offline symbolization script.""" |
129 script_path = '../tools/valgrind/asan/asan_symbolize.py' | 129 script_path = '../tools/valgrind/asan/asan_symbolize.py' |
130 cmd = [sys.executable, script_path] | 130 cmd = [sys.executable, script_path] |
131 if json_path is not None: | 131 if json_path is not None: |
132 cmd.append('--test-summary-json-file=%s' % json_path) | 132 cmd.append('--test-summary-json-file=%s' % json_path) |
| 133 if executable_path is not None: |
| 134 cmd.append('--executable-path=%s' % executable_path) |
133 return cmd | 135 return cmd |
134 | 136 |
135 | 137 |
136 def get_json_path(cmd): | 138 def get_json_path(cmd): |
137 """Extract the JSON test summary path from a command line.""" | 139 """Extract the JSON test summary path from a command line.""" |
138 json_path_flag = '--test-launcher-summary-output=' | 140 json_path_flag = '--test-launcher-summary-output=' |
139 for arg in cmd: | 141 for arg in cmd: |
140 if arg.startswith(json_path_flag): | 142 if arg.startswith(json_path_flag): |
141 return arg.split(json_path_flag).pop() | 143 return arg.split(json_path_flag).pop() |
142 return None | 144 return None |
143 | 145 |
144 | 146 |
145 def symbolize_snippets_in_json(cmd, env): | 147 def symbolize_snippets_in_json(cmd, env): |
146 """Symbolize output snippets inside the JSON test summary.""" | 148 """Symbolize output snippets inside the JSON test summary.""" |
147 json_path = get_json_path(cmd) | 149 json_path = get_json_path(cmd) |
148 if json_path is None: | 150 if json_path is None: |
149 return | 151 return |
150 | 152 |
151 try: | 153 try: |
152 symbolize_command = get_sanitizer_symbolize_command(json_path=json_path) | 154 symbolize_command = get_sanitizer_symbolize_command( |
| 155 json_path=json_path, executable_path=cmd[0]) |
153 p = subprocess.Popen(symbolize_command, stderr=subprocess.PIPE, env=env) | 156 p = subprocess.Popen(symbolize_command, stderr=subprocess.PIPE, env=env) |
154 (_, stderr) = p.communicate() | 157 (_, stderr) = p.communicate() |
155 except OSError as e: | 158 except OSError as e: |
156 print 'Exception while symbolizing snippets: %s' % e | 159 print 'Exception while symbolizing snippets: %s' % e |
157 | 160 |
158 if p.returncode != 0: | 161 if p.returncode != 0: |
159 print "Error: failed to symbolize snippets in JSON:\n" | 162 print "Error: failed to symbolize snippets in JSON:\n" |
160 print stderr | 163 print stderr |
161 | 164 |
162 | 165 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 '\n'.join(' %s=%s' % | 203 '\n'.join(' %s=%s' % |
201 (k, v) for k, v in sorted(extra_env.iteritems())), | 204 (k, v) for k, v in sorted(extra_env.iteritems())), |
202 ' '.join(cmd))) | 205 ' '.join(cmd))) |
203 env.update(extra_env or {}) | 206 env.update(extra_env or {}) |
204 try: | 207 try: |
205 # See above comment regarding offline symbolization. | 208 # See above comment regarding offline symbolization. |
206 if use_symbolization_script: | 209 if use_symbolization_script: |
207 # Need to pipe to the symbolizer script. | 210 # Need to pipe to the symbolizer script. |
208 p1 = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, | 211 p1 = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, |
209 stderr=sys.stdout) | 212 stderr=sys.stdout) |
210 p2 = subprocess.Popen(get_sanitizer_symbolize_command(), | 213 p2 = subprocess.Popen( |
211 env=env, stdin=p1.stdout) | 214 get_sanitizer_symbolize_command(executable_path=cmd[0]), |
| 215 env=env, stdin=p1.stdout) |
212 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. | 216 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. |
213 p1.wait() | 217 p1.wait() |
214 p2.wait() | 218 p2.wait() |
215 # Also feed the out-of-band JSON output to the symbolizer script. | 219 # Also feed the out-of-band JSON output to the symbolizer script. |
216 symbolize_snippets_in_json(cmd, env) | 220 symbolize_snippets_in_json(cmd, env) |
217 return p1.returncode | 221 return p1.returncode |
218 else: | 222 else: |
219 return subprocess.call(cmd, env=env) | 223 return subprocess.call(cmd, env=env) |
220 except OSError: | 224 except OSError: |
221 print >> sys.stderr, 'Failed to start %s' % cmd | 225 print >> sys.stderr, 'Failed to start %s' % cmd |
222 raise | 226 raise |
223 | 227 |
224 | 228 |
225 def main(): | 229 def main(): |
226 return run_executable(sys.argv[1:], os.environ.copy()) | 230 return run_executable(sys.argv[1:], os.environ.copy()) |
227 | 231 |
228 | 232 |
229 if __name__ == '__main__': | 233 if __name__ == '__main__': |
230 sys.exit(main()) | 234 sys.exit(main()) |
OLD | NEW |