]>
Commit | Line | Data |
---|---|---|
1 | #define T_NAMESPACE "xnu.ipc" | |
2 | #include <darwintest.h> | |
3 | #include <mach/mach.h> | |
4 | #include <stdlib.h> | |
5 | #include <stdio.h> | |
6 | ||
7 | T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); | |
8 | ||
9 | #define NR_PORTS 4 | |
10 | ||
11 | T_DECL(mach_port_deallocate, "mach_port_deallocate deallocates also PORT_SET"){ | |
12 | mach_port_t port_set; | |
13 | mach_port_t port[NR_PORTS]; | |
14 | int i, ret; | |
15 | ||
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"); | |
18 | ||
19 | for (i = 0; i < NR_PORTS; i++) { | |
20 | ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port[i]); | |
21 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE"); | |
22 | ||
23 | ret = mach_port_move_member(mach_task_self(), port[i], port_set); | |
24 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_move_member"); | |
25 | } | |
26 | ||
27 | T_LOG("Ports created"); | |
28 | ||
29 | /* do something */ | |
30 | ||
31 | for (i = 0; i < NR_PORTS; i++) { | |
32 | ret = mach_port_mod_refs(mach_task_self(), port[i], MACH_PORT_RIGHT_RECEIVE, -1); | |
33 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_mod_refs -1 RIGHT_RECEIVE"); | |
34 | } | |
35 | ||
36 | ret = mach_port_deallocate(mach_task_self(), port_set); | |
37 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_deallocate PORT_SET"); | |
38 | ||
39 | T_LOG("Ports erased"); | |
40 | } |