def perform_op(self, op): self.record_op(self.curr_state, self.curr_ops, op) try: flags.detect_stop() apptest.interface.select(op) except apptest.exception.RemoteException as e: if "INJECT_EVENT" in e.msg: pass else: raise e except apptest.exception.InstException as e: self.executor.err_handler(e) self.curr_state, self.curr_ops = self.executor.collect()
def search(self): try: apptest.widget.read_hint(self.launcher.app_apk_path) except Exception as e: logger.error("fail to read hints: %r" % e) return if self.batch_no == -1: init_target = Target() self.target_queue.put((init_target.get_priority(), init_target)) while self.batch_no + 1 < self.batch_number: self.batch_no += 1 logger.info("=== execution %d started..." % self.batch_no) flags.detect_stop() if self.curr_target is not None: self.target_restart_count += 1 if self.target_restart_count > TARGET_RESTART_LIMIT: self.curr_target = None self.target_restart_count = 0 if self.curr_target is None: target = self.pick_target() else: target = self.curr_target if target is None: logger.info("=== state queue empty. finish. ===") break self.clear_history() try: self.executor.restart() apptest.interface.disable_checker() apptest.widget.send_hint(self.launcher.app_package) self.launcher.notify_external_events() self.curr_state, self.curr_ops = self.executor.collect() branched = False logger.info("replay start") for step in target.steps: # if self.executor.state_match(self.curr_state, step.state_sig) and step.op < len(self.curr_ops): # logger.debug("replay op %r: %s" % (step.op, step.op_desc)) # self.perform_op(step.op) realop = self.resolve_op(step.op, step.op_desc, self.curr_ops) if realop is not None: self.perform_op(realop) else: # replay failed! # state branch! logger.error("replay failed. fallback to exploration.") self.replay_fail_count += 1 branched = True break if not branched: logger.info("replay finished. start exploration") for op_no in xrange(self.num_of_operations): op = self.select_op(self.curr_state, self.curr_ops) if op is None: logger.info("nothing to do.") break logger.debug("selected op %r: %s" % (op, self.curr_ops[op])) self.perform_op(op) except apptest.exception.ConnectionBroken as e: logger.info("connection broken: %r" % e) if "timeout" in e.message: raise e self.executor.err_handler(e) if not self.launcher.dev_running(): raise e except apptest.exception.StoppedException as e: raise e except Exception as e: logger.error("unknown exception: %r" % e) traceback.print_exc() self.executor.err_handler(e) if not self.launcher.dev_running(): raise e if self.batch_no != self.batch_number - 1: self.executor.clean_state() logger.info("=== execution %d finished..." % self.batch_no) logger.info("=== state count: %5d" % len(self.states)) logger.info("=== queue len: %5d" % self.target_queue.qsize()) logger.info("=== op count: %5d" % len(self.cur_steps)) logger.info("=== replay fail: %5d" % self.replay_fail_count) # if self.target_queue: # logger.info("=== first target depth: %5d" % self.target_queue[0].get_depth()) if not self.launcher.dev_running(): raise apptest.exception.InternalError("device not running!") self.curr_target = None
def crawl(self): try: apptest.widget.read_hint(self.launcher.app_apk_path) except Exception as e: logger.error("fail to read hints: %r" % e) return while self.batch_no + 1 < self.batch_number: self.batch_no += 1 logger.info("=== execution %d started..." % self.batch_no) flags.detect_stop() hit_nothing = False try: self.executor.restart() apptest.interface.disable_checker() apptest.widget.send_hint(self.launcher.app_package) self.launcher.notify_external_events() for op_no in xrange(self.num_of_operations): try: flags.detect_stop() apptest.interface.crawl() self.launcher.test_all_config() hit_nothing = False except apptest.exception.RemoteException as e: if "INJECT_EVENT" in e.msg: pass else: raise e except apptest.exception.InstException as e: self.executor.err_handler(e) except apptest.exception.ActionFailure as e: if e.result == "NothingToDo": if hit_nothing: break else: hit_nothing = True self.launcher.dev.execute("input keyevent 4") apptest.interface.wait_for_idle() else: self.executor.err_handler(e) except apptest.exception.StoppedException: logger.info("got stop signal. stop") break except apptest.exception.ConnectionBroken as e: if "timeout" in e.message: raise e if not self.launcher.dev_running(): raise e self.executor.err_handler(e) except apptest.exception.TimeoutException as e: raise e except Exception as e: self.executor.err_handler(e) logger.info("got exception, check if we should restart") if not self.launcher.dev_running(): logger.info("should restart!") raise e if self.batch_no != self.batch_number - 1: self.executor.clean_state() logger.info("=== execution %d finished..." % self.batch_no) if not self.launcher.dev_running(): raise apptest.exception.InternalError("device not running!")
def crawl(self): try: apptest.widget.read_hint(self.launcher.app_apk_path) except Exception as e: logger.error("fail to read hints: %r" % e) return while self.batch_no + 1 < self.batch_number: self.batch_no += 1 logger.info("=== execution %d started..." % self.batch_no) flags.detect_stop() hit_nothing = False try: self.executor.restart() apptest.interface.disable_checker() apptest.widget.send_hint(self.launcher.app_package) self.launcher.notify_external_events() for op_no in xrange(self.num_of_operations): try: flags.detect_stop() apptest.interface.crawl() self.launcher.test_all_config() hit_nothing = False except apptest.exception.RemoteException as e: if "INJECT_EVENT" in e.msg: pass else: raise e except apptest.exception.InstException as e: self.executor.err_handler(e) except apptest.exception.ActionFailure as e: if e.result == 'NothingToDo': if hit_nothing: break else: hit_nothing = True self.launcher.dev.execute("input keyevent 4") apptest.interface.wait_for_idle() else: self.executor.err_handler(e) except apptest.exception.StoppedException: logger.info("got stop signal. stop") break except apptest.exception.ConnectionBroken as e: if "timeout" in e.message: raise e if not self.launcher.dev_running(): raise e self.executor.err_handler(e) except apptest.exception.TimeoutException as e: raise e except Exception as e: self.executor.err_handler(e) logger.info("got exception, check if we should restart") if not self.launcher.dev_running(): logger.info("should restart!") raise e if self.batch_no != self.batch_number - 1: self.executor.clean_state() logger.info("=== execution %d finished..." % self.batch_no) if not self.launcher.dev_running(): raise apptest.exception.InternalError("device not running!")