##// END OF EJS Templates
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall -
r14019:fbbd5f91 default
parent child Browse files
Show More
@@ -55,12 +55,20 b' import time'
55 55 import re
56 56 import threading
57 57
58 processlock = threading.Lock()
59
58 60 closefds = os.name == 'posix'
59 def Popen4(cmd, timeout):
61 def Popen4(cmd, wd, timeout):
62 processlock.acquire()
63 orig = os.getcwd()
64 os.chdir(wd)
60 65 p = subprocess.Popen(cmd, shell=True, bufsize=-1,
61 66 close_fds=closefds,
62 67 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
63 68 stderr=subprocess.STDOUT)
69 os.chdir(orig)
70 processlock.release()
71
64 72 p.fromchild = p.stdout
65 73 p.tochild = p.stdin
66 74 p.childerr = p.stderr
@@ -457,16 +465,16 b' def outputcoverage(options):'
457 465 os.mkdir(adir)
458 466 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
459 467
460 def pytest(test, options, replacements):
468 def pytest(test, wd, options, replacements):
461 469 py3kswitch = options.py3k_warnings and ' -3' or ''
462 470 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test)
463 471 vlog("# Running", cmd)
464 return run(cmd, options, replacements)
472 return run(cmd, wd, options, replacements)
465 473
466 def shtest(test, options, replacements):
474 def shtest(test, wd, options, replacements):
467 475 cmd = '"%s"' % test
468 476 vlog("# Running", cmd)
469 return run(cmd, options, replacements)
477 return run(cmd, wd, options, replacements)
470 478
471 479 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
472 480 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
@@ -477,7 +485,7 b' def escapef(m):'
477 485 def stringescape(s):
478 486 return escapesub(escapef, s)
479 487
480 def tsttest(test, options, replacements):
488 def tsttest(test, wd, options, replacements):
481 489 t = open(test)
482 490 out = []
483 491 script = []
@@ -518,7 +526,7 b' def tsttest(test, options, replacements)'
518 526
519 527 cmd = '/bin/sh "%s"' % name
520 528 vlog("# Running", cmd)
521 exitcode, output = run(cmd, options, replacements)
529 exitcode, output = run(cmd, wd, options, replacements)
522 530 # do not merge output if skipped, return hghave message instead
523 531 # similarly, with --debug, output is None
524 532 if exitcode == SKIPPED_STATUS or output is None:
@@ -597,7 +605,7 b' def tsttest(test, options, replacements)'
597 605 return exitcode, postout
598 606
599 607 wifexited = getattr(os, "WIFEXITED", lambda x: False)
600 def run(cmd, options, replacements):
608 def run(cmd, wd, options, replacements):
601 609 """Run command in a sub-process, capturing the output (stdout and stderr).
602 610 Return a tuple (exitcode, output). output is None in debug mode."""
603 611 # TODO: Use subprocess.Popen if we're running on Python 2.4
@@ -614,7 +622,7 b' def run(cmd, options, replacements):'
614 622 if ret is None:
615 623 ret = 0
616 624 else:
617 proc = Popen4(cmd, options.timeout)
625 proc = Popen4(cmd, wd, options.timeout)
618 626 def cleanup():
619 627 try:
620 628 proc.terminate()
@@ -775,9 +783,7 b' def runone(options, test):'
775 783 os.path.join(HGTMP, test)
776 784
777 785 os.mkdir(testtmp)
778 os.chdir(testtmp)
779
780 ret, out = runner(testpath, options, [
786 ret, out = runner(testpath, testtmp, options, [
781 787 (re.escape(testtmp), '$TESTTMP'),
782 788 (r':%s\b' % options.port, ':$HGPORT'),
783 789 (r':%s\b' % (options.port + 1), ':$HGPORT1'),
@@ -852,7 +858,6 b' def runone(options, test):'
852 858
853 859 killdaemons()
854 860
855 os.chdir(TESTDIR)
856 861 if not options.keep_tmpdir:
857 862 shutil.rmtree(testtmp, True)
858 863 if skipped:
General Comments 0
You need to be logged in to leave comments. Login now