def remove_device(self, path): "Remove a device from the daemon's internal search list." if self.__get_control_socket(): self.sock.sendall(polybytes("-%s\r\n\x00" % path)) self.sock.recv(12) self.sock.close()
def add_device(self, path): "Add a device to the daemon's internal search list." if self.__get_control_socket(): self.sock.sendall(polybytes("+%s\r\n\x00" % path)) self.sock.recv(12) self.sock.close()
def run(self): """Run the tests.""" try: self.progress("gpsfake: test loop begins\n") while self.daemon: if not self.daemon.is_alive(): raise TestSessionError("daemon died") # We have to read anything that gpsd might have tried # to send to the GPS here -- under OpenBSD the # TIOCDRAIN will hang, otherwise. for device in self.runqueue: if isinstance(device, FakeGPS): device.read() had_output = False chosen = self.choose() if isinstance(chosen, FakeGPS): if (((chosen.exhausted and self.timeout and (time.time() - chosen.exhausted > self.timeout) and chosen.byname in self.fakegpslist))): sys.stderr.write( "Test timed out: maybe increase WRITE_PAD (= %s)\n" % GetDelay(self.slow)) raise SystemExit(1) if not chosen.go_predicate(chosen.index, chosen): if chosen.exhausted == 0: chosen.exhausted = time.time() self.progress( "gpsfake: GPS %s ran out of input\n" % chosen.byname) else: chosen.feed() elif isinstance(chosen, gps.gps): if chosen.enqueued: chosen.send(chosen.enqueued) chosen.enqueued = "" while chosen.waiting(): if not self.daemon or not self.daemon.is_alive(): raise TestSessionError("daemon died") ret = chosen.read() if 0 > ret: raise TestSessionError("daemon output stopped") # FIXME: test for 0 == ret. had_output = True if not chosen.valid & gps.PACKET_SET: continue self.reporter(gps.polybytes(chosen.bresponse)) if ((chosen.data["class"] == "DEVICE" and chosen.data["activated"] == 0 and chosen.data["path"] in self.fakegpslist)): self.gps_remove(chosen.data["path"]) self.progress( "gpsfake: GPS %s removed (notification)\n" % chosen.data["path"]) else: raise TestSessionError("test object of unknown type") if not self.writers and not had_output: self.progress("gpsfake: no writers and no output\n") break self.progress("gpsfake: test loop ends\n") finally: self.cleanup()