Ejemplo n.º 1
0
 def test_fit_allocate_no_double_entry(self):
     roots = list()
     x = self.bump_allocate(16 * 3)
     roots.append(x)
     self.bump_allocate(16 * 1)
     roots.append(self.bump_allocate(16 * 1))
     #
     for r in roots:
         self.push_root(r)
     lib.bump_ptr_reset()
     lib.qcgc_collect()
     for _ in roots:
         self.pop_root()
     #
     self.assertEqual(lib.small_free_list(0).count, 1)
     #
     del roots[0]
     for r in roots:
         self.push_root(r)
     lib.qcgc_collect()
     for _ in roots:
         self.pop_root()
     #
     self.assertEqual(lib.small_free_list(3).count, 1)
     #
     y = lib.qcgc_fit_allocate(16 * 3) # Create double entry
     self.assertEqual(lib.small_free_list(3).count, 0)
     self.assertEqual(lib.small_free_list(0).count, 1)
     self.assertEqual(x, y)
Ejemplo n.º 2
0
    def test_arena_sweep_mixed_2(self):
        arena = lib.qcgc_arena_create()
        i = lib.qcgc_arena_first_cell_index

        layout = [ (0, lib.BLOCK_WHITE)
                 , (5, lib.BLOCK_FREE)
                 , (20, lib.BLOCK_BLACK)
                 , (32, lib.BLOCK_BLACK)
                 , (33, lib.BLOCK_FREE)
                 , (42, lib.BLOCK_BLACK)
                 , (43, lib.BLOCK_WHITE)
                 , (44, lib.BLOCK_WHITE)
                 , (49, lib.BLOCK_BLACK)
                 ]

        for b in layout:
            p = ffi.addressof(lib.arena_cells(arena)[i + b[0]])
            self.set_blocktype(p, b[1])

        lib.qcgc_arena_sweep(arena)

        have_elems = [5,8,19]

        for i in range(lib.qcgc_small_free_lists):
            if (i in have_elems):
                self.assertEqual(1, lib.small_free_list(i).count)
            else:
                self.assertEqual(0, lib.small_free_list(i).count)

        for i in range(lib.qcgc_large_free_lists):
            self.assertEqual(0, lib.large_free_list(i).count)
Ejemplo n.º 3
0
 def test_initialization(self):
     # self.assertEqual( <config_value> ,lib.arenas().size)
     self.assertEqual(1, lib.arenas().count)
     self.assertNotEqual(ffi.NULL, lib.arenas().items)
     # self.assertEqual( <config_value> ,lib.free_arenas().size)
     self.assertEqual(0, lib.free_arenas().count)
     self.assertNotEqual(ffi.NULL, lib.free_arenas().items)
     self.assertEqual(
         ffi.addressof(
             lib.arena_cells(
                 lib.arenas().items[0])[lib.qcgc_arena_first_cell_index]),
         lib._qcgc_bump_allocator.ptr)
     self.assertEqual(
         lib.qcgc_arena_cells_count - lib.qcgc_arena_first_cell_index,
         self.bump_remaining_cells())
     for i in range(lib.qcgc_small_free_lists):
         self.assertEqual(lib.QCGC_SMALL_FREE_LIST_INIT_SIZE,
                          lib.small_free_list(i).size)
         self.assertEqual(0, lib.small_free_list(i).count)
         self.assertNotEqual(ffi.NULL, lib.small_free_list(i).items)
     for i in range(lib.qcgc_large_free_lists):
         self.assertEqual(lib.QCGC_LARGE_FREE_LIST_INIT_SIZE,
                          lib.large_free_list(i).size)
         self.assertEqual(0, lib.large_free_list(i).count)
         self.assertNotEqual(ffi.NULL, lib.large_free_list(i).items)
