Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 if sys.platform == 'darwin': | 98 if sys.platform == 'darwin': |
| 99 isolate_output_dir = os.path.abspath(os.path.dirname(cmd[0])) | 99 isolate_output_dir = os.path.abspath(os.path.dirname(cmd[0])) |
| 100 # This is needed because the test binary has @executable_path embedded in it | 100 # This is needed because the test binary has @executable_path embedded in it |
| 101 # it that the OS tries to resolve to the cache directory and not the mapped | 101 # it that the OS tries to resolve to the cache directory and not the mapped |
| 102 # directory. | 102 # directory. |
| 103 extra_env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir) | 103 extra_env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir) |
| 104 | 104 |
| 105 return extra_env | 105 return extra_env |
| 106 | 106 |
| 107 | 107 |
| 108 def get_sanitizer_symbolize_command(json_path=None): | 108 def get_sanitizer_symbolize_command(json_path=None, executable_path=None): |
| 109 """Construct the command to invoke offline symbolization script.""" | 109 """Construct the command to invoke offline symbolization script.""" |
| 110 script_path = '../tools/valgrind/asan/asan_symbolize.py' | 110 script_path = '../tools/valgrind/asan/asan_symbolize.py' |
| 111 cmd = [sys.executable, script_path] | 111 cmd = [sys.executable, script_path] |
| 112 if json_path is not None: | 112 if json_path is not None: |
| 113 cmd.append('--test-summary-json-file=%s' % json_path) | 113 cmd.append('--test-summary-json-file=%s' % json_path) |
| 114 if executable_path is not None: | |
| 115 cmd.append('--executable-path=%s' % executable_path) | |
| 114 return cmd | 116 return cmd |
| 115 | 117 |
| 116 | 118 |
| 117 def get_json_path(cmd): | 119 def get_json_path(cmd): |
| 118 """Extract the JSON test summary path from a command line.""" | 120 """Extract the JSON test summary path from a command line.""" |
| 119 json_path_flag = '--test-launcher-summary-output=' | 121 json_path_flag = '--test-launcher-summary-output=' |
| 120 for arg in cmd: | 122 for arg in cmd: |
| 121 if arg.startswith(json_path_flag): | 123 if arg.startswith(json_path_flag): |
| 122 return arg.split(json_path_flag).pop() | 124 return arg.split(json_path_flag).pop() |
| 123 return None | 125 return None |
| 124 | 126 |
| 125 | 127 |
| 126 def symbolize_snippets_in_json(cmd, env): | 128 def symbolize_snippets_in_json(cmd, env): |
| 127 """Symbolize output snippets inside the JSON test summary.""" | 129 """Symbolize output snippets inside the JSON test summary.""" |
| 128 json_path = get_json_path(cmd) | 130 json_path = get_json_path(cmd) |
| 129 if json_path is None: | 131 if json_path is None: |
| 130 return | 132 return |
| 131 | 133 |
| 132 try: | 134 try: |
| 133 symbolize_command = get_sanitizer_symbolize_command(json_path=json_path) | 135 symbolize_command = get_sanitizer_symbolize_command( |
| 136 json_path=json_path, executable_path=cmd[0]) | |
| 134 p = subprocess.Popen(symbolize_command, stderr=subprocess.PIPE, env=env) | 137 p = subprocess.Popen(symbolize_command, stderr=subprocess.PIPE, env=env) |
| 135 (_, stderr) = p.communicate() | 138 (_, stderr) = p.communicate() |
| 136 except OSError as e: | 139 except OSError as e: |
| 137 print 'Exception while symbolizing snippets: %s' % e | 140 print 'Exception while symbolizing snippets: %s' % e |
| 138 | 141 |
| 139 if p.returncode != 0: | 142 if p.returncode != 0: |
| 140 print "Error: failed to symbolize snippets in JSON:\n" | 143 print "Error: failed to symbolize snippets in JSON:\n" |
| 141 print stderr | 144 print stderr |
| 142 | 145 |
| 143 | 146 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 '\n'.join(' %s=%s' % | 183 '\n'.join(' %s=%s' % |
| 181 (k, v) for k, v in sorted(extra_env.iteritems())), | 184 (k, v) for k, v in sorted(extra_env.iteritems())), |
| 182 ' '.join(cmd))) | 185 ' '.join(cmd))) |
| 183 env.update(extra_env or {}) | 186 env.update(extra_env or {}) |
| 184 try: | 187 try: |
| 185 # See above comment regarding offline symbolization. | 188 # See above comment regarding offline symbolization. |
| 186 if use_symbolization_script: | 189 if use_symbolization_script: |
| 187 # Need to pipe to the symbolizer script. | 190 # Need to pipe to the symbolizer script. |
| 188 p1 = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, | 191 p1 = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, |
| 189 stderr=sys.stdout) | 192 stderr=sys.stdout) |
| 190 p2 = subprocess.Popen(get_sanitizer_symbolize_command(), | 193 p2 = subprocess.Popen( |
| 191 env=env, stdin=p1.stdout) | 194 get_sanitizer_symbolize_command(executable_path=cmd[0]), |
|
earthdok
2015/02/05 17:56:00
cmd[0] is not guaranteed to be the test binary
tak
| |
| 195 env=env, stdin=p1.stdout) | |
| 192 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. | 196 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. |
| 193 p1.wait() | 197 p1.wait() |
| 194 p2.wait() | 198 p2.wait() |
| 195 # Also feed the out-of-band JSON output to the symbolizer script. | 199 # Also feed the out-of-band JSON output to the symbolizer script. |
| 196 symbolize_snippets_in_json(cmd, env) | 200 symbolize_snippets_in_json(cmd, env) |
| 197 return p1.returncode | 201 return p1.returncode |
| 198 else: | 202 else: |
| 199 return subprocess.call(cmd, env=env) | 203 return subprocess.call(cmd, env=env) |
| 200 except OSError: | 204 except OSError: |
| 201 print >> sys.stderr, 'Failed to start %s' % cmd | 205 print >> sys.stderr, 'Failed to start %s' % cmd |
| 202 raise | 206 raise |
| 203 | 207 |
| 204 | 208 |
| 205 def main(): | 209 def main(): |
| 206 return run_executable(sys.argv[1:], os.environ.copy()) | 210 return run_executable(sys.argv[1:], os.environ.copy()) |
| 207 | 211 |
| 208 | 212 |
| 209 if __name__ == '__main__': | 213 if __name__ == '__main__': |
| 210 sys.exit(main()) | 214 sys.exit(main()) |
| OLD | NEW |