diff options
Diffstat (limited to 'php/config/TestUtil.py')
-rw-r--r-- | php/config/TestUtil.py | 237 |
1 files changed, 175 insertions, 62 deletions
diff --git a/php/config/TestUtil.py b/php/config/TestUtil.py index 79b757c9f93..2c63aa668d6 100644 --- a/php/config/TestUtil.py +++ b/php/config/TestUtil.py @@ -13,53 +13,68 @@ # protocol. Otherwise TCP is used. # -#protocol = "" -protocol = "ssl" +protocol = "" +#protocol = "ssl" # # Set compressed to 1 in case you want to run the tests with # protocol compression. # -#compress = 0 -compress = 1 +compress = 0 +#compress = 1 # -# Set the host to the host name the test servers are running on. If -# not set, Ice will try to find out the IP address for the -# hostname. If you DNS isn't set up propertly, you should therefore -# use "localhost". +# If you don't set "host" below, then the Ice library will try to find +# out the IP address of this host. For the Ice test suite, it's best +# to set the IP address explicitly to 127.0.0.1. This avoid problems +# with incorrect DNS or hostname setups. # -#host = "someotherhost" -host = "localhost" +host = "127.0.0.1" # -# Don't change anything below this line! +# To print the commands that are being run. # -import sys, os, re, errno +debug = 0 +#debug = 1 + +# +# Don't change anything below this line! +# +import sys, os, errno, getopt +from threading import Thread + +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 # # Check for ICE_HOME # -ice_home = os.environ["ICE_HOME"] +ice_home = os.getenv("ICE_HOME", "") if len(ice_home) == 0: print "ICE_HOME is not defined" sys.exit(1) -def getIceVersion(): - - config = open(os.path.join(ice_home, "include", "IceUtil", "Config.h"), "r") - return re.search("ICE_STRING_VERSION \"([0-9\.]*)\"", config.read()).group(1) - -def getIceSoVersion(): - config = open(os.path.join(ice_home, "include", "IceUtil", "Config.h"), "r") - intVersion = int(re.search("ICE_INT_VERSION ([0-9]*)", config.read()).group(1)) - majorVersion = intVersion / 10000 - minorVersion = intVersion / 100 - 100 * majorVersion - return '%d' % (majorVersion * 10 + minorVersion) - def isCygwin(): # The substring on sys.platform is required because some cygwin @@ -82,21 +97,81 @@ def isSolaris(): 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 + +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 + global serverThreads for pid in serverPids: - if isCygwin(): - print "killServers(): not implemented for cygwin python." - sys.exit(1) - elif isWin32(): + + 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: @@ -107,27 +182,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() @@ -137,26 +246,19 @@ 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: - line = pipe.readline() - if not line: + c = pipe.read(1) + if c == "": break - os.write(1, line) - -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 + os.write(1, c) for toplevel in [".", "..", "../..", "../../..", "../../../.."]: toplevel = os.path.normpath(toplevel) @@ -208,33 +310,44 @@ clientOptions = clientProtocol + defaultHost serverOptions = serverProtocol + defaultHost + commonServerOptions clientServerOptions = clientServerProtocol + defaultHost + commonServerOptions +if isWin32(): + php = "php -d extension_dir=\"" + os.path.abspath(os.path.join(toplevel, "bin")) + "\" -d extension=php_ice.dll" +else: + php = "php -d extension_dir=\"" + os.path.abspath(os.path.join(toplevel, "lib")) + "\" -d extension=IcePHP.so" + def clientServerTestWithOptionsAndNames(name, additionalServerOptions, additionalClientOptions, \ serverName, clientName): testdir = os.path.join(toplevel, "test", name) server = os.path.join(ice_home, "test", name, serverName) - client = "php -c . -f " + clientName + client = php + " -c . -f " + clientName cwd = os.getcwd() os.chdir(testdir) print "starting " + serverName + "...", - serverPipe = os.popen(server + serverOptions + additionalServerOptions + " 2>&1") + serverCmd = server + serverOptions + additionalServerOptions + if debug: + print "(" + serverCmd + ")", + serverPipe = os.popen(serverCmd + " 2>&1") getServerPid(serverPipe) getAdapterReady(serverPipe) print "ok" print "starting " + clientName + "...", - clientPipe = os.popen(client + " -- " + clientOptions + additionalClientOptions + " 2>&1") + clientCmd = 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) |