コード例 #1
0
 def __eq__(self, other):
     for key in self.attr:
         if util.unequal(self.get(key, ''), other.get(key, '')):
             return False
     for key in other.attr:
         if util.unequal(self.get(key, ''), other.get(key, '')):
             return False
     return True
コード例 #2
0
ファイル: statemgr.py プロジェクト: marklang1993/appflow
 def prepare_input_state(self, curr_state):
     input_state = state.State()
     if curr_state is not None:
         for key in config.cleanup_dep_keys:
             if util.unequal(curr_state.get(key, ''), ''):
                 input_state.set(key, curr_state.get(key))
     return input_state
コード例 #3
0
ファイル: statemgr.py プロジェクト: marklang1993/appflow
 def check_dirty(self, astate):
     if not self.check_dep(astate):
         return False
     for prop in config.must_cleanup_keys:
         if util.unequal(astate.get(prop, ''), ''):
             return True
     return False
コード例 #4
0
    def query_screen(self, attrs):
        for screen in self.screens:
            match = True
            for key in attrs:
                if util.unequal(attrs[key], screen.get(key, '')):
                    match = False
                    break
            if not match:
                continue

            screen_id = self.get_screen_id(screen)
            if screen_id == -1:
                continue
            screen_info = self.get_screen_info(screen_id)
            routeinfos = self.screens[screen]
            logger.info("%s #%d routes: %d [%d+ %d-]" %
                        (screen, screen_id, len(routeinfos), screen_info.succ,
                         screen_info.fail))
            route = self.pick_route_for_screen(screen, True)
            if route:
                logger.info("  best route: %s", route)
            else:
                logger.info("  NO ROUTE!")

            for routeinfo in routeinfos:
                logger.info("  %d. %s", routeinfo.route.get_id(), routeinfo)
コード例 #5
0
ファイル: statemgr.py プロジェクト: marklang1993/appflow
 def check_dep(self, astate):
     for prop in config.cleanup_dep_keys:
         if util.unequal(astate.get(prop, ''), ''):
             return True
     return False
