4 #define T_NAMESPACE "xnu.ipc"
5 #include <darwintest.h>
11 T_DECL(mach_port_mod_refs
, "mach_port_mod_refs"){
16 ret
= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET
, &port_set
);
17 T_ASSERT_MACH_SUCCESS(ret
, "mach_port_allocate MACH_PORT_RIGHT_PORT_SET");
19 ret
= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE
, &port
);
20 T_ASSERT_MACH_SUCCESS(ret
, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE");
24 * Test all known variants of port rights on each type of port
27 /* can't subtract a send right if it doesn't exist */
28 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_SEND
, -1);
29 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs SEND: -1 on a RECV right");
31 /* can't subtract a send once right if it doesn't exist */
32 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_SEND_ONCE
, -1);
33 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs SEND_ONCE: -1 on a RECV right");
35 /* can't subtract a PORT SET right if it's not a port set */
36 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_PORT_SET
, -1);
37 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs PORT_SET: -1 on a RECV right");
39 /* can't subtract a dead name right if it doesn't exist */
40 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_DEAD_NAME
, -1);
41 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs DEAD_NAME: -1 on a RECV right");
43 /* can't subtract a LABELH right if it doesn't exist */
44 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_LABELH
, -1);
45 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs LABELH: -1 on a RECV right");
47 /* can't subtract an invalid right-type */
48 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_NUMBER
, -1);
49 T_ASSERT_EQ(ret
, KERN_INVALID_VALUE
, "mach_port_mod_refs NUMBER: -1 on a RECV right");
51 /* can't subtract an invalid right-type */
52 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_NUMBER
+ 1, -1);
53 T_ASSERT_EQ(ret
, KERN_INVALID_VALUE
, "mach_port_mod_refs NUMBER+1: -1 on a RECV right");
56 /* can't subtract a send right if it doesn't exist */
57 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_SEND
, -1);
58 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs SEND: -1 on a PORT_SET right");
60 /* can't subtract a send once right if it doesn't exist */
61 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_SEND_ONCE
, -1);
62 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs SEND_ONCE: -1 on a PORT_SET right");
64 /* can't subtract a receive right if it's a port set */
65 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_RECEIVE
, -1);
66 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs RECV: -1 on a PORT_SET right");
68 /* can't subtract a dead name right if it doesn't exist */
69 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_DEAD_NAME
, -1);
70 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs DEAD_NAME: -1 on a PORT_SET right");
72 /* can't subtract a LABELH right if it doesn't exist */
73 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_LABELH
, -1);
74 T_ASSERT_EQ(ret
, KERN_INVALID_RIGHT
, "mach_port_mod_refs LABELH: -1 on a PORT_SET right");
76 /* can't subtract an invalid right-type */
77 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_NUMBER
, -1);
78 T_ASSERT_EQ(ret
, KERN_INVALID_VALUE
, "mach_port_mod_refs NUMBER: -1 on a PORT_SET right");
80 /* can't subtract an invalid right-type */
81 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_NUMBER
+ 1, -1);
82 T_ASSERT_EQ(ret
, KERN_INVALID_VALUE
, "mach_port_mod_refs NUMBER+1: -1 on a PORT_SET right");
85 * deallocate the ports/sets
87 ret
= mach_port_mod_refs(mach_task_self(), port_set
, MACH_PORT_RIGHT_PORT_SET
, -1);
88 T_ASSERT_MACH_SUCCESS(ret
, "mach_port_mod_refs(PORT_SET, -1)");
90 ret
= mach_port_mod_refs(mach_task_self(), port
, MACH_PORT_RIGHT_RECEIVE
, -1);
91 T_ASSERT_MACH_SUCCESS(ret
, "mach_port_mod_refs(RECV_RIGHT, -1)");