Beispiel #1
0
    def test_alloc_multiple_fun_obj(self, object_sizes, ut_size_bits):
        """Test allocating multiple child objects from a single untyped"""
        allocator = BestFitAllocator()
        spec = Spec()
        (total_child_size, children) = TestAllocator.alloc_children(spec, object_sizes)

        ut = Untyped(name="test_ut", size_bits=ut_size_bits, paddr=1<<ut_size_bits)
        allocator.add_untyped(ut)

        self.assertValidSpec(allocator, spec, 1<<ut_size_bits, total_child_size, children, [ut])
Beispiel #2
0
    def test_alloc_single_fun_obj(self, child_size_bits, ut_size_bits):
        """
        Test allocating a single object from a single untyped. Vary the untyped size and object size,
        and make sure it either succeeds (should always succeed if the untyped size is big enough) or fails
        by throwing an AllocatorException
        """
        allocator = BestFitAllocator()
        spec = Spec()

        ut = Untyped(name="test_ut", size_bits=ut_size_bits, paddr=1<<ut_size_bits)
        allocator.add_untyped(ut)

        child = Untyped(name="child_ut", size_bits=child_size_bits)
        spec.add_object(child)

        self.assertValidSpec(allocator, spec, ut_size_bits, child_size_bits, [child], [ut])
Beispiel #3
0
    def test_alloc_no_untyped(self):
        """
        Test allocating something from nothing fails elegantly
        """
        ep = Endpoint(name="test_ep")
        spec = Spec()
        spec.add_object(ep)

        with self.assertRaises(AllocatorException):
            BestFitAllocator().allocate(spec)
Beispiel #4
0
    def test_alloc_multiple_fun_multiple_untyped(self, object_sizes, ut_sizes):
        """Test allocating multiple children from multiple untyped"""
        allocator = BestFitAllocator()
        spec = Spec()
        (total_child_size, children) = TestAllocator.alloc_children(spec, object_sizes)
        untyped = []
        paddr = 0x1
        ut_size = 0

        for i in range(0, len(ut_sizes)):
            size_bits = ut_sizes[i]
            paddr = round_up(paddr, 1 << size_bits)
            ut = Untyped("untyped_{0}".format(i), size_bits=size_bits, paddr=paddr)
            untyped.append(ut)
            allocator.add_untyped(ut)
            paddr += 1<<size_bits
            ut_size += 1<<size_bits

        self.assertValidSpec(allocator, spec, ut_size, total_child_size, children, untyped)
Beispiel #5
0
    def test_regression_unfun_at_end(self):
        """
        Ensure that if an unfun object is the last to get allocated,
        its root ut is included in the spec.
        """
        allocator = BestFitAllocator()
        root_ut_A = Untyped("root_ut_A", size_bits=16, paddr=0x10000)
        root_ut_B = Untyped("root_ut_B", size_bits=16, paddr=0x20000)
        allocator.add_untyped(root_ut_A)
        allocator.add_untyped(root_ut_B)

        spec = Spec()
        my_frame_A0 = Frame("my_frame_A0")
        my_frame_A1 = Frame("my_frame_A1")
        my_pinned_frame_B = Frame("my_pinned_frame_B", paddr=0x20000)
        spec.add_object(my_frame_A0)
        spec.add_object(my_frame_A1)
        spec.add_object(my_pinned_frame_B)

        allocator.allocate(spec)
        self.assertIn(root_ut_B, spec.objs)  # main test
        # other tests:
        for obj in (root_ut_A, root_ut_B, my_frame_A0, my_frame_A1,
                    my_pinned_frame_B):
            self.assertIn(obj, spec.objs)
        for obj in (my_frame_A0, my_frame_A1):
            self.assertIn(obj, root_ut_A.children)
        for obj in (my_pinned_frame_B, ):
            self.assertIn(obj, root_ut_B.children)
