def _signal_handler(self, signum, frame): """ SIGHUP - conditional shutdown e.g. do not shutdown the if there is some work currently in progress. SIGTERM - shut the application down regardless. """ if signum == signal.SIGALRM: self.logger.warn("SIGALRM signal %s caught, raising " "exception." % signum) raise TimeoutException("Timeout exception.") if signum == signal.SIGHUP: # SIGHUP: the service goes down conditionally ... condition = False self.logger.warn("SIGHUP signal %s caught, checking for ..." % signum) # TO BE IMPLEMENTED BY THE TARGET APPLICATION if not contition: m = ("SIGHUP signal %s ... condition ... shutdown." % signum) raise ServiceShutdownBySignal(m) else: self.logger.warn("SIGHUP signal %s - work in progress, " "ignored." % signum) if signum == signal.SIGTERM: m = "SIGTERM signal %s caught, shutting down (forced) ..." % signum raise ServiceShutdownBySignal(m)
def restart_b2g(self): print 'restarting B2G' self.dm.shellCheckOutput(['stop', 'b2g']) time.sleep(10) self.dm.shellCheckOutput(['start', 'b2g']) if not self.wait_for_port(): raise TimeoutException("Timeout waiting for marionette on port '%s'" % self.marionette_port)
def wait_for_condition(self, method, timeout=30): timeout = float(timeout) + time.time() while time.time() < timeout: value = method(self.marionette) if value: return value time.sleep(0.5) else: raise TimeoutException("wait_for_condition timed out")
def start(self): self._check_for_b2g() self.start_adb() qemu_args = self.args[:] if self.copy_userdata: # Make a copy of the userdata.img for this instance of the emulator to use. self._tmp_userdata = tempfile.mktemp(prefix='marionette') shutil.copyfile(self.dataImg, self._tmp_userdata) qemu_args[qemu_args.index('-data') + 1] = self._tmp_userdata original_online, original_offline = self._get_adb_devices() filename = None if self.logcat_dir: filename = os.path.join(self.logcat_dir, 'qemu.log') if os.path.isfile(filename): self.rotate_log(filename) self.proc = LogOutputProc(qemu_args, filename) self.proc.run() online, offline = self._get_adb_devices() now = datetime.datetime.now() while online - original_online == set([]): time.sleep(1) if datetime.datetime.now() - now > datetime.timedelta(seconds=60): raise TimeoutException( 'timed out waiting for emulator to start') online, offline = self._get_adb_devices() self.port = int(list(online - original_online)[0]) self._emulator_launched = True self.dm = devicemanagerADB.DeviceManagerADB( adbPath=self.adb, deviceSerial='emulator-%d' % self.port) # bug 802877 time.sleep(10) self.geo.set_default_location() self.screen.initialize() if self.logcat_dir: self.save_logcat() # setup DNS fix for networking self._run_adb(['shell', 'setprop', 'net.dns1', '10.0.2.3'])
def wait_for_condition_else_raise(marionette, wait_for_condition, expected, script): try: wait_for_condition(lambda m: expected in m.execute_script(script)) except TimeoutException as e: raise TimeoutException(e.msg + " got %s instead of %s" % (marionette.execute_script(script), expected))
def run(self): if self.p: try: self.dbg_msg("begin redirect mode\n") self.p.start() if (self.TIMEOUT is not None): start = time() self.dbg_msg("timeout non-zero\n") raise_timeout = False while self.p.is_alive(): self.dbg_msg("in busy loop : %d , %d \n" % (time() - start, self.TIMEOUT)) self.dbg_msg("SLEEP\n") sleep(5) #poll every 5 seconds if ((time() - start) > self.TIMEOUT): self.dbg_msg("Reached timeout = %d\n" % self.TIMEOUT) raise_timeout = True break # now you try and read all the data from file, , and unlink it all up. self.fProcName = EzhilRedirectOutput.pidFileName( self.p.pid) self.tmpf_name = self.tmpf.name # dump stuff from fProcName into the stdout fp = open(self.fProcName, 'r') print( u"######### ------- dump output ------- ##############" ) self.data = fp.read() print(self.data) fp.close() if raise_timeout: raise TimeoutException(self.TIMEOUT) #os.unlink( fProcName) except Exception as e: print("exception ", unicode(e)) traceback.print_tb(sys.exc_info()[2]) raise e finally: # reset the buffers if (self.redirectop): #self.tmpf.close() sys.stdout = self.old_stdout sys.stderr = self.old_stderr sys.stdout.flush() sys.stderr.flush() # cleanup the cruft files #if self.tmpf and hasattr(self.tmpf,'name'): # os.unlink( self.tmpf.name ) #self.tmpf = None #if self.fProcName: # os.unlink( self.fProcName ) #self.fProcName = None # nuke the process if hasattr(self.p, 'terminate'): self.p.terminate() self.exitcode = self.p.exitcode else: pass #nothing to run