summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpy/allTests.py36
-rw-r--r--py/config/TestUtil.py226
-rw-r--r--py/python/Ice.py16
-rw-r--r--py/test/Ice/binding/Server.py1
-rw-r--r--py/test/Ice/faultTolerance/Server.py6
-rwxr-xr-xpy/test/Ice/faultTolerance/run.py40
6 files changed, 221 insertions, 104 deletions
diff --git a/py/allTests.py b/py/allTests.py
index 0041464267d..731c5f86232 100755
--- a/py/allTests.py
+++ b/py/allTests.py
@@ -18,10 +18,7 @@ for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
else:
raise "can't find toplevel directory!"
-sys.path.append(os.path.join(toplevel, "config"))
-import TestUtil
-
-def runTests(tests, num = 0):
+def runTests(args, tests, num = 0):
#
# Run each of the tests.
@@ -37,7 +34,7 @@ def runTests(tests, num = 0):
print "*** running tests in " + dir,
print
- status = os.system(os.path.join(dir, "run.py"))
+ status = os.system(os.path.join(dir, "run.py " + args))
if status and not (sys.platform.startswith("aix") and status == 256):
if(num > 0):
@@ -65,11 +62,12 @@ tests = [ \
]
def usage():
- print "usage: " + sys.argv[0] + " [-l][-r <regex>]"
+ print "usage: " + sys.argv[0] + " -l -r <regex> -R <regex> --debug --protocol protocol --compress --host host --threadPerConnection"
sys.exit(2)
try:
- opts, args = getopt.getopt(sys.argv[1:], "lr:")
+ opts, args = getopt.getopt(sys.argv[1:], "lr:R:", \
+ ["debug", "protocol=", "compress", "host=", "threadPerConnection"])
except getopt.GetoptError:
usage()
@@ -77,20 +75,28 @@ if(args):
usage()
loop = 0
+args = ""
for o, a in opts:
if o == "-l":
loop = 1
- if o == "-r":
- import re
- regexp = re.compile(a)
- newtests = []
- def rematch(x): return regexp.match(x)
- tests = filter(rematch, tests)
+ if o == "-r" or o == '-R':
+ import re
+ regexp = re.compile(a)
+ if o == '-r':
+ def rematch(x): return regexp.search(x)
+ else:
+ def rematch(x): return not regexp.search(x)
+ tests = filter(rematch, tests)
+ if o in ( "--protocol", "--host" ):
+ args += " " + o + " " + a
+ if o in ( "--debug", "--compress", "--threadPerConnection" ):
+ args += " " + o
+
if loop:
num = 1
while 1:
- runTests(tests, num)
+ runTests(args, tests, num)
num += 1
else:
- runTests(tests)
+ runTests(args, tests)
diff --git a/py/config/TestUtil.py b/py/config/TestUtil.py
index 022d09524b2..518d82c9d0a 100644
--- a/py/config/TestUtil.py
+++ b/py/config/TestUtil.py
@@ -42,10 +42,39 @@ threadPerConnection = 0
host = "127.0.0.1"
#
+# To print the commands that are being run.
+#
+debug = 0
+#debug = 1
+
+#
# Don't change anything below this line!
#
+import sys, os, errno, getopt
+from threading import Thread
-import sys, os, errno
+#
+# Don't change anything below this line!
+#
+def usage():
+ print "usage: " + sys.argv[0] + " --debug --protocol protocol --compress --host host --threadPerConnection"
+ sys.exit(2)
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "", ["debug", "protocol=", "compress", "host=", "threadPerConnection"])
+except getopt.GetoptError:
+ usage()
+
+for o, a in opts:
+ if o == "--debug":
+ debug = 1
+ if o == "--protocol":
+ protocol = a
+ if o == "--compress":
+ compress = 1
+ if o == "--threadPerConnection":
+ threadPerConnection = 1
+ if o == "--host":
+ host = a
def isCygwin():
@@ -98,29 +127,83 @@ def isDarwin():
return 1
else:
return 0
-
+
+def closePipe(pipe):
+
+ try:
+ status = pipe.close()
+ except IOError, ex:
+ # TODO: There's a waitpid problem on CentOS, so we have to ignore ECHILD.
+ if ex.errno == errno.ECHILD:
+ status = 0
+ else:
+ raise
+
+ return status
+
+import thread
+
+class ReaderThread(Thread):
+ def __init__(self, pipe):
+ self.pipe = pipe
+ Thread.__init__(self)
+
+ def run(self):
+
+ #print "started: " + str(self) + ": " + str(thread.get_ident())
+ try:
+ while 1:
+ line = self.pipe.readline()
+ if not line: break
+ # Suppress "adapter ready" messages. Under windows the eol isn't \n.
+ if not line.endswith(" ready\n") and not line.endswith(" ready\r\n"):
+ print "server: " + line,
+ except IOError:
+ pass
+
+ self.status = closePipe(self.pipe)
+ #print "terminating: " + str(self)
+
+ def getStatus(self):
+ return self.status
+
serverPids = []
+serverThreads = []
+allServerThreads = []
+
+def joinServers():
+ global serverThreads
+ global allServerThreads
+ for t in serverThreads:
+ t.join()
+ allServerThreads.append(t)
+ serverThreads = []
+
+def serverStatus():
+ global allServerThreads
+ joinServers()
+ for t in allServerThreads:
+ status = t.getStatus()
+ if status:
+ print "server " + str(t) + " status: " + str(status)
+ return status
+ return 0
+
def killServers():
global serverPids
-
- if isCygwin():
- print "killServers(): not implemented for cygwin python."
-
- #
- # TODO: Michi: Not sure why exit(1) was here. This means that, when
- # we run the test suite with allTests.py under Cygwin, the first sub-test that
- # calls killServers will return non-zero exit status and, therefore,
- # terminate allTests.py, so the subsequent tests are never run.
- #
- #sys.exit(1)
+ global serverThreads
for pid in serverPids:
+
if isWin32():
try:
import win32api
handle = win32api.OpenProcess(1, 0, pid)
win32api.TerminateProcess(handle, 0)
+ except ImportError, ex:
+ print "Sorry: you must install the win32all package for killServers to work."
+ return
except:
pass # Ignore errors, such as non-existing processes.
else:
@@ -131,27 +214,61 @@ def killServers():
serverPids = []
-def getServerPid(serverPipe):
+ #
+ # Now join with all the threads
+ #
+ joinServers()
- output = serverPipe.readline().strip()
+def getServerPid(pipe):
+ global serverPids
+ global serverThreads
- if not output:
- print "failed!"
- killServers()
- sys.exit(1)
+ while 1:
+ output = pipe.readline().strip()
+ if not output:
+ print "failed!"
+ killServers()
+ sys.exit(1)
+ if output.startswith("warning: "):
+ continue
+ break
- serverPids.append(int(output))
+ try:
+ serverPids.append(int(output))
+ except ValueError:
+ print "Output is not a PID: " + output
+ raise
-def getAdapterReady(serverPipe):
+def ignorePid(pipe):
- output = serverPipe.readline().strip()
+ while 1:
+ output = pipe.readline().strip()
+ if not output:
+ print "failed!"
+ killServers()
+ sys.exit(1)
+ if output.startswith("warning: "):
+ continue
+ break
+
+def getAdapterReady(pipe, createThread = True):
+ global serverThreads
+
+ output = pipe.readline().strip()
if not output:
print "failed!"
killServers()
sys.exit(1)
-def waitServiceReady(pipe, token):
+ # Start a thread for this server.
+ if createThread:
+ serverThread = ReaderThread(pipe)
+ serverThread.start()
+ serverThreads.append(serverThread)
+
+def waitServiceReady(pipe, token, createThread = True):
+ global serverThreads
while 1:
output = pipe.readline().strip()
@@ -161,6 +278,12 @@ def waitServiceReady(pipe, token):
if output == token + " ready":
break
+ # Start a thread for this server.
+ if createThread:
+ serverThread = ReaderThread(pipe)
+ serverThread.start()
+ serverThreads.append(serverThread)
+
def printOutputFromPipe(pipe):
while 1:
@@ -169,19 +292,6 @@ def printOutputFromPipe(pipe):
break
os.write(1, c)
-def closePipe(pipe):
-
- try:
- status = pipe.close()
- except IOError, ex:
- # TODO: There's a waitpid problem on CentOS, so we have to ignore ECHILD.
- if ex.errno == errno.ECHILD:
- status = 0
- else:
- raise
-
- return status
-
for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
toplevel = os.path.normpath(toplevel)
if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")):
@@ -264,25 +374,28 @@ def clientServerTestWithOptionsAndNames(name, additionalServerOptions, additiona
os.chdir(testdir)
print "starting " + serverName + "...",
- serverCmd = "python " + server + serverOptions + additionalServerOptions + " 2>&1"
- #print serverCmd
- serverPipe = os.popen(serverCmd)
+ serverCmd = "python " + server + serverOptions + additionalServerOptions
+ if debug:
+ print "(" + serverCmd + ")",
+ serverPipe = os.popen(serverCmd + " 2>&1")
getServerPid(serverPipe)
getAdapterReady(serverPipe)
print "ok"
print "starting " + clientName + "...",
- clientCmd = "python " + client + clientOptions + additionalClientOptions + " 2>&1"
- clientPipe = os.popen(clientCmd)
+ clientCmd = "python " + client + clientOptions + additionalClientOptions
+ if debug:
+ print "(" + clientCmd + ")",
+ clientPipe = os.popen(clientCmd + " 2>&1")
print "ok"
printOutputFromPipe(clientPipe)
clientStatus = closePipe(clientPipe)
- serverStatus = closePipe(serverPipe)
-
- if clientStatus or serverStatus:
+ if clientStatus:
killServers()
+
+ if clientStatus or serverStatus():
sys.exit(1)
os.chdir(cwd)
@@ -306,24 +419,30 @@ def mixedClientServerTestWithOptions(name, additionalServerOptions, additionalCl
os.chdir(testdir)
print "starting server...",
- serverPipe = os.popen("python " + server + clientServerOptions + additionalServerOptions + " 2>&1")
+ serverCmd = "python " + server + clientServerOptions + additionalServerOptions
+ if debug:
+ print "(" + serverCmd + ")",
+ serverPipe = os.popen(serverCmd + " 2>&1")
getServerPid(serverPipe)
getAdapterReady(serverPipe)
print "ok"
print "starting client...",
- clientPipe = os.popen("python " + client + clientServerOptions + additionalClientOptions + " 2>&1")
- getServerPid(clientPipe)
- getAdapterReady(clientPipe)
+ clientCmd = "python " + client + clientServerOptions + additionalClientOptions
+ if debug:
+ print "(" + clientCmd + ")",
+ clientPipe = os.popen(clientCmd + " 2>&1")
+ ignorePid(clientPipe)
+ getAdapterReady(clientPipe, False)
print "ok"
printOutputFromPipe(clientPipe)
clientStatus = closePipe(clientPipe)
- serverStatus = closePipe(serverPipe)
-
- if clientStatus or serverStatus:
+ if clientStatus:
killServers()
+
+ if clientStatus or serverStatus():
sys.exit(1)
os.chdir(cwd)
@@ -341,7 +460,10 @@ def collocatedTestWithOptions(name, additionalOptions):
os.chdir(testdir)
print "starting collocated...",
- collocatedPipe = os.popen("python " + collocated + collocatedOptions + additionalOptions + " 2>&1")
+ command = "python " + collocated + collocatedOptions + additionalOptions
+ if debug:
+ print "(" + command + ")",
+ collocatedPipe = os.popen(command + " 2>&1")
print "ok"
printOutputFromPipe(collocatedPipe)
diff --git a/py/python/Ice.py b/py/python/Ice.py
index d9ec5364914..f77fff00775 100644
--- a/py/python/Ice.py
+++ b/py/python/Ice.py
@@ -12,13 +12,17 @@
Ice module
"""
-import sys, exceptions, string, imp, os, threading, dl, warnings
+import sys, exceptions, string, imp, os, threading, warnings
-#
-# This is necessary for proper operation of Ice plug-ins.
-# Without it, RTTI problems can occur.
-#
-sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
+try:
+ import dl
+ #
+ # This is necessary for proper operation of Ice plug-ins.
+ # Without it, RTTI problems can occur.
+ #
+ sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
+except ImportError:
+ pass
#
# Import the Python extension.
diff --git a/py/test/Ice/binding/Server.py b/py/test/Ice/binding/Server.py
index 989fc448f6c..873b5e1432d 100644
--- a/py/test/Ice/binding/Server.py
+++ b/py/test/Ice/binding/Server.py
@@ -25,6 +25,7 @@ Ice.loadSlice('Test.ice')
import Test, TestI
def run(args, communicator):
+ communicator.getProperties().setProperty("Ice.Warn.Connections", "0")
communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000:udp")
adapter = communicator.createObjectAdapter("TestAdapter")
id = communicator.stringToIdentity("communicator")
diff --git a/py/test/Ice/faultTolerance/Server.py b/py/test/Ice/faultTolerance/Server.py
index 54cf46c1266..0364727cc7a 100644
--- a/py/test/Ice/faultTolerance/Server.py
+++ b/py/test/Ice/faultTolerance/Server.py
@@ -36,13 +36,13 @@ class TestI(Test.TestIntf):
def abort(self, current=None):
print "aborting..."
- sys.exit(0)
+ os._exit(0)
def idempotentAbort(self, current=None):
- sys.exit(0)
+ os._exit(0)
def nonmutatingAbort(self, current=None):
- sys.exit(0)
+ os._exit(0)
def pid(self, current=None):
return os.getpid()
diff --git a/py/test/Ice/faultTolerance/run.py b/py/test/Ice/faultTolerance/run.py
index 314b268625f..5cbe27b4eec 100755
--- a/py/test/Ice/faultTolerance/run.py
+++ b/py/test/Ice/faultTolerance/run.py
@@ -32,49 +32,33 @@ client = "Client.py"
num = 12
base = 12340
-serverPipes = { }
for i in range(0, num):
print "starting server #%d..." % (i + 1),
sys.stdout.flush()
- serverPipes[i] = os.popen("python " + server + TestUtil.serverOptions + " %d" % (base + i) + " 2>&1")
- TestUtil.getServerPid(serverPipes[i])
- TestUtil.getAdapterReady(serverPipes[i])
+ command = "python " + server + TestUtil.serverOptions + " %d" % (base + i)
+ if TestUtil.debug:
+ print "(" + command + ")",
+ serverPipe = os.popen(command + " 2>&1")
+ TestUtil.getServerPid(serverPipe)
+ TestUtil.getAdapterReady(serverPipe)
print "ok"
ports = ""
for i in range(0, num):
ports = "%s %d" % (ports, base + i)
print "starting client...",
-clientPipe = os.popen("python " + client + TestUtil.clientOptions + " " + ports + " 2>&1")
+command = "python " + client + TestUtil.clientOptions + " " + ports
+if TestUtil.debug:
+ print "(" + command + ")",
+clientPipe = os.popen(command + " 2>&1")
print "ok"
-TestUtil.printOutputFromPipe(clientPipe)
+TestUtil.printOutputFromPipe(clientPipe)
clientStatus = TestUtil.closePipe(clientPipe)
-serverStatus = None
-for i in range(0, num):
- serverStatus = serverStatus or TestUtil.closePipe(serverPipes[i])
-
if clientStatus:
TestUtil.killServers()
- sys.exit(1)
-os.chdir(cwd)
-
-#
-# Exit with status 0 even though some servers failed to shutdown
-# properly. There's a problem which is occuring on Linux dual-processor
-# machines, when ssl isn't enabled, and which cause some servers to
-# segfault and abort. It's not clear what the problem is, and it's
-# almost impossible to debug with the very poor information we get
-# from the core file (ulimit -c unlimited to enable core files on
-# Linux).
-#
-if serverStatus:
- TestUtil.killServers()
+if clientStatus or TestUtil.serverStatus():
sys.exit(1)
-# if TestUtil.isWin32():
-# sys.exit(1)
-# else:
-# sys.exit(0)
sys.exit(0)