def atypes_node_remove_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x80) node.setup(0x60, 0x100, NodeType.NT_DEVICE, -5, 12) node.remove()
def atypes_node_str_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x42) node.setup(0x1234, 0x5678, NodeType.NT_DEVICE, -5, 12) assert str(node) == \ "[Node:@000042,p=005678,s=001234,NT_DEVICE,-5,'hello, world!']"
def atypes_node_str_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x42) node.setup(0x1234, 0x5678, NodeType.NT_DEVICE, -5, 12) assert str(node) == \ "[Node:@000042,p=005678,s=001234,NT_DEVICE,-5,'hello, world!']"
def atypes_list_iter_at_test(): l = new_list() n1 = Node(l.mem, 0x50) l.add_tail(n1) n2 = Node(l.mem, 0x60) l.add_tail(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2] assert [a for a in l.iter_at(n1)] == [n1, n2] assert [a for a in l.iter_at(n2)] == [n2]
def add_node(alist, addr, name): n = Node(alist.mem, addr) addr += n.get_type_size() name_addr = addr alist.mem.w_cstr(addr, name) addr += len(name) + 1 if addr & 3 != 0: addr = (addr & ~0x3) + 4 n.set_name(name_addr) alist.add_tail(n) return n, addr
def add_node(alist, addr, name): n = Node(alist.mem, addr) addr += n.get_type_size() name_addr = addr alist.mem.w_cstr(addr, name) addr += len(name) + 1 if addr & 3 != 0: addr = (addr & ~0x3) + 4 n.set_name(name_addr) alist.add_tail(n) return n, addr
def atypes_list_add_tail_test(): l = new_list() n1 = Node(l.mem, 0x50) assert len(l) == 0 l.add_tail(n1) assert len(l) == 1 assert [a for a in l] == [n1] n2 = Node(l.mem, 0x60) l.add_tail(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2]
def atypes_node_alloc_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = Node.alloc(alloc) assert node.get_size() == NodeStruct.get_size() node.free() # min node = Node.alloc_min(alloc) assert node.get_size() == MinNodeStruct.get_size() node.free() assert alloc.is_all_free()
def atypes_list_rem_tail_test(): l = new_list() n1 = Node(l.mem, 0x50) l.add_tail(n1) n2 = Node(l.mem, 0x60) l.add_tail(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2] r1 = l.rem_tail() assert r1 == n2 assert len(l) == 1 assert [a for a in l] == [n1] r2 = l.rem_tail() assert r2 == n1 assert len(l) == 0
def atypes_node_alloc_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = Node.alloc(alloc) assert node.get_size() == NodeStruct.get_size() node.free() assert alloc.is_all_free()
def atypes_node_alloc_name_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = Node.alloc(alloc, "foobar") assert node.get_size() == NodeStruct.get_size() assert node.get_name() == "foobar" node.free() assert alloc.is_all_free()
def atypes_node_alloc_name_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = Node.alloc(alloc, "foobar") assert node.get_size() == NodeStruct.get_size() assert node.get_name() == "foobar" node.free() assert alloc.is_all_free()
def atypes_list_remove_node_test(): l = new_list() n1 = Node(l.mem, 0x50) l.add_tail(n1) n2 = Node(l.mem, 0x60) l.add_tail(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2] n1.remove() assert len(l) == 1 assert [a for a in l] == [n2] n2.remove() assert len(l) == 0
def atypes_node_remove_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x80) node.setup(0x60, 0x100, NodeType.NT_DEVICE, -5, 12) node.remove()
def atypes_node_setup_min_test(): mem = MockMemory() node = Node(mem, 0x42) node.setup_min(1234, 5678) # check node assert node.get_succ() == 1234 assert node.get_pred() == 5678
def atypes_list_remove_node_test(): l = new_list() n1 = Node(l.mem, 0x50) l.add_tail(n1) n2 = Node(l.mem, 0x60) l.add_tail(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2] n1.remove() assert len(l) == 1 assert [a for a in l] == [n2] n2.remove() assert len(l) == 0
def atypes_list_insert_node_test(): l = new_list() n1 = Node(l.mem, 0x50) l.add_tail(n1) n2 = Node(l.mem, 0x60) l.add_tail(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2] # inside list n3 = Node(l.mem, 0x70) l.insert(n3, n1) assert len(l) == 3 assert [a for a in l] == [n1, n3, n2] # tail n4 = Node(l.mem, 0x80) l.insert(n4, n2) assert len(l) == 4 assert [a for a in l] == [n1, n3, n2, n4] # head n5 = Node(l.mem, 0x90) l.insert(n5, Node(l.mem, 0x40)) assert len(l) == 5 assert [a for a in l] == [n5, n1, n3, n2, n4]
def atypes_node_setup_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x42) node.setup(1234, 5678, NodeType.NT_DEVICE, -5, 12) # check node assert node.get_succ() == 1234 assert node.get_pred() == 5678 assert int(node.get_type()) == NodeType.NT_DEVICE assert node.get_pri() == -5 assert node.get_name(True) == 12 assert node.get_name() == text node.set_type(NodeType(NodeType.NT_DEVICE))
def atypes_list_enqueue_node_test(): l = new_list() n1 = Node(l.mem, 0x50) n1.set_pri(0) l.enqueue(n1) assert len(l) == 1 assert [a for a in l] == [n1] # same pri n2 = Node(l.mem, 0x60) n2.set_pri(0) l.enqueue(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2] # higher pri n3 = Node(l.mem, 0x70) n3.set_pri(1) l.enqueue(n3) assert len(l) == 3 assert [a for a in l] == [n3, n1, n2] # lower pri n4 = Node(l.mem, 0x80) n4.set_pri(-1) l.enqueue(n4) assert len(l) == 4 assert [a for a in l] == [n3, n1, n2, n4]
def atypes_node_base_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x42) # set node node.set_succ(1234) node.set_pred(5678) node.set_type(NodeType.NT_LIBRARY) node.set_pri(-3) node.set_name(12) # check node assert node.get_succ() == 1234 assert node.get_pred() == 5678 assert int(node.get_type()) == NodeType.NT_LIBRARY assert node.get_type() == NodeType(NodeType.NT_LIBRARY) assert node.get_pri() == -3 assert node.get_name(True) == 12 assert node.get_name() == text
def atypes_list_enqueue_node_test(): l = new_list() n1 = Node(l.mem, 0x50) n1.set_pri(0) l.enqueue(n1) assert len(l) == 1 assert [a for a in l] == [n1] # same pri n2 = Node(l.mem, 0x60) n2.set_pri(0) l.enqueue(n2) assert len(l) == 2 assert [a for a in l] == [n1, n2] # higher pri n3 = Node(l.mem, 0x70) n3.set_pri(1) l.enqueue(n3) assert len(l) == 3 assert [a for a in l] == [n3, n1, n2] # lower pri n4 = Node(l.mem, 0x80) n4.set_pri(-1) l.enqueue(n4) assert len(l) == 4 assert [a for a in l] == [n3, n1, n2, n4]
def atypes_node_base_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x42) # set node node.set_succ(1234) node.set_pred(5678) node.set_type(NodeType.NT_LIBRARY) node.set_pri(-3) node.set_name(12) # check node assert node.get_succ() == 1234 assert node.get_pred() == 5678 assert int(node.get_type()) == NodeType.NT_LIBRARY assert node.get_type() == NodeType(NodeType.NT_LIBRARY) assert node.get_pri() == -3 assert node.get_name(True) == 12 assert node.get_name() == text
def atypes_node_setup_test(): mem = MockMemory() text = 'hello, world!' mem.w_cstr(12, text) node = Node(mem, 0x42) node.setup(1234, 5678, NodeType.NT_DEVICE, -5, 12) # check node assert node.get_succ() == 1234 assert node.get_pred() == 5678 assert int(node.get_type()) == NodeType.NT_DEVICE assert node.get_pri() == -5 assert node.get_name(True) == 12 assert node.get_name() == text node.set_type(NodeType(NodeType.NT_DEVICE))