def domeasure(ctx): """Perform a power measurement for an indefinite time. """ # Imports are here because this runs in a subprocess import signal from devtest import logging from devtest.devices.monsoon import measure from devtest.devices.monsoon import simple as monsoon_simple def _stop(sig, f): raise monsoon_simple.StopSampling("stop!") ctx["duration"] = None ctx["numsamples"] = 4294967295 if "output" not in ctx: ctx["output"] = "power" logging.info(repr(ctx)) oldint = signal.signal(signal.SIGINT, _stop) oldterm = signal.signal(signal.SIGTERM, _stop) try: measurer = measure.MonsoonCurrentMeasurer(ctx) result = measurer.measure() finally: signal.signal(signal.SIGINT, oldint) signal.signal(signal.SIGTERM, oldterm) return result
def _shutdown_kernel(): global _default_kernel if _default_kernel is not None: kern = _default_kernel _default_kernel = None logging.info("Shutting down curio.Kernel at exit.") kern.run(None, shutdown=True)
def release_for(self, needer, **kwargs): hvpm, _ = self._find_hvpm(needer) result = None if hvpm is not None: logging.info("Releasing {} for {}".format(hvpm, needer)) coproc = self._used.pop(hvpm.serno, None) if coproc is not None: logging.info("Interrupting Monsoon") coproc.interrupt() result = coproc.wait() return result
def run(self): self._data = threading.local() try: os.unlink(CONTROL_SOCKET) except OSError: pass self._data.logdir = "/var/tmp" self._data.channels = {} logging.info("SerialCaptureServer starting.") kern = get_new_kernel() kern.run(self._unix_server(), shutdown=True) logging.info("SerialCaptureServer ended.")
async def _dispatch(self, tag, data): if tag == STOP: while self._data.channels: (name, devicenode), (chan, copy_task) = self._data.channels.popitem() logging.info("SerialCaptureServer stopping {}".format(chan)) await copy_task.cancel() await chan.close() logging.info("SerialCaptureServer STOPPED") return STOPPED, "Server stopped" elif tag == SET_LOGDIR: self._data.logdir = data logging.info("SerialCaptureServer set logdir: {}".format( self._data.logdir)) return OK, self._data.logdir elif tag == ADD_CHANNEL: job = data if self._data.channels.get( (job["name"], job["devicenode"])) is not None: return OK, "Channel already added." job["logdir"] = self._data.logdir try: sc = SerialChannel(job) copy_task = await spawn(sc.copy()) self._data.channels[(job["name"], job["devicenode"])] = (sc, copy_task) logging.info("SerialCaptureServer ADD_CHANNEL {}".format(sc)) return OK, str(sc) except Exception as ex: return ERROR, str(ex) elif tag == CLOSE_CHANNEL: job = data sc, copy_task = self._data.channels.pop( (job["name"], job["devicenode"]), (None, None)) if sc: try: logging.info( "SerialCaptureServer CLOSE_CHANNEL {}".format(sc)) await copy_task.cancel() await sc.close() except Exception as ex: return ERROR, str(ex) return OK, "channel closed" else: return OK, "Channel was not open" else: logging.error("SerialCaptureServer unkown tag: {}".format(tag)) return ERROR, "Unknown tag"
def shell(self, cmd, usepty=False): """Run a shell command and return stdout. Args: cmd: list or string, command to run Returns: The stdout as str (decoded). Raises: AndroidControllerError with exit status and stderr as args. """ logging.info("AndroidController.shell({!r})".format(cmd)) stdout, stderr, es = self.adb.command(cmd, usepty=usepty) if es: return stdout else: raise AndroidControllerError((es, stderr))
def provide_for(self, needer, **kwargs): hvpm, passthrough = self._find_hvpm(needer) if hvpm is None: raise exceptions.ConfigNotFoundError( "Device has no connected HVPM") if hvpm.serno in self._used: raise exceptions.TestImplementationError( "HVPM {} is already being used!".format(hvpm.serno)) ctx = { "serialno": hvpm.serno, "passthrough": passthrough, "voltage": needer.get("voltage", 4.2), } ctx.update(kwargs) pm = process.get_manager() logging.info("Providing {} for {}".format(hvpm, needer)) coproc = pm.coprocess() coproc.start(domeasure, ctx) self._used[hvpm.serno] = coproc
def log_service_dontwant(equipment, service=None, **kwargs): logging.info("service no longer wanted by {!r}: {!r} kwargs={!r}".format( equipment.name, service, kwargs))
def log_receiver_connected(sig, receiver=None, sender=None, weak=None): logging.info( "signal.connect: {name!r} receiver={recv!r} sender={sender!r}".format( name=sig.name, recv=receiver, sender=sender))