Skip to content
Snippets Groups Projects
Commit d17e5d78 authored by Manuel Jacob's avatar Manuel Jacob
Browse files

tests: update vendored test infrastructure from hg@07b79569fdf8

After copying the files, a6ddd3f835af was
reapplied.
parent 91649f46
No related branches found
No related tags found
1 merge request!15update vendored test infrastructure
Pipeline #
......@@ -9,6 +9,13 @@
# The mercurial source repository was typically orignally cloned with the
# system mercurial installation, and may require extensions or settings from
# the system installation.
if [ -n "$HGTESTEXTRAEXTENSIONS" ]; then
for extension in $HGTESTEXTRAEXTENSIONS; do
extraoptions="$extraoptions --config extensions.$extension=!"
done
fi
syshg () {
(
syshgenv
......@@ -48,6 +55,6 @@
alias testrepohg=syshg
alias testrepohgenv=syshgenv
else
alias testrepohg=hg
alias testrepohg="hg $extraoptions"
alias testrepohgenv=:
fi
from __future__ import absolute_import, print_function
import sys
......@@ -1,3 +3,9 @@
import sys
def flush():
sys.stdout.flush()
sys.stderr.flush()
globalvars = {}
......@@ -3,6 +11,5 @@
globalvars = {}
localvars = {}
lines = sys.stdin.readlines()
while lines:
l = lines.pop(0)
if l.startswith('SALT'):
......@@ -5,9 +12,9 @@
lines = sys.stdin.readlines()
while lines:
l = lines.pop(0)
if l.startswith('SALT'):
print l[:-1]
print(l[:-1])
elif l.startswith('>>> '):
snippet = l[4:]
while lines and lines[0].startswith('... '):
l = lines.pop(0)
......@@ -10,7 +17,7 @@
elif l.startswith('>>> '):
snippet = l[4:]
while lines and lines[0].startswith('... '):
l = lines.pop(0)
snippet += "\n" + l[4:]
snippet += l[4:]
c = compile(snippet, '<heredoc>', 'single')
try:
......@@ -15,5 +22,8 @@
c = compile(snippet, '<heredoc>', 'single')
try:
exec c in globalvars, localvars
except Exception, inst:
print repr(inst)
flush()
exec(c, globalvars)
flush()
except Exception as inst:
flush()
print(repr(inst))
......@@ -13,8 +13,9 @@
checks = hghave.checks
def list_features():
for name, feature in sorted(checks.items()):
desc = feature[1]
print(name + ':', desc)
......@@ -16,8 +17,9 @@
def list_features():
for name, feature in sorted(checks.items()):
desc = feature[1]
print(name + ':', desc)
def test_features():
failed = 0
for name, feature in checks.items():
......@@ -29,4 +31,5 @@
failed += 1
return failed
parser = optparse.OptionParser("%prog [options] [features]")
......@@ -32,8 +35,11 @@
parser = optparse.OptionParser("%prog [options] [features]")
parser.add_option("--test-features", action="store_true",
help="test available features")
parser.add_option("--list-features", action="store_true",
help="list available features")
parser.add_option(
"--test-features", action="store_true", help="test available features"
)
parser.add_option(
"--list-features", action="store_true", help="list available features"
)
def _loadaddon():
if 'TESTDIR' in os.environ:
......@@ -49,5 +55,6 @@
sys.path.insert(0, path)
try:
import hghaveaddon
assert hghaveaddon # silence pyflakes
except BaseException as inst:
......@@ -52,7 +59,8 @@
assert hghaveaddon # silence pyflakes
except BaseException as inst:
sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
% (path, inst))
sys.stderr.write(
'failed to import hghaveaddon.py from %r: %s\n' % (path, inst)
)
sys.exit(2)
sys.path.pop(0)
......@@ -56,6 +64,7 @@
sys.exit(2)
sys.path.pop(0)
if __name__ == '__main__':
options, args = parser.parse_args()
_loadaddon()
......
This diff is collapsed.
#!/usr/bin/env python
import os, sys, time, errno, signal
from __future__ import absolute_import
import errno
import os
import signal
import sys
import time
if os.name == 'nt':
import ctypes
_BOOL = ctypes.c_long
_DWORD = ctypes.c_ulong
_UINT = ctypes.c_uint
_HANDLE = ctypes.c_void_p
......@@ -4,6 +17,18 @@
if os.name =='nt':
import ctypes
ctypes.windll.kernel32.CloseHandle.argtypes = [_HANDLE]
ctypes.windll.kernel32.CloseHandle.restype = _BOOL
ctypes.windll.kernel32.GetLastError.argtypes = []
ctypes.windll.kernel32.GetLastError.restype = _DWORD
ctypes.windll.kernel32.OpenProcess.argtypes = [_DWORD, _BOOL, _DWORD]
ctypes.windll.kernel32.OpenProcess.restype = _HANDLE
ctypes.windll.kernel32.TerminateProcess.argtypes = [_HANDLE, _UINT]
ctypes.windll.kernel32.TerminateProcess.restype = _BOOL
ctypes.windll.kernel32.WaitForSingleObject.argtypes = [_HANDLE, _DWORD]
ctypes.windll.kernel32.WaitForSingleObject.restype = _DWORD
def _check(ret, expectederr=None):
if ret == 0:
......@@ -16,6 +41,6 @@
logfn('# Killing daemon process %d' % pid)
PROCESS_TERMINATE = 1
PROCESS_QUERY_INFORMATION = 0x400
SYNCHRONIZE = 0x00100000L
SYNCHRONIZE = 0x00100000
WAIT_OBJECT_0 = 0
WAIT_TIMEOUT = 258
......@@ -20,3 +45,4 @@
WAIT_OBJECT_0 = 0
WAIT_TIMEOUT = 258
WAIT_FAILED = _DWORD(0xFFFFFFFF).value
handle = ctypes.windll.kernel32.OpenProcess(
......@@ -22,9 +48,11 @@
handle = ctypes.windll.kernel32.OpenProcess(
PROCESS_TERMINATE|SYNCHRONIZE|PROCESS_QUERY_INFORMATION,
False, pid)
if handle == 0:
_check(0, 87) # err 87 when process not found
return # process not found, already finished
PROCESS_TERMINATE | SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
False,
pid,
)
if handle is None:
_check(0, 87) # err 87 when process not found
return # process not found, already finished
try:
r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100)
if r == WAIT_OBJECT_0:
......@@ -28,6 +56,6 @@
try:
r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100)
if r == WAIT_OBJECT_0:
pass # terminated, but process handle still available
pass # terminated, but process handle still available
elif r == WAIT_TIMEOUT:
_check(ctypes.windll.kernel32.TerminateProcess(handle, -1))
......@@ -32,8 +60,8 @@
elif r == WAIT_TIMEOUT:
_check(ctypes.windll.kernel32.TerminateProcess(handle, -1))
else:
_check(r)
elif r == WAIT_FAILED:
_check(0) # err stored in GetLastError()
# TODO?: forcefully kill when timeout
# and ?shorter waiting time? when tryhard==True
r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100)
......@@ -36,6 +64,6 @@
# TODO?: forcefully kill when timeout
# and ?shorter waiting time? when tryhard==True
r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100)
# timeout = 100 ms
# timeout = 100 ms
if r == WAIT_OBJECT_0:
......@@ -41,4 +69,4 @@
if r == WAIT_OBJECT_0:
pass # process is terminated
pass # process is terminated
elif r == WAIT_TIMEOUT:
logfn('# Daemon process %d is stuck')
......@@ -43,9 +71,9 @@
elif r == WAIT_TIMEOUT:
logfn('# Daemon process %d is stuck')
else:
check(r) # any error
except: #re-raises
ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error
elif r == WAIT_FAILED:
_check(0) # err stored in GetLastError()
except: # re-raises
ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error
raise
_check(ctypes.windll.kernel32.CloseHandle(handle))
......@@ -49,4 +77,5 @@
raise
_check(ctypes.windll.kernel32.CloseHandle(handle))
else:
......@@ -52,4 +81,5 @@
else:
def kill(pid, logfn, tryhard=True):
try:
os.kill(pid, 0)
......@@ -64,7 +94,7 @@
os.kill(pid, 0)
logfn('# Daemon process %d is stuck - really killing it' % pid)
os.kill(pid, signal.SIGKILL)
except OSError, err:
except OSError as err:
if err.errno != errno.ESRCH:
raise
......@@ -68,8 +98,9 @@
if err.errno != errno.ESRCH:
raise
def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
if not logfn:
logfn = lambda s: s
# Kill off any leftover daemon processes
try:
......@@ -71,12 +102,21 @@
def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
if not logfn:
logfn = lambda s: s
# Kill off any leftover daemon processes
try:
fp = open(pidfile)
for line in fp:
try:
pid = int(line)
except ValueError:
continue
pids = []
with open(pidfile) as fp:
for line in fp:
try:
pid = int(line)
if pid <= 0:
raise ValueError
except ValueError:
logfn(
'# Not killing daemon process %s - invalid pid'
% line.rstrip()
)
continue
pids.append(pid)
for pid in pids:
kill(pid, logfn, tryhard)
......@@ -82,7 +122,6 @@
kill(pid, logfn, tryhard)
fp.close()
if remove:
os.unlink(pidfile)
except IOError:
pass
......@@ -84,6 +123,7 @@
if remove:
os.unlink(pidfile)
except IOError:
pass
if __name__ == '__main__':
......@@ -89,4 +129,6 @@
if __name__ == '__main__':
path, = sys.argv[1:]
killdaemons(path)
if len(sys.argv) > 1:
(path,) = sys.argv[1:]
else:
path = os.environ["DAEMON_PIDS"]
......@@ -92,1 +134,2 @@
killdaemons(path, remove=True)
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment