summaryrefslogtreecommitdiff
path: root/gps/fake.py
Commit message (Collapse)AuthorAgeFilesLines
* gpsfake: Avoid duplicated output after daemon death.Fred Wright2018-12-281-1/+2
| | | | | | | | | | | | Although the client read() method provides a return value to indicate that daemon output has become unavailable (due to its death), the run() method in fake.py was ignoring it, and just repeatedly outputting the old string until it eventually noticed the death. It now pays attention to the failure return. TESTED: All tests pass. Quitting the daemon while stopped at a breakpoint no longer spews duplicated output for a while.
* gpsfake: Notice when daemon dies.Fred Wright2018-12-281-0/+4
| | | | | | | | | | | | Death of the daemon (after initial connection) wasn't being noticed, so that the daemon dying (e.g., by quitting it from a debugger) left gpsfake looping and spewing output. This puts an alive check in the main loop, as well as in an inner loop that's sometimes relevant. TESTED: Quit the daemon after stopping at breakpoints in a couple of different cases; gpsfake now quits with an error. It does still spew a bunch of duplicated output in some cases, though.
* Decreases OSX Write_PAD.Fred Wright2018-12-271-1/+1
| | | | | | | | | | Although there doesn't seem to be any WRITE_PAD value that's 100% reliable, 5ms is usually adequately generous for OSX, and is the override value currently used by MacPorts. The current default 30ms makes some tests way too slow. TESTED: Tests pass on OSX 10.5-10.13.
* gpsfake: Allow timeout to be specified.Fred Wright2018-12-271-4/+6
| | | | | | | | | | | This adds an argument to allow overriding the default 60-second timeout on gpsd's activity. A value of 0 disables the timeout completely. Note that the timeout mechanism is somewhat sloppy, and typically adds about 20s to the value. TESTED: Ran with unspecified (default) timeout, a short timeout, a long timeout, and no timeout, all with reasonable results.
* gps/fake.py: pylint cleanupsGary E. Miller2018-09-221-4/+15
|
* fake.py: Fix for PEP8Gary E. Miller2018-06-201-10/+10
|
* gps/fake.py: code rearrangement to handle pylint complexity warningGary E. Miller2017-07-311-9/+11
|
* fake.py: Fix pylint complaint about a function override.Gary E. Miller2017-07-261-3/+3
| | | | | pylint complains when a class function is overridden with a function taking different arguments.
* fake.py: remove redundant assignment of self.port.Gary E. Miller2017-07-261-1/+0
|
* Fixes some pylint issues.Fred Wright2017-07-141-1/+1
| | | | | | | | | | | This doesn't fix all complaints by pylint, but significantly reduces their number. Ditto for pep8 complaints. Also makes a couple of related cosmetic edits. TESTED: Ran "scons build-all check" with no errors. Both "pylint" and "pep8" targets report fewer issues.
* Fixes bug in gpsfake with default port.Fred Wright2017-07-141-1/+1
| | | | | | | | | | | | The default port number used by gpsfake is (probably incorrectly) specified as a string rather than an integer. The shmkey derivation added in commit 1f209455 expects an integer, causing a failure when the port is not explicitly specified. This fix forces an integer where needed. TESTED: Ran "scons build-all check". Previously failing gpsfake case now works correctly.
* gps/fake.py, gpssim.py: pep8 fixesGary E. Miller2017-07-011-34/+68
|
* Makes 'GPSD' SHM IDs unique during regression tests.Fred Wright2017-03-241-3/+11
| | | | | | | | | | | | | | | | | Prior to this change, multiple gpsd instances would normally share a single SHM segment, confusing anyone using it. This was a problem either when running parallel regression tests, or even when running a single test with a system gpsd also running. Now, each gpsd instance launched by fake.py gets a SHM ID of the form 0x4770xxxx, where xxxx is the TCP or UDP port number. The high-order part is 0x4770 ('Gp') instead of 0x4750 ('GP') to ensure that it doesn't collide with the standard 'GPSD'. This does not do anything about 'NTPx' SHM segments. TESTED: Ran "scons -j24 check", and observed many 'Gpxx' SHM segments with ipcs, all disappearing by the end of testing.
* Makes connect failure to dead fake.py daemon more informative.Fred Wright2017-02-191-1/+6
| | | | | | | | | | | This generates a more specific exception when a connect from client_add() fails due to the daemon's having died. Aside from real daemon failures, this also catches some broken valgrind cases. TESTED: Ran "scons build-all check" on OSX. Also ran failing valgrind-audit and observed more informative (and less verbose) backtrace. Note that this is due to an OSX issue with valgrind itself, not the daemon.
* Reworks local exception definitions in fake.py.Fred Wright2017-02-191-15/+11
| | | | | | | | | This reduces duplicated code by using subclasses for local exceptions. It's not entirely clear that limiting __str__() to only certain exceptions is necessary, but it preserves that behavior. TESTED: Ran "scons build-all check" on several platforms.
* Reworks DaemonInstance in fake.py.Fred Wright2017-02-191-72/+80
| | | | | | | | | | | | | | | | | | | | This does two things: 1) It splits DaemonInstance into a base class and subclass, where the base class is a more generic subprogram runner. This makes it easier to add additional program runners without code duplication. 2) It switches from os.system() to subprocess.Popen() as the mechanism for running subprograms. This is generally cleaner, and in "background mode" is able to use natural parallelism rather than the ugly kludge of using shell backgrounding. Aside from being less ugly, this also makes termination of the "background" process directly visible, avoiding, e.g., hangs when valgrind bombs. TESTED: Ran "scons build-all check" on several platforms. Also ran valgrind-audit where valgrind was installed, though this has issues on some platforms.
* Changes fake.py stream type to 'bytes'.Fred Wright2016-12-251-5/+7
| | | | | | | | | | | | | | | | | | | Given that the data returned bye fake.py may include binary data, 'bytes' is a more appropriate type. Unlike the client API, where it's easy to provide both return types, it would be less convenient to do that here, so 'bytes' is preferred as the one choice (and is consistent with network sockets). When sending such data to stdout (or stderr), the straightforward method is to write to sys.stdXXX.buffer rather than sys.stdXXX. That doesn't exist in Python 2, but a helper function is now provided to get the appropriate 'bytes' stream for stdXXX. Since no previous *release* of GPSD is compatible with Python 3, changing this now doesn't break anything based on released code. TESTED: Ran "scons check" on OSX with all supported Python versions.
* Changes fake.py subclasses to use super() in __init__().Fred Wright2016-04-111-7/+7
| | | | | | | | | | | | | This doesn't really change any behavior, but serves as a better example for future code. Note that this can't be done so easily for gps.gps, due to the mismatched init signatures. This uses the older super() syntax, which is compatible with both Python 2 and Python 3. TESTED: Ran "scons build-all check" with all six supported Python versions. Also tested exception objects manually.
* Fixes gps/*.py to use new-style classes.Fred Wright2016-04-111-4/+4
| | | | | | | | | | | | | | | | | | | | | | | Although this isn't strictly a Python 3 requirement, using the new-style class definition syntax improves consistency between Python 2 and Python 3. Old-style classes have been deprecated since Python 2.2, but many such definitions linger on. Python 3 eliminates old-style classes, but instead of complaining about old-style definitions, it simply unconditionally and silently makes all classes new-style. The only incompatible differences are quite subtle and rarely matter in practice, but things are more consistent across versions if the new-style definitions are used. Also, the preferred method for subclasses to invoke parent init methods is via the super() construct, which is only available with new-style classes. Using super() is especially useful with multiple inheritance, which it handles automatically (provided that the init methods have compatible signatures). TESTED: Ran "scons build-all check valgrind-audit", as well as gegps, gpscat, gpsprof, xgps, and xgpsspeed, with all six supported Python versions (except 2.6 for xgps*).
* Fixes fake.py and gpsfake for Python 3.Fred Wright2016-04-091-15/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This incorporates the following changes: 1) Adds definitions for polystr(), polybytes(), and make_std_wrapper() to misc.py (the most logical place for code needed by multiple modules), using dummy definitions in the Python 2 case. For more info, see the Practical Python Porting guide. 2) Reworks the logfile->daemon data path in fake.py to use 'bytes' consistently. 3) Uses polybytes() in fake.py to construct control-socket commands as 'bytes', as expected by the socket I/O. 4) Uses make_std_wrapper() in gpsfake, to ensure that binary data is correctly written to stdout. 5) Adds 'division' to the future imports in gpsfake for consistency, though it doesn't actually matter in practice. Also updates the compatibility comments in all three files, and fixes a minor typo in misc.py. TESTED: Ran "scons build-all check" with Python 2.7, and ran all daemon regression tests with Python 2.6 and with Python 3.2-3.5 (with appropriately built extensions; not yet a build option).
* Forces Python 3 import behavior in all gps/* modules.Fred Wright2016-04-091-1/+1
| | | | | | | | | | | | This ensures that any future changes that accidentally rely on the Python 2 implicit relative import behavior will fail in Python 2 as well as Python 3. TESTED: Ran "scons build-all check" (with Python 2.7). Also verified that the regression tests and test_maidenhead.py run with Python 2.6, and that gpsfake -T and test_maidenhead.py run with Python 3 when the extensions are built for Python 3 (not yet a build option).
* Fixes fake.py 'packet' import for Python 3.Fred Wright2016-04-091-1/+1
| | | | | | | | | | | | This changes the import of the 'packet' module to be an explicit relative import, which is valid in both Python2 and Python 3. The old implicit relative import doesn't work in Python 3. TESTED: Ran "scons build-all check" (with Python 2.7). Also verified that the regression tests and test_maidenhead.py run with Python 2.6, and that gpsfake -T and test_maidenhead.py run with Python 3 when the extensions are built for Python 3 (not yet a build option).
* Restore language about 2.6 portability, clean up Python imports.Eric S. Raymond2016-03-271-1/+3
|
* Fix Python 3 compatibility.Eric S. Raymond2016-03-241-2/+2
|
* pylint cleanup.Eric S. Raymond2016-03-221-4/+4
|
* Forward-port gps/ Python client code to run polyglot under Python 2 or 3.Eric S. Raymond2016-03-221-10/+12
| | | | | | | Verified by testing gpsprof under both versions. leapecond.py is also OK. Not yet polyglot: gegps, gpscap.py, gpscat, gpsfake, jsongen.py, maskaudit.py, test_maidenhead.py, valgrind_audit.py, xgps, xgpsspeed.
* Makes gpsfake -T take -S into account.Fred Wright2016-03-031-8/+13
| | | | | | | | | | | | | | | | | | | | This makes it possible to view the "slow" as well as the normal WRITE_PAD values with gpsfake -T, without having to look at the source code. It adds a new GetDelay() function to fake.py, which returns the proper delay value, taking into account both the possible environment variable and the "slow" option. This is now used for all hree uses of WRITE_PAD. Because the environment override is now part of the function, the WRITE_PAD constant is no longer modified by the environment value, but instead reflects the platform default. TESTED: Ran the full set of regression tests, with both default and acceptably shortened WRITE_PAD. Also verified that a zero value causes trouble (OSX), and that adding -S to the zero value makes it work. Signed-off-by: Jon Schlueter <jon.schlueter@gmail.com>
* Eliminates spurious gpsd errors with gpsfake in TCP mode.Fred Wright2016-02-291-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Depending on timing, in TCP mode, gpsd may try to reconnect to fake.py between the time that the logfile is complete and the time that the remove_device is issued. With no listener, this results in a set of three error messages from gpsd. They don't affect the test outcome, since they only go to stderr and the "real" output is complete, but they're annoying to the user. The likelihood of this happening increases with longer logfiles and with larger WRITE_PAD values. With a 30ms WRITE_PAD (the default on OSX), most logfiles exhibit this on all platforms, though it's not seen on Linux with the default zero WRITE_PAD. The fix is simply to avoid closing the listener after accepting the incoming connection. It's not necessary to explicitly service the listener further, since the OS listen queue is sufficient to accept the additional connection. Closing the listener at drain time is almost acceptable, but still occasionally fails due to the fact that drain() is (necessarily) called before remove_device(). Not explicitly closing it at all is acceptable, since Python closes it as part of the object cleanup. TESTED: Ran regress-driver in TCP mode with a 30ms WRITE_PAD on all logfiles on three versions of OSX, as well as Linux, FreeBSD, and OpenBSD, both with and without the fix. Observed spurious errors in all cases without the fix, and no cases with the fix. Also verified that no dangling sockets were left at the end of the runs.
* Makes fake.py's TCP and UDP port assignments parallel-compatible.Fred Wright2016-02-291-15/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | The current method for assigning ports uses a counter initialized to a constant. Although this works fine for multiple sessions managed by a single instance of fake.py, it fails miserably when running multiple parallel instances of fake.py. The fix is to allow the OS to assign the port numbers, since it's guaranteed to pick unused ports. In the TCP case, this is simply a matter of specifying 0 as the port, and then extracting the actual assigned port number with getsockname(). In the UDP case, it's more complicated since the port number being picked is actually for *gpsd's* end, which can't be done in a straightforward manner. The workaround, which was already being used to pick the control-socket port for gpsd, is to bind a socket with a reusable address, close it, and then assume that the port will remain available until gpsd grabs it. This change turns the existing code to do that into a function, with the socket type now being specifiable. TESTED: Ran all daemon tests in both TCP and UDP modes, on three versions of OSX as well as Linux, FreeBSD, and OpenBSD. Used default WRITE_PAD values except on OSX, where it was reduced to 1ms to save time. Signed-off-by: Jon Schlueter <jon.schlueter@gmail.com>
* [pep8] cleanup of gps/fake.py for readablityJon Schlueter2016-02-091-20/+19
|
* [pep8] autopep8 whitespace cleanupJon Schlueter2016-02-091-9/+50
| | | | | large scale autopep8 cleanup of several pep8 whitespace warnings
* splint/cppcheck/coverity prerelease cleanup.Eric S. Raymond2015-03-131-1/+1
|
* Fix pty permissions in fake.pyGary E. Miller2015-03-101-0/+2
| | | | | | | | When gpsfake is run as root, it may, depending on OS configuration, create the pty's with 600 permissions that gpsd can not later read. Make fake.py create all pty's permission 666. Solves the problem running scons check as root on Gentoo and OS X.
* Updare some documentation.Eric S. Raymond2015-02-151-9/+3
|
* The capability to set WRITE_PAD in the test frame was buggy.Eric S. Raymond2015-02-141-1/+1
| | | | No logic changes. All regression tests pass.
* Allow setting WRITE_PAD from the environment.Eric S. Raymond2015-02-141-3/+6
|
* Time out hangs in single-shot tests.Eric S. Raymond2015-02-141-1/+7
| | | | All regression tests pass.
* Change the way EOF is injected in hopes of beating a *BSD timing problem.Eric S. Raymond2015-02-111-4/+6
| | | | All regression tests pass.
* Improved instrumentation for tracking down test frame issues.Eric S. Raymond2015-02-101-2/+3
|
* Set FreeBSD WRITE_PAD to 0.01 in report from Hal Murray.Eric S. Raymond2015-02-101-2/+2
|
* Reinstate port-zero allocation magic for tests. All regression tests pass.Eric S. Raymond2015-02-091-6/+14
|
* CLOSE_DELAY is gone. Test source termination is now deterministic.Eric S. Raymond2015-02-091-69/+4
| | | | All regression tests pass.
* Revert to non-blocking I/O. Blocking I/O broke gps-makeregress.Eric S. Raymond2015-02-061-57/+42
| | | | | | | | | Regression tests pass with nonblocking I/O, but a regression test *rebuild* fails with timing errors. Much as we want a solution to the select-buzz problem, this change must go on hold until the root cause of the timing problems is found and fixed. Regression tests still pass.
* test timing: Reduce netbsd5 values.Greg Troxel2015-02-051-1/+2
|
* Clean up pre-blocking-IO tests, organize.Greg Troxel2015-02-031-23/+21
| | | | This commit has no semantic change, just housekeeping.
* Update netbsd5 timing data.Greg Troxel2015-02-031-0/+3
|
* Update os x timing data; shorten delay.Greg Troxel2015-02-031-9/+4
|
* More updates of test delays.Eric S. Raymond2015-02-031-9/+12
|
* Recheck delays for Raspberry Pi Model B.Michael Tatarinov2015-02-031-5/+4
|
* Add delay tests reported by Frank Nicholas.Eric S. Raymond2015-02-031-0/+4
|