def test_cache_policies(self): machine = Machine() policies = [("test_1", 100), ("test_2", 200), ("test_3", 300)] machine.add_cache_policies(policies) for name, val in policies: self.assertEqual(machine.get_cache_policy(name), val) self.assertRaises(MergeError, machine.get_cache_policy, "not_exist")
def test_page_size(self): machine = Machine() # An arbitrary set of pages, in arbitrary order sizes = [1024, 64 * 1024, 1024 * 1024, 4 * 1024] machine.set_page_sizes(sizes) self.assertEqual(machine.min_page_size(), min(sizes)) self.assertEqual(machine.max_page_size(), max(sizes)) for n in range(1, 32): # Natural alignment with powers of two. size = 2**n align = machine.natural_alignment(size) if size <= 1024: self.assertEqual(align, 1024) elif size > 1024 * 1024: self.assertEqual(align, 1024 * 1024) else: self.assertEqual(align, size) # Natural alignment with powers of two plus 1. size = 2**n + 1 align = machine.natural_alignment(size) if size <= 1024: self.assertEqual(align, 1024) elif size > 1024 * 1024: self.assertEqual(align, 1024 * 1024) else: self.assertEqual(align, size - 1) # Natural alignment with powers of two minus 1. size = 2**n - 1 align = machine.natural_alignment(size) if size <= 1024: self.assertEqual(align, 1024) elif size > 1024 * 1024: self.assertEqual(align, 1024 * 1024) else: # We're rounding down, so... self.assertEqual(align, (size + 1) / 2) for n in range(1, 32): for size in [2**n - 1, 2**n, 2**n + 1]: # superpage alignment with powers of two. size = 2**n align = machine.superpage_alignment(size) if size <= 1024: # min page boundary self.assertEqual(align, 1024) elif size < 4 * 1024: self.assertEqual(align, 1024) elif size < 64 * 1024: self.assertEqual(align, 4 * 1024) elif size < 1024 * 1024: self.assertEqual(align, 64 * 1024) else: self.assertEqual(align, 1024 * 1024)
def test_kernel_heap_proximity(self): machine = Machine() # By default it should be 64MB as is the arm requirement. self.assertEqual(machine.kernel_heap_proximity, 64 * 1024 * 1024) # We can set it to a different value machine.kernel_heap_proximity = 32 * 1024 * 1024 self.assertEqual(machine.kernel_heap_proximity, 32 * 1024 * 1024) # Assigning a value of None should keep it the same machine.kernel_heap_proximity = None self.assertEqual(machine.kernel_heap_proximity, 32 * 1024 * 1024)
def test_physical_dev(self): machine = Machine() mem = [(0, 0x1000, None), (0x1000, 0x2000, None), (0x4000, 0x8000, None)] machine.add_physical_mem("test_mem", mem) dev = machine.add_phys_device("test_device") dev_mem = [(0x10000, 0x11000, None), (0x11000, 0x12000, None), (0x14000, 0x18000, None)] dev.add_physical_mem("dev_mem", dev_mem) self.assertEquals(machine.get_physical_memory("dev_mem"), dev_mem)
def test_virtual_mem(self): machine = Machine() mem = [(0, 0x1000, None), (0x1000, 0x2000, None), (0x4000, 0x8000, None)] machine.add_virtual_mem("test_mem", mem) overlap = [(0x800, 0x1800, None)] self.assertRaises(MergeError, machine.add_virtual_mem, "overlap", overlap) self.assertEqual(machine.get_virtual_memory("test_mem"), mem) self.assertRaises(MergeError, machine.get_virtual_memory, "not_exists")
def test_word_size(self): machine = Machine() self.assertEqual(machine.word_size, 32) self.assertEqual(machine.sizeof_word, 4) self.assertEqual(machine.sizeof_pointer, 4) machine.word_size = 64 self.assertEqual(machine.word_size, 64) self.assertEqual(machine.sizeof_word, 8) self.assertEqual(machine.sizeof_pointer, 8) # We don't accept non 8-byte word sizes try: machine.word_size = 63 except AssertionError: pass else: self.assertEqual(0, 1)