diff -r 9bdbae6007cb -r 4da6285efe4c tests/run-tests.py --- a/tests/run-tests.py Fri Feb 05 17:57:36 2010 +0000 +++ b/tests/run-tests.py Wed Feb 17 11:15:18 2010 +0100 @@ -41,11 +41,11 @@ # completes fairly quickly, includes both shell and Python scripts, and # includes some scripts that run daemon processes.) -from ConfigParser import ConfigParser import difflib import errno import optparse import os +import signal import subprocess import shutil import signal @@ -134,8 +134,7 @@ parser.add_option("--inotify", action="store_true", help="enable inotify extension when running tests") parser.add_option("--blacklist", action="append", - help="skip tests listed in the specified section of " - "the blacklist file") + help="skip tests listed in the specified blacklist file") for option, default in defaults.items(): defaults[option] = int(os.environ.get(*default)) @@ -202,12 +201,22 @@ if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0): parser.error('--py3k-warnings can only be used on Python 2.6+') if options.blacklist: - configparser = ConfigParser() - configparser.read("blacklist") blacklist = dict() - for section in options.blacklist: - for (item, value) in configparser.items(section): - blacklist["test-" + item] = section + for filename in options.blacklist: + try: + path = os.path.expanduser(os.path.expandvars(filename)) + f = open(path, "r") + except IOError, err: + if err.errno != errno.ENOENT: + raise + print "warning: no such blacklist file: %s" % filename + continue + + for line in f.readlines(): + line = line.strip() + if line and not line.startswith('#'): + blacklist[line] = filename + options.blacklist = blacklist return (options, args) @@ -231,7 +240,7 @@ if last: lines.append(last) return lines - lines.append(text[i:n+1]) + lines.append(text[i:n + 1]) i = n + 1 def parsehghaveoutput(lines): @@ -275,6 +284,31 @@ else: print "WARNING: Did not find prerequisite tool: "+p +def killdaemons(): + # Kill off any leftover daemon processes + try: + fp = open(DAEMON_PIDS) + for line in fp: + try: + pid = int(line) + except ValueError: + continue + try: + os.kill(pid, 0) + vlog('# Killing daemon process %d' % pid) + os.kill(pid, signal.SIGTERM) + time.sleep(0.25) + os.kill(pid, 0) + vlog('# Daemon process %d is stuck - really killing it' % pid) + os.kill(pid, signal.SIGKILL) + except OSError, err: + if err.errno != errno.ESRCH: + raise + fp.close() + os.unlink(DAEMON_PIDS) + except IOError: + pass + def cleanup(options): if not options.keep_tmpdir: vlog("# Cleaning up HGTMP", HGTMP) @@ -424,6 +458,14 @@ ret = 0 else: proc = Popen4(cmd) + def cleanup(): + os.kill(proc.pid, signal.SIGTERM) + ret = proc.wait() + if ret == 0: + ret = signal.SIGTERM << 8 + killdaemons() + return ret + try: output = '' proc.tochild.close() @@ -433,12 +475,14 @@ ret = os.WEXITSTATUS(ret) except Timeout: vlog('# Process %d timed out - killing it' % proc.pid) - os.kill(proc.pid, signal.SIGTERM) - ret = proc.wait() - if ret == 0: - ret = signal.SIGTERM << 8 + ret = cleanup() output += ("\n### Abort: timeout after %d seconds.\n" % options.timeout) + except KeyboardInterrupt: + vlog('# Handling keyboard interrupt') + cleanup() + raise + return ret, splitnewlines(output) def runone(options, test, skips, fails): @@ -581,29 +625,7 @@ f.write(line) f.close() - # Kill off any leftover daemon processes - try: - fp = open(DAEMON_PIDS) - for line in fp: - try: - pid = int(line) - except ValueError: - continue - try: - os.kill(pid, 0) - vlog('# Killing daemon process %d' % pid) - os.kill(pid, signal.SIGTERM) - time.sleep(0.25) - os.kill(pid, 0) - vlog('# Daemon process %d is stuck - really killing it' % pid) - os.kill(pid, signal.SIGKILL) - except OSError, err: - if err.errno != errno.ESRCH: - raise - fp.close() - os.unlink(DAEMON_PIDS) - except IOError: - pass + killdaemons() os.chdir(TESTDIR) if not options.keep_tmpdir: @@ -660,9 +682,11 @@ jobs = [[] for j in xrange(options.jobs)] while tests: for job in jobs: - if not tests: break + if not tests: + break job.append(tests.pop()) fps = {} + for j, job in enumerate(jobs): if not job: continue @@ -674,6 +698,7 @@ vlog(' '.join(cmdline)) fps[os.spawnvp(os.P_NOWAIT, cmdline[0], cmdline)] = os.fdopen(rfd, 'r') os.close(wfd) + signal.signal(signal.SIGINT, signal.SIG_IGN) failures = 0 tested, skipped, failed = 0, 0, 0 skips = [] @@ -682,7 +707,10 @@ pid, status = os.wait() fp = fps.pop(pid) l = fp.read().splitlines() - test, skip, fail = map(int, l[:3]) + try: + test, skip, fail = map(int, l[:3]) + except ValueError: + test, skip, fail = 0, 0, 0 split = -fail or len(l) for s in l[3:split]: skips.append(s.split(" ", 1)) @@ -743,9 +771,9 @@ for test in tests: if options.blacklist: - section = options.blacklist.get(test) - if section is not None: - skips.append((test, "blacklisted (%s section)" % section)) + filename = options.blacklist.get(test) + if filename is not None: + skips.append((test, "blacklisted (%s)" % filename)) skipped += 1 continue @@ -759,7 +787,7 @@ if k in t: break else: - skipped +=1 + skipped += 1 continue ret = runone(options, test, skips, fails) @@ -915,6 +943,7 @@ else: runtests(options, tests) finally: + time.sleep(1) cleanup(options) main()