summaryrefslogtreecommitdiff
path: root/java/config/TestUtil.py
diff options
context:
space:
mode:
Diffstat (limited to 'java/config/TestUtil.py')
-rw-r--r--java/config/TestUtil.py166
1 files changed, 100 insertions, 66 deletions
diff --git a/java/config/TestUtil.py b/java/config/TestUtil.py
index bcab8888793..d9301f2fd0d 100644
--- a/java/config/TestUtil.py
+++ b/java/config/TestUtil.py
@@ -100,23 +100,79 @@ def isWin9x():
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
-# Only used for C++ programs
+class ReaderThread(Thread):
+ def __init__(self, pipe):
+ self.pipe = pipe
+ Thread.__init__(self)
+
+ def run(self):
+
+ 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 line,
+ except IOError:
+ pass
+
+ self.status = closePipe(self.pipe)
+
+ 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."
- return;
+ 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:
@@ -126,11 +182,17 @@ def killServers():
pass # Ignore errors, such as non-existing processes.
serverPids = []
-
-# Only used for C++ programs
-def getServerPid(serverPipe):
- output = serverPipe.readline().strip()
+ #
+ # Now join with all the threads
+ #
+ joinServers()
+
+def getServerPid(pipe):
+ global serverPids
+ global serverThreads
+
+ output = pipe.readline().strip()
if not output:
print "failed!"
@@ -139,18 +201,33 @@ def getServerPid(serverPipe):
serverPids.append(int(output))
-def getAdapterReady(serverPipe):
+def ignorePid(pipe):
+
+ output = pipe.readline().strip()
+
+ if not output:
+ print "failed!"
+ killServers()
+ sys.exit(1)
+
+def getAdapterReady(pipe, createThread = True):
+ global serverThreads
- output = serverPipe.readline()
- if compress and output.strip() == "warning: bzip2 support not available, Ice.Override.Compress ignored":
- output = serverPipe.readline()
+ 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()
@@ -160,6 +237,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:
@@ -168,42 +251,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
-
-class ReaderThread(Thread):
- def __init__(self, pipe, token):
- self.pipe = pipe
- self.token = token
- Thread.__init__(self)
-
- def run(self):
-
- try:
- while 1:
- line = self.pipe.readline()
- if not line: break
- # supress object adapter ready messages.
- if line[len(line)-7:len(line)] != " ready\n":
- print self.token + ": " + line,
- except IOError:
- pass
-
- self.status = closePipe(self.pipe)
-
- def getStatus(self):
- return self.status
-
for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
toplevel = os.path.normpath(toplevel)
if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")):
@@ -316,15 +363,11 @@ def clientServerTestWithOptions(additionalServerOptions, additionalClientOptions
clientPipe = os.popen(clientCmd)
print "ok"
- serverThread = ReaderThread(serverPipe, "Server")
- serverThread.start()
printOutputFromPipe(clientPipe)
clientStatus = closePipe(clientPipe)
- serverThread.join()
- serverStatus = serverThread.getStatus()
- if clientStatus or serverStatus:
+ if clientStatus or serverStatus():
killServers()
sys.exit(1)
@@ -350,19 +393,14 @@ def clientServerTestWithClasspath(serverClasspath, clientClasspath):
os.environ["CLASSPATH"] = classpath
print "ok"
- serverThread = ReaderThread(serverPipe, "Server")
- serverThread.start()
printOutputFromPipe(clientPipe)
clientStatus = closePipe(clientPipe)
- serverThread.join()
- serverStatus = serverThread.getStatus()
- if clientStatus or serverStatus:
+ if clientStatus or serverStatus():
killServers()
sys.exit(1)
-
def clientServerTest():
clientServerTestWithOptions("", "")
@@ -385,15 +423,11 @@ def mixedClientServerTestWithOptions(additionalServerOptions, additionalClientOp
clientPipe = os.popen(clientCmd + " 2>&1")
print "ok"
- serverThread = ReaderThread(serverPipe, "Server")
- serverThread.start()
printOutputFromPipe(clientPipe)
clientStatus = closePipe(clientPipe)
- serverThread.join()
- serverStatus = serverThread.getStatus()
- if clientStatus or serverStatus:
+ if clientStatus or serverStatus():
killServers()
sys.exit(1)