Show More
@@ -45,6 +45,7 b' import difflib' | |||
|
45 | 45 | import errno |
|
46 | 46 | import optparse |
|
47 | 47 | import os |
|
48 | import signal | |
|
48 | 49 | import subprocess |
|
49 | 50 | import shutil |
|
50 | 51 | import signal |
@@ -283,6 +284,31 b' def checktools():' | |||
|
283 | 284 | else: |
|
284 | 285 | print "WARNING: Did not find prerequisite tool: "+p |
|
285 | 286 | |
|
287 | def killdaemons(): | |
|
288 | # Kill off any leftover daemon processes | |
|
289 | try: | |
|
290 | fp = open(DAEMON_PIDS) | |
|
291 | for line in fp: | |
|
292 | try: | |
|
293 | pid = int(line) | |
|
294 | except ValueError: | |
|
295 | continue | |
|
296 | try: | |
|
297 | os.kill(pid, 0) | |
|
298 | vlog('# Killing daemon process %d' % pid) | |
|
299 | os.kill(pid, signal.SIGTERM) | |
|
300 | time.sleep(0.25) | |
|
301 | os.kill(pid, 0) | |
|
302 | vlog('# Daemon process %d is stuck - really killing it' % pid) | |
|
303 | os.kill(pid, signal.SIGKILL) | |
|
304 | except OSError, err: | |
|
305 | if err.errno != errno.ESRCH: | |
|
306 | raise | |
|
307 | fp.close() | |
|
308 | os.unlink(DAEMON_PIDS) | |
|
309 | except IOError: | |
|
310 | pass | |
|
311 | ||
|
286 | 312 | def cleanup(options): |
|
287 | 313 | if not options.keep_tmpdir: |
|
288 | 314 | vlog("# Cleaning up HGTMP", HGTMP) |
@@ -432,6 +458,14 b' def run(cmd, options):' | |||
|
432 | 458 | ret = 0 |
|
433 | 459 | else: |
|
434 | 460 | proc = Popen4(cmd) |
|
461 | def cleanup(): | |
|
462 | os.kill(proc.pid, signal.SIGTERM) | |
|
463 | ret = proc.wait() | |
|
464 | if ret == 0: | |
|
465 | ret = signal.SIGTERM << 8 | |
|
466 | killdaemons() | |
|
467 | return ret | |
|
468 | ||
|
435 | 469 | try: |
|
436 | 470 | output = '' |
|
437 | 471 | proc.tochild.close() |
@@ -441,12 +475,14 b' def run(cmd, options):' | |||
|
441 | 475 | ret = os.WEXITSTATUS(ret) |
|
442 | 476 | except Timeout: |
|
443 | 477 | vlog('# Process %d timed out - killing it' % proc.pid) |
|
444 | os.kill(proc.pid, signal.SIGTERM) | |
|
445 | ret = proc.wait() | |
|
446 | if ret == 0: | |
|
447 | ret = signal.SIGTERM << 8 | |
|
478 | ret = cleanup() | |
|
448 | 479 | output += ("\n### Abort: timeout after %d seconds.\n" |
|
449 | 480 | % options.timeout) |
|
481 | except KeyboardInterrupt: | |
|
482 | vlog('# Handling keyboard interrupt') | |
|
483 | cleanup() | |
|
484 | raise | |
|
485 | ||
|
450 | 486 | return ret, splitnewlines(output) |
|
451 | 487 | |
|
452 | 488 | def runone(options, test, skips, fails): |
@@ -589,29 +625,7 b' def runone(options, test, skips, fails):' | |||
|
589 | 625 | f.write(line) |
|
590 | 626 | f.close() |
|
591 | 627 | |
|
592 | # Kill off any leftover daemon processes | |
|
593 | try: | |
|
594 | fp = open(DAEMON_PIDS) | |
|
595 | for line in fp: | |
|
596 | try: | |
|
597 | pid = int(line) | |
|
598 | except ValueError: | |
|
599 | continue | |
|
600 | try: | |
|
601 | os.kill(pid, 0) | |
|
602 | vlog('# Killing daemon process %d' % pid) | |
|
603 | os.kill(pid, signal.SIGTERM) | |
|
604 | time.sleep(0.25) | |
|
605 | os.kill(pid, 0) | |
|
606 | vlog('# Daemon process %d is stuck - really killing it' % pid) | |
|
607 | os.kill(pid, signal.SIGKILL) | |
|
608 | except OSError, err: | |
|
609 | if err.errno != errno.ESRCH: | |
|
610 | raise | |
|
611 | fp.close() | |
|
612 | os.unlink(DAEMON_PIDS) | |
|
613 | except IOError: | |
|
614 | pass | |
|
628 | killdaemons() | |
|
615 | 629 | |
|
616 | 630 | os.chdir(TESTDIR) |
|
617 | 631 | if not options.keep_tmpdir: |
@@ -672,6 +686,7 b' def runchildren(options, tests):' | |||
|
672 | 686 | break |
|
673 | 687 | job.append(tests.pop()) |
|
674 | 688 | fps = {} |
|
689 | ||
|
675 | 690 | for j, job in enumerate(jobs): |
|
676 | 691 | if not job: |
|
677 | 692 | continue |
@@ -683,6 +698,7 b' def runchildren(options, tests):' | |||
|
683 | 698 | vlog(' '.join(cmdline)) |
|
684 | 699 | fps[os.spawnvp(os.P_NOWAIT, cmdline[0], cmdline)] = os.fdopen(rfd, 'r') |
|
685 | 700 | os.close(wfd) |
|
701 | signal.signal(signal.SIGINT, signal.SIG_IGN) | |
|
686 | 702 | failures = 0 |
|
687 | 703 | tested, skipped, failed = 0, 0, 0 |
|
688 | 704 | skips = [] |
@@ -691,7 +707,10 b' def runchildren(options, tests):' | |||
|
691 | 707 | pid, status = os.wait() |
|
692 | 708 | fp = fps.pop(pid) |
|
693 | 709 | l = fp.read().splitlines() |
|
694 | test, skip, fail = map(int, l[:3]) | |
|
710 | try: | |
|
711 | test, skip, fail = map(int, l[:3]) | |
|
712 | except ValueError: | |
|
713 | test, skip, fail = 0, 0, 0 | |
|
695 | 714 | split = -fail or len(l) |
|
696 | 715 | for s in l[3:split]: |
|
697 | 716 | skips.append(s.split(" ", 1)) |
@@ -925,6 +944,7 b' def main():' | |||
|
925 | 944 | else: |
|
926 | 945 | runtests(options, tests) |
|
927 | 946 | finally: |
|
947 | time.sleep(1) | |
|
928 | 948 | cleanup(options) |
|
929 | 949 | |
|
930 | 950 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now