Esempio n. 1
0
    def test_basic_no_prune(self):
        inp1 = MockConnectToControllers(fingerprint="a")
        inp2 = MockInputEvent(fingerprint="b")
        int1 = MockInternalEvent(fingerprint="c")
        inp3 = MockInputEvent(fingerprint="d")
        events = [inp1, inp2, int1, inp3]

        def fake_find_internal_events(replay_dag, inject_input, wait_time):
            if inject_input == inp1:
                return []
            elif inject_input == inp2:
                return [int1]
            elif inject_input == inp3:
                return []
            else:
                raise AssertionError("Unexpected event sequence queried: %s" %
                                     replay_dag.events)

        # first, prefix peeker
        self.prefix_peeker.find_internal_events = fake_find_internal_events
        new_dag = self.prefix_peeker.peek(EventDag(events))
        self.assertEquals(events, new_dag.events)

        # next, snapshot peeker
        # Hack alert! throw away first two args
        def snapshotter_fake_find_internal_events(s, c, dag_interval,
                                                  inject_input, wait_time):
            return (fake_find_internal_events(dag_interval, inject_input,
                                              wait_time),
                    self.mock_snapshotter)

        self.snapshot_peeker.find_internal_events = snapshotter_fake_find_internal_events
        new_dag = self.snapshot_peeker.peek(EventDag(events))
        self.assertEquals(events, new_dag.events)
Esempio n. 2
0
 def test_basic_noop(self):
     """ test_basic_noop: running on a dag with no input events returns the same dag """
     events = [
         MockInputEvent(fingerprint=("class", f)) for f in range(1, 7)
     ]
     new_dag = self.peeker.peek(EventDag(events))
     self.assertEquals(events, new_dag.events)
Esempio n. 3
0
 def test_basic_noop(self):
     """ test_basic_noop: running on a dag with no internal events returns the same dag """
     events = [MockConnectToControllers(fingerprint=("class", 0))] + [
         MockInputEvent(fingerprint=("class", f)) for f in range(1, 7)
     ]
     new_dag = self.prefix_peeker.peek(EventDag(events))
     self.assertEquals(events, new_dag.events)
     new_dag = self.snapshot_peeker.peek(EventDag(events))
     self.assertEquals(events, new_dag.events)
Esempio n. 4
0
    def test_basic_prune(self):
        inp1 = MockInputEvent(fingerprint="a")
        inp2 = MockInputEvent(fingerprint="b")
        int1 = MockInternalEvent(fingerprint="c")
        inp3 = MockInputEvent(fingerprint="d")
        int2 = MockInternalEvent(fingerprint="e")
        all_events = [inp1, inp2, int1, inp3, int2]
        sub_events = [inp2, int1, inp3, int2]

        def fake_find_internal_events(replay_dag, wait_time):
            if replay_dag.events == [inp2]:
                return []
            elif replay_dag.events == [inp2, inp3]:
                return [int2]
            else:
                raise AssertionError("Unexpected event sequence queried: %s" %
                                     replay_dag.events)

        self.peeker.find_internal_events = fake_find_internal_events
        new_dag = self.peeker.peek(EventDag(sub_events))
        self.assertEquals([inp2, inp3, int2], new_dag.events)
Esempio n. 5
0
 def setUp(self):
     self.input_trace = [
         MockInputEvent(fingerprint=("class", f)) for f in range(1, 7)
     ]
     self.dag = EventDag(self.input_trace)
     self.prefix_peeker = PrefixPeeker(None)
     IPAddressSpace._claimed_addresses.clear()
     ControllerConfig._controller_labels.clear()
     controller_cfg = ControllerConfig(start_cmd="sleep")
     simulation_cfg = SimulationConfig(controller_configs=[controller_cfg])
     self.snapshot_peeker = SnapshotPeeker(simulation_cfg,
                                           default_dp_permit=True)
     self.snapshot_peeker.setup_simulation = lambda: (None, None)
     # N.B. this assumes that no internal events occur before the first input
     # event.
     self.snapshot_peeker.snapshot_and_play_forward = lambda *args: ([],
                                                                     None)
     self.snapshot_peeker.replay_interval = lambda *args: []
     self.mock_snapshotter = MockSnapshotter()
Esempio n. 6
0
 def setUp(self):
     self.input_trace = [
         MockInputEvent(fingerprint=("class", f)) for f in range(1, 7)
     ]
     self.dag = EventDag(self.input_trace)
     self.peeker = Peeker(None)