def test_full_allocations(self): all_comps = [hpd.Component({'2048': 256})] any_comps = [hpd.Component({'1048576': 1, '2048': 512})] hpd._allocate_all(self.numa_nodes, all_comps) hpd._allocate_any(self.numa_nodes, any_comps) self._check((0, {PAGE_2MIB: 512, PAGE_1GIB: 1}), (0, {PAGE_2MIB: 512}))
def test_any_allocation_multy_component(self): any_comps = [hpd.Component({'2048': 512}), hpd.Component({'1048576': 2})] self.assertNotRaises(ValueError, hpd._allocate_any, self.numa_nodes, any_comps) self._check((0, {PAGE_1GIB: 2}), (0, {PAGE_2MIB: 512}))
def test_empty_component_allocation(self): comp = hpd.Component({'2048': 0}) self.assertTrue(comp.is_done()) allocated = self.numa_node.allocate(comp) self.assertTrue(allocated) self.assertEqual(self.numa_node.pages, {})
def test_any_allocation_simple(self): any_comps = [hpd.Component({'1048576': 1})] self.assertNotRaises(ValueError, hpd._allocate_any, self.numa_nodes, any_comps) self._check((PAGE_1GIB, {PAGE_1GIB: 1}), (PAGE_1GIB, {}))
def test_all_allocation(self): all_comps = [hpd.Component({'2048': 512})] self.assertNotRaises(ValueError, hpd._allocate_all, self.numa_nodes, all_comps) self._check((PAGE_1GIB, {PAGE_2MIB: 512}), (0, {PAGE_2MIB: 512}))
def test_failed_allocation_on_full_node(self): numa_node = hpd.NumaNode(0, 1024) # node with 1 MiB memory comp = hpd.Component({'2048': 1}) allocated = numa_node.allocate(comp) self.assertFalse(allocated) self.assertEqual(comp._pages, {PAGE_2MIB: 1}) self.assertEqual(numa_node.pages, {})
def test_all_allocation_raises(self): all_comps = [hpd.Component({'1048576': 100500})] self.assertRaisesWithMessageIn( ValueError, 'could not require more memory than node has', hpd._allocate_all, self.numa_nodes, all_comps)
def test_allocation_enough_memory(self): comp = hpd.Component({'2048': 3, '1048576': 2}) allocated = self.numa_node.allocate(comp) self.assertTrue(allocated) self.assertEqual( self.numa_node.free_memory, self.numa_node_memory - (PAGE_2MIB * 3) - (PAGE_1GIB * 2)) self.assertEqual(self.numa_node.pages, {PAGE_2MIB: 3, PAGE_1GIB: 2}) self.assertTrue(comp.is_done())
def test_allocation_not_enough_memory(self): comp = hpd.Component({'2048': 513, '1048576': 127}) allocated = self.numa_node.allocate(comp) self.assertTrue(allocated) # Checks that we allocate 127 1GiB pages and 512 2MiB pages. # And component steel need 1 2MiB page self.assertEqual(self.numa_node.free_memory, 0) self.assertEqual(self.numa_node.pages, {PAGE_2MIB: 512, PAGE_1GIB: 127}) self.assertFalse(comp.is_done()) self.assertEqual(comp._pages, {PAGE_2MIB: 1})
def test_allocation(self): comp = hpd.Component({'2048': 1, '1048576': 3}) allocated = comp.allocate(PAGE_2MIB, 2) self.assertEqual(allocated, 1) self.assertEqual(list(comp._pages.values()), [3]) allocated = comp.allocate(PAGE_1GIB, 1) self.assertEqual(allocated, 1) self.assertEqual(list(comp._pages.values()), [2]) allocated = comp.allocate(PAGE_2MIB, 1) self.assertEqual(allocated, 0) self.assertEqual(list(comp._pages.values()), [2])
def test_initialization(self): comp = hpd.Component({'2048': 1, '1048576': 3}) self.assertEqual(comp._pages, {PAGE_2MIB: 1, PAGE_1GIB: 3}) # check ordering self.assertEqual(list(comp._pages.keys()), [PAGE_1GIB, PAGE_2MIB])
def test_pages(self): comp = hpd.Component({'2048': 1, '1048576': 3}) self.assertEqual(list(comp.pages()), [(PAGE_1GIB, 3), (PAGE_2MIB, 1)])
def test_empty(self): comp = hpd.Component({'2048': 0}) self.assertEqual(comp._pages, {})
def test_is_done(self): comp = hpd.Component({'2048': 1, '1048576': 0}) self.assertFalse(comp.is_done()) comp.allocate(PAGE_2MIB, 1) self.assertTrue(comp.is_done())