]>
git.saurik.com Git - apple/xnu.git/blob - tests/mach_port_insert_right.c
3 #include <mach/message.h>
4 #include <darwintest.h>
6 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
8 static inline mach_port_type_t
9 get_port_type(mach_port_t mp
)
11 mach_port_type_t type
;
13 T_ASSERT_MACH_SUCCESS(mach_port_type(mach_task_self(), mp
, &type
),
14 "mach_port_type(mP)");
18 T_DECL(mach_port_insert_right
, "insert send right for an existing right", T_META_CHECK_LEAKS(false))
20 mach_port_t port
= MACH_PORT_NULL
;
21 mach_port_t port2
= MACH_PORT_NULL
;
24 mach_port_t task
= mach_task_self();
26 retval
= mach_port_allocate(task
, MACH_PORT_RIGHT_RECEIVE
, &port
);
27 T_ASSERT_MACH_SUCCESS(retval
, "allocate a port=[%d]", port
);
29 T_ASSERT_EQ(get_port_type(port
), MACH_PORT_TYPE_RECEIVE
,
30 "0x%x should be a receive right", port
);
32 retval
= mach_port_insert_right(task
, port
, port
, MACH_MSG_TYPE_MAKE_SEND
);
33 T_ASSERT_MACH_SUCCESS(retval
, "insert a send right for port=[%d] with name=[%d]", port
, port
);
34 T_ASSERT_EQ(get_port_type(port
), MACH_PORT_TYPE_RECEIVE
| MACH_PORT_TYPE_SEND
,
35 "0x%x should be a send-receive right", port
);
37 mach_port_name_t name
= 123;
39 retval
= mach_port_insert_right(task
, name
, port
, MACH_MSG_TYPE_MAKE_SEND
);
40 T_ASSERT_MACH_ERROR(retval
, KERN_FAILURE
, "insert a send right for port=[%d] with name=[%d]", port
, name
);
43 retval
= mach_port_insert_right(task
, name
, port
, MACH_MSG_TYPE_MAKE_SEND
);
44 T_ASSERT_MACH_ERROR(retval
, KERN_FAILURE
, "insert a send right for port=[%d] with name=[%d]", port
, name
);
46 retval
= mach_port_allocate(task
, MACH_PORT_RIGHT_RECEIVE
, &port2
);
47 T_ASSERT_MACH_SUCCESS(retval
, "allocate a port=[%d]", port2
);
49 T_ASSERT_EQ(get_port_type(port2
), MACH_PORT_TYPE_RECEIVE
,
50 "0x%x should be a receive right", port2
);
53 retval
= mach_port_insert_right(task
, name
, port2
, MACH_MSG_TYPE_MAKE_SEND
);
54 T_ASSERT_MACH_ERROR(retval
, KERN_RIGHT_EXISTS
, "insert a send right for port=[%d] with name=[%d]", port2
, name
);