Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: dart/tools/testing/drt-trampoline.py

Issue 10834363: Install a signal handler to ensure drt-trampoline.py cleans up after itself. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add a few comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 # 4 #
5 # For now we have to use this trampoline to turn --dart-flags command line 5 # For now we have to use this trampoline to turn --dart-flags command line
6 # switch into env variable DART_FLAGS. Eventually, DumpRenderTree should 6 # switch into env variable DART_FLAGS. Eventually, DumpRenderTree should
7 # support --dart-flags and this hack may go away. 7 # support --dart-flags and this hack may go away.
8 # 8 #
9 # Expected invocation: python drt-trampoline.py <path to DRT> <DRT command line> 9 # Expected invocation: python drt-trampoline.py <path to DRT> <DRT command line>
10 10
11 import os 11 import os
12 import signal
12 import subprocess 13 import subprocess
13 import sys 14 import sys
14 15
15 DART_FLAGS_PREFIX = '--dart-flags=' 16 DART_FLAGS_PREFIX = '--dart-flags='
16 OUT_EXPECTATION_PREFIX = '--out-expectation=' 17 OUT_EXPECTATION_PREFIX = '--out-expectation='
17 18
18 def main(argv): 19 def main(argv):
19 drt_path = argv[1] 20 drt_path = argv[1]
20 command_line = argv[2:] 21 command_line = argv[2:]
21 22
(...skipping 24 matching lines...) Expand all
46 cmd.append(arg) 47 cmd.append(arg)
47 48
48 if is_png: 49 if is_png:
49 # pixel tests are specified by running DRT "foo.html'-p" 50 # pixel tests are specified by running DRT "foo.html'-p"
50 cmd.append(test_file + "'-p") 51 cmd.append(test_file + "'-p")
51 else: 52 else:
52 cmd.append(test_file) 53 cmd.append(test_file)
53 54
54 stdout = subprocess.PIPE if out_expected_file else None 55 stdout = subprocess.PIPE if out_expected_file else None
55 p = subprocess.Popen(cmd, env=env, stdout=stdout) 56 p = subprocess.Popen(cmd, env=env, stdout=stdout)
57
58 def signal_handler(signal, frame):
59 p.terminate()
60 sys.exit(0)
61
62 # SIGINT is Ctrl-C.
63 signal.signal(signal.SIGINT, signal_handler)
64 # SIGTERM is sent by test.dart when a process times out.
65 signal.signal(signal.SIGTERM, signal_handler)
56 output, error = p.communicate() 66 output, error = p.communicate()
67 signal.signal(signal.SIGINT, signal.SIG_DFL)
68 signal.signal(signal.SIGTERM, signal.SIG_DFL)
69
57 if p.returncode != 0: 70 if p.returncode != 0:
58 raise Exception('Failed to run command. return code=%s' % p.returncode) 71 raise Exception('Failed to run command. return code=%s' % p.returncode)
59 72
60 if out_expected_file: 73 if out_expected_file:
61 # Compare output to the given expectation file. 74 # Compare output to the given expectation file.
62 expectation = None 75 expectation = None
63 if is_png: 76 if is_png:
64 # DRT prints the image to STDOUT, but includes extra text that we trim: 77 # DRT prints the image to STDOUT, but includes extra text that we trim:
65 # - several header lines until a line saying 'Content-Length:' 78 # - several header lines until a line saying 'Content-Length:'
66 # - a '#EOF\n' at the end 79 # - a '#EOF\n' at the end
(...skipping 28 matching lines...) Expand all
95 print 'You can update expectations by running:\n' 108 print 'You can update expectations by running:\n'
96 print 'cp %s %s\n' % (out_file, out_expected_file) 109 print 'cp %s %s\n' % (out_file, out_expected_file)
97 print '#EOF' 110 print '#EOF'
98 111
99 if __name__ == '__main__': 112 if __name__ == '__main__':
100 try: 113 try:
101 sys.exit(main(sys.argv)) 114 sys.exit(main(sys.argv))
102 except StandardError as e: 115 except StandardError as e:
103 print 'Fail: ' + str(e) 116 print 'Fail: ' + str(e)
104 sys.exit(1) 117 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698