]> git.saurik.com Git - apple/xnu.git/blob - tests/proc_info_44873309.c
xnu-6153.101.6.tar.gz
[apple/xnu.git] / tests / proc_info_44873309.c
1 #include <darwintest.h>
2 #include <mach/mach.h>
3 #include <mach/mach_types.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
7 #include <stdlib.h>
8
9 #include <stdio.h>
10 #include <assert.h>
11 #include <err.h>
12 #include <libproc.h>
13
14 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
15
16 T_DECL(proc_info_44873309, "ensure new proc_pidinfo flavor returns correct table sizes",
17 T_META_CHECK_LEAKS(false), T_META_ASROOT(true))
18 {
19 mach_port_t port;
20 int retval;
21
22 pid_t pid = getpid();
23 struct proc_ipctableinfo table_info = {};
24 retval = proc_pidinfo(pid, PROC_PIDIPCTABLEINFO, 0, (void *)&table_info, (uint32_t)sizeof(table_info));
25 T_WITH_ERRNO; T_EXPECT_GT(retval, 0, "proc_pidinfo(PROC_PIDIPCTABLEINFO) returned %d", retval);
26 T_EXPECT_EQ(retval, (int)sizeof(table_info), "proc_pidinfo(PROC_PIDIPCTABLEINFO) table_size = %u, table_free = %u",
27 table_info.table_size, table_info.table_free);
28
29 kern_return_t ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port);
30 T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE");
31
32 struct proc_ipctableinfo table_info2 = {};
33 retval = proc_pidinfo(pid, PROC_PIDIPCTABLEINFO, 0, (void *)&table_info2, (uint32_t)sizeof(table_info2));
34 T_WITH_ERRNO; T_EXPECT_GT(retval, 0, "proc_pidinfo(PROC_PIDIPCTABLEINFO) returned %d", retval);
35 T_EXPECT_EQ(retval, (int)sizeof(table_info2), "proc_pidinfo(PROC_PIDIPCTABLEINFO) table_size2 = %u, table_free2 = %u",
36 table_info2.table_size, table_info2.table_free);
37
38 T_EXPECT_EQ(table_info.table_free, table_info2.table_free + 1, "Comparing the table_free values");
39 }