Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2012-02-24 04:30:18 -0500
committerAnton Leherbauer2012-02-24 04:30:18 -0500
commit84ac79df5152259c5b32eb04bffcdd07ac7fe72f (patch)
treec848826fbce77d47bcdbde375607e909f3aa1524
parente29a28376424d9b5488a79e60a92fedd45eff300 (diff)
downloadorg.eclipse.tcf-84ac79df5152259c5b32eb04bffcdd07ac7fe72f.tar.gz
org.eclipse.tcf-84ac79df5152259c5b32eb04bffcdd07ac7fe72f.tar.xz
org.eclipse.tcf-84ac79df5152259c5b32eb04bffcdd07ac7fe72f.zip
TCF Python: Improve BasicTests and make PEP8 compliant
-rw-r--r--python/src/tcf/tests/BasicTests.py316
1 files changed, 228 insertions, 88 deletions
diff --git a/python/src/tcf/tests/BasicTests.py b/python/src/tcf/tests/BasicTests.py
index 83c2847ff..338b104a8 100644
--- a/python/src/tcf/tests/BasicTests.py
+++ b/python/src/tcf/tests/BasicTests.py
@@ -1,4 +1,4 @@
-# *******************************************************************************
+# *****************************************************************************
# * Copyright (c) 2011 Wind River Systems, Inc. and others.
# * All rights reserved. This program and the accompanying materials
# * are made available under the terms of the Eclipse Public License v1.0
@@ -7,26 +7,37 @@
# *
# * Contributors:
# * Wind River Systems - initial API and implementation
-# *******************************************************************************
+# *****************************************************************************
-import sys, time, threading, atexit
+import sys
+import time
+import threading
+import atexit
import tcf
from tcf import protocol, channel, errors
from tcf.util import sync
__TRACE = False
+
+
class TraceListener(channel.TraceListener):
- def onMessageReceived(self, type, token, service, name, data):
- print "<<<", type, token, service, name, data
- def onMessageSent(self, type, token, service, name, data):
- print ">>>", type, token, service, name, data
+
+ def onMessageReceived(self, msgType, token, service, name, data):
+ print "<<<", msgType, token, service, name, data
+
+ def onMessageSent(self, msgType, token, service, name, data):
+ print ">>>", msgType, token, service, name, data
+
def onChannelClosed(self, error):
- print>>sys.stderr, "*** closed ***", error
+ print >> sys.stderr, "*** closed ***", error
_suspended = []
_memory = []
+_services = []
+
def test():
+ global _services
protocol.startEventQueue()
atexit.register(protocol.getEventQueue().shutdown)
#testTimer()
@@ -36,30 +47,31 @@ def test():
protocol.log(e)
sys.exit()
assert c.state == channel.STATE_OPEN
- if __TRACE: protocol.invokeLater(c.addTraceListener, TraceListener())
- def printServices():
- print "services=", c.getRemoteServices()
- protocol.invokeLater(printServices)
+ if __TRACE:
+ protocol.invokeAndWait(c.addTraceListener, TraceListener())
+ _services = protocol.invokeAndWait(c.getRemoteServices)
+ print "services=", _services
+ if "RunControl" in _services:
+ # RunControl must be first
+ _services.remove("RunControl")
+ _services.insert(0, "RunControl")
+ for service in _services:
+ testFct = globals().get("test" + service)
+ if testFct:
+ print "Testing service '%s'..." % service
+ try:
+ testFct(c)
+ print "Completed test of service '%s'." % service
+ except Exception as e:
+ protocol.log("Exception testing %s" % service, e)
+ else:
+ print "No test for service '%s' found." % service
try:
- testRunControl(c)
- testStackTrace(c)
- testDisassembly(c)
- testBreakpoints(c)
- testSymbols(c)
- testRegisters(c)
- testExpressions(c)
- testLineNumbers(c)
testSyncCommands(c)
testTasks(c)
testEvents(c)
testDataCache(c)
- testProcesses(c)
- testFileSystem(c)
- testMemory(c)
- testMemoryMap(c)
- testPathMap(c)
- testSysMonitor(c)
except Exception as e:
protocol.log(e)
@@ -71,6 +83,7 @@ def test():
def testTimer():
cond = threading.Condition()
+
def countdown(left):
if left == 0:
print "Ignition sequence started!"
@@ -84,12 +97,15 @@ def testTimer():
protocol.invokeLaterWithDelay(0, countdown, 10)
cond.wait(15)
+
def testRunControl(c):
lock = threading.Condition()
from tcf.services import runcontrol
+
def getContexts():
rctrl = c.getRemoteService(runcontrol.NAME)
pending = []
+
class DoneGetContext(runcontrol.DoneGetContext):
def doneGetContext(self, token, error, context):
pending.remove(token)
@@ -97,11 +113,15 @@ def testRunControl(c):
protocol.log("Error from RunControl.getContext", error)
else:
print context
+
class DoneGetState(runcontrol.DoneGetState):
- def doneGetState(self, token, error, suspended, pc, reason, params):
+
+ def doneGetState(self, token, error, suspended, pc, reason,
+ params):
pending.remove(token)
if error:
- protocol.log("Error from RunControl.getState", error)
+ protocol.log(
+ "Error from RunControl.getState", error)
else:
print "suspended: ", suspended
print "pc: ", pc
@@ -112,10 +132,12 @@ def testRunControl(c):
if len(pending) == 0:
with lock:
lock.notify()
- if context and context.hasState(): pending.append(context.getState(DoneGetState()))
+ if context and context.hasState():
+ pending.append(context.getState(DoneGetState()))
if len(pending) == 0:
with lock:
lock.notify()
+
class DoneGetChildren(runcontrol.DoneGetChildren):
def doneGetChildren(self, token, error, context_ids):
pending.remove(token)
@@ -132,33 +154,42 @@ def testRunControl(c):
with lock:
protocol.invokeLater(getContexts)
lock.wait(5)
+
def listenerTest():
rc = c.getRemoteService(runcontrol.NAME)
+
class RCListener(runcontrol.RunControlListener):
def contextSuspended(self, *args):
print "context suspended: ", args
rc.removeListener(self)
+
def contextResumed(self, *args):
print "context resumed: ", args
+
def containerSuspended(self, *args):
print "container suspended:", args
rc.removeListener(self)
+
def containerResumed(self, *args):
print "container resumed:", args
rc.addListener(RCListener())
+
class DoneGetContext(runcontrol.DoneGetContext):
def doneGetContext(self, token, error, context):
if error:
protocol.log("Error from RunControl.getContext", error)
- with lock: lock.notify()
+ with lock:
+ lock.notify()
return
+
class DoneResume(runcontrol.DoneCommand):
def doneCommand(self, token, error):
if error:
protocol.log("Error from RunControl.resume", error)
else:
context.suspend(runcontrol.DoneCommand())
- with lock: lock.notify()
+ with lock:
+ lock.notify()
context.resume(runcontrol.RM_RESUME, 1, None, DoneResume())
rc.getContext(_suspended[0], DoneGetContext())
@@ -167,68 +198,84 @@ def testRunControl(c):
protocol.invokeLater(listenerTest)
lock.wait(5)
+
def testBreakpoints(c):
from tcf.services import breakpoints
+
def testBPQuery():
bps = c.getRemoteService(breakpoints.NAME)
+
def doneGetIDs(token, error, ids):
if error:
protocol.log("Error from Breakpoints.getIDs", error)
return
print "Breakpoints :", ids
+
def doneGetProperties(token, error, props):
if error:
protocol.log("Error from Breakpoints.getProperties", error)
return
print "Breakpoint Properties: ", props
+
def doneGetStatus(token, error, props):
if error:
protocol.log("Error from Breakpoints.getStatus", error)
return
print "Breakpoint Status: ", props
- for id in ids:
- bps.getProperties(id, doneGetProperties)
- bps.getStatus(id, doneGetStatus)
+ for bpid in ids:
+ bps.getProperties(bpid, doneGetProperties)
+ bps.getStatus(bpid, doneGetStatus)
bps.getIDs(doneGetIDs)
protocol.invokeLater(testBPQuery)
+
def testBPSet():
bpsvc = c.getRemoteService(breakpoints.NAME)
+
class BPListener(breakpoints.BreakpointsListener):
- def breakpointStatusChanged(self, id, status):
- print "breakpointStatusChanged", id, status
+ def breakpointStatusChanged(self, bpid, status):
+ print "breakpointStatusChanged", bpid, status
+
def contextAdded(self, bps):
print "breakpointAdded", bps
bpsvc.removeListener(self)
+
def contextChanged(self, bps):
print "breakpointChanged", bps
+
def contextRemoved(self, ids):
print "breakpointRemoved", ids
bpsvc.addListener(BPListener())
+
def doneSet(token, error):
if error:
protocol.log("Error from Breakpoints.set", error)
return
bp = {
- breakpoints.PROP_ID : "python:1",
- breakpoints.PROP_ENABLED : True,
- breakpoints.PROP_LOCATION : "sysClkRateGet"
+ breakpoints.PROP_ID: "python:1",
+ breakpoints.PROP_ENABLED: True,
+ breakpoints.PROP_LOCATION: "sysClkRateGet"
}
bpsvc.set([bp], doneSet)
protocol.invokeLater(testBPSet)
+
def testStackTrace(c):
from tcf.services import stacktrace
+
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)
+ protocol.log(
+ "Error from StackTrace.getContext", error)
return
if ctxs:
for ctx in ctxs:
@@ -238,8 +285,10 @@ def testStackTrace(c):
for ctx_id in _suspended:
protocol.invokeLater(stackTest, ctx_id)
+
def testDisassembly(c):
- if not _suspended: return
+ if not _suspended:
+ return
ctl = sync.CommandControl(c)
try:
dis = ctl.Disassembly
@@ -259,19 +308,24 @@ def testDisassembly(c):
for line in lines:
print line
+
def testSymbols(c):
from tcf.services import symbols
+
def symTest(ctx_id):
syms = c.getRemoteService(symbols.NAME)
+
class DoneList(symbols.DoneList):
def doneList(self, token, error, ctx_ids):
if error:
protocol.log("Error from Symbols.list", error)
return
+
class DoneGetContext(symbols.DoneGetContext):
def doneGetContext(self, token, error, ctx):
if error:
- protocol.log("Error from Symbols.getContext", error)
+ protocol.log(
+ "Error from Symbols.getContext", error)
return
print ctx
if ctx_ids:
@@ -281,15 +335,21 @@ def testSymbols(c):
for ctx_id in _suspended:
protocol.invokeLater(symTest, ctx_id)
+
def testRegisters(c):
- if not _suspended: return
+ if not _suspended:
+ return
from tcf.services import registers
lock = threading.Condition()
+
def regTest(ctx_id):
regs = c.getRemoteService(registers.NAME)
pending = []
+
def onDone():
- with lock: lock.notify()
+ with lock:
+ lock.notify()
+
class DoneGetChildren(registers.DoneGetChildren):
def doneGetChildren(self, token, error, ctx_ids):
pending.remove(token)
@@ -297,63 +357,84 @@ def testRegisters(c):
protocol.log("Error from Registers.getChildren", error)
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)
+ protocol.log(
+ "Error from Registers.getContext", error)
else:
print ctx
- if ctx.isReadable() and not ctx.isReadOnce() and ctx.getSize() >= 2:
+ 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))
+ 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)
+ protocol.log(
+ "Error from Registers.getm",
+ error)
else:
- print "getm", ctx.getID(), map(ord, value)
+ 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:
+ 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))
+ 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)
+ protocol.log(
+ "Error from Registers.setm",
+ error)
if not pending:
onDone()
- pending.append(regs.setm(locs, (255, 255), DoneSetM()))
+ pending.append(
+ regs.setm(locs, (255, 255), DoneSetM()))
if not pending:
onDone()
if ctx_ids:
for ctx_id in ctx_ids:
- pending.append(regs.getContext(ctx_id, DoneGetContext()))
+ 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(5)
+
def testExpressions(c):
- if not _suspended: return
+ if not _suspended:
+ return
from tcf.services import expressions
ctl = sync.CommandControl(c)
exprs = ctl.Expressions
e = exprs.create(_suspended[0], None, "1+2*(3-4/2)").getE()
- id = e.get(expressions.PROP_ID)
- val, cls = exprs.evaluate(id).getE()
+ eid = e.get(expressions.PROP_ID)
+ val, cls = exprs.evaluate(eid).getE()
print e.get(expressions.PROP_EXPRESSION), "=", val
- exprs.dispose(id)
+ exprs.dispose(eid)
+
def testLineNumbers(c):
- if not _suspended: return
+ if not _suspended:
+ return
from tcf.services import stacktrace
ctl = sync.CommandControl(c)
stack = ctl.StackTrace
@@ -364,8 +445,10 @@ def testLineNumbers(c):
bt = stack.getContext(bt).get()
for frame in bt:
addr = frame.get(stacktrace.PROP_INSTRUCTION_ADDRESS)
- area = lineNumbers.mapToSource(ctx_id, addr, addr+1).get()
- print "Frame %d - CodeArea: %s" % (frame.get(stacktrace.PROP_LEVEL), area)
+ area = lineNumbers.mapToSource(ctx_id, addr, addr + 1).get()
+ print "Frame %d - CodeArea: %s" % (
+ frame.get(stacktrace.PROP_LEVEL), area)
+
def testSyncCommands(c):
# simplified command execution
@@ -392,28 +475,40 @@ def testSyncCommands(c):
frame_ids = ctl.StackTrace.getChildren(ctx_id).get()
if frame_ids:
error, args = ctl.StackTrace.getContext(frame_ids)
- if not error: print "Stack contexts:", args
+ if not error:
+ print "Stack contexts:", args
+ try:
+ ctl.Breakpoints
+ except AttributeError:
+ # no Breakpoints service
+ return
+
def gotBreakpoints(error, bps):
print "Got breakpoint list:", bps
ctl.Breakpoints.getIDs(onDone=gotBreakpoints)
try:
print ctl.Processes.getChildren(None, False)
except:
- pass # no Processes service
+ pass # no Processes service
+
def testTasks(c):
- if not _suspended: return
+ if not _suspended:
+ return
from tcf.services import expressions
from tcf.util import task
+
def compute(expr, done=None):
es = c.getRemoteService(expressions.NAME)
if not es:
done(Exception("No Expressions service"), None)
return
+
def doneCreate(token, error, ctx):
if error:
done(error, None)
return
+
def doneEval(token, error, val):
done(error, val)
es.evaluate(ctx.getID(), doneEval)
@@ -422,6 +517,7 @@ def testTasks(c):
val = t.get()
print "Task result:", val
+
def testEvents(c):
from tcf.util import event
recorder = event.EventRecorder(c)
@@ -433,7 +529,8 @@ def testEvents(c):
# no RunControl service
return
ctxs = rc.getChildren(None).get()
- if not ctxs: return
+ if not ctxs:
+ return
ctx = ctxs[0]
rc.resume(ctx, 0, 1, None).wait()
print recorder
@@ -441,9 +538,13 @@ def testEvents(c):
print recorder
recorder.stop()
+
def testDataCache(c):
from tcf.util import cache
from tcf.services import runcontrol
+ if not runcontrol.NAME in _services:
+ return
+
class ContextsCache(cache.DataCache):
def startDataRetrieval(self):
rc = self._channel.getRemoteService(runcontrol.NAME)
@@ -453,11 +554,13 @@ def testDataCache(c):
cache = self
pending = []
contexts = []
+
class DoneGetChildren(runcontrol.DoneGetChildren):
def doneGetChildren(self, token, error, context_ids):
pending.remove(token)
if error:
- protocol.log("Error from RunControl.GetChildren", error)
+ protocol.log(
+ "Error from RunControl.GetChildren", error)
else:
for c in context_ids:
contexts.append(c)
@@ -466,24 +569,37 @@ def testDataCache(c):
cache.set(None, None, contexts)
pending.append(rc.getChildren(None, DoneGetChildren()))
contextsCache = ContextsCache(c)
+
def done():
print "ContextsCache is valid:", contextsCache.getData()
protocol.invokeLater(contextsCache.validate, done)
+
def testProcesses(c):
from tcf.services import processes, processes_v1
+ lock = threading.Condition()
+
def processTest():
- proc = c.getRemoteService(processes_v1.NAME) or c.getRemoteService(processes.NAME)
+ proc = c.getRemoteService(processes_v1.NAME) or \
+ c.getRemoteService(processes.NAME)
if not proc:
+ with lock:
+ lock.notify()
return
+
class DoneGetChildren(processes.DoneGetChildren):
def doneGetChildren(self, token, error, context_ids):
if error:
protocol.log("Error from Processes.GetChildren", error)
else:
print "Processes:", context_ids
+ with lock:
+ lock.notify()
proc.getChildren(None, False, DoneGetChildren())
- protocol.invokeLater(processTest)
+ with lock:
+ protocol.invokeLater(processTest)
+ lock.wait(5)
+
def testFileSystem(c):
cmd = sync.CommandControl(c)
@@ -497,12 +613,15 @@ def testFileSystem(c):
user = fs.user().get()
print "User info: ", user
+
def testMemory(c):
lock = threading.Condition()
from tcf.services import memory
+
def getContexts():
mem = c.getRemoteService(memory.NAME)
pending = []
+
class DoneGetContext(memory.DoneGetContext):
def doneGetContext(self, token, error, context):
pending.remove(token)
@@ -513,6 +632,7 @@ def testMemory(c):
if len(pending) == 0:
with lock:
lock.notify()
+
class DoneGetChildren(memory.DoneGetChildren):
def doneGetChildren(self, token, error, context_ids):
pending.remove(token)
@@ -531,45 +651,55 @@ def testMemory(c):
protocol.invokeLater(getContexts)
lock.wait(5)
+
def testMemoryMap(c):
- if not _memory: return
+ if not _memory:
+ return
cmd = sync.CommandControl(c)
try:
mm = cmd.MemoryMap
except AttributeError:
# no MemoryMap service
return
- id = _memory[0]
+ map_id = _memory[0]
lock = threading.Condition()
from tcf.services import memorymap
+
def getMap():
mm = c.getRemoteService(memorymap.NAME)
+
class DoneGet(memorymap.DoneGet):
- def doneGet(self, token, error, map):
+ def doneGet(self, token, error, mmap):
if error:
protocol.log("Error from MemoryMap.get", error)
else:
- print map
+ print mmap
with lock:
lock.notify()
- mm.get(id, DoneGet())
+ mm.get(map_id, DoneGet())
with lock:
protocol.invokeLater(getMap)
lock.wait(1)
+
def setMap():
mm = c.getRemoteService(memorymap.NAME)
+
class DoneSet(memorymap.DoneSet):
def doneSet(self, token, error):
if error:
protocol.log("Error from MemoryMap.set", error)
with lock:
lock.notify()
- mm.set(id, {memorymap.PROP_FILE_NAME : "/tmp/system.elf"}, DoneSet())
+ mm.set(
+ id,
+ {memorymap.PROP_FILE_NAME: "/tmp/system.elf"},
+ DoneSet())
with lock:
protocol.invokeLater(setMap)
lock.wait(1)
- map = mm.get(id).get()
- print "Memory map:", map
+ mmap = mm.get(id).get()
+ print "Memory map:", mmap
+
def testPathMap(c):
cmd = sync.CommandControl(c)
@@ -580,35 +710,40 @@ def testPathMap(c):
return
lock = threading.Condition()
from tcf.services import pathmap
+
def getMap():
pm = c.getRemoteService(pathmap.NAME)
+
class DoneGet(pathmap.DoneGet):
- def doneGet(self, token, error, map):
+ def doneGet(self, token, error, mmap):
if error:
protocol.log("Error from PathMap.get", error)
else:
- print map
+ print mmap
with lock:
lock.notify()
pm.get(DoneGet())
with lock:
protocol.invokeLater(getMap)
lock.wait(1)
+
def setMap():
pm = c.getRemoteService(pathmap.NAME)
+
class DoneSet(pathmap.DoneSet):
def doneSet(self, token, error):
if error:
protocol.log("Error from PathMap.set", error)
with lock:
lock.notify()
- pm.set({pathmap.PROP_SOURCE : "/tmp",
- pathmap.PROP_DESTINATION : "/home"}, DoneSet())
+ pm.set({pathmap.PROP_SOURCE: "/tmp",
+ pathmap.PROP_DESTINATION: "/home"}, DoneSet())
with lock:
protocol.invokeLater(setMap)
lock.wait(1)
- map = pm.get().get()
- print "Path map:", map
+ mmap = pm.get().get()
+ print "Path map:", mmap
+
def testSysMonitor(c):
cmd = sync.CommandControl(c)
@@ -620,9 +755,11 @@ def testSysMonitor(c):
lock = threading.Condition()
from tcf.services import sysmonitor
processes = []
+
def getProcesses():
sm = c.getRemoteService(sysmonitor.NAME)
pending = []
+
class DoneGetChildren(sysmonitor.DoneGetChildren):
def doneGetChildren(self, token, error, context_ids):
pending.remove(token)
@@ -633,14 +770,16 @@ def testSysMonitor(c):
def doneGetContext(self, token, error, context):
pending.remove(token)
if error:
- protocol.log("Error from SysMonitor.getContext", error)
+ protocol.log(
+ "Error from SysMonitor.getContext", error)
else:
processes.append(context)
if not pending:
with lock:
lock.notify()
- for id in context_ids:
- pending.append(sm.getContext(id, DoneGetContext()))
+ for ctx_id in context_ids:
+ pending.append(
+ sm.getContext(ctx_id, DoneGetContext()))
if not pending:
with lock:
lock.notify()
@@ -652,7 +791,8 @@ def testSysMonitor(c):
for p in processes:
print p
cmdl = sm.getCommandLine(p.getID()).get()
- if cmdl: print "Command line: ", cmdl
+ if cmdl:
+ print "Command line: ", cmdl
envp = sm.getEnvironment(p.getID()).get()
print "Environment: ", envp

Back to the top