honeynet/droidbot

Is this check necessary during add transition?

junior291492659 opened this issue · 1 comments

Hello, Thanks for your amazing project!

In utg.py https://github.com/honeynet/droidbot/blob/master/droidbot/utg.py#L54,

def add_transition(self, event, old_state, new_state):

    self.add_node(old_state)
    self.add_node(new_state)

    # make sure the states are not None
    if not old_state or not new_state:
        return

    event_str = event.get_event_str(old_state)
    self.input_event_count += 1

    if old_state.state_str == new_state.state_str:
        self.ineffective_event_strs.add(event_str)
        # delete the transitions including the event from utg
        for new_state_str in self.G[old_state.state_str]:
            if event_str in self.G[old_state.state_str][new_state_str]["events"]:
                self.G[old_state.state_str][new_state_str]["events"].pop(event_str)
        if event_str in self.effective_event_strs:
            self.effective_event_strs.remove(event_str)
        return

    self.effective_event_strs.add(event_str)
    self.effective_event_count += 1

    if (old_state.state_str, new_state.state_str) not in self.G.edges():
        self.G.add_edge(old_state.state_str, new_state.state_str, events={})

    self.G[old_state.state_str][new_state.state_str]["events"][event_str] = {
        "event": event,
        "id": self.effective_event_count
    }
    self.last_state_str = new_state.state_str
    self.last_transition = (old_state.state_str, new_state.state_str)
    self.__output_utg()

Is this loop "for new_state_str in self.G[old_state.state_str]" to "pop" the ineffective event in other transitions between old_state and other state necessary?

If there are other transitions between the old_state and other states indeed, then the events in these transitons are capable of leading the old_state to new states, so the event, which gets to the scenario where old_state.state_str equals to new_state.state_str, is not supposed to be in these events, otherwise a new transition of the old_state can not be generated.

It would be really appreciated to get your reply.

Hi, the event's effect may change during testing. For example, in a book app, clicking a "next page" button may lead to a new state at first, while when there is no more page, the button will have no effect. In the code, I wanted to keep the effect of actions up to date.