diff options
author | Matthew Newhook <matthew@zeroc.com> | 2006-06-08 19:26:52 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2006-06-08 19:26:52 +0000 |
commit | 5f8fa3a28ab685393f8e34e366375470409cfda6 (patch) | |
tree | 273bba81ef164ee4adf91b223db5a42ac1fcdfd6 /cs/config/TestUtil.py | |
parent | Matthew's fix (diff) | |
download | ice-5f8fa3a28ab685393f8e34e366375470409cfda6.tar.bz2 ice-5f8fa3a28ab685393f8e34e366375470409cfda6.tar.xz ice-5f8fa3a28ab685393f8e34e366375470409cfda6.zip |
updates to the python test harness.
Diffstat (limited to 'cs/config/TestUtil.py')
-rw-r--r-- | cs/config/TestUtil.py | 146 |
1 files changed, 88 insertions, 58 deletions
diff --git a/cs/config/TestUtil.py b/cs/config/TestUtil.py index a92c844559f..4cac9366eee 100644 --- a/cs/config/TestUtil.py +++ b/cs/config/TestUtil.py @@ -67,12 +67,69 @@ def isWin32(): 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 + +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: + return status + return 0 + def killServers(): global serverPids + global serverThreads for pid in serverPids: + if isWin32(): try: import win32api @@ -91,9 +148,16 @@ def killServers(): serverPids = [] -def getServerPid(serverPipe): + # + # Now join with all the threads + # + joinServers() + +def getServerPid(pipe): + global serverPids + global serverThreads - output = serverPipe.readline().strip() + output = pipe.readline().strip() if not output: print "failed!" @@ -102,27 +166,33 @@ def getServerPid(serverPipe): serverPids.append(int(output)) -def ignorePid(serverPipe): +def ignorePid(pipe): - output = serverPipe.readline().strip() + output = pipe.readline().strip() if not output: print "failed!" killServers() sys.exit(1) -def getAdapterReady(serverPipe): +def getAdapterReady(pipe, createThread = True): + global serverThreads - output = serverPipe.readline().strip() - 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() @@ -132,6 +202,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: @@ -140,42 +216,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")): @@ -308,18 +348,13 @@ def clientServerTestWithOptionsAndNames(mono, name, additionalServerOptions, add clientPipe = os.popen(clientCmd) print "ok" - serverThread = ReaderThread(serverPipe, "Server") - serverThread.start() printOutputFromPipe(clientPipe) clientStatus = closePipe(clientPipe) if clientStatus: killServers() - serverThread.join() - serverStatus = serverThread.getStatus() - - if clientStatus or serverStatus: + if clientStatus or serverStatus(): sys.exit(1) def clientServerTestWithOptions(mono, name, additionalServerOptions, additionalClientOptions): @@ -350,21 +385,16 @@ def mixedClientServerTestWithOptions(mono, name, additionalServerOptions, additi #print "clientCmd = " + clientCmd clientPipe = os.popen(clientCmd) ignorePid(clientPipe) - getAdapterReady(clientPipe) + getAdapterReady(clientPipe, False) print "ok" - serverThread = ReaderThread(serverPipe, "Server") - serverThread.start() printOutputFromPipe(clientPipe) clientStatus = closePipe(clientPipe) if clientStatus: killServers() - serverThread.join() - serverStatus = serverThread.getStatus() - - if clientStatus or serverStatus: + if clientStatus or serverStatus(): sys.exit(1) def mixedClientServerTest(mono, name): |