]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
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 | #define NR_PORTS 4 | |
8 | ||
9 | T_DECL(mach_port_deallocate, "mach_port_deallocate deallocates also PORT_SET"){ | |
10 | mach_port_t port_set; | |
11 | mach_port_t port[NR_PORTS]; | |
12 | int i,ret; | |
13 | ||
14 | ret= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &port_set); | |
15 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_PORT_SET"); | |
16 | ||
17 | for(i=0;i<NR_PORTS;i++){ | |
18 | ret= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port[i]); | |
19 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE"); | |
20 | ||
21 | ret= mach_port_move_member(mach_task_self(), port[i], port_set); | |
22 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_move_member"); | |
23 | } | |
24 | ||
25 | T_LOG("Ports created"); | |
26 | ||
27 | /* do something */ | |
28 | ||
29 | for(i=0;i<NR_PORTS;i++){ | |
30 | ret= mach_port_mod_refs(mach_task_self(), port[i], MACH_PORT_RIGHT_RECEIVE, -1); | |
31 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_mod_refs -1 RIGHT_RECEIVE"); | |
32 | } | |
33 | ||
34 | ret= mach_port_deallocate(mach_task_self(), port_set); | |
35 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_deallocate PORT_SET"); | |
36 | ||
37 | T_LOG("Ports erased"); | |
38 | } |