| OLD | NEW |
| 1 #!/bin/env python | 1 #!/bin/env python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 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 # common.py | 6 # common.py |
| 7 | 7 |
| 8 """ Common code used by purify_test.py and quantify_test.py in order to automate | 8 """ Common code used by purify_test.py and quantify_test.py in order to automate |
| 9 running of Rational Purify and Quantify in a consistent manner. | 9 running of Rational Purify and Quantify in a consistent manner. |
| 10 """ | 10 """ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 else: | 76 else: |
| 77 # For non-detached processes, manually read and print out stdout and stderr. | 77 # For non-detached processes, manually read and print out stdout and stderr. |
| 78 # By default, the subprocess is supposed to inherit these from its parent, | 78 # By default, the subprocess is supposed to inherit these from its parent, |
| 79 # however when run under buildbot, it seems unable to read data from a | 79 # however when run under buildbot, it seems unable to read data from a |
| 80 # grandchild process, so we have to read the child and print the data as if | 80 # grandchild process, so we have to read the child and print the data as if |
| 81 # it came from us for buildbot to read it. We're not sure why this is | 81 # it came from us for buildbot to read it. We're not sure why this is |
| 82 # necessary. | 82 # necessary. |
| 83 # TODO(erikkay): should we buffer stderr and stdout separately? | 83 # TODO(erikkay): should we buffer stderr and stdout separately? |
| 84 p = subprocess.Popen(proc, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 84 p = subprocess.Popen(proc, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 85 | 85 |
| 86 logging.info("started subprocess") |
| 87 |
| 86 # How long to wait (in seconds) before printing progress log messages. | 88 # How long to wait (in seconds) before printing progress log messages. |
| 87 progress_delay = 300 | 89 progress_delay = 300 |
| 88 progress_delay_time = time.time() + progress_delay | 90 progress_delay_time = time.time() + progress_delay |
| 89 did_timeout = False | 91 did_timeout = False |
| 90 if timeout > 0: | 92 if timeout > 0: |
| 91 wait_until = time.time() + timeout | 93 wait_until = time.time() + timeout |
| 92 while p.poll() is None and not did_timeout: | 94 while p.poll() is None and not did_timeout: |
| 93 if not detach: | 95 if not detach: |
| 94 line = p.stdout.readline() | 96 line = p.stdout.readline() |
| 95 while line: | 97 while line: |
| 96 _print_line(line) | 98 _print_line(line) |
| 97 line = p.stdout.readline() | 99 line = p.stdout.readline() |
| 98 else: | 100 else: |
| 99 # When we detach, blocking on reading stdout doesn't work, so we sleep | 101 # When we detach, blocking on reading stdout doesn't work, so we sleep |
| 100 # a short time and poll. | 102 # a short time and poll. |
| 101 time.sleep(0.5) | 103 time.sleep(0.5) |
| 102 if time.time() >= progress_delay_time: | 104 if time.time() >= progress_delay_time: |
| 103 # Force output on a periodic basis to avoid getting killed off by the | 105 # Force output on a periodic basis to avoid getting killed off by the |
| 104 # buildbot. | 106 # buildbot. |
| 105 # TODO(erikkay): I'd prefer a less obtrusive 'print ".",' with a flush | 107 # TODO(erikkay): I'd prefer a less obtrusive 'print ".",' with a flush |
| 106 # but because of how we're doing subprocesses, this doesn't appear to | 108 # but because of how we're doing subprocesses, this doesn't appear to |
| 107 # work reliably. | 109 # work reliably. |
| 108 logging.info("%s still running..." % os.path.basename(proc[0])) | 110 logging.info("%s still running..." % os.path.basename(proc[0])) |
| 109 progress_delay_time = time.time() + progress_delay | 111 progress_delay_time = time.time() + progress_delay |
| 110 if timeout > 0: | 112 if timeout > 0: |
| 111 did_timeout = time.time() > wait_until | 113 did_timeout = time.time() > wait_until |
| 112 | 114 |
| 113 if did_timeout: | 115 if did_timeout: |
| 116 logging.info("process timed out") |
| 117 else: |
| 118 logging.info("process ended, did not time out") |
| 119 |
| 120 if did_timeout: |
| 114 subprocess.call(["taskkill", "/T", "/F", "/PID", str(p.pid)]) | 121 subprocess.call(["taskkill", "/T", "/F", "/PID", str(p.pid)]) |
| 115 logging.error("KILLED %d" % p.pid) | 122 logging.error("KILLED %d" % p.pid) |
| 116 # Give the process a chance to actually die before continuing | 123 # Give the process a chance to actually die before continuing |
| 117 # so that cleanup can happen safely. | 124 # so that cleanup can happen safely. |
| 118 time.sleep(1.0) | 125 time.sleep(1.0) |
| 119 logging.error("TIMEOUT waiting for %s" % proc[0]) | 126 logging.error("TIMEOUT waiting for %s" % proc[0]) |
| 120 raise TimeoutError(proc[0]) | 127 raise TimeoutError(proc[0]) |
| 121 elif not detach: | 128 elif not detach: |
| 122 for line in p.stdout.readlines(): | 129 for line in p.stdout.readlines(): |
| 123 _print_line(line, False) | 130 _print_line(line, False) |
| 131 logging.info("flushing stdout") |
| 124 p.stdout.flush() | 132 p.stdout.flush() |
| 125 | 133 |
| 134 logging.info("collecting result code") |
| 126 result = p.poll() | 135 result = p.poll() |
| 127 if result: | 136 if result: |
| 128 logging.error("%s exited with non-zero result code %d" % (proc[0], result)) | 137 logging.error("%s exited with non-zero result code %d" % (proc[0], result)) |
| 129 return result | 138 return result |
| 130 | 139 |
| 131 | 140 |
| 132 def FixPath(path): | 141 def FixPath(path): |
| 133 """We pass computed paths to Rational as arguments, so these paths must be | 142 """We pass computed paths to Rational as arguments, so these paths must be |
| 134 valid windows paths. When running in cygwin's python, computed paths | 143 valid windows paths. When running in cygwin's python, computed paths |
| 135 wind up looking like /cygdrive/c/..., so we need to call out to cygpath | 144 wind up looking like /cygdrive/c/..., so we need to call out to cygpath |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 file = os.path.join(self._cache_dir, cfile); | 327 file = os.path.join(self._cache_dir, cfile); |
| 319 if os.path.isfile(file): | 328 if os.path.isfile(file): |
| 320 try: | 329 try: |
| 321 os.remove(file) | 330 os.remove(file) |
| 322 except: | 331 except: |
| 323 logging.warning("unable to delete file %s: %s" % (file, | 332 logging.warning("unable to delete file %s: %s" % (file, |
| 324 sys.exc_info()[0])) | 333 sys.exc_info()[0])) |
| 325 | 334 |
| 326 | 335 |
| 327 | 336 |
| OLD | NEW |