Beispiel #6
0
    def test_alloc_paddr(self, unfun_paddr, ut_paddr):
        """
        Test allocating a single unfun untyped in and out of bounds of an untyped
        """

        allocator = BestFitAllocator()
        size_bits = 12

        unfun_paddr = unfun_paddr << size_bits
        ut_paddr = ut_paddr << size_bits
        unfun_end = unfun_paddr + (1 << size_bits)
        ut_end = ut_paddr + (1 << size_bits)

        parent = Untyped("parent_ut", size_bits=size_bits, paddr=ut_paddr)
        allocator.add_untyped(parent)
        spec = Spec()
        child = Untyped("child_ut", size_bits=size_bits, paddr=unfun_paddr)
        spec.add_object(child)

        if unfun_paddr >= ut_paddr and unfun_end <= ut_end:
            self.assertValidSpec(allocator, spec, size_bits, size_bits,
                                 [child], [parent])
        else:
            with self.assertRaises(AllocatorException):
                allocator.allocate(spec)
Beispiel #7
0
 def test_alloc_no_spec(self):
     """
     Test allocating nothing from something works
     """
     allocator = BestFitAllocator()
     allocator.add_untyped(Untyped(name="test_ut", size_bits=16, paddr=0))
     allocator.allocate(Spec())
Beispiel #8
0
    def test_placeholder_uts(self, sizes):
        """
        Test allocating a collection of unfun objects that do not align and have placeholder uts between them
        """
        allocator = BestFitAllocator()
        start_paddr = 1<<(max(sizes) + len(sizes).bit_length())
        paddr = start_paddr
        ut_size = 0

        children = []
        spec = Spec()
        for i in range(0, len(sizes)):
            paddr = round_up(paddr, 1<<sizes[i])
            ut = Untyped("ut_{0}".format(i), size_bits=sizes[i], paddr=paddr)
            spec.add_object(ut)
            paddr += 1<<sizes[i]
            ut_size += 1<<sizes[i]
            children.append(ut)

        ut_size_bits = (paddr - start_paddr).bit_length()
        ut = Untyped("ut_parent", size_bits=ut_size_bits, paddr=start_paddr)
        allocator.add_untyped(ut)
        self.assertValidSpec(allocator, spec, 1<<ut_size_bits, ut_size, children, [ut])
Beispiel #9
0
 def test_alloc_unsized(self):
     """Test allocating an object with no size"""
     irq_ctrl = IRQControl("irq_control")
     spec = Spec()
     spec.add_object(irq_ctrl)
     allocator = BestFitAllocator()
     allocator.add_untyped(Untyped(name="test_ut", size_bits=16, paddr=0x10000))
     allocator.allocate(spec)
     self.assertTrue(irq_ctrl in spec.objs)
Beispiel #10
0
    def test_overlapping_paddr_larger(self):
        """Test allocating unfun objects with overlapping paddrs, where the overlapping paddr is from a larger object"""
        allocator = BestFitAllocator()

        paddr = 0xAAAA0000
        allocator.add_untyped(Untyped("deadbeef", size_bits=16, paddr=paddr))

        spec = Spec()
        spec.add_object(Untyped("obj_untyped_1", size_bits=14, paddr=paddr + 2 * (1 << 15)))
        spec.add_object(Untyped("obj_untyped_2", size_bits=15, paddr=paddr))

        with self.assertRaises(AllocatorException):
            allocator.allocate(spec)
Beispiel #11
0
    def test_overlapping_paddr_smaller(self, offset):
        """Test allocating unfun objects with overlapping paddrs, where the overlapping paddr is from a smaller
        object """

        paddr = 0xAAAA0000
        size_bits = 16
        overlap_paddr = paddr + offset * (1<<(size_bits-2))

        allocator = BestFitAllocator()
        allocator.add_untyped(Untyped("parent", paddr=paddr, size_bits=size_bits))

        spec = Spec()
        spec.add_object(Untyped("child", paddr=paddr, size_bits=size_bits))
        spec.add_object(Untyped("overlap_child", paddr=overlap_paddr, size_bits=size_bits-2))

        with self.assertRaises(AllocatorException):
            allocator.allocate(spec)
Beispiel #12
0
    def test_device_ut_only(self, ut_sizes, obj_sizes):
        """
        Test allocating fun objects from only device untypeds
        """
        allocator = BestFitAllocator()
        paddr = 0x1
        for i in range(0, len(ut_sizes)):
            paddr = round_up(paddr, 1<<ut_sizes[i])
            allocator.add_device_untyped(Untyped("device_untyped_{0}".format(i), size_bits=ut_sizes[i], paddr=paddr))
            paddr += 1<<ut_sizes[i]

        spec = Spec()
        for i in range(0, len(obj_sizes)):
            spec.add_object(Untyped("obj_untyped_{0}".format(i), size_bits=obj_sizes[i]))

        with self.assertRaises(AllocatorException):
            allocator.allocate(spec)
