xref: /xnu-10063.121.3/tests/task_is_self.c (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions #include <darwintest.h>
2*2c2f96dcSApple OSS Distributions #include <mach/mach.h>
3*2c2f96dcSApple OSS Distributions #include <mach/task.h>
4*2c2f96dcSApple OSS Distributions #include <mach/mach_init.h>
5*2c2f96dcSApple OSS Distributions 
6*2c2f96dcSApple OSS Distributions T_GLOBAL_META(
7*2c2f96dcSApple OSS Distributions 	T_META_NAMESPACE("xnu.ipc"),
8*2c2f96dcSApple OSS Distributions 	T_META_RUN_CONCURRENTLY(TRUE),
9*2c2f96dcSApple OSS Distributions 	T_META_RADAR_COMPONENT_NAME("xnu"),
10*2c2f96dcSApple OSS Distributions 	T_META_RADAR_COMPONENT_VERSION("IPC"));
11*2c2f96dcSApple OSS Distributions 
12*2c2f96dcSApple OSS Distributions T_DECL(mach_task_is_self,
13*2c2f96dcSApple OSS Distributions     "test task port comparison check")
14*2c2f96dcSApple OSS Distributions {
15*2c2f96dcSApple OSS Distributions 	mach_port_t self_insp, self_read, self_name, port;
16*2c2f96dcSApple OSS Distributions 
17*2c2f96dcSApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(task_get_special_port(mach_task_self(), TASK_READ_PORT, &self_read), "task_get_special_port failed");
18*2c2f96dcSApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(task_get_special_port(mach_task_self(), TASK_INSPECT_PORT, &self_insp), "task_get_special_port failed");
19*2c2f96dcSApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(task_get_special_port(mach_task_self(), TASK_NAME_PORT, &self_name), "task_get_special_port failed");
20*2c2f96dcSApple OSS Distributions 
21*2c2f96dcSApple OSS Distributions 	T_ASSERT_MACH_SUCCESS(mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port), "mach_port_allocate failed");
22*2c2f96dcSApple OSS Distributions 
23*2c2f96dcSApple OSS Distributions 	T_EXPECT_NE(self_read, self_insp, "read and inspect port should be different");
24*2c2f96dcSApple OSS Distributions 	T_EXPECT_NE(self_read, mach_task_self(), "read and control port should be different");
25*2c2f96dcSApple OSS Distributions 
26*2c2f96dcSApple OSS Distributions 	T_EXPECT_EQ(1, mach_task_is_self(mach_task_self()), "control port should point to self");
27*2c2f96dcSApple OSS Distributions 	T_EXPECT_EQ(1, mach_task_is_self(self_read), "read port should point to self");
28*2c2f96dcSApple OSS Distributions 	T_EXPECT_EQ(1, mach_task_is_self(self_insp), "inspect port should point to self");
29*2c2f96dcSApple OSS Distributions 	T_EXPECT_EQ(1, mach_task_is_self(self_name), "name port should point to self");
30*2c2f96dcSApple OSS Distributions 	T_EXPECT_NE(1, mach_task_is_self(port), "_port_ should not point to self");
31*2c2f96dcSApple OSS Distributions }
32