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