Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraleherbau2011-04-05 12:31:59 +0000
committeraleherbau2011-04-05 12:31:59 +0000
commitc1641a0ba3d0fc310fb909fe0b62531f55440c93 (patch)
treeb85b98e46d5b9d826c796a1105697c1d26efed87 /python/src
parent559ca401ad7f4f02875edeefaf2b56dc79702000 (diff)
downloadorg.eclipse.tcf-c1641a0ba3d0fc310fb909fe0b62531f55440c93.tar.gz
org.eclipse.tcf-c1641a0ba3d0fc310fb909fe0b62531f55440c93.tar.xz
org.eclipse.tcf-c1641a0ba3d0fc310fb909fe0b62531f55440c93.zip
Fixed serialization issues and added Diagnostics tests
Diffstat (limited to 'python/src')
-rw-r--r--python/src/tcf/channel/Command.py2
-rw-r--r--python/src/tcf/channel/__init__.py8
-rw-r--r--python/src/tcf/errors.py2
-rw-r--r--python/src/tcf/tests/BasicTests.py129
-rw-r--r--python/src/tcf/util/sync.py12
5 files changed, 106 insertions, 47 deletions
diff --git a/python/src/tcf/channel/Command.py b/python/src/tcf/channel/Command.py
index 5150ad0b7..58f517c05 100644
--- a/python/src/tcf/channel/Command.py
+++ b/python/src/tcf/channel/Command.py
@@ -110,7 +110,7 @@ class Command(object):
return buf.getvalue()
def toError(self, data, include_command_text=True):
- if not data: return None
+ if not isinstance(data, dict): return None
map = data
bf = cStringIO.StringIO()
bf.write("TCF error report:\n")
diff --git a/python/src/tcf/channel/__init__.py b/python/src/tcf/channel/__init__.py
index 0b81bbc73..a85ed1de6 100644
--- a/python/src/tcf/channel/__init__.py
+++ b/python/src/tcf/channel/__init__.py
@@ -139,15 +139,17 @@ def toByteArray(data):
if data is None: return None
t = type(data)
if t is bytearray: return data
- if t is types.StringType:
+ elif t is str:
return binascii.a2b_base64(data)
+ elif t is unicode:
+ return binascii.a2b_base64(str(data))
raise exceptions.TypeError(str(t))
class TCFJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, bytearray):
- return binascii.b2a_base64(o)
- elif hasattr('__iter__', o):
+ return binascii.b2a_base64(o)[:-1]
+ elif hasattr(o, '__iter__'):
return tuple(o)
else:
json.JSONEncoder.default(self, o)
diff --git a/python/src/tcf/errors.py b/python/src/tcf/errors.py
index 7a6c69364..53c856000 100644
--- a/python/src/tcf/errors.py
+++ b/python/src/tcf/errors.py
@@ -78,7 +78,7 @@ class ErrorReport(exceptions.Exception):
if type(attrs) is types.IntType:
attrs = {
ERROR_CODE : attrs,
- ERROR_TIME : time.time(),
+ ERROR_TIME : int(time.time()),
ERROR_FORMAT : msg,
ERROR_SEVERITY : SEVERITY_ERROR
}
diff --git a/python/src/tcf/tests/BasicTests.py b/python/src/tcf/tests/BasicTests.py
index 757b0ca4b..692f35df1 100644
--- a/python/src/tcf/tests/BasicTests.py
+++ b/python/src/tcf/tests/BasicTests.py
@@ -11,7 +11,7 @@
import sys, time, threading, exceptions
import tcf
-from tcf import protocol, channel
+from tcf import protocol, channel, errors
from tcf.util import sync
__TRACE = False
@@ -34,14 +34,18 @@ def test():
print "services=", c.getRemoteServices()
protocol.invokeLater(r2)
- testRunControl(c)
- testBreakpoints(c)
- testSymbols(c)
- testRegisters(c)
- testSyncCommands(c)
- testEvents(c)
- testDataCache(c)
-
+ try:
+ testRunControl(c)
+ testStackTrace(c)
+ testBreakpoints(c)
+ testSymbols(c)
+ testRegisters(c)
+ testSyncCommands(c)
+ testEvents(c)
+ testDataCache(c)
+ except exceptions.Exception as e:
+ protocol.log(e)
+
if c.state == channel.STATE_OPEN:
time.sleep(10)
protocol.invokeLater(c.close)
@@ -72,7 +76,6 @@ def testRunControl(c):
print "params: ", params
if suspended:
_suspended.append(context.getID())
- testStackTrace(c, context.getID())
if len(pending) == 0:
with lock:
lock.notify()
@@ -184,24 +187,27 @@ def testBreakpoints(c):
bpsvc.set([bp], DoneSet())
protocol.invokeLater(r4)
-def testStackTrace(c, ctx_id):
+def testStackTrace(c):
from tcf.services import stacktrace
- stack = c.getRemoteService(stacktrace.NAME)
- class DoneGetChildren(stacktrace.DoneGetChildren):
- def doneGetChildren(self, token, error, ctx_ids):
- if error:
- protocol.log("Error from StackTrace.getChildren", error)
- return
- class DoneGetContext(stacktrace.DoneGetContext):
- def doneGetContext(self, token, error, ctxs):
- if error:
- protocol.log("Error from StackTrace.getContext", error)
- return
- if ctxs:
- for ctx in ctxs:
- print ctx
- stack.getContext(ctx_ids, DoneGetContext())
- stack.getChildren(ctx_id, DoneGetChildren())
+ def stackTest(ctx_id):
+ stack = c.getRemoteService(stacktrace.NAME)
+ class DoneGetChildren(stacktrace.DoneGetChildren):
+ def doneGetChildren(self, token, error, ctx_ids):
+ if error:
+ protocol.log("Error from StackTrace.getChildren", error)
+ return
+ class DoneGetContext(stacktrace.DoneGetContext):
+ def doneGetContext(self, token, error, ctxs):
+ if error:
+ protocol.log("Error from StackTrace.getContext", error)
+ return
+ if ctxs:
+ for ctx in ctxs:
+ print ctx
+ stack.getContext(ctx_ids, DoneGetContext())
+ stack.getChildren(ctx_id, DoneGetChildren())
+ for ctx_id in _suspended:
+ protocol.invokeLater(stackTest, ctx_id)
def testSymbols(c):
from tcf.services import symbols
@@ -227,36 +233,85 @@ def testSymbols(c):
def testRegisters(c):
from tcf.services import registers
+ lock = threading.Condition()
def regTest(ctx_id):
regs = c.getRemoteService(registers.NAME)
+ pending = []
+ def onDone():
+ with lock: lock.notify()
class DoneGetChildren(registers.DoneGetChildren):
def doneGetChildren(self, token, error, ctx_ids):
+ pending.remove(token)
if error:
protocol.log("Error from Registers.getChildren", error)
- return
+ if not pending:
+ onDone()
class DoneGetContext(registers.DoneGetContext):
def doneGetContext(self, token, error, ctx):
+ pending.remove(token)
if error:
protocol.log("Error from Registers.getContext", error)
- return
- print ctx
+ else:
+ print ctx
+ if ctx.isReadable() and not ctx.isReadOnce() and ctx.getSize() >= 2:
+ locs = []
+ locs.append(registers.Location(ctx.getID(), 0, 1))
+ locs.append(registers.Location(ctx.getID(), 1, 1))
+ class DoneGetM(registers.DoneGet):
+ def doneGet(self, token, error, value):
+ pending.remove(token)
+ if error:
+ protocol.log("Error from Registers.getm", error)
+ else:
+ print "getm", ctx.getID(), map(ord, value)
+ if not pending:
+ onDone()
+ pending.append(regs.getm(locs, DoneGetM()))
+ if ctx.isWriteable() and not ctx.isWriteOnce() and ctx.getSize() >= 2:
+ locs = []
+ locs.append(registers.Location(ctx.getID(), 0, 1))
+ locs.append(registers.Location(ctx.getID(), 1, 1))
+ class DoneSetM(registers.DoneSet):
+ def doneGet(self, token, error):
+ pending.remove(token)
+ if error:
+ protocol.log("Error from Registers.setm", error)
+ if not pending:
+ onDone()
+ pending.append(regs.setm(locs, (255, 255), DoneSetM()))
+ if not pending:
+ onDone()
if ctx_ids:
for ctx_id in ctx_ids:
- regs.getContext(ctx_id, DoneGetContext())
- regs.getChildren(ctx_id, DoneGetChildren())
- for ctx_id in _suspended:
- protocol.invokeLater(regTest, ctx_id)
-
+ pending.append(regs.getContext(ctx_id, DoneGetContext()))
+ pending.append(regs.getChildren(ctx_id, DoneGetChildren()))
+ with lock:
+ for ctx_id in _suspended:
+ protocol.invokeLater(regTest, ctx_id)
+ lock.wait(5000)
+
def testSyncCommands(c):
# simplified command execution
ctl = sync.CommandControl(c)
+ diag = ctl.Diagnostics
+ s = "Hello TCF World"
+ r = diag.echo(s).getE()
+ assert s == r
+ pi = 3.141592654
+ r = diag.echoFP(pi).getE()
+ assert pi == r
+ e = errors.ErrorReport("Test", errors.TCF_ERROR_OTHER)
+ r = diag.echoERR(e.getAttributes()).getE()
+ assert e.getAttributes() == r
+ print "Diagnostic tests:", diag.getTestList().getE()
+
for ctx_id in _suspended:
- print ctl.Symbols.list(ctx_id)
+ print "Symbols:", ctl.Symbols.list(ctx_id)
for ctx_id in _suspended:
frame_ids = ctl.StackTrace.getChildren(ctx_id).get()
if frame_ids:
error, args = ctl.StackTrace.getContext(frame_ids)
- if not error: print args
+ if not error: print "Stack contexts:", args
def gotBreakpoints(error, bps):
print "Got breakpoint list:", bps
ctl.Breakpoints.getIDs(onDone=gotBreakpoints)
diff --git a/python/src/tcf/util/sync.py b/python/src/tcf/util/sync.py
index cb44b94d6..e37420974 100644
--- a/python/src/tcf/util/sync.py
+++ b/python/src/tcf/util/sync.py
@@ -84,13 +84,13 @@ class CommandControl(object):
if not error and args:
# error result is usually in args[0]
if service == "StackTrace" and command == "getContext":
- err = self.toError(args[1])
+ error = self.toError(args[1])
+ resultArgs = (args[0],)
+ elif service == "Diagnostics" and command.startswith("echo"):
resultArgs = (args[0],)
else:
- err = self.toError(args[0])
+ error = self.toError(args[0])
resultArgs = args[1:]
- if err:
- error = err
cmdCtrl._doneCommand(self.token, error, resultArgs)
def wait(self, timeout=None):
cmdCtrl._waitForCommand(self.token, timeout)
@@ -142,7 +142,9 @@ class CommandControl(object):
if cmd._async: self._complete.append(cmd)
isDone = self.isDone()
if isDone: self._lock.notifyAll()
- if cmd._onDone: cmd._onDone(error, *args)
+ if cmd._onDone:
+ if args is None: args = (None,)
+ cmd._onDone(error, *args)
if isDone and self._onDone: self._onDone()
def isDone(self):
with self._lock:

Back to the top