xref: /xnu-10002.41.9/tests/mach_port_deallocate_21692215.c (revision 699cd48037512bf4380799317ca44ca453c82f57)
1*699cd480SApple OSS Distributions #include <darwintest.h>
2*699cd480SApple OSS Distributions #include <mach/mach.h>
3*699cd480SApple OSS Distributions #include <stdlib.h>
4*699cd480SApple OSS Distributions #include <stdio.h>
5*699cd480SApple OSS Distributions 
6*699cd480SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true),
7*699cd480SApple OSS Distributions     T_META_NAMESPACE("xnu.ipc"),
8*699cd480SApple OSS Distributions     T_META_RADAR_COMPONENT_NAME("xnu"),
9*699cd480SApple OSS Distributions     T_META_RADAR_COMPONENT_VERSION("IPC"));
10*699cd480SApple OSS Distributions 
11*699cd480SApple OSS Distributions #define NR_PORTS 4
12*699cd480SApple OSS Distributions 
13*699cd480SApple OSS Distributions T_DECL(mach_port_deallocate, "mach_port_deallocate deallocates also PORT_SET"){
14*699cd480SApple OSS Distributions 	mach_port_t port_set;
15*699cd480SApple OSS Distributions 	mach_port_t port[NR_PORTS];
16*699cd480SApple OSS Distributions 	int i, ret;
17*699cd480SApple OSS Distributions 
18*699cd480SApple OSS Distributions 	ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &port_set);
19*699cd480SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_PORT_SET");
20*699cd480SApple OSS Distributions 
21*699cd480SApple OSS Distributions 	for (i = 0; i < NR_PORTS; i++) {
22*699cd480SApple OSS Distributions 		ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port[i]);
23*699cd480SApple OSS Distributions 		T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE");
24*699cd480SApple OSS Distributions 
25*699cd480SApple OSS Distributions 		ret = mach_port_move_member(mach_task_self(), port[i], port_set);
26*699cd480SApple OSS Distributions 		T_ASSERT_MACH_SUCCESS(ret, "mach_port_move_member");
27*699cd480SApple OSS Distributions 	}
28*699cd480SApple OSS Distributions 
29*699cd480SApple OSS Distributions 	T_LOG("Ports created");
30*699cd480SApple OSS Distributions 
31*699cd480SApple OSS Distributions 	/* do something */
32*699cd480SApple OSS Distributions 
33*699cd480SApple OSS Distributions 	for (i = 0; i < NR_PORTS; i++) {
34*699cd480SApple OSS Distributions 		ret = mach_port_mod_refs(mach_task_self(), port[i], MACH_PORT_RIGHT_RECEIVE, -1);
35*699cd480SApple OSS Distributions 		T_ASSERT_MACH_SUCCESS(ret, "mach_port_mod_refs -1 RIGHT_RECEIVE");
36*699cd480SApple OSS Distributions 	}
37*699cd480SApple OSS Distributions 
38*699cd480SApple OSS Distributions 	ret = mach_port_deallocate(mach_task_self(), port_set);
39*699cd480SApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(ret, "mach_port_deallocate PORT_SET");
40*699cd480SApple OSS Distributions 
41*699cd480SApple OSS Distributions 	T_LOG("Ports erased");
42*699cd480SApple OSS Distributions }
43