diff options
author | Matthew Newhook <matthew@zeroc.com> | 2010-01-06 11:51:57 -0330 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2010-01-06 11:51:57 -0330 |
commit | 48c029443c595fcb914dbebeac58b5d2fb6f017a (patch) | |
tree | 6766161cceb5c0a38127433fd72d54d812a889ed /scripts/TestUtil.py | |
parent | Updated Windows READMEs (diff) | |
download | ice-48c029443c595fcb914dbebeac58b5d2fb6f017a.tar.bz2 ice-48c029443c595fcb914dbebeac58b5d2fb6f017a.tar.xz ice-48c029443c595fcb914dbebeac58b5d2fb6f017a.zip |
http://bugzilla/bugzilla/show_bug.cgi?id=4489 - Unhandled exception in thread started by Error in sys.excepthook
- Use atexit handler to join with the watch dog thread.
- Use atexit handler for Php cleanup.
- Use p is None, not p == None.
Diffstat (limited to 'scripts/TestUtil.py')
-rwxr-xr-x | scripts/TestUtil.py | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/scripts/TestUtil.py b/scripts/TestUtil.py index 260702ffc81..c192d97794c 100755 --- a/scripts/TestUtil.py +++ b/scripts/TestUtil.py @@ -7,7 +7,7 @@ # # ********************************************************************** -import sys, os, re, getopt, time, StringIO, string, threading +import sys, os, re, getopt, time, StringIO, string, threading, atexit # Global flags and their default values. protocol = "" # If unset, default to TCP. Valid values are "tcp" or "ssl". @@ -140,15 +140,15 @@ def sanitize(cp): return np def quoteArgument(arg): - if arg == None: + if arg is None: return None return '"%s"' % arg def dumpenv(env, lang): - if env == None: + if env is None: env = os.environ vars = ["PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "SHLIB_PATH", "LIBPATH", "LD_LIBRARY_PATH_64"] - if lang == None: + if lang is None: vars.extend(["CLASSPATH", "MONO_PATH", "DEVPATH", "PYTHONPATH", "RUBYLIB"]) elif lang == "cpp": pass @@ -475,6 +475,10 @@ def getIceDir(subdir = None): else: return toplevel +def phpCleanup(): + if os.path.exists("tmp.ini"): + os.remove("tmp.ini") + def phpSetup(): extDir = None ext = None @@ -528,6 +532,7 @@ def phpSetup(): print "unable to find IcePHP extension!" sys.exit(1) + atexit.register(phpCleanup) tmpini = open("tmp.ini", "w") tmpini.write("; Automatically generated by Ice test driver.\n") if extDir: @@ -919,14 +924,14 @@ def isDebug(): return debug def getQtSqlOptions(prefix, dataDir = None): - if sqlType == None: + if sqlType is None: return ''; options = '--Ice.Plugin.DB=' + prefix + 'SqlDB:createSqlDB'; options += ' --' + prefix+ '.SQL.DatabaseType=' + sqlType options += ' --' + prefix+ '.SQL.DatabaseName=' - if sqlDbName == None: + if sqlDbName is None: if sqlType == "QSQLITE": if dataDir != None: options += dataDir + '/SQL.db' @@ -938,7 +943,7 @@ def getQtSqlOptions(prefix, dataDir = None): options += sqlDbName options += ' --' + prefix+ '.SQL.HostName=' - if sqlHost == None: + if sqlHost is None: if sqlType == "QODBC": options += '.\SQLExpress' else: @@ -951,7 +956,7 @@ def getQtSqlOptions(prefix, dataDir = None): options += sqlPort options += ' --' + prefix+ '.SQL.UserName=' - if sqlUser == None: + if sqlUser is None: options += 'test' else: options += sqlUser @@ -966,7 +971,7 @@ import Expect def spawn(cmd, env=None, cwd=None, startReader=True, lang=None): # Start/Reset the watch dog thread global watchDog - if watchDog == None: + if watchDog is None: watchDog = WatchDog() else: watchDog.reset() @@ -1037,7 +1042,7 @@ def appVerifierAfterTestEnd(targets, cwd=os.getcwd()): # Export appverifier logs to a xml file in cwd logName = cwd - if logName == None: + if logName is None: logName = os.path.dirname(exe) logName += "/" + os.path.basename(exe) + "_appverifier_log.xml" cmd = "appverif -export log -for " + exe + " -with To=" + logName @@ -1188,9 +1193,9 @@ def cleanDbDir(path): os.remove(filename) def startClient(exe, args = "", config=None, env=None, echo = True, startReader = True): - if config == None: + if config is None: config = DriverConfig("client") - if env == None: + if env is None: env = getTestEnv(getDefaultMapping(), os.getcwd()) cmd = getCommandLine(exe, config) + ' ' + args if config.lang == "php": @@ -1198,18 +1203,18 @@ def startClient(exe, args = "", config=None, env=None, echo = True, startReader return spawnClient(cmd, env = env, echo = echo, startReader = startReader, lang=config.lang) def startServer(exe, args = "", config=None, env=None, adapter = None, count = 1, echo = True): - if config == None: + if config is None: config = DriverConfig("server") - if env == None: + if env is None: env = getTestEnv(getDefaultMapping(), os.getcwd()) cmd = getCommandLine(exe, config) + ' ' + args return spawnServer(cmd, env = env, adapter = adapter, count = count, echo = echo,lang=config.lang) def startColloc(exe, args, config=None, env=None): exe = quoteArgument(exe) - if config == None: + if config is None: config = DriverConfig("colloc") - if env == None: + if env is None: env = getTestEnv(lang, testdir) cmd = getCommandLine(exe, config) + ' ' + args return spawnClient(cmd, env = env, lang=config.lang) @@ -1242,7 +1247,7 @@ def getCppBinDir(): def getServiceDir(): global serviceDir - if serviceDir == None: + if serviceDir is None: if iceHome: serviceDir = os.path.join(iceHome, "bin") else: @@ -1271,25 +1276,31 @@ def getTestName(): # The crossTests list is in UNIX format. return os.path.join(*here).replace(os.sep, '/') +def joindog(dog): + dog.stop() + dog.join() + class WatchDog(threading.Thread): def __init__(self): self._reset = False + self._stop = False self._cv = threading.Condition() threading.Thread.__init__(self) - # The thread is marked as a daemon thread. This is done so that if - # an expect script runs off the end of main without kill/wait on each - # spawned process the script will not hang trying to join with the - # thread. + # The thread is marked as a daemon thread. The atexit handler + # joins with the thread on exit. If the thread is not daemon, + # the atexit handler will not be called. self.setDaemon(True) - self.start() + atexit.register(joindog, self) def run(self): try: self._cv.acquire() while True: self._cv.wait(180) + if self._stop: + break if self._reset: self._reset = False else: @@ -1310,21 +1321,11 @@ class WatchDog(threading.Thread): self._cv.notify() self._cv.release() -class PhpCleanup: - def __del__(self): - if os.path.exists("tmp.ini"): - os.remove("tmp.ini") - -# TODO: Perhaps this should be done when the tmp.ini file is created. -try: - lang = getDefaultMapping() - if getDefaultMapping() == "php": - # Instantiate a PhpCleanup object. The __del__ method will - # cleanup when the scritp is done. - p = PhpCleanup() -except: - # Can't figure default mapping, so it's not PHP - pass + def stop(self): + self._cv.acquire() + self._stop = True + self._cv.notify() + self._cv.release() def processCmdLine(): def usage(): |