Beispiel #13
0
 def test_alloc_no_spec_no_untyped(self):
     """
     Test allocating nothing from nothing works.
     """
     BestFitAllocator().allocate(Spec())
Beispiel #14
0
def main():
    parser = argparse.ArgumentParser(
        description="")
    parser.add_argument('--architecture', '--arch', default='aarch32',
                        type=lambda x: type('')(x).lower(), choices=valid_architectures(),
                        help='Target architecture.')
    parser.add_argument('--object-sizes', required=True, type=argparse.FileType('r'))
    subparsers = parser.add_subparsers()
    parser_a = subparsers.add_parser('build_cnode')
    parser_a.add_argument('--ccspace', nargs='+', type=argparse.FileType('w'), action='append')
    parser_a.set_defaults(which="build_cnode")
    parser_a.add_argument('--manifest-in', type=argparse.FileType('rb'))
    parser_a.add_argument('--elffile', nargs='+', action='append')
    parser_b = subparsers.add_parser('gen_cdl')
    parser_b.add_argument('--outfile', type=argparse.FileType('w'))
    parser_b.set_defaults(which="gen_cdl")
    parser_b.add_argument('--manifest-in', type=argparse.FileType('rb'))
    parser_b.add_argument('--elffile', nargs='+', action='append')
    parser_b.add_argument('--keys', nargs='+', action='append')
    parser_b.add_argument('--fprovide-tcb-caps', action='store_true',
                          default=True, help='Hand out TCB caps to components, allowing them to '
                          'exit cleanly.')
    parser_b.add_argument('--fno-provide-tcb-caps', action='store_false',
                          dest='fprovide_tcb_caps', help='Do not hand out TCB caps, causing '
                          'components to fault on exiting.')
    parser_b.add_argument('--save-object-state', type=argparse.FileType('wb'))
    parser_b.add_argument('--static-alloc', action='store_true',
                          help='Perform static object allocation (requires --untyped)')
    parser_b.add_argument('--dynamic-alloc', action='store_false', dest='static_alloc',
                          help='Cancel --static-alloc')
    parser_b.add_argument('--untyped', type=argparse.FileType('r'),
                          help="YAML file with available seL4 bootinfo untypeds")

    args = parser.parse_args()
    register_object_sizes(yaml.load(args.object_sizes, Loader=yaml.FullLoader))

    if args.which == "build_cnode":
        data = yaml.load(args.manifest_in, Loader=yaml.FullLoader)
        assert 'cap_symbols' in data and 'region_symbols' in data, "Invalid file format"
        elfs = [item for sublist in args.elffile for item in sublist]
        cspaces = [item for sublist in args.ccspace for item in sublist]
        targets = zip(elfs, cspaces)
        manifest(data['cap_symbols'], data['region_symbols'], args.architecture, targets)
        return 0

    if args.which == "gen_cdl":
        if args.static_alloc and not args.untyped:
            parser.error('--static-alloc requires --untyped')

        allocator_state = pickle.load(args.manifest_in)
        elfs = [item for sublist in args.elffile for item in sublist]
        keys = [item for sublist in args.keys for item in sublist]
        targets = zip(elfs, keys)
        obj_space = final_spec(args, allocator_state.obj_space, allocator_state.cspaces,
                               allocator_state.addr_spaces, targets, args.architecture)

        # Calculate final layout for objects and ASID slots...
        ASIDTableAllocator().allocate(obj_space.spec)
        if args.static_alloc:
            alloc = BestFitAllocator()
            for ut in yaml.load(args.untyped, Loader=yaml.FullLoader):
                if len(ut):
                    is_device, paddr, size_bits = ut['device'], ut['paddr'], ut['size_bits']
                    alloc.add_untyped(Untyped("root_untyped_0x%x" % paddr,
                                              size_bits=size_bits, paddr=paddr), is_device)
            alloc.allocate(obj_space.spec)

        args.outfile.write(repr(obj_space.spec))
        if args.save_object_state:
            pickle.dump(allocator_state, args.save_object_state)

    return 0