コード例 #6
0
ファイル: miner.py プロジェクト: marklang1993/appflow
    def mine_now(self, rounds):
        self.round_no = 0
        curr_state = None
        continue_test = False
        if config.do_init_clean:
            self.statemgr.init_clean()
        self.kbd_on()
        while True:
            self.round_clear()

            self.round_no += 1
            if self.round_no > rounds:
                if continue_test:
                    logger.info("clean before exit")
                    self.statemgr.cleanup(
                        curr_state.to_essential(self.tlib.essential_props()))
                break
            perfmon.record_stop("miner", "round")
            perfmon.record_start("miner", "round")
            self.watchdog.kick()
            try:
                logger.info("mine round %d", self.round_no)
                self.print_stat()
                #logger.info("current test lib: %s", self.tlib)
                logger.info("current screen lib: %s", self.slib)
            except:
                logger.exception("maintainance err")
            self.save_stat()
            self.save_memory()

            test_to_try = None
            if continue_test:
                essential_state = curr_state.to_essential(
                    self.slib.essential_props)
                test_to_try = self.tlib.pick_continuous_test(
                    essential_state, self.slib)

            if test_to_try is None:
                if continue_test:
                    self.statemgr.cleanup(
                        curr_state.to_essential(self.tlib.essential_props()))

                test_to_try = self.tlib.pick_test(self.slib)
                continue_test = False
            else:
                self.report_prog("CONT  %s" % test_to_try.short_name())
                continue_test = True

            if test_to_try is None:
                if self.should_terminate():
                    break
                else:
                    continue

            testinfo = self.tlib.get_testinfo(test_to_try)

            self.watchdog.kick()
            if not continue_test:
                curr_state = state.State({'screen': 'init'})
                (route_to_try,
                 target_state) = self.slib.pick_route(test_to_try, testinfo)
                logger.info("picked %s", target_state)
                logger.info("picked %s", route_to_try)
                self.report_prog("PICKED %s FROM %s" %
                                 (test_to_try.short_name(), target_state))
                self.report_prog(" ROUTE %s" % route_to_try)

                passed_states = []
                if not self.replay_route(route_to_try, curr_state,
                                         passed_states):
                    self.report_prog("REPLAY FAIL %s" % route_to_try)
                    self.statemgr.observe_and_clean_all(curr_state)
                    continue

                passed_essential_states = []
                for astate in passed_states:
                    passed_essential_states.append(
                        astate.to_essential(self.slib.essential_props))

                gui_state = self.observer.grab_state(self.dev)
                if gui_state is None:
                    logger.error("fail to grab current state")
                    continue

                curr_state.merge(gui_state)

            self.watchdog.kick()
            # starting from target_state
            # now, curr_state = state after replay
            if test_to_try.usable(curr_state):
                if not continue_test:
                    self.slib.mark_route_succ(route_to_try)
                continue_test = False
                from_state = copy.deepcopy(target_state)
                logger.info("proceed to try '%s' from %s",
                            test_to_try.short_name(), target_state)
                error = False
                self.report_prog("RUN TEST %s" % test_to_try.short_name())
                try:
                    succd = test_to_try.attempt(self.dev, self.observer,
                                                curr_state, self.tlib)
                except:
                    logger.exception("try test exception")
                    succd = False
                    error = True

                new_essential = curr_state.to_essential(
                    self.slib.essential_props)

                #gui_state = self.observe()
                #curr_state.merge(gui_state)
                # now, curr_state = state after test execution
                if succd:
                    logger.info("===== test SUCCEEDED =====")
                    self.report_prog("TEST %s SUCC, reached %s" %
                                     (test_to_try.short_name(), new_essential))
                    if not self.batch:
                        time.sleep(1)

                    self.tlib.handle_sys_screen(curr_state, self.dev,
                                                self.observer)

                    self.tlib.mark_succ(test_to_try, target_state,
                                        new_essential)
                    self.slib.mark_screen_succ(target_state)

                    repeated_state = False
                    for astate in passed_essential_states:
                        if new_essential == astate:
                            logger.info("repeated state, discard route")
                            repeated_state = True
                            break

                    (new_route, new_state) = self.record_new_state(
                        curr_state, route_to_try, test_to_try, repeated_state)
                    if new_essential == target_state:
                        # same state
                        # should not change route_to_try
                        # should not change target state
                        route_to_try = copy.deepcopy(route_to_try)
                        target_state = copy.deepcopy(target_state)
                    else:
                        route_to_try = new_route
                        target_state = curr_state.to_essential(
                            self.slib.essential_props)
                    curr_state = copy.deepcopy(new_state)
                elif error:
                    logger.info("===== test EXCEPTION =====")
                    if not self.batch:
                        time.sleep(180)
                    self.tlib.mark_error(test_to_try)
                else:
                    logger.info("===== test    FAILED =====")
                    self.report_prog("TEST %s FAIL" % test_to_try.short_name())
                    if not self.batch:
                        time.sleep(1)
                    self.tlib.mark_fail(test_to_try, target_state)
                    self.slib.mark_screen_fail(target_state)

                self.watchdog.kick()
                state_changed = False
                if error or not succd:
                    # must cleanup now
                    for prop in config.must_cleanup_keys:
                        origval = target_state.get(prop, '')
                        need_clean = False
                        if prop in test_to_try.get_change_keys():
                            if test_to_try.get_change_val(prop) != origval:
                                # maybe the state is changed! maybe not!
                                self.statemgr.observe_and_clean(
                                    prop, curr_state)
                                state_changed = True
                            elif util.unequal(origval, ''):
                                # not changed, must clear
                                need_clean = True
                        elif util.unequal(origval, ''):
                            # not changed, must clear
                            need_clean = True
                        if need_clean:
                            #self.statemgr.cleanup_prop(prop, origval, target_state)
                            # although it should be cleared...
                            # sometimes the property is still local
                            # and a restart would clear it
                            # so asking for a clean directly may fail
                            self.statemgr.observe_and_clean(prop, target_state)
                            state_changed = True

                continue_test = self.should_continue(succd, error,
                                                     state_changed,
                                                     test_to_try, from_state,
                                                     curr_state, route_to_try,
                                                     passed_essential_states,
                                                     new_essential)

                if (config.read_only_continue and test_to_try.read_only
                        and not state_changed):
                    continue_test = True

                if succd and not continue_test:
                    # successd, but should not continue. just clean up
                    self.statemgr.cleanup(
                        curr_state.to_essential(self.tlib.essential_props()))

                if continue_test:
                    if (len(passed_essential_states) == 0
                            or passed_essential_states[-1] != new_essential):
                        passed_essential_states.append(new_essential)

            else:
                logger.warning("replayed state does not match expectation")
                self.report_prog("REPLAY MISMATCH %s" % route_to_try)
                self.slib.mark_route_fail(route_to_try)
                self.statemgr.cleanup(
                    curr_state.to_essential(self.tlib.essential_props()))
                continue_test = False

            logger.info("continue test: %s", continue_test)
コード例 #7
0
 def matches(self, other):
     for key in self.attr:
         if util.unequal(self.attr[key], other.get(key, '')):
             return False
     return True