Ejemplo n.º 4
0
 def test_fit_allocate_no_double_entry(self):
     roots = list()
     x = self.bump_allocate(16 * 3)
     roots.append(x)
     self.bump_allocate(16 * 1)
     roots.append(self.bump_allocate(16 * 1))
     #
     for r in roots:
         self.push_root(r)
     lib.bump_ptr_reset()
     lib.qcgc_collect()
     for _ in roots:
         self.pop_root()
     #
     self.assertEqual(lib.small_free_list(0).count, 1)
     #
     del roots[0]
     for r in roots:
         self.push_root(r)
     lib.qcgc_collect()
     for _ in roots:
         self.pop_root()
     #
     self.assertEqual(lib.small_free_list(3).count, 1)
     #
     y = lib.qcgc_fit_allocate(16 * 3)  # Create double entry
     self.assertEqual(lib.small_free_list(3).count, 0)
     self.assertEqual(lib.small_free_list(0).count, 1)
     self.assertEqual(x, y)
Ejemplo n.º 5
0
    def test_arena_sweep_no_double_add(self):
        arena = lib.qcgc_arena_create()
        i = lib.qcgc_arena_first_cell_index

        layout = [ (0, lib.BLOCK_BLACK)
                 , (1, lib.BLOCK_WHITE)
                 , (2, lib.BLOCK_BLACK)
                 ]

        for b in layout:
            p = ffi.addressof(lib.arena_cells(arena)[i + b[0]])
            self.set_blocktype(p, b[1])

        lib.qcgc_arena_sweep(arena)

        have_elems = [0]

        for i in range(lib.qcgc_small_free_lists):
            if (i in have_elems):
                self.assertEqual(1, lib.small_free_list(i).count)
            else:
                self.assertEqual(0, lib.small_free_list(i).count)

        for i in range(lib.qcgc_large_free_lists):
            self.assertEqual(0, lib.large_free_list(i).count)

        # Now mark the black blocks black again
        layout = [ (0, lib.BLOCK_BLACK)
                 , (2, lib.BLOCK_BLACK)
                 ]

        i = lib.qcgc_arena_first_cell_index
        for b in layout:
            p = ffi.addressof(lib.arena_cells(arena)[i + b[0]])
            self.set_blocktype(p, b[1])

        lib.qcgc_arena_sweep(arena)

        have_elems = [0]

        for i in range(lib.qcgc_small_free_lists):
            if (i in have_elems):
                self.assertEqual(1, lib.small_free_list(i).count)
            else:
                self.assertEqual(0, lib.small_free_list(i).count)

        for i in range(lib.qcgc_large_free_lists):
            self.assertEqual(0, lib.large_free_list(i).count)
Ejemplo n.º 6
0
 def test_init_values(self):
     self.assertNotEqual(ffi.NULL, lib.arenas)
     for i in range(lib.qcgc_small_free_lists):
         l = lib.small_free_list(i)
         self.assertNotEqual(ffi.NULL, l)
     for i in range(lib.qcgc_large_free_lists):
         l = lib.large_free_list(i)
         self.assertNotEqual(ffi.NULL, l)
Ejemplo n.º 7
0
 def test_initialization(self):
     # self.assertEqual( <config_value> ,lib.arenas().size)
     self.assertEqual(1, lib.arenas().count)
     self.assertNotEqual(ffi.NULL, lib.arenas().items)
     # self.assertEqual( <config_value> ,lib.free_arenas().size)
     self.assertEqual(0, lib.free_arenas().count)
     self.assertNotEqual(ffi.NULL, lib.free_arenas().items)
     self.assertEqual(ffi.addressof(lib.arena_cells(lib.arenas().items[0])[lib.qcgc_arena_first_cell_index]), lib._qcgc_bump_allocator.ptr)
     self.assertEqual(lib.qcgc_arena_cells_count - lib.qcgc_arena_first_cell_index, self.bump_remaining_cells())
     for i in range(lib.qcgc_small_free_lists):
         self.assertEqual(lib.QCGC_SMALL_FREE_LIST_INIT_SIZE, lib.small_free_list(i).size)
         self.assertEqual(0, lib.small_free_list(i).count)
         self.assertNotEqual(ffi.NULL, lib.small_free_list(i).items)
     for i in range(lib.qcgc_large_free_lists):
         self.assertEqual(lib.QCGC_LARGE_FREE_LIST_INIT_SIZE, lib.large_free_list(i).size)
         self.assertEqual(0, lib.large_free_list(i).count)
         self.assertNotEqual(ffi.NULL, lib.large_free_list(i).items)
