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