Пример #1
0
 def test_alloc_triads_too_big(self):
     # Should fail if something too big is requested
     a = Allocator(3, 4)
     assert a._alloc_triads(4, 4) is None
     assert a._alloc_triads(3, 5) is None
     assert a._alloc_triads(4, 5) is None
     assert a._alloc_boards(3*4*3 + 1) is None
Пример #2
0
    def test_alloc_triads_single(self):
        # Should be able to allocate single blocks
        w, h = 3, 4
        next_id = 10
        a = Allocator(w, h, next_id=next_id)

        for _ in range(w * h):
            allocation_id, boards, periphery, torus = a._alloc_triads(1, 1)

            assert torus is WrapAround.none

            assert allocation_id == next_id
            next_id += 1

            assert len(boards) == 3
            xys = set((x, y) for (x, y, z) in boards)
            assert len(xys) == 1
            assert set(z for (x, y, z) in boards) == set(range(3))

            x, y = xys.pop()
            assert periphery == set((x, y, z, link)
                                    for z in range(3)
                                    for link in Links
                                    if (board_down_link(x, y, z,
                                                        link, w, h)[:2] !=
                                        (x, y)))

        # Should get full
        assert a._alloc_triads(1, 1) is None
Пример #3
0
 def test_alloc_triads_empty(self):
     # Should fail if nothing or negative amounts requested
     a = Allocator(3, 4)
     assert a._alloc_triads(0, 1) is None
     assert a._alloc_triads(-1, 1) is None
     assert a._alloc_triads(1, -1) is None
     assert a._alloc_triads(1, 0) is None
     assert a._alloc_boards(0) is None
     assert a._alloc_boards(-1) is None
Пример #4
0
 def test_alloc_triads_bad_torus(self):
     # Should not be able to allocate a torus unless requesting the full
     # machine
     a = Allocator(3, 4)
     assert a._alloc_triads(1, 2, require_torus=True) is None
     assert a._alloc_triads(3, 2, require_torus=True) is None
     assert a._alloc_triads(2, 4, require_torus=True) is None
     assert a._alloc_boards(1*2*3, require_torus=True) is None
     assert a._alloc_boards(3*2*3, require_torus=True) is None
     assert a._alloc_boards(2*4*3, require_torus=True) is None
    def test_free_triad(self):
        a = Allocator(2, 1, seconds_before_free=0.1)

        id0, _0, _1, _2 = a._alloc_triads(1, 1)
        id1, _0, _1, _2 = a._alloc_triads(1, 1)

        # The pack tree should be full
        assert a.pack_tree.allocated is False
        assert a.pack_tree.children is not None
        assert a.pack_tree.children[0].allocated is True
        assert a.pack_tree.children[1].allocated is True

        # Triad should be freed after timeout and allocation
        a.free(id1)
        assert a.pack_tree.allocated is False
        assert a.pack_tree.children is not None
        assert a.pack_tree.children[0].allocated is True
        assert a.pack_tree.children[1].allocated is True
        time.sleep(a.seconds_before_free)
        a.check_free()
        assert a.pack_tree.allocated is False
        assert a.pack_tree.children is not None
        assert a.pack_tree.children[0].allocated is True
        assert a.pack_tree.children[1].allocated is False

        # Full tree should be freed too
        a.free(id0)
        time.sleep(a.seconds_before_free)
        a.check_free()
        assert a.pack_tree.allocated is False
        assert a.pack_tree.children is None
    def test_alloc_triads_torus(self, require_torus):
        # Should be able to allocate the full machine in one go
        w, h = 3, 4
        next_id = 10
        a = Allocator(w, h, next_id=next_id)

        allocation_id, boards, periphery, torus = a._alloc_triads(
            w, h, require_torus=require_torus)

        assert allocation_id == next_id
        assert boards == set((x, y, z) for x in range(w) for y in range(h)
                             for z in range(3))
        assert periphery == set()
        assert torus is WrapAround.both

        # Should get full
        assert a._alloc_triads(1, 1, require_torus=require_torus) is None
Пример #7
0
    def test_free_triad(self):
        a = Allocator(2, 1)

        id0, _0, _1, _2 = a._alloc_triads(1, 1)
        id1, _0, _1, _2 = a._alloc_triads(1, 1)

        # The pack tree should be full
        assert a.pack_tree.allocated is False
        assert a.pack_tree.children is not None
        assert a.pack_tree.children[0].allocated is True
        assert a.pack_tree.children[1].allocated is True

        # Triad should be freed
        a.free(id1)
        assert a.pack_tree.allocated is False
        assert a.pack_tree.children is not None
        assert a.pack_tree.children[0].allocated is True
        assert a.pack_tree.children[1].allocated is False

        # Full tree should be freed too
        a.free(id0)
        assert a.pack_tree.allocated is False
        assert a.pack_tree.children is None
Пример #8
0
 def test_alloc_triads_non_machine(self):
     # Should fail if machine too small
     a = Allocator(3, 4)
     assert a._alloc_triads(0, 0) is None
     assert a._alloc_triads(0, 1) is None
     assert a._alloc_triads(1, 0) is None
Пример #9
0
 def test_alloc_triads_dead_links(self):
     # Should not be able to allocate if too many links are dead
     a = Allocator(3, 4, dead_links=set([(0, 0, 0, Links.north)]))
     assert a._alloc_triads(3, 4, max_dead_links=0) is None
     assert a._alloc_boards(3*4*3, max_dead_links=0) is None