Ejemplo n.º 8
0
 def test_init_values(self):
     self.assertNotEqual(ffi.NULL, lib.arenas)
     for i in range(lib.qcgc_small_free_lists):
         l = lib.small_free_list(i)
         self.assertNotEqual(ffi.NULL, l)
     for i in range(lib.qcgc_large_free_lists):
         l = lib.large_free_list(i)
         self.assertNotEqual(ffi.NULL, l)
Ejemplo n.º 9
0
    def test_add_small(self):
        blocks = list()
        for i in range(1, lib.qcgc_small_free_lists + 1):
            p = self.bump_allocate_cells(i)
            lib.qcgc_arena_mark_free(p)
            blocks.append(p)
            lib.qcgc_fit_allocator_add(p, i)

        for i in range(lib.qcgc_small_free_lists):
            l = lib.small_free_list(i)
            self.assertEqual(l.count, 1)
            self.assertEqual(blocks[i], l.items[0])
Ejemplo n.º 10
0
    def test_add_small(self):
        blocks = list()
        for i in range(1, lib.qcgc_small_free_lists + 1):
            p = self.bump_allocate_cells(i)
            lib.qcgc_arena_mark_free(p)
            blocks.append(p)
            lib.qcgc_fit_allocator_add(p, i)

        for i in range(lib.qcgc_small_free_lists):
            l = lib.small_free_list(i)
            self.assertEqual(l.count, 1)
            self.assertEqual(blocks[i], l.items[0])
Ejemplo n.º 11
0
    def test_arena_sweep_white(self):
        arena = lib.qcgc_arena_create()
        i = lib.qcgc_arena_first_cell_index

        for j in range(10):
            lib.qcgc_arena_mark_allocated(
                    ffi.addressof(lib.arena_cells(arena)[i + j]),
                    1)
        self.assertEqual(lib.qcgc_arena_white_blocks(arena), 10)

        self.assertTrue(lib.qcgc_arena_sweep(arena))
        self.assertEqual(lib.qcgc_arena_black_blocks(arena), 0)
        self.assertEqual(lib.qcgc_arena_white_blocks(arena), 0)
        self.assertEqual(lib.qcgc_arena_free_blocks(arena), 1)

        self.assertTrue(lib.qcgc_arena_is_empty(arena))
        self.assertTrue(lib.qcgc_arena_is_coalesced(arena))
        for i in range(lib.qcgc_small_free_lists):
            self.assertEqual(0, lib.small_free_list(i).count)

        for i in range(lib.qcgc_large_free_lists):
            self.assertEqual(0, lib.large_free_list(i).count)
Ejemplo n.º 12
0
    def test_arena_sweep_black(self):
        arena = lib.qcgc_arena_create()
        i = lib.qcgc_arena_first_cell_index

        for j in range(10):
            p = ffi.addressof(lib.arena_cells(arena)[i + j])
            lib.qcgc_arena_mark_allocated(p, 1)
            self.set_blocktype(p, lib.BLOCK_BLACK)

        self.assertEqual(lib.qcgc_arena_black_blocks(arena), 10)

        self.assertFalse(lib.qcgc_arena_sweep(arena))
        self.assertEqual(lib.qcgc_arena_black_blocks(arena), 0)
        self.assertEqual(lib.qcgc_arena_white_blocks(arena), 10)
        self.assertEqual(lib.qcgc_arena_free_blocks(arena), 1)

        self.assertTrue(lib.qcgc_arena_is_coalesced(arena))
        for i in range(lib.qcgc_small_free_lists):
            self.assertEqual(0, lib.small_free_list(i).count)

        for i in range(lib.qcgc_large_free_lists - 1):
            self.assertEqual(0, lib.large_free_list(i).count)
        self.assertEqual(1, lib.large_free_list(lib.qcgc_large_free_lists - 1).count)