summaryrefslogtreecommitdiff
path: root/demoscript/Util.py
diff options
context:
space:
mode:
Diffstat (limited to 'demoscript/Util.py')
-rw-r--r--demoscript/Util.py100
1 files changed, 87 insertions, 13 deletions
diff --git a/demoscript/Util.py b/demoscript/Util.py
index 6ad51faa61c..dcce6928348 100644
--- a/demoscript/Util.py
+++ b/demoscript/Util.py
@@ -7,6 +7,11 @@
#
# **********************************************************************
+import sys
+if sys.platform == "win32":
+ print "demoscript only supports cygwin python under Windows (use /usr/bin/python expect.py)"
+ sys.exit(1)
+
#
# Timeout after the initial spawn.
#
@@ -26,7 +31,13 @@ host = "127.0.0.1"
#
debug = False
-import sys, getopt, pexpect, os
+#
+# The test language.
+#
+defaultLanguage = None
+
+import getopt, os, signal
+import demoscript.pexpect as pexpect
def usage():
print "usage: " + sys.argv[0] + " --fast --trace --debug --host host --mode=[debug|release]"
@@ -50,9 +61,8 @@ for o, a in opts:
fast = True
if o == "--mode":
mode = a
- if mode != 'debug' or mode != 'release':
- print "usage: " + sys.argv[0] + " --trace --debug --host host --mode=[debug|release]"
- sys.exit(2)
+ if mode != 'debug' and mode != 'release':
+ usage()
if host != "":
defaultHost = " --Ice.Default.Host=%s" % (host)
@@ -64,20 +74,20 @@ def isCygwin():
# versions return variations like "cygwin_nt-4.01".
return sys.platform[:6] == "cygwin"
-def isWin32():
- return sys.platform == "win32" or isCygwin()
-
def isDarwin():
return sys.platform == "darwin"
-def mono():
- if isWin32():
- return ""
+def isMono():
+ return not isCygwin()
+
+def python():
+ if isCygwin():
+ return "python -u "
else:
- return "mono "
+ return "python "
def getIceBox():
- if isWin32():
+ if isCygwin():
if mode == 'release':
return "icebox"
else:
@@ -87,28 +97,92 @@ def getIceBox():
# Automatically adds default host, and uses our default timeout for
# expect.
class spawn(pexpect.spawn):
- def __init__(self, command):
+ def __init__(self, command, language = None):
if defaultHost:
command = '%s %s' % (command, defaultHost)
if debug:
print '(%s)' % (command)
+ if not language:
+ self.language = defaultLanguage
+ else:
+ self.language = language
self.expectFirst = True
if trace:
logfile = sys.stdout
else:
logfile = None
+ self.sentKill = None
+ if self.language == "C#":
+ if isMono():
+ command = "mono " + command
+ else:
+ command = "./" + command
+ if self.language == "Python":
+ command = python() + command
pexpect.spawn.__init__(self, command, logfile = logfile)
+
def expect(self, pattern, timeout = defaultTimeout, searchwindowsize=None):
if self.expectFirst and timeout == defaultTimeout:
timeout = initialTimeout
self.expectFirst = False
return pexpect.spawn.expect(self, pattern, timeout, searchwindowsize)
+
def wait(self):
try:
return pexpect.spawn.wait(self)
except pexpect.ExceptionPexpect, e:
return self.exitstatus
+ def kill(self, sig):
+ if isCygwin():
+ sig = signal.SIGTERM
+ self.sentKill = sig
+ return pexpect.spawn.kill(self, sig)
+
+ # status == 0 is normal exit status for C++
+ #
+ # status == 130 is normal exit status for a Java app that was
+ # SIGINT interrupted.
+ #
+ # signalstatus == SIGINT is normal exit status for a mono app,
+ # or if under cygwin (since cygwin spawned expect apps cannot
+ # catch SIGINT).
+ #
+ def waitTestSuccess(self, exitstatus = 0, timeout = None):
+ if not timeout:
+ self.expect(pexpect.EOF)
+ else:
+ self.expect(pexpect.EOF, timeout)
+ status = self.wait()
+ if self.language == "C++" or self.language == "Python" or self.language == "Ruby" or self.language == "PHP":
+ if isCygwin() and self.sentKill:
+ assert self.signalstatus == self.sentKill
+ else:
+ assert status == exitstatus
+ elif self.language == "C#":
+ if isMono() or isCygwin() and self.sentKill:
+ assert self.signalstatus == self.sentKill
+ else:
+ assert status == exitstatus
+ elif self.language == "Java":
+ if self.sentKill:
+ if isCygwin():
+ assert self.signalstatus == self.sentKill
+ else:
+ if self.sentKill == signal.SIGINT:
+ assert status == 130
+ else:
+ assert False
+ else:
+ assert status == exitstatus
+ else:
+ # Unknown language
+ print "Warning: unknown language"
+ if not self.sentKill:
+ assert status == exitstatus
+ else:
+ assert status == exitstatus or status == 130 or self.signalstatus == self.sentKill
+
def cleanDbDir(path):
for filename in [ os.path.join(path, f) for f in os.listdir(path) if f != ".gitignore" and f != "DB_CONFIG"]:
if os.path.isdir(filename):