예제 #1
0
    def test_same_attributes_different_count(self):
        tree_1 = Prototype()
        root = tree_1.add_node("root", pid=1, ppid=0, tme=0, exit_tme=0)
        for _ in range(5):
            root.add_node("node", pid=2, ppid=1, tme=0, exit_tme=0)
        tree_2 = Prototype()
        root = tree_2.add_node("root", pid=1, ppid=0, tme=0, exit_tme=0)
        for _ in range(35):
            root.add_node("node", pid=2, ppid=1, tme=0, exit_tme=0)

        signature = ParentChildByNameTopologySignature()
        algorithm = IncrementalDistanceAlgorithm(
            signature=signature,
            distance=lambda **kwargs: StartExitDistance(weight=0, **kwargs),
            cache_statistics=SplittedStatistics)
        algorithm.prototypes = [tree_1, tree_2]
        decorator = DistanceMatrixDecorator(normalized=False)
        decorator.wrap_algorithm(algorithm)

        algorithm.start_tree()
        for event in tree_1.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        algorithm.start_tree()
        for event in tree_2.event_iter(supported=algorithm.supported):
            try:
                algorithm.add_event(event)
            except EventNotSupportedException:
                pass
        algorithm.finish_tree()
        data = decorator.data()
        self.assertEqual(data[0][0][1], data[1][0][0])
예제 #2
0
    def test_parameter_distance(self):
        prototype = Prototype()
        root = prototype.add_node("root", tme=0, exit_tme=0, pid=1, ppid=0, param=1)
        for i in range(5):
            root.add_node("child_%d" % i, tme=0, exit_tme=0, pid=i + 2, ppid=1, param=1)
        next(root.children()).add_node("child", tme=0, exit_tme=0, pid=8, ppid=2, param=1)

        tree = Prototype()
        root = tree.add_node("root", tme=0, exit_tme=0, pid=1, ppid=0, param=1)
        for i in range(5):
            root.add_node("child_%d" % i, tme=0, exit_tme=0, pid=i + 2, ppid=1, param=4)
        next(root.children()).add_node("child", tme=0, exit_tme=0, pid=8, ppid=2, param=4)

        for weight, result in [(1, 0), (.5, 6), (0, 12)]:
            def distance(**kwargs):
                distance = StartExitDistance(weight=weight, **kwargs)
                distance.supported = {
                    ProcessStartEvent: True,
                    ProcessExitEvent: True,
                    ParameterEvent: True
                }
                return distance
            signature = EnsembleSignature(signatures=[ParentChildByNameTopologySignature()])
            algorithm = IncrementalDistanceAlgorithm(
                signature=signature,
                distance=distance,
                cache_statistics=SetStatistics
            )
            decorator = DistanceMatrixDecorator(normalized=False)
            decorator.wrap_algorithm(algorithm)
            algorithm.prototypes = [prototype]
            algorithm.start_tree()
            algorithm.add_events(tree.event_iter(supported=algorithm.supported))
            algorithm.finish_tree()
            self.assertEqual(result, decorator.data()[0][0][0])
예제 #3
0
    def test_event_order(self):
        tree = Prototype()
        root = tree.add_node("root", pid=1, ppid=0, tme=0, exit_tme=0, param=2)
        for i in range(5):
            root.add_node("child_%d" % i, pid=i + 2, ppid=1, tme=0, exit_tme=0,
                          param=i * 2)
        child = next(root.children())
        child.add_node("child", pid=8, ppid=child.pid, tme=0, exit_tme=0, param=5)

        nodes = []
        for event in tree.event_iter(supported={
            ProcessStartEvent: True,
            ProcessExitEvent: True,
            ParameterEvent: True
        }):
            print(event)
            if type(event) == ProcessStartEvent:
                if event.ppid != 0:
                    self.assertTrue(event.ppid in nodes)
                nodes.append(event.pid)
            elif type(event) == ProcessExitEvent:
                self.assertTrue(event.pid in nodes)
                nodes.remove(event.pid)
            elif type(event) == ParameterEvent:
                self.assertTrue(event.pid in nodes)
예제 #4
0
    def test_streaming_order(self):
        prototype = Prototype()
        root = prototype.add_node("root", pid=2, ppid=1, tme=1, exit_tme=5)
        nodes = [root,
                 root.add_node("one", pid=3, ppid=2, tme=1, exit_tme=2),
                 root.add_node("two", pid=4, ppid=2, tme=1, exit_tme=2),
                 root.add_node("four", pid=5, ppid=2, tme=2, exit_tme=3),
                 root.add_node("three", pid=6, ppid=2, tme=1, exit_tme=3)]

        index = 0
        for event in prototype.event_iter(supported={ProcessStartEvent: True}):
            if isinstance(event, ProcessStartEvent):
                self.assertEquals(nodes[index].name, event.name)
                index += 1
        self.assertEquals(index, len(nodes))
예제 #5
0
 def test_parent_child_event_iter(self):
     prototype = Prototype()
     root = prototype.add_node("root", pid=1, ppid=0, tme=0, exit_tme=3, traffic=[])
     one = root.add_node("one", pid=2, ppid=1, tme=0, exit_tme=2, traffic=[])
     one.add_node("one.one", pid=3, ppid=2, tme=1, exit_tme=2, traffic=[])
     one.add_node("one.two", pid=5, ppid=2, tme=2, exit_tme=2, traffic=[])
     root.add_node("two", pid=4, ppid=1, tme=1, exit_tme=2, traffic=[])
     finished = set()
     for event in prototype.event_iter(
             supported={
                 ProcessStartEvent: True,
                 ProcessExitEvent: True
             }):
         if isinstance(event, ProcessStartEvent):
             self.assertTrue(
                 event.ppid not in finished,
                 "Node with pid %s is already gone..." % event.ppid)
         if isinstance(event, ProcessExitEvent):
             self.assertTrue(
                 event.ppid not in finished,
                 "Node with pid %s has already been finished" % event.ppid)
             finished.add(event.pid)