summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-06-27 14:17:11 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-06-27 14:17:11 +0000
commit7c4cc0858e33dc26722cd4c6c5a798da7563bd6f (patch)
treec34b2c7b6d58a320bb8a06a8f42c21b7e1016535
parente5d6d85976a045fa39d0942cd1b9b143a1c40bdd (diff)
downloadgpsd-7c4cc0858e33dc26722cd4c6c5a798da7563bd6f.tar.gz
Add progress messages to test framework.
-rw-r--r--gpsfake.py32
-rw-r--r--gpsfake.xml2
-rwxr-xr-xvalgrind-audit29
3 files changed, 52 insertions, 11 deletions
diff --git a/gpsfake.py b/gpsfake.py
index f177af3f..caa249a5 100644
--- a/gpsfake.py
+++ b/gpsfake.py
@@ -270,6 +270,10 @@ class DaemonInstance:
self.pid = None
time.sleep(1) # Give signal time to land
+class TestSessionError(exceptions.Exception):
+ def __init__(self, msg):
+ self.msg = msg
+
class TestSession:
"Manage a session including a daemon with fake GPS and client threads."
def __init__(self, prefix=None, options=None):
@@ -279,6 +283,7 @@ class TestSession:
self.clients = []
self.client_id = 0
self.reporter = lambda x: None
+ self.progress = sys.stderr.write
for sig in (signal.SIGQUIT, signal.SIGINT, signal.SIGTERM):
signal.signal(sig, lambda signal, frame: self.killall())
self.daemon.spawn(background=True, prefix=prefix, options=options)
@@ -289,6 +294,7 @@ class TestSession:
self.default_predicate = pred
def gps_add(self, name, speed=4800, pred=None):
"Add a simulated GPS being fed by the specified logfile."
+ self.progress("gpsfake: gps_add(%s, %d)\n" % (name, speed))
if name not in self.fakegpslist:
if not name.endswith(".log"):
logfile = name + ".log"
@@ -304,28 +310,35 @@ class TestSession:
return newgps.slave
def gps_remove(self, name):
"Remove a simulated GPS from the daeon's search list."
+ self.progress("gpsfake: gps_remove(%s)\n" % name)
self.fakegpslist[name].stop()
self.daemon.remove_device(name)
def client_add(self, commands):
"Initiate a client session and force connection to a fake GPS."
newclient = gps.gps()
+ self.progress("gpsfake: Adding client %d on %s\n" % (self.client_id+1,newclient.device))
self.client_id += 1
newclient.id = self.client_id
self.clients.append(newclient)
newclient.query("of\n")
- time.sleep(0.05) # Avoid mysterious "connection reset by peer"
- self.fakegpslist[newclient.device].start(thread=True)
- newclient.set_thread_hook(lambda x: self.reporter(x))
- if commands:
- newclient.query(commands)
- return newclient.id
+ time.sleep(1) # Avoid mysterious "connection reset by peer"
+ if not newclient.device:
+ raise TestSessionError("gpsd returned no device for client open.\n")
+ else:
+ self.fakegpslist[newclient.device].start(thread=True)
+ newclient.set_thread_hook(lambda x: self.reporter(x))
+ if commands:
+ newclient.query(commands)
+ return newclient.id
def client_order(self, id, commands):
"Ship a command down a client channel, accept a response."
+ self.progress("gpsfake: client_order(commands, %d)\n" % (commands, id))
for client in self.clients:
if client.id == id:
client.query(commands)
def client_remove(self, id):
"Terminate a client session."
+ self.progress("gpsfake: client_remove(%d)\n" % id)
for client in self.clients:
if client.id == id:
self.fakegpslist[client.device].release()
@@ -336,23 +349,26 @@ class TestSession:
return False
def wait(self, seconds):
"Wait, doing nothing."
+ self.progress("gpsfake: wait(%d)\n" % seconds)
time.sleep(seconds)
def gps_count(self):
"Return the number of GPSes active in this session"
tc = 0
for fakegps in self.fakegpslist.values():
- if fakegps.thread.isAlive():
+ if fakegps.thread and fakegps.thread.isAlive():
tc += 1
return tc
def cleanup(self):
"Wait for all threads to end and kill the daemon."
+ self.progress("gpsfake: cleanup()\n")
while self.gps_count():
time.sleep(0.1)
self.daemon.kill()
def killall(self):
"Kill all fake-GPS threads and the daemon."
+ self.progress("gpsfake: killall()\n")
for fakegps in self.fakegpslist.values():
- if fakegps.thread.isAlive():
+ if fakegps.thread and fakegps.thread.isAlive():
fakegps.stop()
self.daemon.kill()
diff --git a/gpsfake.xml b/gpsfake.xml
index e372f4ce..cd40e723 100644
--- a/gpsfake.xml
+++ b/gpsfake.xml
@@ -88,7 +88,7 @@ data to be cycled at the device. <application>gpsfake</application>
will print a notification each time it cycles.</para>
</refsect1>
-<refsect1 id='options'><title>CUSTOM TESTS</title>
+<refsect1 id='custom'><title>CUSTOM TESTS</title>
<para><application>gpsfake</application> is a trivial wrapper around a
Python module, also named gpsfake, that can be used to fully script
diff --git a/valgrind-audit b/valgrind-audit
index 8c4ba239..9c3847e9 100755
--- a/valgrind-audit
+++ b/valgrind-audit
@@ -22,6 +22,7 @@ try:
print "\n**** Remove the GPS.\n"
test.gps_remove(gps1)
print "*** Test #1 complete."
+ test.wait(3)
######################################################################
@@ -44,6 +45,30 @@ try:
print "\n**** Remove the GPS.\n"
test.gps_remove(gps1)
print "*** Test #2 complete."
- test.wait(15)
-finally:
+ test.wait(3)
+
+ ######################################################################
+
+ print "\n*** Test #3: Overlapping client sessions."
+ print "**** Add a GPS.\n"
+ gps1 = test.gps_add("test/bu303-climbing.log")
+
+ print "\n**** Add first client.\n"
+ c1 = test.client_add("w\n")
+ test.wait(2)
+ print "\n**** Add second client.\n"
+ c2 = test.client_add("w\n")
+ test.wait(3)
+ print "\n**** Remove first client.\n"
+ test.client_remove(c1)
+ test.wait(2)
+ print "\n**** Remove second client.\n"
+ test.client_remove(c2)
+
+ print "\n**** Remove the GPS.\n"
+ test.gps_remove(gps1)
+ print "*** Test #3 complete."
+
test.cleanup();
+finally:
+ test.killall();