]>
Commit | Line | Data |
---|---|---|
1 | #include <darwintest.h> | |
2 | #include <mach/mach.h> | |
3 | #include <mach/task.h> | |
4 | #include <mach/mach_init.h> | |
5 | ||
6 | T_DECL(mach_task_is_self, | |
7 | "test task port comparison check") | |
8 | { | |
9 | mach_port_t self_insp, self_read, self_name, port; | |
10 | ||
11 | T_ASSERT_MACH_SUCCESS(task_get_special_port(mach_task_self(), TASK_READ_PORT, &self_read), "task_get_special_port failed"); | |
12 | T_ASSERT_MACH_SUCCESS(task_get_special_port(mach_task_self(), TASK_INSPECT_PORT, &self_insp), "task_get_special_port failed"); | |
13 | T_ASSERT_MACH_SUCCESS(task_get_special_port(mach_task_self(), TASK_NAME_PORT, &self_name), "task_get_special_port failed"); | |
14 | ||
15 | T_ASSERT_MACH_SUCCESS(mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port), "mach_port_allocate failed"); | |
16 | ||
17 | T_EXPECT_NE(self_read, self_insp, "read and inspect port should be different"); | |
18 | T_EXPECT_NE(self_read, mach_task_self(), "read and control port should be different"); | |
19 | ||
20 | T_EXPECT_EQ(1, mach_task_is_self(mach_task_self()), "control port should point to self"); | |
21 | T_EXPECT_EQ(1, mach_task_is_self(self_read), "read port should point to self"); | |
22 | T_EXPECT_EQ(1, mach_task_is_self(self_insp), "inspect port should point to self"); | |
23 | T_EXPECT_EQ(1, mach_task_is_self(self_name), "name port should point to self"); | |
24 | T_EXPECT_NE(1, mach_task_is_self(port), "_port_ should not point to self"); | |
25 | } |