Esempio n. 1
0
    def setUp(self):
        Machine.register()
        VirtualPool.register()
        PhysicalPool.register()
        Kernel.register()

        import weaver.cells.iguana_cell
Esempio n. 2
0
    def setUp(self):
        Machine.register()
        VirtualPool.register()
        PhysicalPool.register()
        Kernel.register()

        import weaver.cells.iguana_cell
Esempio n. 3
0
    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")
Esempio n. 4
0
    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)
Esempio n. 5
0
    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")
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
0
    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")
Esempio n. 10
0
    def test_physical_mem(self):
        machine = Machine()

        mem = [(0, 0x1000, None),
               (0x1000, 0x2000, None),
               (0x4000, 0x8000, None)]
        machine.add_physical_mem("test_mem", mem)

        overlap = [(0x800, 0x1800, None)]
        self.assertRaises(MergeError, machine.add_physical_mem, "overlap", overlap)

        self.assertEqual(machine.get_physical_memory("test_mem"), mem)
        self.assertRaises(MergeError, machine.get_physical_memory, "not_exists")
Esempio n. 11
0
    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)
Esempio n. 12
0
    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)
Esempio n. 13
0
    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)
Esempio n. 14
0
    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)
Esempio n. 15
0
def merge(spec_file, options):
    """Based on a given spec file, process it and merge into
    the output_file."""
    image = weaver.image.Image(options.program_header_offset)

    namespace = weaver.namespace.ObjectNameSpace(None, '/')

    # parsed is an in memory tree of Element Objects
    # which is created from spec_file

    Machine.register()
    VirtualPool.register()
    PhysicalPool.register()
    Kernel.register()

    if options.spec_is_string:
        parsed = parse_spec_xml_string(spec_file)
    else:
        parsed = parse_spec_xml(spec_file)

    machine, kernel, pools, found_cells = \
        collect_image_objects(parsed, options.ignore_name,
                              options.kernel_heap_size,
                              namespace, image)

    # Resolve unknown cap names.  This will generate references to
    # kernel caps, which are needed by kernel.layout_cells_pre().
    for cell in found_cells:
        cell.env.snap(cell)

    kernel.layout_cells_pre()

    # For each found cell generate any dynamic segments that need processing
    for cell in found_cells:
        cell.generate_dynamic_segments(namespace, machine, pools, kernel, image)

    # Kernel dynamic elements need to be performed after all the cells
    # have been completed in order for the cell's enviornment memsections
    # to be populated before we generate the kernel's init script
    kernel.create_dynamic_segments(namespace, image, machine, pools)

    image.layout(machine, pools)
    notes = NotesSection(kernel)
    notes.set_mempool(image.phys_pool_stack.bot())
    image.get_elf().add_section(notes.encode_section(image.get_elf()))

    # The ELF file must be prepared to calculate the offset value of
    # the segment info records in the environment.
    image.prepare()

    kernel.layout_cells_post(image)

    # Perform any generation code that needs to be run for each found cell
    for cell in found_cells:
        cell.generate_init(machine, pools, kernel, image)
    kernel.generate_init_script(image, machine)

    image.apply_patches()
    image.write_out_image(options.output_file, image, kernel, machine)

    # If wanted, print out the final tree.
    if options.dump_layout:
        image.dump()

    if options.last_phys:
        pools.print_last_phys()
Esempio n. 16
0
def merge(spec_file, options):
    """Based on a given spec file, process it and merge into
    the output_file."""
    image = weaver.image.Image(options.program_header_offset)

    namespace = weaver.namespace.ObjectNameSpace(None, '/')

    # parsed is an in memory tree of Element Objects
    # which is created from spec_file

    Machine.register()
    VirtualPool.register()
    PhysicalPool.register()
    Kernel.register()

    if options.spec_is_string:
        parsed = parse_spec_xml_string(spec_file)
    else:
        parsed = parse_spec_xml(spec_file)

    machine, kernel, pools, found_cells = \
        collect_image_objects(parsed, options.ignore_name,
                              options.kernel_heap_size,
                              namespace, image)

    # Resolve unknown cap names.  This will generate references to
    # kernel caps, which are needed by kernel.layout_cells_pre().
    for cell in found_cells:
        cell.env.snap(cell)

    kernel.layout_cells_pre()

    # For each found cell generate any dynamic segments that need processing
    for cell in found_cells:
        cell.generate_dynamic_segments(namespace, machine, pools, kernel,
                                       image)

    # Kernel dynamic elements need to be performed after all the cells
    # have been completed in order for the cell's enviornment memsections
    # to be populated before we generate the kernel's init script
    kernel.create_dynamic_segments(namespace, image, machine, pools)

    image.layout(machine, pools)
    notes = NotesSection(kernel)
    notes.set_mempool(image.phys_pool_stack.bot())
    image.get_elf().add_section(notes.encode_section(image.get_elf()))

    # The ELF file must be prepared to calculate the offset value of
    # the segment info records in the environment.
    image.prepare()

    kernel.layout_cells_post(image)

    # Perform any generation code that needs to be run for each found cell
    for cell in found_cells:
        cell.generate_init(machine, pools, kernel, image)
    kernel.generate_init_script(image, machine)

    image.apply_patches()
    image.write_out_image(options.output_file, image, kernel, machine)

    # If wanted, print out the final tree.
    if options.dump_layout:
        image.dump()

    if options.last_phys:
        pools.print_last_phys()