diff options
author | Fred Wright <fw@fwright.net> | 2017-03-24 17:45:18 -0700 |
---|---|---|
committer | Fred Wright <fw@fwright.net> | 2017-03-24 18:25:00 -0700 |
commit | 1f209455dd2e850b164a3f7985ad845e88efef57 (patch) | |
tree | b21312d77041359dd4c4a06cf4b3848f9f96e6ff | |
parent | 4ee196cd9c34f7a268118d4088392e392546fe42 (diff) | |
download | gpsd-1f209455dd2e850b164a3f7985ad845e88efef57.tar.gz |
Makes 'GPSD' SHM IDs unique during regression tests.
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.
-rw-r--r-- | gps/fake.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/gps/fake.py b/gps/fake.py index b2da7ae1..dd652064 100644 --- a/gps/fake.py +++ b/gps/fake.py @@ -446,8 +446,9 @@ class SubprogramInstance(object): self.spawncmd = None self.process = None self.returncode = None + self.env = None - def spawn(self, program, options, background=False, prefix=""): + def spawn(self, program, options, background=False, prefix="", env=None): "Spawn a subprogram instance." spawncmd = None @@ -474,7 +475,10 @@ class SubprogramInstance(object): self.spawncmd = [spawncmd] + options.split() if prefix: self.spawncmd = prefix.split() + self.spawncmd - self.process = subprocess.Popen(self.spawncmd) + if env: + self.env = os.environ.copy() + self.env.update(env) + self.process = subprocess.Popen(self.spawncmd, env=self.env) if not background: self.returncode = status = self.process.wait() if os.WIFSIGNALED(status) or os.WEXITSTATUS(status): @@ -523,7 +527,11 @@ class DaemonInstance(SubprogramInstance): # anything we can use to implement the FakeGPS.read() method opts = (" -b -N -S %s -F %s %s" % (port, self.control_socket, options)) - super(DaemonInstance, self).spawn('gpsd', opts, background, prefix) + # Derive a unique SHM key from the port # to avoid collisions. + # Use 'Gp' as the prefix to avoid colliding with 'GPSD'. + shmkey = '0x4770%.04X' % port + env = {'GPSD_SHM_KEY': shmkey} + super(DaemonInstance, self).spawn('gpsd', opts, background, prefix, env) def wait_ready(self): "Wait for the daemon to create the control socket." |