summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-09-29 08:29:51 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-09-29 08:29:51 -0400
commit790e9c47262937c65812ba0a2addbf40e335b31d (patch)
treec4b9616711478beb8aef4aa7d9be52f4e9c216ea
parent73e6088325d980e7cf5f2c50bc57511289724de7 (diff)
downloadgpsd-790e9c47262937c65812ba0a2addbf40e335b31d.tar.gz
Enhance gpsfake so it can be used to test TCP sources.
-rw-r--r--gps/fake.py32
-rwxr-xr-xgpsfake9
-rw-r--r--gpsfake.xml13
3 files changed, 47 insertions, 7 deletions
diff --git a/gps/fake.py b/gps/fake.py
index 1fe71d34..f4a2d386 100644
--- a/gps/fake.py
+++ b/gps/fake.py
@@ -142,8 +142,10 @@ class TestLoad:
raise TestLoadError("bad serial-parameter spec in %s"%\
logfp.name)
self.serial = (baud, databits, parity, stopbits)
- elif "UDP" in packet:
+ elif "Transport: UDP" in packet:
self.sourcetype = "UDP"
+ elif "Transport: TCP" in packet:
+ self.sourcetype = "TCP"
else:
if type_latch is None:
type_latch = ptype
@@ -267,6 +269,28 @@ class FakePTY(FakeGPS):
"Wait for the associated device to drain (e.g. before closing)."
termios.tcdrain(self.fd)
+class FakeTCP(FakeGPS):
+ "A TCP broadcaster with a test log ready to be cycled to it."
+ def __init__(self, testload,
+ ipaddr, port,
+ progress=None):
+ FakeGPS.__init__(self, testload, progress)
+ self.ipaddr = ipaddr
+ self.port = port
+ self.byname = "tcp://" + ipaddr + ":" + port
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ def read(self):
+ "Discard control strings written by gpsd."
+ pass
+
+ def write(self, line):
+ self.sock.sendto(line, (self.ipaddr, int(self.port)))
+
+ def drain(self):
+ "Wait for the associated device to drain (e.g. before closing)."
+ pass
+
class FakeUDP(FakeGPS):
"A UDP broadcaster with a test log ready to be cycled to it."
def __init__(self, testload,
@@ -408,7 +432,7 @@ class TestSessionError(exceptions.Exception):
class TestSession:
"Manage a session including a daemon with fake GPSes and clients."
- def __init__(self, prefix=None, port=None, options=None, verbose=0, predump=False, udp=False):
+ def __init__(self, prefix=None, port=None, options=None, verbose=0, predump=False, udp=False, tcp=False):
"Initialize the test session by launching the daemon."
self.prefix = prefix
self.port = port
@@ -416,6 +440,7 @@ class TestSession:
self.verbose = verbose
self.predump = predump
self.udp = udp
+ self.tcp = tcp
self.daemon = DaemonInstance()
self.fakegpslist = {}
self.client_id = 0
@@ -448,6 +473,9 @@ class TestSession:
if testload.sourcetype == "UDP" or self.udp:
newgps = FakeUDP(testload, ipaddr="127.0.0.1", port="5000",
progress=self.progress)
+ if testload.sourcetype == "TCP" or self.tcp:
+ newgps = FakeTCP(testload, ipaddr="127.0.0.1", port="5000",
+ progress=self.progress)
else:
newgps = FakePTY(testload, speed=speed,
progress=self.progress)
diff --git a/gpsfake b/gpsfake
index 29f8a9d0..f6c3702e 100755
--- a/gpsfake
+++ b/gpsfake
@@ -94,7 +94,7 @@ def fakehook(linenumber, fakegps):
if __name__ == '__main__':
try:
- (options, arguments) = getopt.getopt(sys.argv[1:], "1bc:D:fghilm:no:pP:r:s:uvx")
+ (options, arguments) = getopt.getopt(sys.argv[1:], "1bc:D:fghilm:no:pP:r:s:tuvx")
except getopt.GetoptError, msg:
print "gpsfake: " + str(msg)
raise SystemExit, 1
@@ -111,6 +111,7 @@ if __name__ == '__main__':
promptme = False
client_init = '?WATCH={"json":true,"nmea":true}'
doptions = ""
+ tcp = False
udp = False
verbose = 0
for (switch, val) in options:
@@ -146,6 +147,8 @@ if __name__ == '__main__':
client_init = val
elif (switch == '-s'):
speed = int(val)
+ elif (switch == '-t'):
+ tcp = True
elif (switch == '-u'):
udp = True
elif (switch == '-v'):
@@ -163,7 +166,9 @@ if __name__ == '__main__':
else:
print >>sys.stderr, "Processing %s" % ",".join(arguments)
- test = gpsfake.TestSession(prefix=monitor, port=port, options=doptions, udp=udp, verbose=verbose, predump=predump)
+ test = gpsfake.TestSession(prefix=monitor, port=port, options=doptions,
+ tcp=tcp, udp=udp, verbose=verbose,
+ predump=predump)
if pipe:
test.reporter = sys.stdout.write
diff --git a/gpsfake.xml b/gpsfake.xml
index 7a509392..e2280d81 100644
--- a/gpsfake.xml
+++ b/gpsfake.xml
@@ -39,6 +39,7 @@ BSD terms apply: see the file COPYING in the distribution root for details.
<arg choice='opt'>-r <replaceable>initcmd</replaceable></arg>
<arg choice='opt'>-s <replaceable>speed</replaceable></arg>
<arg choice='opt'>-u</arg>
+ <arg choice='opt'>-t</arg>
<arg choice='opt'>-v</arg>
<arg rep='repeat'>
<arg choice='plain'><replaceable>logfile</replaceable></arg>
@@ -144,9 +145,15 @@ The default is <command>?WATCH={"enable":true,"json":true}</command>.</para>
<para>The <option>-s</option> sets the baud rate for the slave tty. The
default is 4800.</para>
-<para>The <option>-u</option> forces the test framework to use UDP rather than
-pty devices. This may be useful for testing from within chroot jails
-where access to pty devices is locked out.</para>
+<para>The <option>-t</option> forces the test framework to use TCP
+rather than pty devices. Besides being a test of TCP source handling,
+this may be useful for testing from within chroot jails where access
+to pty devices is locked out.</para>
+
+<para>The <option>-u</option> forces the test framework to use UDP
+rather than pty devices. Besides being a test of UDP source handling,
+this may be useful for testing from within chroot jails where access
+to pty devices is locked out.</para>
<para>The <option>-v</option> enables verbose progress reports to stderr. It is
mainly useful for debugging <application>gpsfake</application>